Mercurial > repos > iuc > extract_genomic_dna
annotate extract_genomic_dna.py @ 5:c8467246b57e draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit 19ea4feff5ccf3744c549b9a67259947a1cb90ba
author | iuc |
---|---|
date | Sat, 21 Jan 2017 14:41:27 -0500 |
parents | b71579ad576c |
children | 3088e7e70888 |
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 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
|
6 import bx.seq.twobit |
3
b71579ad576c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit bd4fbe120288bf8452e479cbd82aa1bbf5c4bd31
iuc
parents:
2
diff
changeset
|
7 from bx.intervals.io import Comment, Header |
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
|
8 |
5
c8467246b57e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit 19ea4feff5ccf3744c549b9a67259947a1cb90ba
iuc
parents:
3
diff
changeset
|
9 import extract_genomic_dna_utils as egdu # noqa: I100 |
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
|
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") |
2
702970e4a134
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit 9192c1e90e2fd5017e6044884bcc6f2e80ba8b31
iuc
parents:
0
diff
changeset
|
20 parser.add_argument('--fasta_header_type', dest='fasta_header_type', default=None, help="Fasta header format") |
702970e4a134
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit 9192c1e90e2fd5017e6044884bcc6f2e80ba8b31
iuc
parents:
0
diff
changeset
|
21 parser.add_argument('--fasta_header_delimiter', dest='fasta_header_delimiter', default=None, help="Fasta header field delimiter") |
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
|
22 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
|
23 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
|
24 |
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 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
|
26 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
|
27 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
|
28 # 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
|
29 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
|
30 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
|
31 # 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
|
32 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
|
33 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
|
34 |
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 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 |
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 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
|
42 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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 |
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 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
|
57 # 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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 # 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
|
64 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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 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
|
70 # 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 # 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
|
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 sequence = nib.get(start, end - start) |
3
b71579ad576c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit bd4fbe120288bf8452e479cbd82aa1bbf5c4bd31
iuc
parents:
2
diff
changeset
|
113 except Exception as e: |
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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 # 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
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 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
|
156 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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 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
|
162 start, end = egdu.convert_bed_coords_to_gff([start, end]) |
2
702970e4a134
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit 9192c1e90e2fd5017e6044884bcc6f2e80ba8b31
iuc
parents:
0
diff
changeset
|
163 if args.fasta_header_type == "bedtools_getfasta_default": |
702970e4a134
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit 9192c1e90e2fd5017e6044884bcc6f2e80ba8b31
iuc
parents:
0
diff
changeset
|
164 out.write(">%s\n" % egdu.get_bedtools_getfasta_default_header(str(chrom), |
702970e4a134
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit 9192c1e90e2fd5017e6044884bcc6f2e80ba8b31
iuc
parents:
0
diff
changeset
|
165 str(start), |
702970e4a134
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit 9192c1e90e2fd5017e6044884bcc6f2e80ba8b31
iuc
parents:
0
diff
changeset
|
166 str(end), |
702970e4a134
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit 9192c1e90e2fd5017e6044884bcc6f2e80ba8b31
iuc
parents:
0
diff
changeset
|
167 strand, |
702970e4a134
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit 9192c1e90e2fd5017e6044884bcc6f2e80ba8b31
iuc
parents:
0
diff
changeset
|
168 includes_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
|
169 else: |
2
702970e4a134
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit 9192c1e90e2fd5017e6044884bcc6f2e80ba8b31
iuc
parents:
0
diff
changeset
|
170 # args.fasta_header_type == "char_delimited": |
702970e4a134
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit 9192c1e90e2fd5017e6044884bcc6f2e80ba8b31
iuc
parents:
0
diff
changeset
|
171 fields = [args.genome, str(chrom), str(start), str(end), strand] |
702970e4a134
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit 9192c1e90e2fd5017e6044884bcc6f2e80ba8b31
iuc
parents:
0
diff
changeset
|
172 field_delimiter = egdu.get_fasta_header_delimiter(args.fasta_header_delimiter) |
702970e4a134
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit 9192c1e90e2fd5017e6044884bcc6f2e80ba8b31
iuc
parents:
0
diff
changeset
|
173 meta_data = field_delimiter.join(fields) |
702970e4a134
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit 9192c1e90e2fd5017e6044884bcc6f2e80ba8b31
iuc
parents:
0
diff
changeset
|
174 if name.strip(): |
702970e4a134
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit 9192c1e90e2fd5017e6044884bcc6f2e80ba8b31
iuc
parents:
0
diff
changeset
|
175 out.write(">%s %s\n" % (meta_data, name)) |
702970e4a134
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit 9192c1e90e2fd5017e6044884bcc6f2e80ba8b31
iuc
parents:
0
diff
changeset
|
176 else: |
702970e4a134
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit 9192c1e90e2fd5017e6044884bcc6f2e80ba8b31
iuc
parents:
0
diff
changeset
|
177 out.write(">%s\n" % meta_data) |
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
|
178 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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 # 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
|
184 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
|
185 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
|
186 "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
|
187 "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
|
188 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
|
189 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
|
190 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
|
191 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
|
192 ".", |
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 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
|
194 else: |
2
702970e4a134
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit 9192c1e90e2fd5017e6044884bcc6f2e80ba8b31
iuc
parents:
0
diff
changeset
|
195 # Here fields was set up around line 73. |
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
|
196 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
|
197 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
|
198 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
|
199 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
|
200 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
|
201 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
|
202 # 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 |
8dd8e89c0603
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff
changeset
|
209 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
|
210 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
|
211 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
|
212 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
|
213 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
|
214 # 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
|
215 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
|
216 |
8dd8e89c0603
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff
changeset
|
217 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
|
218 os.remove(seq_path) |