def test_mutate_insert(self): self.assertEqual('99012345', str(Component('012345').mutate([INS(0, '99')]).seq)) self.assertEqual('09912345', str(Component('012345').mutate([INS(1, '99')]).seq)) self.assertEqual( '9912345', str(Component('012345').mutate([INS(0, '99', replace=True)]).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_from_mutations_simple(self): tt = MutableTranslationTable.from_mutations( 'ABCDEFGHI', (DEL(1, 2), INS(7, 'insert'))) self.assertEqual([0, None, None, 1, 2, 9, 10, 11, 12], list(tt)) self.assertEqual( [0, 3, 4, None, None, None, None, None, None, 5, 6, 7, 8], list(~tt))
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_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_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)))
from co.converters import GenbankConverter from co.mutation import DEL, INS component = GenbankConverter.from_file('NC_000913_3.gb') updated_component = component.mutate([ DEL(2173363 - 1, 2), INS(3560456 - 1, 'G'), INS(4296381 - 1, 'CG') ]) GenbankConverter.to_file(updated_component, 'bop27.gb')