view commons/tools/tests/Test_CalcCoordCumulLength.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 os
import time
from commons.tools.CalcCoordCumulLength import CalcCoordCumulLength
from commons.core.utils.FileUtils import FileUtils
from pyRepet.util.Stat import Stat


class Test_CalcCoordCumulLength( unittest.TestCase ):
    
    def setUp( self ):
        self._i = CalcCoordCumulLength()
        self._uniqId = time.strftime("%Y%m%d%H%M%S")
        
        
    def tearDown( self ):
        self._i = None
        self._uniqId = None
        
        
    def test_mergeCoordinates( self ):
        inFileName = "dummyInFile_%s"  %( self._uniqId )
        inF = open( inFileName, "w" )
        inF.write( "TE1\tchr1\t101\t200\n" )
        inF.write( "TE2\tchr1\t401\t600\n" )
        inF.write( "TE2\tchr1\t451\t500\n" )
        inF.close()
        expFileName = "dummyExpFile_%s"  %( self._uniqId )
        expF = open( expFileName, "w" )
        expF.write( "TE1\tchr1\t101\t200\n" )
        expF.write( "TE2\tchr1\t401\t600\n" )
        expF.close()
        self._i.setInputFileName( inFileName )
        obsFileName = self._i.mergeCoordinates()
        self.assertTrue( FileUtils.are2FilesIdentical( obsFileName, expFileName ) )
        for f in [ inFileName, expFileName, obsFileName ]: os.remove( f )
        
        
    def test_getStatsPerChr( self ):
        inFileName = "dummyInFile_%s"  %( self._uniqId )
        inF = open( inFileName, "w" )
        inF.write( "TE1\tchr1\t101\t200\n" )
        inF.write( "TE2\tchr1\t401\t600\n" )
        inF.write( "TE1\tchr2\t1301\t1600\n" )
        inF.close()
        dExp = { "chr1": Stat(), "chr2": Stat() }
        dExp["chr1"].add( 200-101+1 )
        dExp["chr1"].add( 600-401+1 )
        dExp["chr2"].add( 1600-1301+1 )
        dObs = self._i.getStatsPerChr( inFileName )
        self.assertEqual( dObs, dExp )
        
        
    def test_zRunAsScript( self ):
        cDir = os.getcwd()
        inFileName = "dummyInFile_%s"  %( self._uniqId )
        inF = open( inFileName, "w" )
        inF.write( "TE1\tchr1\t101\t200\n" )
        inF.write( "TE2\tchr1\t401\t600\n" )
        inF.write( "TE2\tchr1\t451\t500\n" )
        inF.close()
        outFileName = "dummyOutFile_%s"  %( self._uniqId )
        cmd = "CalcCoordCumulLength.py"
        cmd += " -i %s" % ( inFileName )
        cmd += " -o %s" % ( outFileName )
        cmd += " -v 0"
        log = os.system( cmd )
        self.assertTrue( log == 0 )
        
        for f in [ inFileName, outFileName ]: os.remove( f )
        os.chdir( cDir )
        
if __name__ == "__main__":
        unittest.main()