comparison genetrack_util.py @ 4:b41a4bb828a3 draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genetrack commit 2772547f531819d3f6d892ed041fa39b82e3550f
author iuc
date Wed, 05 Jul 2017 11:56:54 -0400
parents 41887967ef14
children
comparison
equal deleted inserted replaced
3:41887967ef14 4:b41a4bb828a3
4 import subprocess 4 import subprocess
5 import sys 5 import sys
6 import tempfile 6 import tempfile
7 7
8 import numpy 8 import numpy
9 from six import Iterator
9 10
10 GFF_EXT = 'gff' 11 GFF_EXT = 'gff'
11 SCIDX_EXT = 'scidx' 12 SCIDX_EXT = 'scidx'
12 13
13 14
39 for fn in conversion_functions(in_fmt, out_fmt): 40 for fn in conversion_functions(in_fmt, out_fmt):
40 data = fn(data) 41 data = fn(data)
41 return data 42 return data
42 43
43 44
44 class ChromosomeManager(object): 45 class ChromosomeManager(Iterator):
45 """ 46 """
46 Manages a CSV reader of an index file to only load one chrom at a time 47 Manages a CSV reader of an index file to only load one chrom at a time
47 """ 48 """
48 49
49 def __init__(self, reader): 50 def __init__(self, reader):
51 self.reader = reader 52 self.reader = reader
52 self.processed_chromosomes = [] 53 self.processed_chromosomes = []
53 self.current_index = 0 54 self.current_index = 0
54 self.next_valid() 55 self.next_valid()
55 56
56 def next(self): 57 def __next__(self):
57 self.line = self.reader.next() 58 self.line = next(self.reader)
58 59
59 def is_valid(self, line): 60 def is_valid(self, line):
60 if len(line) not in [4, 5, 9]: 61 if len(line) not in [4, 5, 9]:
61 return False 62 return False
62 try: 63 try:
75 76
76 def next_valid(self): 77 def next_valid(self):
77 """ 78 """
78 Advance to the next valid line in the reader 79 Advance to the next valid line in the reader
79 """ 80 """
80 self.line = self.reader.next() 81 self.line = next(self.reader)
81 s = 0 82 s = 0
82 while not self.is_valid(self.line): 83 while not self.is_valid(self.line):
83 self.line = self.reader.next() 84 self.line = next(self.reader)
84 s += 1 85 s += 1
85 if s > 0: 86 if s > 0:
86 # Skip initial line(s) of file 87 # Skip initial line(s) of file
87 pass 88 pass
88 89
113 msg = 'Reads in chromosome %s are not sorted by index. (At index %d)' % (cname, self.current_index) 114 msg = 'Reads in chromosome %s are not sorted by index. (At index %d)' % (cname, self.current_index)
114 stop_err(msg) 115 stop_err(msg)
115 self.current_index = read[0] 116 self.current_index = read[0]
116 self.add_read(read) 117 self.add_read(read)
117 try: 118 try:
118 self.next() 119 next(self)
119 except StopIteration: 120 except StopIteration:
120 self.done = True 121 self.done = True
121 break 122 break
122 self.processed_chromosomes.append(cname) 123 self.processed_chromosomes.append(cname)
123 self.current_index = 0 124 self.current_index = 0
269 270
270 def normal_func(x): 271 def normal_func(x):
271 return math.exp(-x * x / (2 * sigma2)) 272 return math.exp(-x * x / (2 * sigma2))
272 273
273 # width is the half of the distribution 274 # width is the half of the distribution
274 values = map(normal_func, range(-width, width)) 275 values = list(map(normal_func, range(-width, width)))
275 values = numpy.array(values, numpy.float) 276 values = numpy.array(values, numpy.float)
276 # normalization 277 # normalization
277 if normalize: 278 if normalize:
278 values = 1.0 / math.sqrt(2 * numpy.pi * sigma2) * values 279 values = 1.0 / math.sqrt(2 * numpy.pi * sigma2) * values
279 return values 280 return values