def test_blastx_parser(self): "Testing blastx parser" blastx_output = open(testutil.datafile("blastx_output.txt"), "r") seq_dict = {"gi|171854975|dbj|AB364477.1|": self.dna["gi|171854975|dbj|AB364477.1|"]} try: results = blast.read_blast_alignment( blastx_output, seq_dict, blast.BlastIDIndex(self.prot), translateSrc=True ) finally: blastx_output.close() correct = [ (143, 143, 429, 0.53146853146853146), (143, 145, 429, 0.28275862068965518), (143, 145, 429, 0.28965517241379313), (143, 145, 429, 0.29655172413793102), (143, 145, 429, 0.30344827586206896), (144, 144, 432, 0.4513888888888889), (144, 144, 432, 0.4513888888888889), (145, 145, 435, 0.45517241379310347), (145, 145, 435, 0.51034482758620692), (146, 142, 438, 0.35616438356164382), (146, 146, 438, 0.4589041095890411), (146, 146, 438, 0.46575342465753422), (146, 146, 438, 0.4726027397260274), (146, 146, 438, 0.4726027397260274), (146, 146, 438, 0.4863013698630137), (146, 146, 438, 0.59589041095890416), (146, 146, 438, 0.62328767123287676), (146, 146, 438, 0.66438356164383561), (146, 146, 438, 0.74657534246575341), (146, 146, 438, 0.91095890410958902), (146, 146, 438, 0.97945205479452058), ] check_results([results], correct, lambda t: (len(t[0]), len(t[1]), len(t[0].sequence), t[2].pIdentity()))
def test_multiblast_parser_long(self): "Testing multiblast parser with long input" longerFile = testutil.datafile("sp_all_hbb") sp_all_hbb = seqdb.SequenceFileDB(longerFile) filename = testutil.datafile("multiblast_long_output.txt") multiblast_output = open(filename, "r") try: al = cnestedlist.NLMSA("blasthits", "memory", pairwiseMode=True, bidirectional=False) al = blast.read_blast_alignment(multiblast_output, sp_all_hbb, self.prot, al) finally: multiblast_output.close() al.build() results = [] for seq in sp_all_hbb.values(): try: results.append(al[seq]) except KeyError: pass correctfile = file(testutil.datafile("multiblast_long_correct.txt"), "r") try: correct = [] for line in correctfile: t = line.split() correct.append((t[0], t[1], float(t[2]))) finally: correctfile.close() check_results(results, correct, pair_identity_tuple)
def test_multiblast_parser(self): "Testing multiblast parser" multiblast_output = open(testutil.datafile("multiblast_output.txt"), "r") try: al = cnestedlist.NLMSA("blasthits", "memory", pairwiseMode=True, bidirectional=False) al = blast.read_blast_alignment(multiblast_output, self.prot, blast.BlastIDIndex(self.prot), al) finally: multiblast_output.close() al.build() results = [al[seq] for seq in self.prot.values()] check_results(results, correct_multiblast_results, pair_identity_tuple)
def test_blastp_parser(self): "Testing blastp parser" blastp_output = open(testutil.datafile("blastp_output.txt"), "r") seq_dict = {"HBB1_XENLA": self.prot["HBB1_XENLA"]} prot_index = blast.BlastIDIndex(self.prot) try: alignment = blast.read_blast_alignment(blastp_output, seq_dict, prot_index) results = alignment[self.prot["HBB1_XENLA"]] finally: blastp_output.close() check_results([results], blastp_correct_results, pair_identity_tuple)
def test_tblastn_parser(self): "Testing tblastn parser" seq_dict = {"HBB1_XENLA": self.prot["HBB1_XENLA"]} dna_db = blast.BlastIDIndex(self.dna) tblastn_output = open(testutil.datafile("tblastn_output.txt"), "r") try: al = blast.read_blast_alignment(tblastn_output, seq_dict, dna_db, translateDest=True) result = al[self.prot["HBB1_XENLA"]] finally: tblastn_output.close() src, dest, edge = iter(result.edges()).next() self.assertEqual( str(src), "LTAHDRQLINSTWGKLCAKTIGQEALGRLLWTYPWTQRYFSSFGNLNSADAVFHNEAVAAHGEK" "VVTSIGEAIKHMDDIKGYYAQLSKYHSETLHVDPLNFKRFGGCLSIALARHFHEEYTPELHAAY" "EHLFDAIADALGKGYH", ) self.assertEqual( str(dest), "LTDAEKAAVSGLWGKVNSDEVGGEALGRLLVVYPWTQRYFDSFGDLSSASAIMGNAKVKAHGKK" "VITAFNEGLNHLDSLKGTFASLSELHCDKLHVDPENFRLLGNMIVIVLGHHLGKDFTPAAQAAF" "QKVMAGVATALAHKYH", ) self.assertEqual( str(dest.sequence), "CTGACTGATGCTGAGAAGGCTGCTGTCTCTGGCCTGTGGGGAAAGGTGAACTCCGATGAAGTTG" "GTGGTGAGGCCCTGGGCAGGCTGCTGGTTGTCTACCCTTGGACCCAGAGGTACTTTGATAGCTT" "TGGAGACCTATCCTCTGCCTCTGCTATCATGGGTAATGCCAAAGTGAAGGCCCATGGCAAGAAA" "GTGATAACTGCCTTTAACGAGGGCCTGAATCACTTGGACAGCCTCAAGGGCACCTTTGCCAGCC" "TCAGTGAGCTCCACTGTGACAAGCTCCATGTGGATCCTGAGAACTTCAGGCTCCTGGGCAATAT" "GATCGTGATTGTGCTGGGCCACCACCTGGGCAAGGATTTCACCCCCGCTGCACAGGCTGCCTTC" "CAGAAGGTGATGGCTGGAGTGGCCACTGCCCTGGCTCACAAGTACCAC", ) self.assertAlmostEqual(edge.pIdentity(), 0.451, 3)