def filter_records(self, records): for record in records: a = record.annotations clip_right = a['clip_flow_right'] flows = a['flow_values'] flows = [float(i) / 100.0 for i in flows] trim_flows = flows[:clip_right] trim_flows = self.filter_record(trim_flows) trimmed_reading = sff.flow_to_seq(trim_flows) m = self.primer_re.match(trimmed_reading) if (self.min_flows is None or len(trim_flows) >= self.min_flows) and m: sequence = m.group(1) # Truncate the flow result to a maximum length # Note that the FASTA result is unchanged flow_result = trim_flows[:self.max_flows] # AmpliconNoise reports flowgram lengths to the nearest power of 4 trim_len = int(math.ceil(len(flow_result) / 4.0)) * 4 self.passed += 1 yield (record.id, sequence, trim_len, flows[:self.max_flows]) else: self.failed += 1
def __iter__(self): while True: header = next(self._fp)[1:] split_line = next(self._fp).split() flow_length = int(split_line[0]) flows = split_line[1:] flows = map(float, flows) bases = sff.flow_to_seq(flows) sequence = Seq(bases, generic_dna) record = SeqRecord(sequence, id=header) # Add flows and clip as annotations record.annotations["flow_values"] = [int(i * 100) for i in flows] record.annotations["clip_flow_right"] = flow_length yield record
def __iter__(self): while True: header = next(self._fp)[1:] split_line = next(self._fp).split() flow_length = int(split_line[0]) flows = split_line[1:] flows = map(float, flows) bases = sff.flow_to_seq(flows) sequence = Seq(bases, generic_dna) record = SeqRecord(sequence, id=header) # Add flows and clip as annotations record.annotations['flow_values'] = [int(i * 100) for i in flows] record.annotations['clip_flow_right'] = flow_length yield record
def setUp(self): flows = (101, 1, 99, 2, 0, 103, 2, 100, 0, 111, 110, 1, 3, 108, 0, 2, 107, 0, 0, 103, 101, 1, 13, 102, 0, 8, 204, 12, 0, 105, 1, 290, 2, 92, 7, 98, 9, 6, 98, 4, 101, 10, 0, 199, 5, 299, 3, 101, 4, 99) bases = sff.flow_to_seq(flows) sequence = Seq(bases, generic_dna) self.record = SeqRecord(sequence, id='FTWCYXX01BTPDQ') self.record.annotations['clip_qual_right'] = 14 self.record.annotations['clip_qual_left'] = 4 self.record.annotations['flow_values'] = flows self.record.annotations['flow_index'] = (1, 2, 3, 2, 2, 1, 3, 3, 3, 1, 3, 3, 0, 3, 2, 0, 0, 2, 2, 3, 2, 3, 0, 2, 0, 0, 2, 2, 3, 0, 2, 1, 3, 3, 0, 3, 0, 1, 0, 3, 2, 0, 2, 3, 0, 3, 0, 2, 0, 0)
def test_flow_to_seq_int(self): actual = sff.flow_to_seq(self.test_flow_int) self.assertEqual(self.test_expected, actual)