def test_score_threshold(self): # Upper bound (lower=True)) stream = fstream([(1,0.91),(2,0.45),(3,0.01)], fields=['start','score']) res = list(score_threshold(stream,threshold=0.05,fields='score',lower=False)) expected = [(1,0.91),(2,0.45)] self.assertListEqual(res,expected) # Lower bound (lower=False) stream = fstream([(1,0.91),(2,0.45),(3,0.01)], fields=['start','score']) res = list(score_threshold(stream,threshold=0.05,fields='score',lower=True)) expected = [(3,0.01)] self.assertListEqual(res,expected)
def __call__(self, **kw): func = kw.get('function', "log2") l_track = kw.get('SigMulti', {}).get('track', []) if not isinstance(l_track, list): l_track = [l_track] outall = [] for tname in l_track: tinput = track(tname) if 'score' not in tinput.fields: continue format = kw.get('format', tinput.format) out_name = tinput.name + '_' + func + '.' + format outtemp = self.temporary_path(out_name) out_track = track(outtemp, chrmeta=tinput.chrmeta) filtered = score_threshold(tinput, strict=(func[:3] == "log")) out_track.write(apply(filtered, 'score', eval(func)), mode='write') out_track.close() outall.append(outtemp) tinput.close() if len(outall) == 1: self.new_file(outall[0], 'converted_track') elif len(outall) > 1: tar_name = self.temporary_path(fname="numeric_operation_out.tgz") tar = tarfile.open(tar_name, "w:gz") [tar.add(f, arcname=os.path.basename(f)) for f in outall] tar.close() self.new_file(tar_name, 'converted_track_tar') return self.display_time()
def __call__(self, **kw): func = kw.get('function',"log2") #l_track = kw.get('SigMulti', {}).get('track',[]) l_track = kw.get('track',[]) if not isinstance(l_track, list): l_track = [l_track] outall = [] for tname in l_track : tinput = track(tname) if 'score' not in tinput.fields: continue format = kw.get('output',tinput.format) out_name = tinput.name+'_'+func+'.'+format outtemp = self.temporary_path(out_name) out_track = track(outtemp,chrmeta=tinput.chrmeta) filtered = score_threshold(tinput, strict=(func[:3] == "log")) out_track.write(apply(filtered,'score',eval(func)), mode='write') out_track.close() outall.append(outtemp) tinput.close() if len(outall) == 1: self.new_file(outall[0], 'converted_track') elif len(outall) > 1: tar_name = self.temporary_path(fname="numeric_operation_out.tgz") tar = tarfile.open(tar_name, "w:gz") [tar.add(f,arcname=os.path.basename(f)) for f in outall] tar.close() self.new_file(tar_name, 'converted_track_tar') return self.display_time()
def test_score_threshold(self): # Upper bound (lower=True)) stream = fstream([(1, 0.91), (2, 0.45), (3, 0.01)], fields=['start', 'score']) res = list( score_threshold(stream, threshold=0.05, fields='score', lower=False)) expected = [(1, 0.91), (2, 0.45)] self.assertListEqual(res, expected) # Lower bound (lower=False) stream = fstream([(1, 0.91), (2, 0.45), (3, 0.01)], fields=['start', 'score']) res = list( score_threshold(stream, threshold=0.05, fields='score', lower=True)) expected = [(3, 0.01)] self.assertListEqual(res, expected)