| 18 | 1 import unittest | 
|  | 2 import os | 
|  | 3 from commons.core.utils.FileUtils import FileUtils | 
|  | 4 | 
|  | 5 | 
|  | 6 class Test_CorrelateTEageWithGCcontent( unittest.TestCase ): | 
|  | 7 | 
|  | 8     def test_zLaunchAsScript( self ): | 
|  | 9         cDir = os.getcwd() | 
|  | 10 | 
|  | 11         coordFile = "dummyPathFile" | 
|  | 12         coordFileHandler = open( coordFile, "w" ) | 
|  | 13         coordFileHandler.write( "1\tchr1\t1\t5\tTE1\t1\t5\t0.0\t100\t98.7\n" ) | 
|  | 14         coordFileHandler.write( "1\tchr1\t11\t20\tTE1\t6\t15\t0.0\t100\t98.7\n" ) | 
|  | 15         coordFileHandler.write( "2\tchr1\t26\t30\tTE1\t1\t5\t0.0\t100\t96.7\n" ) | 
|  | 16         coordFileHandler.write( "3\tchr2\t1\t10\tTE2\t1\t10\t0.0\t100\t98.7\n" ) | 
|  | 17         coordFileHandler.close() | 
|  | 18 | 
|  | 19         genomeFile = "dummyGenomeFile" | 
|  | 20         genomeFileHandler = open( genomeFile, "w" ) | 
|  | 21         genomeFileHandler.write( ">chr1\n" ) | 
|  | 22         genomeFileHandler.write( "AGCTGTTTTTAGCAGACGCATTTTTGGAGGTTTT\n" ) | 
|  | 23         genomeFileHandler.write( ">chr2\n" ) | 
|  | 24         genomeFileHandler.write( "ATATATATGGTTTTTTTTTT\n" ) | 
|  | 25         genomeFileHandler.close() | 
|  | 26 | 
|  | 27         refseqFile = "dummyRefseqFile" | 
|  | 28         refseqFileHandler = open( refseqFile, "w" ) | 
|  | 29         refseqFileHandler.write( ">TE1\nAGCAGCGACGACGACGACGACTTTT\n" ) | 
|  | 30         refseqFileHandler.write( ">TE2\nAGCAGCGACGACGACGACGACTTTT\n" ) | 
|  | 31         refseqFileHandler.write( ">TE3\nAGCAGCGACGACGACGACGACTTTT\n" ) | 
|  | 32         refseqFileHandler.close() | 
|  | 33 | 
|  | 34         expFile = "dummyExpFile" | 
|  | 35         expFileHandler = open( expFile, "w" ) | 
|  | 36         expFileHandler.write( "copy\tTE\tchr\tlength\tid\tGC\tlengthPerc\n" ) | 
|  | 37         expFileHandler.write( "1\tTE1\tchr1\t15\t98.70\t%.2f\t%.2f\n" % ( 100 * 9 / 15.0, 100 * 15 / 25.0 ) ) | 
|  | 38         expFileHandler.write( "2\tTE1\tchr1\t5\t96.70\t%.2f\t%.2f\n" % ( 100 * 4 / 5.0, 100 * 5 / 25.0 ) ) | 
|  | 39         expFileHandler.write( "3\tTE2\tchr2\t10\t98.70\t%.2f\t%.2f\n" % ( 100 * 2 / 10.0, 100 * 10 / 25.0 ) ) | 
|  | 40         expFileHandler.close() | 
|  | 41 | 
|  | 42         obsFile = "dummyObsFile" | 
|  | 43 | 
|  | 44         cmd = "CorrelateTEageWithGCcontent.py" | 
|  | 45         cmd += " -i %s" % ( coordFile ) | 
|  | 46         cmd += " -g %s" % ( genomeFile ) | 
|  | 47         cmd += " -r %s" % ( refseqFile ) | 
|  | 48         cmd += " -o %s" % ( obsFile ) | 
|  | 49         cmd += " -v %i" % ( 0 ) | 
|  | 50         returnStatus = os.system( cmd ) | 
|  | 51 | 
|  | 52         self.assertTrue( returnStatus == 0 ) | 
|  | 53         self.assertTrue( FileUtils.are2FilesIdentical( expFile, obsFile ) ) | 
|  | 54 | 
|  | 55         for f in [ coordFile, genomeFile, refseqFile, expFile, obsFile ]: | 
|  | 56             os.remove( f ) | 
|  | 57         os.chdir( cDir ) | 
|  | 58 | 
|  | 59 if __name__ == "__main__": | 
|  | 60         unittest.main() |