Mercurial > repos > yufei-luo > s_mart
comparison commons/tools/tests/Test_GetSpecificTELibAccordingToAnnotation.py @ 31:0ab839023fe4
Uploaded
| author | m-zytnicki |
|---|---|
| date | Tue, 30 Apr 2013 14:33:21 -0400 |
| parents | 94ab73e8a190 |
| children |
comparison
equal
deleted
inserted
replaced
| 30:5677346472b5 | 31:0ab839023fe4 |
|---|---|
| 1 import os | |
| 2 import unittest | |
| 3 from commons.core.utils.FileUtils import FileUtils | |
| 4 from commons.core.sql.DbMySql import DbMySql | |
| 5 from commons.tools.GetSpecificTELibAccordingToAnnotation import GetSpecificTELibAccordingToAnnotation | |
| 6 | |
| 7 class Test_GetSpecificTELibAccordingToAnnotation(unittest.TestCase): | |
| 8 | |
| 9 def test_writeFastaFileFromGiveInfoTEAnnot(self): | |
| 10 self._iDb = DbMySql() | |
| 11 fileName = "GiveInfoTEannot.txt" | |
| 12 self._writeGiveInfoTEannotOutput(fileName) | |
| 13 tableName = "projectName_refTEs_chr_seq" | |
| 14 self._createConsensusTable(tableName) | |
| 15 expFileName = "consensusExp.fa" | |
| 16 self._writeExpConsensusFile(expFileName) | |
| 17 obsFileName = "%s.fa" % os.path.splitext(fileName)[0] | |
| 18 iGetTElib = GetSpecificTELibAccordingToAnnotation() | |
| 19 iGetTElib.setTableName(tableName) | |
| 20 iGetTElib.writeFastaFileFromGiveInfoTEAnnot(fileName) | |
| 21 self._iDb.dropTable(tableName) | |
| 22 self._iDb.close() | |
| 23 self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName)) | |
| 24 os.remove(fileName) | |
| 25 os.remove(expFileName) | |
| 26 os.remove(obsFileName) | |
| 27 | |
| 28 def _writeGiveInfoTEannotOutput(self, fileName): | |
| 29 f = open(fileName, "w") | |
| 30 f.write("TE\tmaxLength\tmeanLength\tcovg\tfrags\tfullLgthFrags\tcopies\tfullLgthCopies\tmeanId\tsdId\tminId\tq25Id\tmedId\tq75Id\tmaxId\tmeanLgth\tsdLgth\tminLgth\tq25Lgth\tmedLgth\tq75Lgth\tmaxLgth\tmeanLgthPerc\tsdLgthPerc\tminLgthPerc\tq25LgthPerc\tmedLgthPerc\tq75LgthPerc\tmaxLgthPerc\n") | |
| 31 f.write("Atha_benchs-B-P66.38-Map20_classII-Helitron-incomp\t2150\t2150\t195657\t158\t49\t152\t52\t84.88\t8.75\t74.29\t77.16\t80.08\t96.40\t97.83\t1287.32\t776.47\t21\t570.00\t1320.50\t2077.00\t2272\t59.88\t36.11\t0.98\t26.51\t61.42\t96.60\t105.67\n") | |
| 32 f.write("Atha_benchs-B-R1047-Map6_classI-LINE-comp\t1653\t1653\t25423\t57\t4\t56\t4\t79.09\t8.21\t64.32\t73.63\t79.21\t83.65\t96.65\t453.98\t488.66\t29\t98.00\t244.00\t634.00\t1650\t27.46\t29.56\t1.75\t5.93\t14.76\t38.35\t99.82\n") | |
| 33 f.write("Atha_benchs-B-R1276-Map4_classII-Helitron-incomp\t1293\t1293\t24416\t48\t4\t47\t4\t80.31\t5.74\t75.14\t77.00\t78.25\t80.89\t99.46\t519.60\t419.01\t37\t171.00\t334.00\t838.00\t1296\t40.19\t32.41\t2.86\t13.23\t25.83\t64.81\t100.23\n") | |
| 34 f.close() | |
| 35 | |
| 36 def _createConsensusTable(self, tableName): | |
| 37 fileName = "consensus.fa" | |
| 38 f = open(fileName, "w") | |
| 39 f.write(">Atha_benchs-B-P66.38-Map20_classII-Helitron-incomp\n") | |
| 40 f.write("ATGCTAGCTAGCT\n") | |
| 41 f.write(">Atha_benchs-B-R12-Map5_classII-Helitron-comp\n") | |
| 42 f.write("ATGCTAGCTAGCTATGCTAGCTAGCATGCTAGCTAGCTT\n") | |
| 43 f.write(">Atha_benchs-B-R1047-Map6_classI-LINE-comp\n") | |
| 44 f.write("ATGCTAGCTAGCT\n") | |
| 45 f.write(">Atha_benchs-B-G56-Map5_classII-Helitron-comp\n") | |
| 46 f.write("ATGCTAGCTAGCTATGCTAGCTAGCT\n") | |
| 47 f.write(">Atha_benchs-B-R1276-Map4_classII-Helitron-incomp\n") | |
| 48 f.write("ATGCTAGCTAGCATGCTAGCTAGCTATGCTAGCTAGCTATGCTAGCTAGCTT\n") | |
| 49 f.close() | |
| 50 self._iDb.createTable(tableName, "seq", fileName, True) | |
| 51 os.remove(fileName) | |
| 52 | |
| 53 def _writeExpConsensusFile(self, fileName): | |
| 54 f = open(fileName, "w") | |
| 55 f.write(">Atha_benchs-B-P66.38-Map20_classII-Helitron-incomp\n") | |
| 56 f.write("ATGCTAGCTAGCT\n") | |
| 57 f.write(">Atha_benchs-B-R1047-Map6_classI-LINE-comp\n") | |
| 58 f.write("ATGCTAGCTAGCT\n") | |
| 59 f.write(">Atha_benchs-B-R1276-Map4_classII-Helitron-incomp\n") | |
| 60 f.write("ATGCTAGCTAGCATGCTAGCTAGCTATGCTAGCTAGCTATGCTAGCTAGCTT\n") | |
| 61 f.close() | |
| 62 | |
| 63 if __name__ == "__main__": | |
| 64 unittest.main() |
