Back to index

python-biopython  1.60
test_Compass.py
Go to the documentation of this file.
00001 """Tests for parsing Compass output.
00002 """
00003 import os
00004 import unittest
00005 
00006 from Bio import Compass
00007 
00008 
00009 class CompassTest(unittest.TestCase):
00010     def setUp(self):
00011         file_dir = os.path.join("Compass")
00012         self.test_files = [
00013           os.path.join(file_dir, "comtest1"),
00014           os.path.join(file_dir, "comtest2"),
00015           os.path.join(file_dir, "comtest3")]
00016 
00017     def testCompassScanAndConsume(self):
00018         handle = open(self.test_files[0])
00019         com_record = Compass.read(handle)
00020         handle.close()
00021 
00022         self.assertEqual("60456.blo.gz.aln", com_record.query)
00023         self.assertEqual("60456.blo.gz.aln", com_record.hit)
00024         self.assertEqual(0.5, com_record.gap_threshold)
00025 
00026         self.assertEqual(388, com_record.query_length)
00027         self.assertEqual(386, com_record.query_filtered_length)
00028         self.assertEqual(388, com_record.hit_length)
00029         self.assertEqual(386, com_record.hit_filtered_length)
00030 
00031         self.assertEqual(399, com_record.query_nseqs)
00032         self.assertEqual(12.972, com_record.query_neffseqs)
00033         self.assertEqual(399, com_record.hit_nseqs)
00034         self.assertEqual(12.972, com_record.hit_neffseqs)
00035                                                       
00036         self.assertEqual(2759, com_record.sw_score)
00037         self.assertEqual(float("0.00e+00"), com_record.evalue)
00038 
00039     def testCompassParser(self):
00040         handle = open(self.test_files[0])
00041         com_record = Compass.read(handle)
00042         handle.close()
00043 
00044         self.assertEqual("60456.blo.gz.aln", com_record.query)
00045 
00046     def testCompassIteratorEasy(self):
00047         handle = open(self.test_files[0])
00048         records = Compass.parse(handle)
00049         com_record = records.next()
00050         self.assertEqual("60456.blo.gz.aln", com_record.query)
00051         self.assertRaises(StopIteration, records.next)
00052         handle.close()
00053         
00054     def testCompassIteratorHard(self):
00055         handle = open(self.test_files[1])
00056         records = Compass.parse(handle)
00057 
00058         com_record = records.next()
00059         self.assertEqual("allscop//14982.blo.gz.aln", com_record.hit)
00060         self.assertEqual(float('1.01e+03'), com_record.evalue)
00061         
00062         com_record = records.next()
00063         self.assertEqual("allscop//14983.blo.gz.aln", com_record.hit)
00064         self.assertEqual(float('1.01e+03'), com_record.evalue)
00065                                       
00066         com_record = records.next()
00067         self.assertEqual("allscop//14984.blo.gz.aln", com_record.hit)
00068         self.assertEqual(float('5.75e+02'), com_record.evalue)
00069 
00070         handle.close()
00071                                                                                     
00072     def testAlignmentParsingOne(self):
00073         handle = open(self.test_files[1])
00074         records = Compass.parse(handle)
00075 
00076         com_record = records.next()
00077         self.assertEqual(178, com_record.query_start)
00078         self.assertEqual("KKDLEEIAD", com_record.query_aln)
00079         self.assertEqual(9, com_record.hit_start)
00080         self.assertEqual("QAAVQAVTA", com_record.hit_aln)
00081         self.assertEqual("++ ++++++", com_record.positives)
00082         
00083         com_record = records.next()
00084         com_record = records.next()
00085         self.assertEqual(371, com_record.query_start)
00086         self.assertEqual("LEEAMDRMER~~~V", com_record.query_aln)
00087         self.assertEqual(76, com_record.hit_start)
00088         self.assertEqual("LQNFIDQLDNpddL", com_record.hit_aln)
00089         self.assertEqual("+ ++++ + +   +", com_record.positives)
00090 
00091         handle.close()
00092 
00093     def testAlignmentParsingTwo(self):
00094         handle = open(self.test_files[0])
00095         records = Compass.parse(handle)
00096         com_record = records.next()
00097         self.assertEqual(2, com_record.query_start)
00098         self.assertEqual(2, com_record.hit_start)
00099         self.assertEqual("LKERKL", com_record.hit_aln[-6:])
00100         handle.close()
00101 
00102 if __name__ == "__main__":
00103     runner = unittest.TextTestRunner(verbosity = 2)
00104     unittest.main(testRunner=runner)