def test_inherit_feature_delete(self): orig = Component('TTACCCATT', features=[SeqFeature(FeatureLocation(0, 1), type='tt')]) f = orig.features.add(FeatureLocation(3, 6), type='ccc') self.assertEqual('CCC', str(f.seq)) mutated = orig.mutate([DEL(3, 3)]) self.assertEqual('TTAATT', str(mutated.seq)) self.assertEqual([Feature(mutated, FeatureLocation(0, 1), type='tt')], list(mutated.features))
def test_feature_non_strict_order(self): """ In non-strict mode, potentially ambiguous mutations are allowed where the order in which the order in which the mutations are applied is significant. """ component = Component('12345', feature_class=Feature) component.features.add(FeatureLocation(2, 4), type='34') # |████| |████| # 12|3 4|5 12|3 4|5 # 12|3xy4|5 12|3 -|5 # 12|3xy|-5 12|3 xy|5 mutated_1 = component.mutate([DEL(3), INS(3, 'xy')], strict=False) self.assertEqual('3xy', str(list(mutated_1.features)[0].seq)) # 3 would also be acceptable. self.assertEqual('123xy5', str(mutated_1.seq)) mutated_2 = component.mutate([INS(3, 'xy'), DEL(3)], strict=False) self.assertEqual('3xy', str(list(mutated_2.features)[0].seq)) self.assertEqual('123xy5', str(mutated_2.seq))
def test_lineage_simple(self): generation1 = Component('Ax') generation2 = generation1.mutate([INS(1, 'B')]) generation3 = generation2.mutate([INS(2, 'C')]) other = Component('a') self.assertEqual('ABx', str(generation2.seq)) self.assertEqual(False, generation1.inherits_from(generation3)) self.assertEqual(True, generation3.inherits_from(generation1)) self.assertEqual(False, generation3.inherits_from(other)) self.assertEqual([generation2, generation1], list(generation3.get_lineage()))
def test_inherit_features(self): component = Component('ABCDEFGHIerrorJKLMNOPQRSTUVXYZ') component.features.add(FeatureLocation(0, 3), id='abc') # fine component.features.add(FeatureLocation(9, 14), id='error') # fine component.features.add(FeatureLocation(6, 12), id='GHI..err') component.features.add(FeatureLocation(11, 17), id='ror..JKL') component.features.add(FeatureLocation(8, 15), id='I..error..J') # fine component.features.add(FeatureLocation(29, 30), id='end') # fine mutated = component.mutate([DEL(9, 5)]) self.assertEqual({'JKL', 'Z', 'ABC', 'GHI', 'IJ'}, set(str(f.seq) for f in mutated.features))
def test_feature_non_strict_order(self): """ In non-strict mode, potentially ambiguous mutations are allowed where the order in which the order in which the mutations are applied is significant. """ component = Component('12345', feature_class=Feature) component.features.add(FeatureLocation(2, 4), type='34') # |████| |████| # 12|3 4|5 12|3 4|5 # 12|3xy4|5 12|3 -|5 # 12|3xy|-5 12|3 xy|5 mutated_1 = component.mutate([DEL(3), INS(3, 'xy')], strict=False) self.assertEqual('3xy', str(list( mutated_1.features)[0].seq)) # 3 would also be acceptable. self.assertEqual('123xy5', str(mutated_1.seq)) mutated_2 = component.mutate([INS(3, 'xy'), DEL(3)], strict=False) self.assertEqual('3xy', str(list(mutated_2.features)[0].seq)) self.assertEqual('123xy5', str(mutated_2.seq))
def test_inherited_search(self): letters = Component('AABBDDEE', features=[ SeqFeature(FeatureLocation(0, 1), type='vowel'), SeqFeature(FeatureLocation(2, 5), type='consonant'), SeqFeature(FeatureLocation(5, 6), type='vowel')]) letters = letters.mutate([INS(4, 'CC')]) self.assertEqual('AABBCCDDEE', str(letters.seq)) self.assertEqual([Feature(letters, FeatureLocation(0, 1), type='vowel'), Feature(letters, FeatureLocation(7, 8), type='vowel')], list(letters.features.find(type='vowel'))) self.assertEqual([], list(letters.features.find(type='consonant', between_end=1)))
def test_mutate_1(self): component = Component('ABCDEFGHIJKLMNOPQRSTUVWXYZ') # . . . . . . mutated = component.mutate( # 01234567 8901234567890 12345 [SNP(3, 'd'), # ABCdEFGH IJKLMNOPQRSTU VWXYZ DEL(1), # A-CdEFGH IJKLMNOPQRSTU VWXYZ INS(21, 'xx'), # A-CdEFGH IJKLMNOPQRSTUxxVWXYZ Mutation(10, 9, 'oops'), # A-CdEFGH IJoops-----TUxxVWXYZ SUB(4, 'ef'), # A-CdefGH IJoops-----TUxxVWXYZ Mutation(7, 1, 'Hh')], # A-CdefGHhIJoops-----TUxxVWXYZ strict=False) # 0 1234567890123 457890123 # . . . . . self.assertEqual('ACdefGHhIJoopsTUxxVWXYZ', str(mutated.seq))
def test_inherit_feature_delete(self): orig = Component( 'TTACCCATT', features=[SeqFeature(FeatureLocation(0, 1), type='tt')]) f = orig.features.add(FeatureLocation(3, 6), type='ccc') self.assertEqual('CCC', str(f.seq)) mutated = orig.mutate([DEL(3, 3)]) self.assertEqual('TTAATT', str(mutated.seq)) self.assertEqual([Feature(mutated, FeatureLocation(0, 1), type='tt')], list(mutated.features))
def test_quickstart_feature_inherit(self): slogan = Component('CoPy is for DNA components', features=[ SeqFeature(FeatureLocation(0, 4), type='name'), SeqFeature(FeatureLocation(12, 15), id='DNA')]) self.assertEqual('components', str(slogan.features.add(FeatureLocation(16, 26)).seq)) self.assertEqual(['CoPy', 'DNA', 'components'], [str(f.seq) for f in slogan.features]) new_slogan = slogan.mutate([DEL(2, 2), DEL(12, 4)]) self.assertEqual('Co is for components', str(new_slogan.seq)) self.assertEqual([Feature(new_slogan, FeatureLocation(0, 2), type='name'), Feature(new_slogan, FeatureLocation(10, 20))], list(new_slogan.features)) self.assertEqual(['Co', 'components'], [str(f.seq) for f in new_slogan.features])
def test_mutate_1(self): component = Component('ABCDEFGHIJKLMNOPQRSTUVWXYZ') # . . . . . . mutated = component.mutate( # 01234567 8901234567890 12345 [ SNP(3, 'd'), # ABCdEFGH IJKLMNOPQRSTU VWXYZ DEL(1), # A-CdEFGH IJKLMNOPQRSTU VWXYZ INS(21, 'xx'), # A-CdEFGH IJKLMNOPQRSTUxxVWXYZ Mutation(10, 9, 'oops'), # A-CdEFGH IJoops-----TUxxVWXYZ SUB(4, 'ef'), # A-CdefGH IJoops-----TUxxVWXYZ Mutation(7, 1, 'Hh') ], # A-CdefGHhIJoops-----TUxxVWXYZ strict=False) # 0 1234567890123 457890123 # . . . . . self.assertEqual('ACdefGHhIJoopsTUxxVWXYZ', str(mutated.seq))
def test_quickstart_feature_inherit(self): slogan = Component('CoPy is for DNA components', features=[ SeqFeature(FeatureLocation(0, 4), type='name'), SeqFeature(FeatureLocation(12, 15), id='DNA') ]) self.assertEqual('components', str(slogan.features.add(FeatureLocation(16, 26)).seq)) self.assertEqual(['CoPy', 'DNA', 'components'], [str(f.seq) for f in slogan.features]) new_slogan = slogan.mutate([DEL(2, 2), DEL(12, 4)]) self.assertEqual('Co is for components', str(new_slogan.seq)) self.assertEqual([ Feature(new_slogan, FeatureLocation(0, 2), type='name'), Feature(new_slogan, FeatureLocation(10, 20)) ], list(new_slogan.features)) self.assertEqual(['Co', 'components'], [str(f.seq) for f in new_slogan.features])
def test_inherited_search(self): letters = Component('AABBDDEE', features=[ SeqFeature(FeatureLocation(0, 1), type='vowel'), SeqFeature(FeatureLocation(2, 5), type='consonant'), SeqFeature(FeatureLocation(5, 6), type='vowel') ]) letters = letters.mutate([INS(4, 'CC')]) self.assertEqual('AABBCCDDEE', str(letters.seq)) self.assertEqual([ Feature(letters, FeatureLocation(0, 1), type='vowel'), Feature(letters, FeatureLocation(7, 8), type='vowel') ], list(letters.features.find(type='vowel'))) self.assertEqual([], list( letters.features.find(type='consonant', between_end=1)))