def _extend_with_reads_as_single_end(self, reads1, reads2): left_seqs, right_seqs = self._extensions_from_reads_file(reads1) left_seqs2, right_seqs2 = self._extensions_from_reads_file(reads2) left_kmers = kmers.Kmers(verbose=self.verbose, left=True) right_kmers = kmers.Kmers(verbose=self.verbose, left=False) left_kmers.extend(left_seqs) left_kmers.extend(left_seqs2) right_kmers.extend(right_seqs) right_kmers.extend(right_seqs2) left_extension = left_kmers.extension(self.ext_min_cov, self.ext_min_ratio, self.extend_length) right_extension = right_kmers.extension(self.ext_min_cov, self.ext_min_ratio, self.extend_length) self.seed_lengths.append( (len(self.seq), len(left_extension), len(right_extension))) if self.verbose >= 2: print(' Extend seed. new length=', len(self.seq), '. Bases added left:', len(left_extension), '. Bases added right:', len(right_extension), sep='') self.seq = left_extension + self.seq + right_extension if self.verbose >= 2: print(' new seed:', self.seq)
def extend(self, min_cov, min_ratio, extend_bases): if self.verbose >= 2: print(' trying to extend left end ...') new_left_seq = self.left_kmers.extension(min_cov, min_ratio, extend_bases) if self.verbose >= 2: print(' trying to extend right end ...') new_right_seq = self.right_kmers.extension(min_cov, min_ratio, extend_bases) if self.verbose >= 1: print(' new left sequence:', new_left_seq) print(' new right sequence:', new_right_seq) self.fa.seq = new_left_seq + self.fa.seq + new_right_seq self.left_kmers = kmers.Kmers(left=True, verbose=self.verbose) self.right_kmers = kmers.Kmers(verbose=self.verbose) return len(new_left_seq), len(new_right_seq)
def test_append(self): '''Test append''' k = kmers.Kmers(kmer='A') k.append('G') self.assertListEqual(['A', 'G'], k.kmers) k.append('N') self.assertListEqual(['A', 'G'], k.kmers)
def test_extension(self): '''Test extension''' k = kmers.Kmers(kmer='AT', left=True) self.assertEqual(k.extension(1, 2, 100), 'AT') k.extend(['GGT'] * 5) self.assertEqual(k.extension(5, 2, 100), 'GGT') self.assertEqual(k.extension(5, 2, 2), 'GT') k = kmers.Kmers() self.assertEqual(k.extension(5, 2, 100), '') k.extend(['ACG'] * 5) self.assertEqual(k.extension(5, 2, 100), 'ACG') self.assertEqual(k.extension(6, 2, 100), '') self.assertEqual(k.extension(5, 2, 2), 'AC') self.assertEqual(k.extension(5, 2, 1), 'A') k.extend(['ACC'] * 2) self.assertEqual(k.extension(5, 2, 100), 'ACG') self.assertEqual(k.extension(5, 3, 100), 'AC')
def test_kmer_dict(self): '''Test kmer_dict''' k = kmers.Kmers(kmer='A') k.extend(['A', 'C', 'GT', 'GC', 'ACT']) expected = [{ 'A': 3, 'C': 1, 'G': 2 }, { 'GT': 1, 'GC': 1, 'AC': 1 }, { 'ACT': 1 }] for i in range(3): d = k._kmer_dict(i + 1) self.assertDictEqual(d, expected[i])
def test_commonest_kmers(self): k = kmers.Kmers(kmer='AC') k.extend(['AT'] * 4) k.append('ATT') commonest_kmers, counts = k._commonest_kmers(1) self.assertEqual(commonest_kmers, (None, 'A')) self.assertEqual(counts, (None, 6)) commonest_kmers, counts = k._commonest_kmers(2) self.assertEqual(commonest_kmers, ('AC', 'AT')) self.assertEqual(counts, (1, 5)) commonest_kmers, counts = k._commonest_kmers(3) self.assertEqual(commonest_kmers, (None, 'ATT')) self.assertEqual(counts, (None, 1)) commonest_kmers, counts = k._commonest_kmers(4) self.assertEqual(commonest_kmers, (None, None)) self.assertEqual(counts, (None, None))
def __init__(self, fasta, verbose=0): self.fa = fasta self.verbose = verbose self.left_kmers = kmers.Kmers(left=True, verbose=verbose) self.right_kmers = kmers.Kmers(verbose=verbose)
def test_init(self): '''Test __init__''' k = kmers.Kmers(kmer='ACGGT') self.assertListEqual(['ACGGT'], k.kmers) k = kmers.Kmers(kmer='ACGGT', left=True) self.assertListEqual(['TGGCA'], k.kmers)
def test_extend(self): '''Test extend''' k = kmers.Kmers(kmer='A') k.extend(['A', 'C']) self.assertListEqual(['A', 'A', 'C'], k.kmers)