Mercurial > repos > yufei-luo > s_mart
view commons/tools/tests/Test_srptTableOverlap.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 import pyRepet.sql.RepetDBMySQL from commons.core.utils.FileUtils import FileUtils from commons.tools import srptTableOverlap class Test_srptTableOverlap( unittest.TestCase ): def setUp(self): self._uniqId = "%s_%s" % ( time.strftime("%Y%m%d%H%M%S") , os.getpid() ) self._db = pyRepet.sql.RepetDBMySQL.RepetDB( os.environ["REPET_USER"], os.environ["REPET_HOST"], os.environ["REPET_PW"], os.environ["REPET_DB"] ) def test_getOverlapAllPaths(self): qryFileName = "dummyQryFile_%s" % ( self._uniqId ) qryF = open( qryFileName, "w" ) qryF.write("1\tchr1\t1301\t2000\tTE2\t11\t17\t1e-20\t30\t90.2\n") qryF.close() qryTable = "dummyQryTable_%s" % ( self._uniqId ) self._db.create_table( self._db, qryTable, qryFileName, "path" ) sbjFileName = "dummySbjFile_%s" % ( self._uniqId ) sbjF = open( sbjFileName, "w" ) sbjF.write("1\tchr1\t1001\t1500\tTE1\t11\t17\t1e-20\t30\t90.2\n") # 200-bp overlap: 1301-1500 sbjF.write("2\tchr1\t1401\t1800\tTE2\t11\t17\t1e-20\t30\t90.2\n") # 300-bp overlap: 1501-1800 sbjF.write("3\tchr1\t2001\t2100\tTE2\t11\t17\t1e-20\t30\t90.2\n") sbjF.write("4\tchr2\t1301\t2000\tTE2\t11\t17\t1e-20\t30\t90.2\n") # different query sbjF.close() sbjTable = "dummySbjTable_%s" % ( self._uniqId ) self._db.create_table( self._db, sbjTable, sbjFileName, "path" ) exp_sum_osize, exp_sum_non_osize, exp_sum_qsize = 500, 200, 700 obs_sum_osize, obs_sum_non_osize, obs_sum_qsize = srptTableOverlap.getOverlapAllPaths( qryTable, "path", sbjTable, "path", self._db ) self.assertEqual( obs_sum_osize, exp_sum_osize ) self.assertEqual( obs_sum_non_osize, exp_sum_non_osize ) self.assertEqual( obs_sum_qsize, exp_sum_qsize ) os.remove( qryFileName ) os.remove( sbjFileName ) self._db.remove_if_exist( qryTable ) self._db.remove_if_exist( sbjTable ) def test_pathOverlapByPath(self): qryFileName = "dummyQryFile_%s" % ( self._uniqId ) qryF = open( qryFileName, "w" ) qryF.write("1\tchr1\t1301\t2000\tTE2\t1\t700\t1e-80\t850\t90.2\n") qryF.write("1\tchr1\t2301\t3000\tTE2\t801\t1500\t1e-90\t930\t90.2\n") qryF.close() qryTable = "dummyQryTable_%s" % ( self._uniqId ) self._db.create_table( self._db, qryTable, qryFileName, "path" ) sbjFileName = "dummySbjFile_%s" % ( self._uniqId ) sbjF = open( sbjFileName, "w" ) sbjF.write("1\tchr1\t1401\t1800\tTE2\t11\t17\t1e-20\t30\t90.2\n") sbjF.write("1\tchr1\t2101\t250000\tTE2\t11\t17\t1e-20\t30\t90.2\n") sbjF.write("2\tchr1\t3501\t4000\tTE3\t11\t17\t1e-20\t30\t90.2\n") sbjF.close() sbjTable = "dummySbjTable_%s" % ( self._uniqId ) self._db.create_table( self._db, sbjTable, sbjFileName, "path" ) expFileName = "dummyOutFileExp_%s" % ( self._uniqId ) expF = open( expFileName, "w" ) expF.write("1\tTE2\t1400\t1:TE2\t1\t248300\t1100\t0.785714\t0.004430\n") expF.close() obsFileName = "dummyOutFileObs_%s" % ( self._uniqId ) obsF = open( obsFileName, "w" ) srptTableOverlap.pathOverlapByPath( qryTable, "path", sbjTable, "path", self._db, obsF ) obsF.close() self.assertTrue( FileUtils.are2FilesIdentical( obsFileName, expFileName ) ) for f in [ qryFileName, sbjFileName, expFileName, obsFileName ]: os.remove( f ) self._db.remove_if_exist( qryTable ) self._db.remove_if_exist( sbjTable ) self._db.remove_if_exist( sbjTable+"_bin" ) if __name__ == "__main__": unittest.main()