def test_bad(self): """NcbiFastaParser should raise error on bad records if strict""" # if strict, starting anywhere in the first 15 lines should cause # errors for i in range(15): self.assertRaises(RecordError, list, NcbiFastaParser(self.nasty[i:])) # ...but the 16th is OK. r = list(NcbiFastaParser(self.nasty[15:]))[0] self.assertEqual(r, ("123", "ucagUCAGtgacNNNN")) # test that we get what we expect if not strict r = list(NcbiFastaParser(self.nasty, Sequence, strict=False)) self.assertEqual(len(r), 4) a, b, c, d = r self.assertEqual( (a[1], a[1].info.GI, a[1].info.RefSeq, a[1].info.Description), ("UCAG", ["abc"], ["def"], ""), ) self.assertEqual( (b[1], b[1].info.GI, b[1].info.GenBank, b[1].info.Description), ("UUUUCCCC", ["xyz"], ["qwe"], "descr"), ) self.assertEqual( (c[1], c[1].info.GI, c[1].info.RefSeq, c[1].info.Description), ("XYZ", ["bad"], ["stuff"], "label"), ) self.assertEqual( (d[1], d[1].info.GI, d[1].info.DDBJ, d[1].info.Description), ("ucagUCAGtgacNNNN".upper(), ["123"], ["456"], "desc|with|pipes|"), ) # ...and when we explicitly supply a constructor r = list(NcbiFastaParser(self.nasty, Dna, strict=False)) self.assertEqual(len(r), 3) a, b, c = r a, b, c = a[1], b[1], c[1] self.assertEqual( (a, a.info.GI, a.info.RefSeq, a.info.Description), ("TCAG", ["abc"], ["def"], ""), ) self.assertEqual( (b, b.info.GI, b.info.GenBank, b.info.Description), ("TTTTCCCC", ["xyz"], ["qwe"], "descr"), ) self.assertEqual( (c, c.info.GI, c.info.DDBJ, c.info.Description), ("tcagTCAGtgacNNNN".upper(), ["123"], ["456"], "desc|with|pipes|"), )
def test_normal(self): """NcbiFastaParser should accept normal record if loose or strict""" f = list(NcbiFastaParser(self.peptide, Protein)) self.assertEqual(len(f), 2) a, b = f a, b = a[1], b[1] # field 0 is the name self.assertEqual( a, "MNMSKQPVSNVRAIQANINIPMGAFRPGAGQPPRRKECTPEVEEGVPPTSDEEKKPIPGAKKLPGPAVNLSEIQNIKSELKYVPKAEQ", ) self.assertEqual(a.info.GI, ["10047090"]) self.assertEqual(a.info.RefSeq, ["NP_055147.1"]) self.assertEqual(a.info.DDBJ, []) self.assertEqual(a.info.Description, "small muscle protein, X-linked [H**o sapiens]") self.assertEqual( b, "MANRGPSYGLSREVQEKIEQKYDADLENKLVDWIILQCAEDIEHPPPGRAHFQKWLMDGTVLCKLINSLYPPGQEPIPKISESKMAFKQMEQISQFLKAAETYGVRTTDIFQTVDLWEGKDMAAVQRTLMALGSVAVTKD", ) self.assertEqual(b.info.GI, ["10047092"]) self.assertEqual(b.info.RefSeq, ["NP_037391.1"]) self.assertEqual(b.info.Description, "neuronal protein [H**o sapiens]")
def test_empty(self): """NcbiFastaParser should accept empty input""" self.assertEqual(list(NcbiFastaParser(self.empty)), []) self.assertEqual(list(NcbiFastaParser(self.empty, Protein)), [])