def test_should_single_point_crossover_work_properly_case_g(self, random_call): """ Example of MSA in Ortuño's paper GKGD---PK|KP, GKGD-PK|KP => GKGD---PK-KP, GKGD-PK--KP M------QD|RV, --M--QD|RV => M------QD-RV, --M--QD--RV MKKLKKHPD|FP, MKKLKKHPD|FP => MKKLKKHPD-FP, MKKLKKHPDFP M--------|HI, ---M--H|I- => M--------HI-, ---M--H---I """ # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2', 'seq3', 'seq4'] problem.number_of_variables = 4 msa_1 = MSASolution(problem, msa=[('seq1', 'GKGD---PKKP'), ('seq2', 'M------QDRV'), ('seq3', 'MKKLKKHPDFP'), ('seq4', 'M--------HI')]) msa_2 = MSASolution(problem, msa=[('seq1', 'GKGD-PKKP'), ('seq2', '--M--QDRV'), ('seq3', 'MKKLKKHPDFP'), ('seq4', '---M--HI-')]) crossover = SPXMSA(probability=1.0, remove_gap_columns=False) # run random_call.return_value = 8 children = crossover.execute([msa_1, msa_2]) # check self.assertEqual(["GKGD---PK-KP", "M------QD-RV", "MKKLKKHPD-FP", "M--------HI-"], children[0].decode_alignment_as_list_of_sequences()) self.assertEqual(["GKGD-PK--KP", "--M--QD--RV", "MKKLKKHPDFP", "---M--H---I"], children[1].decode_alignment_as_list_of_sequences())
def test_should_create_new_gaps_group(self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1'] problem.number_of_variables = 1 msa_1 = MSASolution(problem, msa=[('seq1', 'A-')]) msa_2 = MSASolution(problem, msa=[('seq1', '-A')]) msa_3 = MSASolution(problem, msa=[('seq1', 'A-C')]) msa_4 = MSASolution(problem, msa=[('seq1', 'AAA')]) # run msa_1.add_gap_to_sequence_at_index(seq_index=0, gap_position=0) msa_2.add_gap_to_sequence_at_index(seq_index=0, gap_position=2) msa_3.add_gap_to_sequence_at_index(seq_index=0, gap_position=3) msa_4.add_gap_to_sequence_at_index(seq_index=0, gap_position=1) # check self.assertEqual([('seq1', '-A-')], msa_1.decode_alignment_as_list_of_pairs()) self.assertEqual([('seq1', '-A-')], msa_2.decode_alignment_as_list_of_pairs()) self.assertEqual([('seq1', 'A-C-')], msa_3.decode_alignment_as_list_of_pairs()) self.assertEqual([('seq1', 'A-AA')], msa_4.decode_alignment_as_list_of_pairs())
def test_should_single_point_crossover_work_properly_real_case(self): # setup problem = MSA(score_list=[]) problem.identifiers = ['a', 'b', 'c', 'd'] problem.number_of_variables = 4 msa_1 = MSASolution(problem, msa=[ ('a', '----GKGDPKKPRGKMSSYAFFVQTSREEHKKKHPDASVNFSEFSKKCSERWKTMSAKEKGKFEDMAKADKARYEREMKTYIPPK----------GE'), ('b', '-------MQDRVKRPMNAFIVWSRDQRRKMALENPRMRN--SEISKQLGYQWKMLTEAEKWPFFQEAQKLQAMHREKYPNYKYRP---RRKAKMLPK'), ('c', 'MKKLK---KHPDFPKKPLTPYFRFFMEKRAKYAKLHPEMSNLDLTKILSKKYKELPEKKKMKYIQDFQREKQEFERNLARFREDH---PDLIQNAKK'), ('d', '---------MHIKKPLNAFMLYMKEMRANVVAESTLKES--AAINQILGRRWHALSREEQAKYYELARKERQLHMQLYPGWSARDNYGKKKKRKREK') ]) msa_2 = MSASolution(problem, msa=[ ('a', '----GKGDPKKPRGKMSSYAFFVQTSREEHKKKHPDASVNFSEFSKKCSERWKTMSAKEKGKFEDMAKADKARYEREMKTYIPPK---GE-------'), ('b', '----M---QDRVKRPMNAFIVWSRDQRRKMALENPRMRN--SEISKQLGYQWKMLTEAEKWPFFQEAQKLQAMHREKYPNYKYRP---RRKAKMLPK'), ('c', 'MKKLK-KHPDFPKKPLTPYFRFFMEKRAKYAKLHPEMSN--LDLTKILSKKYKELPEKKKMKYIQDFQREKQEFERNLARFREDH---PDLIQNAKK'), ('d', '-------MH--IKKPLNAFMLYMKEMRANVVAESTLKES--AAINQILGRRWHALSREEQAKYYELARKERQLHMQLYPGWSARDNYGKKKKRKREK') ]) crossover = SPXMSA(probability=1.0, remove_gap_columns=False) # run children = crossover.cross_parents(10, [msa_1, msa_2], [10, 10, 10, 10], [10, 10, 8, 8]) # check self.assertTrue(children[0].is_valid_msa()) self.assertTrue(children[1].is_valid_msa())
def test_should_split_gap_column(self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2', 'seq3'] problem.number_of_variables = 3 msa_1 = MSASolution(problem, msa=[('seq1', '----AC'), ('seq2', 'T----C'), ('seq3', '--A-A-')]) msa_2 = MSASolution(problem, msa=[('seq1', '----AC'), ('seq2', 'T----C'), ('seq3', '--A-A-')]) msa_3 = MSASolution(problem, msa=[('seq1', '----AC'), ('seq2', 'T----C'), ('seq3', '-A----')]) # actual = [[0, 2], [1, 3], [0, 1, 3, 3, 5, 5]] msa_1.split_gap_column(1) msa_2.split_gap_column(2) # actual = [[0, 2], [1, 3], [0, 0, 2, 5]] msa_3.split_gap_column(4) # check self.assertEqual([[0, 1, 2, 3], [1, 1, 2, 4], [0, 1, 3, 3, 5, 5]], msa_1.gaps_groups) self.assertEqual([[0, 2, 3, 3], [1, 2, 3, 4], [0, 1, 3, 3, 5, 5]], msa_2.gaps_groups) self.assertEqual([[0, 3], [1, 4], [0, 0, 2, 4, 5, 5]], msa_3.gaps_groups)
def test_should_return_gap_columns(self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2', 'seq3'] problem.number_of_variables = 3 msa = MSASolution(problem, msa=[('seq1', '--AA-'), ('seq2', '--AA-'), ('seq3', '--AA-')]) # check self.assertEqual([0, 1, 4], msa.get_gap_columns_from_alignment())
def test_should_return_gaps_groups(self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2', 'seq3'] problem.number_of_variables = 3 msa = MSASolution(problem, msa=[('seq1', 'AC---TGAC'), ('seq2', 'AT--CT--C'), ('seq3', 'AAC---TGC')]) # check self.assertEqual([[2, 4], [2, 3, 6, 7], [3, 5]], msa.gaps_groups)
def test_should_return_original_alignment_size(self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2', 'seq3'] problem.number_of_variables = 3 msa = MSASolution(problem, msa=[('seq1', 'AC---TGAC'), ('seq2', 'AT--CT--C'), ('seq3', 'AAC---TGC')]) # check self.assertEqual(9, msa.get_length_of_alignment())
def test_should_return_number_of_gaps_of_one_sequences(self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2', 'seq3'] problem.number_of_variables = 3 msa = MSASolution(problem, msa=[('seq1', 'AC---TGAC'), ('seq2', 'AT--CT--C'), ('seq3', 'AAC---TGC')]) # check self.assertEqual(3, msa.get_number_of_gaps_of_sequence_at_index(0))
def test_should_return_is_gap_column(self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2', 'seq3'] problem.number_of_variables = 3 msa = MSASolution(problem, msa=[('seq1', 'AC---TGAC'), ('seq2', 'AT--CT--C'), ('seq3', 'AAC---TGC')]) # check self.assertTrue(msa.is_gap_column(3)) self.assertFalse(msa.is_gap_column(4))
def test_should_return_original_sequences(self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2', 'seq3'] problem.number_of_variables = 3 msa = MSASolution(problem, msa=[('seq1', 'AC---TGAC'), ('seq2', 'AT--CT--C'), ('seq3', 'AAC---TGC')]) # check self.assertEqual(['AC---TGAC', 'AT--CT--C', 'AAC---TGC'], msa.decode_alignment_as_list_of_sequences())
def test_should_single_point_crossover_work_properly_real_case(self, random_call): # setup problem = MSA(score_list=[]) problem.identifiers = ['1bbt_ac', '1al2_ad', '1b35_C', '1bbt_ab', '1mec_aa', '1bbt_aa', '1al2_ab', '1al2_ac'] problem.number_of_variables = 8 msa_1 = MSASolution(problem, msa=[ ('1bbt_ac', '------GIFPVACSDGYGGLVTTDPKTAD---PVYGKVFNPPRNQLPGRFTNLLDVAEACP--------TFLRFEGGVPYVTTKTDSDRVLAQFDMSL----AAKHMSNTFLAG---------------------LAQYYTQYSGT-----INLHFMFTGPTDAKA-------RYMVAY----APPGMEPPKTPEAAAH---------------CIHAEWDTGLNSKF---------TFSIPYLSAADYT----YTASDVAETTNV--------QGWVCLFQ--------ITHGKADG-------DALVVLASAGKDF-----------------------ELRLPVDARAE----'), ('1al2_ad', '-------GLPVMNTPGSNQYLTADNFQSP---CALPEFDVTPPIDIPGEVKNMMELAEIDTMIPFDL--SATKKNTMEMYRVRLSDKPHTDDPILCLSLSPASDPRLSHTMLGE---------------------ILNYYTHWAGS-----LKFTFLFCGSMMATG-------KLLVSY----APPGADPPKKRKEAML---------------GTHVIWDIGLQSSC---------TMVVPWISNTT------YRQTIDDSFTE---------GGYISVFYQTRIV---VPLSTPRE-------MDILGFVSACNDF-----------------------SVRLLRDTTHIEQKA'), ('1b35_C', 'SKPTVQGKIGECKLRGQGRMANFDGMDMSHKMALSSTNEIETNEGLAGTSLDVMDLSRVLSIPNYWDRFTWKTSDVINTVLWDNYVSPFKVKPYSATI-----TDRFRCTHMGK---------------------VANAFTYWRGS-----MVYTFKFVKTQYHSG---RLRISFIPYYYNTTISTGTPDVSRTQKI---------------------VVDLRTSTAV---------SFTVPYIGSRPWLYCIRPESSWLSKDNTDGALMYNCVSGIVRVEVLNQLVAAQNVFSEIDVICEVNGGPDLEFAGPTCPRY----------VPYAGDFTLADTRKIEAERTQEYSNNED'), ('1bbt_ab', '-------LLEDRILTTRNGHTTSTTQSS----VGVTYGYATAEDFVSGPNTSGLETRVV----------QAERFFKTHLFDWVTSDSFGRCHLLELPT---------DHKGVYGS--------------------LTDSYAYMRNG-----WDVEVTAVGNQFNGG-------CLLVAM----VPELCSIQKRELYQLT--------------LFPHQFINPRTNMTA---------HITVPFVGVNR------YDQYKVHKP-----------WTLVVMVVAPLTV---NTEGAPQI-------KVYANIAPTNVHV-----------------------AGEFPSKE-------'), ('1mec_aa', '------------------GVENAEKGVTEN--TDATADFVAQPVYLPENQTKVAFFYDRSSPIGRFAVKSGSLESGFAPFSNKACPNSVILTPGPQFDPAYDQLRPQRLTEIWGNGNEETSEVFPLKTKQDYSFCLFSPFVYYKCD-----LEVTLSPHTSGAHGL---------LVRW----CPTGTPTKPTTQVLHEVSSLSEGRT------PQVYSAGPGTSNQI---------SFVVPYNSPLSVLPAVWYNGHKRFDNTGD--------LGIAPNSDFGTLF---FAGTKPDI-------KFTVYLRYKNMRVFCPRP--TVFFPWPT----SGDKIDMTPRAGVL-----'), ('1bbt_aa', '---------------------TTSAGESADPVTTTVENYGGETQIQRRQHTDVSFI--------------------MDRFVKVTPQNQINILDLMQVP---------SHTLVGG---------------------LLRASTYYFSD-----LEIAVK------HEG---------DLTW----VPNGAPEK---------------------------ALDNTTNPTAYHKAPLT--RLALPYTAPHRVLATV-YNGECRTLPTSFN-------YGAIKATRVTELL---YRMKRAETYCP----RPLLAIHPTEARH---------------------KQKIVAP----------'), ('1al2_ab', '------AATSRDALPNTEASGPTHSKEIP---ALTAVETGATNPLVPSDTVQTRHVVQH----------RSRSESSIESFFARGACVTIMTVDNPAST-----TNKDKLFAVWKITYKDTVQLRR----------KLEFFTYSRFD-----MELTFVVTANFTETNNGHALNQVYQIMY----IPPGAPVP----EKWD-----------------DYTWQTSSNPSIFYTYGTAPARISVPYVGISN-AYSHFYDGFSKVPLKDQSAALGDSLYGAASLNDFGILAVRVVNDHNPTKVT----SKIRVYLKPKHIRVWCPRPPRAVAYYGPGVDYKDGTLTPLSTKDLTTY----'), ('1al2_ac', '----EACGYSDRVLQLTLGNSTITTQEA----ANSVVAYGRWPEYLRDSEANPVDQPTEPDV-------AACRFYTLDTVSWTKESRGWWWKLPDALRDMGLFGQNMYYHYLGRSGYTVHVQCNASKFHQGALGVFAVPEMCLAGDSNTTTMHTSYQNANPGEKGG-------TFTGTF----TPDNNQTSPARRFCPVDYLLGNGTLLGNAFVFPHQIINLRTNNCA---------TLVLPYVNSLS------IDSMVKHNN-----------WGIAILPLAPLNF---ASESSPEI-------PITLTIAPMCCEF-------------------NGLRNITLPRLQ-------'), ]) msa_2 = MSASolution(problem, msa=[ ('1bbt_ac', '------GIFPVACSDGYGGLVTTDPKTAD---PVYGKVFNPPRNQLPGRFTNLLDVAEACP--------TFLRFEGGVPYVTTKTDSDRVLAQFDMSL----AAKHMSNTFLAG---------------------LAQYYTQYSGT-----INLHFMFTGPTDAKA-------RYMVAY----APPGMEPPKTPEAAAH---------------CIHAEWDTGLNSKF---------TFSIPYLSAADYT----YTASDVAETTNV--------QGWVCLFQ--------ITHGKADG-------DALVVLASAGKDF-----------------------ELRLPVDARAE----'), ('1al2_ad', '-------GLPVMNTPGSNQYLTADNFQSP---CALPEFDVTPPIDIPGEVKNMMELAEIDTMIPFDL--SATKKNTMEMYRVRLSDKPHTDDPILCLSLSPASDPRLSHTMLGE---------------------ILNYYTHWAGS-----LKFTFLFCGSMMATG-------KLLVSY----APPGADPPKKRKEAML---------------GTHVIWDIGLQSSC---------TMVVPWISNTT------YRQTIDDSFTE---------GGYISVFYQTRIV---VPLSTPRE-------MDILGFVSACNDF-----------------------SVRLLRDTTHIEQKA'), ('1b35_C', 'SKPTVQGKIGECKLRGQGRMANFDGMDMSHKMALSSTNEIETNEGLAGTSLDVMDLSRVLSIPNYWDRFTWKTSDVINTVLWDNYVSPFKVKPYSATI-----TDRFRCTHMGK---------------------VANAFTYWRGS-----MVYTFKFVKTQYHSG---RLRISFIPYYYNTTISTGTPDVSRTQKI---------------------VVDLRTSTAV---------SFTVPYIGSRPWLYCIRPESSWLSKDNTDGALMYNCVSGIVRVEVLNQLVAAQNVFSEIDVICEVNGGPDLEFAGPTCPRY----------VPYAGDFTLADTRKIEAERTQEYSNNED'), ('1bbt_ab', '-------LLEDRILTTRNGHTTSTTQSS----VGVTYGYATAEDFVSGPNTSGLETRVV----------QAERFFKTHLFDWVTSDSFGRCHLLELPT---------DHKGVYGS--------------------LTDSYAYMRNG-----WDVEVTAVGNQFNGG-------CLLVAM----VPELCSIQKRELYQLT--------------LFPHQFINPRTNMTA---------HITVPFVGVNR------YDQYKVHKP-----------WTLVVMVVAPLTV---NTEGAPQI-------KVYANIAPTNVHV-----------------------AGEFPSKE-------'), ('1mec_aa', '------------------GVENAEKGVTEN--TDATADFVAQPVYLPENQTKVAFFYDRSSPIGRFAVKSGSLESGFAPFSNKACPNSVILTPGPQFDPAYDQLRPQRLTEIWGNGNEETSEVFPLKTKQDYSFCLFSPFVYYKCD-----LEVTLSPHTSGAHGL---------LVRW----CPTGTPTKPTTQVLHEVSSLSEGRT------PQVYSAGPGTSNQI---------SFVVPYNSPLSVLPAVWYNGHKRFDNTGD--------LGIAPNSDFGTLF---FAGTKPDI-------KFTVYLRYKNMRVFCPRP--TVFFPWPT----SGDKIDMTPRAGVL-----'), ('1bbt_aa', '---------------------TTSAGESADPVTTTVENYGGETQIQRRQHTDVSFI--------------------MDRFVKVTPQNQINILDLMQVP---------SHTLVGG---------------------LLRASTYYFSD-----LEIAVK------HEG---------DLTW----VPNGAPEK---------------------------ALDNTTNPTAYHKAPLT--RLALPYTAPHRVLATV-YNGECRTLPTSFN-------YGAIKATRVTELL---YRMKRAETYCP----RPLLAIHPTEARH---------------------KQKIVAP----------'), ('1al2_ab', '------AATSRDALPNTEASGPTHSKEIP---ALTAVETGATNPLVPSDTVQTRHVVQH----------RSRSESSIESFFARGACVTIMTVDNPAST-----TNKDKLFAVWKITYKDTVQLRR----------KLEFFTYSRFD-----MELTFVVTANFTETNNGHALNQVYQIMY----IPPGAPVP----EKWD-----------------DYTWQTSSNPSIFYTYGTAPARISVPYVGISN-AYSHFYDGFSKVPLKDQSAALGDSLYGAASLNDFGILAVRVVNDHNPTKVT----SKIRVYLKPKHIRVWCPRPPRAVAYYGPGVDYKDGTLTPLSTKDLTTY----'), ('1al2_ac', '----EACGYSDRVLQLTLGNSTITTQEA----ANSVVAYGRWPEYLRDSEANPVDQPTEPDV-------AACRFYTLDTVSWTKESRGWWWKLPDALRDMGLFGQNMYYHYLGRSGYTVHVQCNASKFHQGALGVFAVPEMCLAGDSNTTTMHTSYQNANPGEKGG-------TFTGTF----TPDNNQTSPARRFCPVDYLLGNGTLLGNAFVFPHQIINLRTNNCA---------TLVLPYVNSLS------IDSMVKHNN-----------WGIAILPLAPLNF---ASESSPEI-------PITLTIAPMCCEF-------------------NGLRNITLPRLQ-------'), ]) crossover = SPXMSA(probability=1.0, remove_gap_columns=False) # run random_call.return_value = 176 children = crossover.execute([msa_1, msa_2]) # check self.assertTrue(children[0].is_valid_msa()) self.assertTrue(children[1].is_valid_msa())
def test_should_remove_all_gap_columns_case_d(self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2'] problem.number_of_variables = 2 msa = MSASolution(problem, msa=[('seq1', 'AB--CDE-'), ('seq2', 'AB--CD-E')]) msa.remove_full_of_gaps_columns() # check self.assertEqual(['ABCDE-', 'ABCD-E'], msa.decode_alignment_as_list_of_sequences())
def test_should_return_length_of_gaps_groups(self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2', 'seq3'] problem.number_of_variables = 3 msa_1 = MSASolution(problem, msa=[('seq1', 'AC---TGAC'), ('seq2', 'AT--CT--C'), ('seq3', 'AAC---TGC')]) problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2', 'seq3', 'seq4'] problem.number_of_variables = 4 msa_2 = MSASolution(problem, msa=[('seq1', 'GKGD---PKKP'), ('seq2', 'M------QDRV'), ('seq3', 'MKKLKKHPDFP'), ('seq4', 'M--------HI-')]) # check self.assertEqual(3, msa_1.get_length_of_gaps(0)) self.assertEqual(4, msa_1.get_length_of_gaps(1)) self.assertEqual(3, msa_1.get_length_of_gaps(2)) self.assertEqual(3, msa_2.get_length_of_gaps(0)) self.assertEqual(6, msa_2.get_length_of_gaps(1)) self.assertEqual(0, msa_2.get_length_of_gaps(2)) self.assertEqual(9, msa_2.get_length_of_gaps(3))
def test_should_remove_all_gap_columns_case_b(self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2', 'seq3'] problem.number_of_variables = 3 msa = MSASolution(problem, msa=[('seq1', 'AC--T--GC'), ('seq2', 'AC-----AC'), ('seq3', 'A---C--AC')]) msa.remove_full_of_gaps_columns() # check self.assertEqual(['ACTGC', 'AC-AC', 'A-CAC'], msa.decode_alignment_as_list_of_sequences())
def test_should_find_max_sequence_length(self): # setup problem = MSA(score_list=[]) problem.identifiers = ['a', 'b', 'c'] problem.number_of_variables = 3 msa = MSASolution(problem, msa=[('a', 'AAC'), ('b', 'AAAAAAAC'), ('c', 'C')]) crossover = SPXMSA(probability=1.0, remove_gap_columns=False) # run max = crossover.find_length_of_the_largest_sequence(msa) # check self.assertEqual(8, max)
def test_remove_gap_group_at_column(self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2', 'seq3'] problem.number_of_variables = 3 msa = MSASolution(problem, msa=[('seq1', '--AA-'), ('seq2', '---AA'), ('seq3', '--AA-')]) msa.remove_gap_group_from_sequence_at_column(0, 0) msa.remove_gap_group_from_sequence_at_column(1, 0) msa.remove_gap_group_from_sequence_at_column(2, 4) # check self.assertEqual([[4, 4], [], [0, 1]], msa.gaps_groups)
def test_should_find_original_positions_in_solution_with_gaps(self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2'] problem.number_of_variables = 2 msa = MSASolution(problem, msa=[('seq1', 'BC-D-E---'), ('seq2', '--C--E---')]) crossover = SPXMSA(probability=1.0, remove_gap_columns=False) # run cutting_points = crossover.find_original_positions_in_original_sequences(msa, 5) # check self.assertEqual(3, cutting_points[0]) self.assertEqual(1, cutting_points[1])
def test_should_find_the_cutting_points_in_the_first_parent_return_minus_one_if_the_point_is_in_a_gap_group_ending_the_sequence( self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2'] problem.number_of_variables = 2 msa = MSASolution(problem, msa=[('seq1', 'BC-D-E--'), ('seq2', 'ABC-E---')]) crossover = SPXMSA(probability=1.0, remove_gap_columns=False) # run cutting_points = crossover.find_cutting_points_in_first_parent(msa, 6) # check self.assertEqual([-1, -1], cutting_points)
def test_should_remove_gap(self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2', 'seq3'] problem.number_of_variables = 3 msa = MSASolution(problem, msa=[('seq1', 'AC---TGAC'), ('seq2', 'AC---TGAC'), ('seq3', 'AC---TGAC')]) msa.remove_gap_from_sequence(0, 2) msa.remove_gap_from_sequence(1, 2) msa.remove_gap_from_sequence(2, 2) # check self.assertEqual(['AC--TGAC', 'AC--TGAC', 'AC--TGAC'], msa.decode_alignment_as_list_of_sequences())
def test_should_find_the_cutting_points_in_the_first_parent_return_the_column_position_if_it_is_occupied_by_gap( self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2'] problem.number_of_variables = 2 msa = MSASolution(problem, msa=[('seq1', 'BC-DE'), ('seq2', 'ABC-E')]) crossover = SPXMSA(probability=1.0, remove_gap_columns=False) # run cutting_points = crossover.find_cutting_points_in_first_parent(msa, 2) # check self.assertEqual(3, cutting_points[0]) self.assertEqual(2, cutting_points[1])
def test_should_return_if_msa_is_valid(self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2', 'seq3'] problem.number_of_variables = 3 msa_valid = MSASolution(problem, msa=[('seq1', 'AC---TGAC'), ('seq2', 'AT--CT--C'), ('seq3', 'AAC---TGC')]) msa_not_valid = MSASolution(problem, msa=[('seq1', 'A'), ('seq2', 'A'), ('seq3', 'AA')]) # check self.assertTrue(msa_valid.is_valid_msa()) self.assertFalse(msa_not_valid.is_valid_msa())
def test_should_single_point_crossover_work_properly_case_j(self, random_call): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2'] problem.number_of_variables = 2 msa_1 = MSASolution(problem, msa=[('seq1', 'MIKMIM-IK'), ('seq2', 'A-B-CDEF-')]) msa_2 = MSASolution(problem, msa=[('seq1', '--MIKMIMIK'), ('seq2', 'ABC-D-E-F-')]) crossover = SPXMSA(probability=1.0, remove_gap_columns=True) # run random_call.return_value = 2 children = crossover.execute([msa_1, msa_2]) # check self.assertEqual(["MIK--MIMIK", "A-BCD-E-F-"], children[0].decode_alignment_as_list_of_sequences()) self.assertEqual(["--MIKMIM-IK", "AB----CDEF-"], children[1].decode_alignment_as_list_of_sequences())
def test_should_merge_gaps_groups_case_b(self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1'] problem.number_of_variables = 1 aln_seq = [('seq1', 'ACTGAC')] msa = MSASolution(problem, msa=aln_seq) msa.gaps_groups[0] = [2, 4, 4, 8, 8, 10] self.assertEqual(["AC-----------TGAC"], msa.decode_alignment_as_list_of_sequences()) # run msa.merge_gaps_groups() # check self.assertEqual([2, 10], msa.gaps_groups[0])
def test_should_remove_gap_case_c(self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1'] problem.number_of_variables = 1 msa = MSASolution(problem, msa=[('seq1', 'AB----CD-E-')]) msa.remove_gap_from_sequence(0, 3) self.assertEqual(['AB---CD-E-'], msa.decode_alignment_as_list_of_sequences()) msa.remove_gap_from_sequence(0, 3) self.assertEqual(['AB--CD-E-'], msa.decode_alignment_as_list_of_sequences()) msa.remove_gap_from_sequence(0, 8) self.assertEqual(['AB--CD-E'], msa.decode_alignment_as_list_of_sequences())
def test_should_is_gap_at_char_sequence_raise_exception_if_position_is_negative( self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2', 'seq3'] problem.number_of_variables = 3 msa = MSASolution(problem, msa=[('seq1', '--AA-'), ('seq2', '--AA-'), ('seq3', '--AA-')]) # check self.assertTrue(msa.is_gap_char_at_sequence(0, 0)) self.assertTrue(msa.is_gap_char_at_sequence(0, 1)) self.assertTrue(msa.is_gap_char_at_sequence(1, 4)) self.assertTrue(msa.is_gap_char_at_sequence(2, 1)) with self.assertRaises(Exception): msa.is_gap_char_at_sequence(0, -1)
def test_should_single_point_crossover_work_properly_case_h(self, random_call): """ MSA with no crossover in the first sequence -----------|-M, --M|------ => ------------M------, --M """ # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1'] problem.number_of_variables = 1 msa_1 = MSASolution(problem, msa=[('seq1', '------------M')]) msa_2 = MSASolution(problem, msa=[('seq1', '--M------')]) crossover = SPXMSA(probability=1.0, remove_gap_columns=False) # run random_call.return_value = 10 children = crossover.execute([msa_1, msa_2]) # check self.assertEqual(["------------M------"], children[0].decode_alignment_as_list_of_sequences()) self.assertEqual(["--M"], children[1].decode_alignment_as_list_of_sequences())
def test_should_single_point_crossover_work_properly_case_c(self, random_call): """ A|B-CD-EF, ---A|BCD-EF => ABCD-EF, ---AB-CD-EF """ # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1'] problem.number_of_variables = 1 msa_1 = MSASolution(problem, msa=[('seq1', 'AB-CD-EF')]) msa_2 = MSASolution(problem, msa=[('seq1', '---ABCD-EF')]) crossover = SPXMSA(probability=1.0, remove_gap_columns=False) # run random_call.return_value = 0 children = crossover.execute([msa_1, msa_2]) # check self.assertEqual(["ABCD-EF"], children[0].decode_alignment_as_list_of_sequences()) self.assertEqual(["---AB-CD-EF"], children[1].decode_alignment_as_list_of_sequences())
def test_should_the_solution_remain_unchanged_if_the_probability_is_zero(self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2', 'seq3'] problem.number_of_variables = 3 msa_1 = MSASolution(problem, msa=[('seq1', 'ACTC'), ('seq2', 'A-TC'), ('seq3', 'A--C')]) msa_2 = MSASolution(problem, msa=[('seq1', 'CT-G'), ('seq2', '-T-G'), ('seq3', '-ATG')]) crossover = SPXMSA(probability=0.0, remove_gap_columns=False) # run offspring = crossover.execute([msa_1, msa_2]) # check self.assertEqual([('seq1', 'ACTC'), ('seq2', 'A-TC'), ('seq3', 'A--C')], offspring[0].decode_alignment_as_list_of_pairs()) self.assertEqual([('seq1', 'CT-G'), ('seq2', '-T-G'), ('seq3', '-ATG')], offspring[1].decode_alignment_as_list_of_pairs())
def test_should_get_original_char_position_in_aligned_sequence(self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2', 'seq3'] problem.number_of_variables = 3 msa = MSASolution(problem, msa=[('seq1', '-ABC'), ('seq2', 'ABCD'), ('seq3', '--AB')]) # check self.assertEqual( 1, msa.get_original_char_position_in_aligned_sequence(seq_index=0, position=0)) self.assertEqual( 2, msa.get_original_char_position_in_aligned_sequence(seq_index=0, position=1)) self.assertEqual( 3, msa.get_original_char_position_in_aligned_sequence(seq_index=0, position=2)) self.assertEqual( 0, msa.get_original_char_position_in_aligned_sequence(seq_index=1, position=0)) self.assertEqual( 1, msa.get_original_char_position_in_aligned_sequence(seq_index=1, position=1)) self.assertEqual( 2, msa.get_original_char_position_in_aligned_sequence(seq_index=1, position=2)) self.assertEqual( 2, msa.get_original_char_position_in_aligned_sequence(seq_index=2, position=0)) self.assertEqual( 3, msa.get_original_char_position_in_aligned_sequence(seq_index=2, position=1))
def test_should_single_point_crossover_work_properly_case_f(self, random_call): """ GKGD---P|KK, GKGD-P|KK => GKGD---PKK, GKGD-P-KK M------Q|DR-, --M--Q|DR => M------QDR, --M--QDR- """ # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2'] problem.number_of_variables = 2 msa_1 = MSASolution(problem, msa=[('seq1', 'GKGD---PKK'), ('seq2', 'M------QDR-')]) msa_2 = MSASolution(problem, msa=[('seq1', 'GKGD-PKK'), ('seq2', '--M--QDR')]) crossover = SPXMSA(probability=1.0, remove_gap_columns=False) # run random_call.return_value = 7 children = crossover.execute([msa_1, msa_2]) # check self.assertEqual(["GKGD---PKK", "M------QDR"], children[0].decode_alignment_as_list_of_sequences()) self.assertEqual(["GKGD-P-KK", "--M--QDR-"], children[1].decode_alignment_as_list_of_sequences())