Back to index

python-biopython  1.60
test_Wise.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # This code is part of the Biopython distribution and governed by its
00003 # license.  Please see the LICENSE file that should have been included
00004 # as part of this package.
00005 
00006 __version__ = "$Revision: 1.11 $"
00007 
00008 import cStringIO
00009 import doctest, unittest
00010 import sys
00011 
00012 if 'requires_wise' in sys.modules:
00013     del sys.modules['requires_wise']
00014 import requires_wise
00015 
00016 from Bio import Wise
00017 
00018 class TestWiseDryRun(unittest.TestCase):
00019     def setUp(self):
00020         self.old_stdout = sys.stdout
00021         sys.stdout = cStringIO.StringIO()
00022         
00023     def test_dnal(self):
00024         """Call dnal, and do a trivial check on its output."""
00025         Wise.align(["dnal"], ("seq1.fna", "seq2.fna"), kbyte=100000, dry_run=True)
00026         #If test output is redirected to a file, the wrapper adds -quiet
00027         output = sys.stdout.getvalue().replace(" -quiet ", " ")
00028         self.assertTrue(output.startswith("dnal -kbyte 100000 seq1.fna seq2.fna"), output[:200])
00029 
00030     def test_psw(self):
00031         """Call psw, and do a trivial check on its output."""
00032         Wise.align(["psw"], ("seq1.faa", "seq2.faa"), dry_run=True, kbyte=4)
00033         #If test output is redirected to a file, the wrapper adds -quiet
00034         output = sys.stdout.getvalue().replace(" -quiet ", " ")
00035         self.assertTrue(output.startswith("psw -kbyte 4 seq1.faa seq2.faa"), output[:200])
00036 
00037     def tearDown(self):
00038         sys.stdout = self.old_stdout
00039 
00040 class TestWise(unittest.TestCase):
00041     def test_align(self):
00042         """Call dnal with optional arguments, and do a trivial check on the output."""
00043         temp_file = Wise.align(["dnal"], ("Wise/human_114_g01_exons.fna_01", "Wise/human_114_g02_exons.fna_01"), kbyte=100000, force_type="DNA", quiet=True)
00044         line = temp_file.readline().rstrip()
00045         if line == "Score 114":
00046             #Wise 2.4.1 includes a score line, even in quiet mode, ignore this
00047             line = temp_file.readline().rstrip()
00048         if line == "ENSG00000172135   AGGGAAAGCCCCTAAGCTC--CTGATCTATGCTGCATCCAGTTTGCAAAGTGGGGTCCC":
00049             #This is what we expect from wise 2.2.0 (and earlier)
00050             pass
00051         elif line == "ENSG00000172135   AGGGAAAGCCCCTAAGCTC--CTGATCTATGCTGCATCCAGTTTGCAAAG-TGGGGTCC":
00052             #This is what we expect from wise 2.4.1
00053             pass
00054         else:
00055             #Bad!
00056             self.assertTrue(False, line)
00057 
00058 
00059 if __name__ == "__main__":
00060     unittest_suite = unittest.TestLoader().loadTestsFromName("test_Wise")
00061     doctest_suite = doctest.DocTestSuite(Wise)
00062     suite = unittest.TestSuite((unittest_suite, doctest_suite))
00063     runner = unittest.TextTestRunner(sys.stdout, verbosity = 2)
00064     runner.run(suite)