annotate extract_genomic_dna.py @ 0:8dd8e89c0603 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
author iuc
date Tue, 19 Jan 2016 09:34:23 -0500
parents
children 702970e4a134
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
1 #!/usr/bin/env python
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
2 import argparse
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
3 import os
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
4
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
5 import extract_genomic_dna_utils as egdu
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
6 import bx.seq.nib
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
7 import bx.seq.twobit
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
8 from bx.intervals.io import Header, Comment
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
9
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
10
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
11 parser = argparse.ArgumentParser()
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
12 parser.add_argument('--input_format', dest='input_format', help="Input dataset format")
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
13 parser.add_argument('--input', dest='input', help="Input dataset")
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
14 parser.add_argument('--genome', dest='genome', help="Input dataset genome build")
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
15 parser.add_argument('--interpret_features', dest='interpret_features', default=None, help="Interpret features if input format is gff")
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
16 parser.add_argument('--columns', dest='columns', help="Columns to use in input file")
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
17 parser.add_argument('--reference_genome_source', dest='reference_genome_source', help="Source of reference genome file")
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
18 parser.add_argument('--reference_genome', dest='reference_genome', help="Reference genome file")
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
19 parser.add_argument('--output_format', dest='output_format', help="Output format")
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
20 parser.add_argument('--output', dest='output', help="Output dataset")
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
21 args = parser.parse_args()
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
22
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
23 input_is_gff = args.input_format == 'gff'
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
24 interpret_features = input_is_gff and args.interpret_features == "yes"
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
25 if len(args.columns.split(',')) == 5:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
26 # Bed file.
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
27 chrom_col, start_col, end_col, strand_col, name_col = egdu.parse_cols_arg(args.columns)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
28 else:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
29 # Gff file.
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
30 chrom_col, start_col, end_col, strand_col = egdu.parse_cols_arg(args.columns)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
31 name_col = False
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
32
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
33 if args.reference_genome_source == "history":
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
34 seq_path = egdu.convert_to_twobit(args.reference_genome)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
35 else:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
36 seq_path = args.reference_genome
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
37 seq_dir = os.path.split(seq_path)[0]
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
38
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
39 includes_strand_col = strand_col >= 0
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
40 strand = None
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
41 nibs = {}
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
42 skipped_lines = 0
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
43 first_invalid_line = 0
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
44 invalid_lines = []
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
45 warnings = []
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
46 warning = ''
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
47 twobitfile = None
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
48 line_count = 1
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
49 file_iterator = open(args.input)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
50 if interpret_features:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
51 file_iterator = egdu.GFFReaderWrapper(file_iterator, fix_strand=False)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
52 out = open(args.output, 'wt')
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
53
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
54 for feature in file_iterator:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
55 # Ignore comments, headers.
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
56 if isinstance(feature, (Header, Comment)):
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
57 line_count += 1
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
58 continue
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
59 name = ""
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
60 if interpret_features:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
61 # Processing features.
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
62 egdu.convert_gff_coords_to_bed(feature)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
63 chrom = feature.chrom
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
64 start = feature.start
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
65 end = feature.end
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
66 strand = feature.strand
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
67 else:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
68 # Processing lines, either interval or GFF format.
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
69 line = feature.rstrip('\r\n')
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
70 if line and not line.startswith("#"):
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
71 fields = line.split('\t')
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
72 try:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
73 chrom = fields[chrom_col]
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
74 start = int(fields[start_col])
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
75 end = int(fields[end_col])
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
76 if name_col:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
77 name = fields[name_col]
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
78 if input_is_gff:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
79 start, end = egdu.convert_gff_coords_to_bed([start, end])
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
80 if includes_strand_col:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
81 strand = fields[strand_col]
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
82 except:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
83 warning = "Invalid chrom, start or end column values. "
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
84 warnings.append(warning)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
85 if not invalid_lines:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
86 invalid_lines = egdu.get_lines(feature)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
87 first_invalid_line = line_count
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
88 skipped_lines += len(invalid_lines)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
89 continue
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
90 if start > end:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
91 warning = "Invalid interval, start '%d' > end '%d'. " % (start, end)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
92 warnings.append(warning)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
93 if not invalid_lines:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
94 invalid_lines = egdu.get_lines(feature)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
95 first_invalid_line = line_count
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
96 skipped_lines += len(invalid_lines)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
97 continue
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
98 if strand not in ['+', '-']:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
99 strand = '+'
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
100 sequence = ''
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
101 else:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
102 continue
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
103 # Open sequence file and get sequence for feature/interval.
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
104 if os.path.exists("%s/%s.nib" % (seq_dir, chrom)):
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
105 if chrom in nibs:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
106 nib = nibs[chrom]
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
107 else:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
108 nibs[chrom] = nib = bx.seq.nib.NibFile(open("%s/%s.nib" % (seq_path, chrom)))
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
109 try:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
110 sequence = nib.get(start, end - start)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
111 except Exception, e:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
112 warning = "Unable to fetch the sequence from '%d' to '%d' for build '%s'. " % (start, end - start, args.genome)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
113 warnings.append(warning)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
114 if not invalid_lines:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
115 invalid_lines = egdu.get_lines(feature)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
116 first_invalid_line = line_count
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
117 skipped_lines += len(invalid_lines)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
118 continue
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
119 elif os.path.isfile(seq_path):
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
120 if not(twobitfile):
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
121 twobitfile = bx.seq.twobit.TwoBitFile(open(seq_path))
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
122 try:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
123 if interpret_features:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
124 # Create sequence from intervals within a feature.
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
125 sequence = ''
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
126 for interval in feature.intervals:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
127 sequence += twobitfile[interval.chrom][interval.start:interval.end]
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
128 else:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
129 sequence = twobitfile[chrom][start:end]
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
130 except:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
131 warning = "Unable to fetch the sequence from '%d' to '%d' for chrom '%s'. " % (start, end - start, chrom)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
132 warnings.append(warning)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
133 if not invalid_lines:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
134 invalid_lines = egdu.get_lines(feature)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
135 first_invalid_line = line_count
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
136 skipped_lines += len(invalid_lines)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
137 continue
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
138 else:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
139 warning = "Chromosome by name '%s' was not found for build '%s'. " % (chrom, args.genome)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
140 warnings.append(warning)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
141 if not invalid_lines:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
142 invalid_lines = egdu.get_lines(feature)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
143 first_invalid_line = line_count
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
144 skipped_lines += len(invalid_lines)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
145 continue
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
146 if sequence == '':
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
147 warning = "Chrom: '%s', start: '%d', end: '%d' is either invalid or not present in build '%s'. " % (chrom, start, end, args.genome)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
148 warnings.append(warning)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
149 if not invalid_lines:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
150 invalid_lines = egdu.get_lines(feature)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
151 first_invalid_line = line_count
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
152 skipped_lines += len(invalid_lines)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
153 continue
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
154 if includes_strand_col and strand == "-":
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
155 sequence = egdu.reverse_complement(sequence)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
156 if args.output_format == "fasta":
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
157 l = len(sequence)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
158 c = 0
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
159 if input_is_gff:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
160 start, end = egdu.convert_bed_coords_to_gff([start, end])
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
161 fields = [args.genome, str(chrom), str(start), str(end), strand]
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
162 meta_data = "_".join(fields)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
163 if name.strip():
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
164 out.write(">%s %s\n" % (meta_data, name))
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
165 else:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
166 out.write(">%s\n" % meta_data)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
167 while c < l:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
168 b = min(c + 50, l)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
169 out.write("%s\n" % str(sequence[c:b]))
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
170 c = b
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
171 else:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
172 # output_format == "interval".
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
173 if interpret_features:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
174 meta_data = "\t".join([feature.chrom,
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
175 "galaxy_extract_genomic_dna",
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
176 "interval",
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
177 str(feature.start),
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
178 str(feature.end),
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
179 feature.score,
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
180 feature.strand,
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
181 ".",
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
182 egdu.gff_attributes_to_str(feature.attributes, "GTF")])
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
183 else:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
184 # Where is fields being set here?
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
185 meta_data = "\t".join(fields)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
186 if input_is_gff:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
187 format_str = "%s seq \"%s\";\n"
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
188 else:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
189 format_str = "%s\t%s\n"
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
190 out.write(format_str % (meta_data, str(sequence)))
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
191 # Update line count.
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
192 if isinstance(feature, egdu.GFFFeature):
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
193 line_count += len(feature.intervals)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
194 else:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
195 line_count += 1
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
196 out.close()
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
197
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
198 if warnings:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
199 warn_msg = "%d warnings, 1st is: " % len(warnings)
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
200 warn_msg += warnings[0]
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
201 print warn_msg
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
202 if skipped_lines:
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
203 # Error message includes up to the first 10 skipped lines.
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
204 print 'Skipped %d invalid lines, 1st is #%d, "%s"' % (skipped_lines, first_invalid_line, '\n'.join(invalid_lines[:10]))
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
205
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
206 if args.reference_genome_source == "history":
8dd8e89c0603 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
207 os.remove(seq_path)