Back to index

python-biopython  1.60
test_SffIO.py
Go to the documentation of this file.
00001 import re
00002 import unittest
00003 from Bio import SeqIO
00004 
00005 # sffinfo E3MFGYR02_random_10_reads.sff | sed -n '/>\|Run Prefix\|Region\|XY/p'
00006 test_data = """
00007 >E3MFGYR02JWQ7T
00008   Run Prefix:   R_2008_01_09_16_16_00_
00009   Region #:     2
00010   XY Location:  3946_2103
00011 >E3MFGYR02JA6IL
00012   Run Prefix:   R_2008_01_09_16_16_00_
00013   Region #:     2
00014   XY Location:  3700_3115
00015 >E3MFGYR02JHD4H
00016   Run Prefix:   R_2008_01_09_16_16_00_
00017   Region #:     2
00018   XY Location:  3771_2095
00019 >E3MFGYR02GFKUC
00020   Run Prefix:   R_2008_01_09_16_16_00_
00021   Region #:     2
00022   XY Location:  2520_2738
00023 >E3MFGYR02FTGED
00024   Run Prefix:   R_2008_01_09_16_16_00_
00025   Region #:     2
00026   XY Location:  2268_2739
00027 >E3MFGYR02FR9G7
00028   Run Prefix:   R_2008_01_09_16_16_00_
00029   Region #:     2
00030   XY Location:  2255_0361
00031 >E3MFGYR02GAZMS
00032   Run Prefix:   R_2008_01_09_16_16_00_
00033   Region #:     2
00034   XY Location:  2468_1618
00035 >E3MFGYR02HHZ8O
00036   Run Prefix:   R_2008_01_09_16_16_00_
00037   Region #:     2
00038   XY Location:  2958_1574
00039 >E3MFGYR02GPGB1
00040   Run Prefix:   R_2008_01_09_16_16_00_
00041   Region #:     2
00042   XY Location:  2633_0607
00043 >E3MFGYR02F7Z7G
00044   Run Prefix:   R_2008_01_09_16_16_00_
00045   Region #:     2
00046   XY Location:  2434_1658"""
00047 
00048 class TestUAN(unittest.TestCase):
00049     def setUp(self):
00050         self.records = [record for record in SeqIO.parse('Roche/E3MFGYR02_random_10_reads.sff', 'sff')]
00051         self.test_annotations = {}
00052         for line in test_data.splitlines():
00053             fields = re.split(r"\s+", line.strip())
00054             if '>' in line:
00055                 current_name = fields[0].lstrip('>')
00056                 self.test_annotations[current_name] = {}
00057             elif 'Prefix' in line:
00058                 time_list = map(int, fields[2].split('_')[1:-1])
00059                 self.test_annotations[current_name]["time"] = time_list
00060             elif 'Region' in line:
00061                 region = int(fields[-1])
00062                 self.test_annotations[current_name]["region"] = region
00063             elif 'XY' in line:
00064                 x, y = map(int, fields[-1].split('_'))
00065                 self.test_annotations[current_name]["coords"] = (x, y)
00066     def test_time(self):
00067         for record in self.records:
00068             self.assertEqual(record.annotations["time"], self.test_annotations[record.name]["time"])
00069     def test_region(self):
00070         for record in self.records:
00071             self.assertEqual(record.annotations["region"], self.test_annotations[record.name]["region"])
00072     def test_coords(self):
00073         for record in self.records:
00074             self.assertEqual(record.annotations["coords"], self.test_annotations[record.name]["coords"])
00075 
00076 if __name__ == '__main__':
00077     unittest.main()