comparison extract_genomic_dna_utils.py @ 7:3088e7e70888 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/extract_genomic_dna commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
author iuc
date Mon, 23 Oct 2017 13:26:18 -0400
parents b71579ad576c
children
comparison
equal deleted inserted replaced
6:53db9cb721f1 7:3088e7e70888
4 import sys 4 import sys
5 import tempfile 5 import tempfile
6 6
7 from bx.intervals.io import Comment, GenomicInterval, Header 7 from bx.intervals.io import Comment, GenomicInterval, Header
8 from bx.intervals.io import GenomicIntervalReader, NiceReaderWrapper, ParseError 8 from bx.intervals.io import GenomicIntervalReader, NiceReaderWrapper, ParseError
9 from six import Iterator
9 10
10 # Default chrom, start, end, strand cols for a bed file 11 # Default chrom, start, end, strand cols for a bed file
11 BED_DEFAULT_COLS = 0, 1, 2, 5 12 BED_DEFAULT_COLS = 0, 1, 2, 5
12 13
13 14
97 for interval in self.intervals: 98 for interval in self.intervals:
98 lines.append('\t'.join(interval.fields)) 99 lines.append('\t'.join(interval.fields))
99 return lines 100 return lines
100 101
101 102
102 class GFFReaderWrapper(NiceReaderWrapper): 103 class GFFReaderWrapper(Iterator, NiceReaderWrapper):
103 """ 104 """
104 Reader wrapper for GFF files which has two major functions: 105 Reader wrapper for GFF files which has two major functions:
105 1. group entries for GFF file (via group column), GFF3 (via id attribute), 106 1. group entries for GFF file (via group column), GFF3 (via id attribute),
106 or GTF (via gene_id/transcript id); 107 or GTF (via gene_id/transcript id);
107 2. convert coordinates from GFF format--starting and ending coordinates 108 2. convert coordinates from GFF format--starting and ending coordinates
126 interval = GFFInterval(self, line.split("\t"), self.chrom_col, self.feature_col, self.start_col, 127 interval = GFFInterval(self, line.split("\t"), self.chrom_col, self.feature_col, self.start_col,
127 self.end_col, self.strand_col, self.score_col, self.default_strand, 128 self.end_col, self.strand_col, self.score_col, self.default_strand,
128 fix_strand=self.fix_strand) 129 fix_strand=self.fix_strand)
129 return interval 130 return interval
130 131
131 def next(self): 132 def __next__(self):
132 """ 133 """
133 Returns next GFFFeature. 134 Returns next GFFFeature.
134 """ 135 """
135 136
136 def handle_parse_error(parse_error): 137 def handle_parse_error(e):
137 """ 138 """
138 Actions to take when ParseError found. 139 Actions to take when ParseError found.
139 """ 140 """
140 if self.outstream: 141 if self.outstream:
141 if self.print_delegate and hasattr(self.print_delegate, "__call__"): 142 if self.print_delegate and hasattr(self.print_delegate, "__call__"):
365 if cols: 366 if cols:
366 # Handle case where no strand column included - in this case, cols 367 # Handle case where no strand column included - in this case, cols
367 # looks something like 1,2,3, 368 # looks something like 1,2,3,
368 if cols.endswith(','): 369 if cols.endswith(','):
369 cols += '0' 370 cols += '0'
370 col_list = map(lambda x: int(x) - 1, cols.split(",")) 371 col_list = [int(x) - 1 for x in cols.split(",")]
371 return col_list 372 return col_list
372 else: 373 else:
373 return BED_DEFAULT_COLS 374 return BED_DEFAULT_COLS
374 375
375 376