Mercurial > repos > yufei-luo > s_mart
view commons/tools/tests/Test_OrientSequences.py @ 19:9bcfa7936eec
Deleted selected files
author | m-zytnicki |
---|---|
date | Mon, 29 Apr 2013 03:23:29 -0400 |
parents | 94ab73e8a190 |
children |
line wrap: on
line source
import unittest import time import os from commons.core.utils.FileUtils import FileUtils from commons.tools.OrientSequences import OrientSequences class Test_OrientSequences( unittest.TestCase ): def setUp( self ): self._i = OrientSequences () self._uniqId = "%s_%s" % ( time.strftime("%Y%m%d%H%M%S"), os.getpid() ) def tearDown( self ): self._i = None self._uniqId = None def test_parseMummerOutput( self ): inFileName = "dummyInFile_%s" % ( self._uniqId ) inF = open( inFileName, "w" ) inF.write( "> seq1\n" ) inF.write( " seq2 20 1 20\n" ) inF.write( "> seq1 Reverse\n" ) inF.write( " seq2 100 1 100\n" ) inF.write( " seq2 450 400 50\n" ) inF.close() dExp = { "direct": 1, "reverse": 2 } self._i._verbose = 0 dObs = self._i.parseMummerOutput( inFileName, "seq1", "seq2" ) self.assertEqual( dObs, dExp ) os.remove( inFileName ) def test_getSequencesToReverseFromMatrix_2seq( self ): lNewHeaders = [ "seq1", "seq2" ] dMatrix = { "1_vs_2": { "direct": 1, "reverse": 2 } } lExp = [ "seq2" ] self._i._verbose = 0 lObs = self._i.getSequencesToReverseFromMatrix( dMatrix, lNewHeaders ) lExp.sort() lObs.sort() self.assertEqual( lObs, lExp ) def test_getSequencesToReverseFromMatrix_3seq( self ): lNewHeaders = [ "seq1", "seq2", "seq3" ] dMatrix = { "1_vs_2": { "direct": 1, "reverse": 10 }, "1_vs_3": { "direct": 10, "reverse": 1 }, "2_vs_3": { "direct": 1, "reverse": 10 } } lExp = [ "seq2" ] self._i._verbose = 0 lObs = self._i.getSequencesToReverseFromMatrix( dMatrix, lNewHeaders ) lExp.sort() lObs.sort() self.assertEqual( lExp, lObs ) def test_getSequencesToReverseFromMatrix_4seq( self ): lNewHeaders = [ "seq1", "seq2", "seq3", "seq4" ] dMatrix = { "1_vs_2": { "direct": 10, "reverse": 1 }, "1_vs_3": { "direct": 1, "reverse": 10 }, "1_vs_4": { "direct": 1, "reverse": 10 }, "2_vs_3": { "direct": 1, "reverse": 10 }, "2_vs_4": { "direct": 1, "reverse": 10 }, "3_vs_4": { "direct": 1, "reverse": 2 } } lExp = [ "seq3", "seq4" ] self._i._verbose = 0 lObs = self._i.getSequencesToReverseFromMatrix( dMatrix, lNewHeaders ) lExp.sort() lObs.sort() self.assertEqual( lExp, lObs ) def test_orientInputSequences( self ): lSeqToOrient = [ "seq1" ] tmpFileName = "dummyInFile_%s" % ( self._uniqId ) tmpF = open( tmpFileName, "w" ) tmpF.write( ">seq1\n" ) tmpF.write( "ATGCGGTGCATG\n" ) tmpF.write( ">seq2\n" ) tmpF.write( "GGCGAAGTGAAA\n" ) tmpF.close() expFileName = "dummyExpFile_%s" % ( self._uniqId ) expF = open( expFileName, "w" ) expF.write( ">seq1 re-oriented\n" ) expF.write( "CATGCACCGCAT\n" ) expF.write( ">seq2\n" ) expF.write( "GGCGAAGTGAAA\n" ) expF.close() obsFileName = "dummyObsFile_%s" % ( self._uniqId ) self._i._verbose = 0 self._i._outFileName = obsFileName self._i.orientInputSequences( lSeqToOrient, tmpFileName ) self.assertTrue( FileUtils.are2FilesIdentical( obsFileName, expFileName ) ) for f in [ tmpFileName, expFileName, obsFileName ]: os.remove( f ) if __name__ == "__main__": unittest.main()