Mercurial > repos > iuc > extract_genomic_dna
diff extract_genomic_dna.py @ 7:3088e7e70888 draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
author | iuc |
---|---|
date | Mon, 23 Oct 2017 13:26:18 -0400 |
parents | c8467246b57e |
children | e400dcbc60d0 |
line wrap: on
line diff
--- a/extract_genomic_dna.py Mon Jul 03 07:19:41 2017 -0400 +++ b/extract_genomic_dna.py Mon Oct 23 13:26:18 2017 -0400 @@ -1,4 +1,6 @@ #!/usr/bin/env python +from __future__ import print_function + import argparse import os @@ -81,7 +83,7 @@ start, end = egdu.convert_gff_coords_to_bed([start, end]) if includes_strand_col: strand = fields[strand_col] - except: + except Exception: warning = "Invalid chrom, start or end column values. " warnings.append(warning) if not invalid_lines: @@ -129,7 +131,7 @@ sequence += twobitfile[interval.chrom][interval.start:interval.end] else: sequence = twobitfile[chrom][start:end] - except: + except Exception: warning = "Unable to fetch the sequence from '%d' to '%d' for chrom '%s'. " % (start, end - start, chrom) warnings.append(warning) if not invalid_lines: @@ -156,8 +158,6 @@ if includes_strand_col and strand == "-": sequence = egdu.reverse_complement(sequence) if args.output_format == "fasta": - l = len(sequence) - c = 0 if input_is_gff: start, end = egdu.convert_bed_coords_to_gff([start, end]) if args.fasta_header_type == "bedtools_getfasta_default": @@ -175,8 +175,10 @@ out.write(">%s %s\n" % (meta_data, name)) else: out.write(">%s\n" % meta_data) - while c < l: - b = min(c + 50, l) + c = 0 + sequence_length = len(sequence) + while c < sequence_length: + b = min(c + 50, sequence_length) out.write("%s\n" % str(sequence[c:b])) c = b else: @@ -209,10 +211,10 @@ if warnings: warn_msg = "%d warnings, 1st is: " % len(warnings) warn_msg += warnings[0] - print warn_msg + print(warn_msg) if skipped_lines: # Error message includes up to the first 10 skipped lines. - print 'Skipped %d invalid lines, 1st is #%d, "%s"' % (skipped_lines, first_invalid_line, '\n'.join(invalid_lines[:10])) + print('Skipped %d invalid lines, 1st is #%d, "%s"' % (skipped_lines, first_invalid_line, '\n'.join(invalid_lines[:10]))) if args.reference_genome_source == "history": os.remove(seq_path)