Mercurial > repos > yufei-luo > s_mart
view commons/tools/tests/Test_F_GameXmlMaker.py @ 18:94ab73e8a190
Uploaded
author | m-zytnicki |
---|---|
date | Mon, 29 Apr 2013 03:20:15 -0400 |
parents | |
children |
line wrap: on
line source
import unittest import os import glob from commons.core.utils.FileUtils import FileUtils from commons.core.sql.DbFactory import DbFactory from commons.tools.GameXmlMaker import GameXmlMaker class Test_F_GameXmlMaker(unittest.TestCase): def setUp(self): pass def tearDown(self): FileUtils.removeFilesByPattern("*gamexml") def test_run_as_script_step1(self): fastaFileName = "input.fa" self._writeFastaFile(fastaFileName) cmd = "GameXmlMaker.py -f %s " % fastaFileName os.system(cmd) lObsGameXmlNew = glob.glob("*.gamexml") self._writeStep1ExpectedXmls() self.assertTrue(len(lObsGameXmlNew) > 0) for obsGameXmlNew in lObsGameXmlNew: expGameXmlNew = "exp_%s" % obsGameXmlNew self.assertTrue(FileUtils.are2FilesIdentical(expGameXmlNew,obsGameXmlNew)) os.remove(fastaFileName) def test_run_as_script_step2(self): self._tableFileName = "annotation_tables.txt" self._writeStep2InputTableFile() self._writeStep2InputXmls() self._writeStep2InputPathFile() self._writeStep2InputSetFile() self._writeStep2InputMapFile() self._createStep2Tables() lObsGameXmlNew = glob.glob("*.gamexml") cmd = "GameXmlMaker.py -t %s " % self._tableFileName os.system(cmd) self._writeStep2ExpXmls() self.assertTrue(len(lObsGameXmlNew) > 0) for obsGameXmlNew in lObsGameXmlNew: expGameXmlNew = "exp_%s" % obsGameXmlNew self.assertTrue(FileUtils.are2FilesIdentical(expGameXmlNew,obsGameXmlNew)) os.remove("Test_F_GameXmlMaker_path.path") os.remove("Test_F_GameXmlMaker_set.set") os.remove("Test_F_GameXmlMaker_chk_map.map") os.remove(self._tableFileName) os.system("ListAndDropTables.py -d Test_F_GameXmlMaker") def test_run_step2(self): self._tableFileName = "annotation_tables.txt" self._writeStep2InputTableFile() self._writeStep2InputXmls() self._writeStep2InputPathFile() self._writeStep2InputSetFile() self._writeStep2InputMapFile() self._createStep2Tables() lObsGameXmlNew = glob.glob("*.gamexml") iGameXmlMaker = GameXmlMaker(tablesFileName = self._tableFileName) iGameXmlMaker.run() self._writeStep2ExpXmls() self.assertTrue(len(lObsGameXmlNew) > 0) for obsGameXmlNew in lObsGameXmlNew: expGameXmlNew = "exp_%s" % obsGameXmlNew self.assertTrue(FileUtils.are2FilesIdentical(expGameXmlNew,obsGameXmlNew)) os.remove("Test_F_GameXmlMaker_path.path") os.remove("Test_F_GameXmlMaker_set.set") os.remove("Test_F_GameXmlMaker_chk_map.map") os.remove(self._tableFileName) os.system("ListAndDropTables.py -d Test_F_GameXmlMaker") def _writeFastaFile(self, inFileName): f = open(inFileName,'w') f.write('>seq1\n') f.write('TGTTCATATTCATAGGATGGAGCTAGTAAGCGATGTCGGCTTAGCTCATCCACATGAATG\n') f.write('CAGGAATCATGAAGGGTACGACTGTTCGTCGATTAAAGAGCTACACGAGCTGGGTTAAAT\n') f.write('CAGGAATCATGAAGGGTACGACTGTTCGTCGATTAAAGAGCTACA\n') f.write('>seq2\n') f.write('TGTTCATATTCATAGGATGGAGCTAGTAAGCGATGTCGGCTTAGCTCATCCACATGAATG\n') f.write('CAGGAATCATGAAGGGTACGACTGTTCGTCGATTAAAGAGCTACACGAGCTGGGTTAAAT\n') f.write('CAGGAATCATGAAGGGTACGACTGTTCGTCGATTAAAGAGCTACACGAGCTGGGTTAAAT\n') f.write('>seq3\n') f.write('CCTAGACAATTAATTATAATAATTAATAAACTATTAGGCTAGTAGTAGGTAATAATAAAA\n') f.write('GGATTACTACTAAGCTGCGCTATGTAGATATTTAAAACATGTGGCTTAGGCAAGAGTATA\n') f.write('>seq4\n') f.write('TGTTCATATTCATAGGATGGAGCTAGTAAGCGATGTCGGCTTAGCTCATCCACATGAATG\n') f.write('CAGGAATCATGAAGGGTACGACTGTTCG\n') f.close() def _writeStep1ExpectedXmls(self): f = open("exp_seq1.gamexml", 'w') f.write('<?xml version="1.0" ?><game><seq focus="true" id="seq1"><name>seq1</name>') f.write('<residues>TGTTCATATTCATAGGATGGAGCTAGTAAGCGATGTCGGCTTAGCTCATCCACATGAATGCAGGAATCATGAAGGGTACGACTGTTCGTCGATTAAAGAGCTACACGAGCTGGGTTAAATCAGGAATCATGAAGGGTACGACTGTTCGTCGATTAAAGAGCTACA</residues>') f.write('</seq><map_position><arm>seq1</arm><span><start>1</start><end>165</end></span></map_position></game>') f.close() f = open("exp_seq2.gamexml", 'w') f.write('<?xml version="1.0" ?><game><seq focus="true" id="seq2"><name>seq2</name>') f.write('<residues>TGTTCATATTCATAGGATGGAGCTAGTAAGCGATGTCGGCTTAGCTCATCCACATGAATGCAGGAATCATGAAGGGTACGACTGTTCGTCGATTAAAGAGCTACACGAGCTGGGTTAAATCAGGAATCATGAAGGGTACGACTGTTCGTCGATTAAAGAGCTACACGAGCTGGGTTAAAT</residues>') f.write('</seq><map_position><arm>seq2</arm><span><start>1</start><end>180</end></span></map_position></game>') f.close() f = open("exp_seq3.gamexml", 'w') f.write('<?xml version="1.0" ?><game><seq focus="true" id="seq3"><name>seq3</name>') f.write('<residues>CCTAGACAATTAATTATAATAATTAATAAACTATTAGGCTAGTAGTAGGTAATAATAAAAGGATTACTACTAAGCTGCGCTATGTAGATATTTAAAACATGTGGCTTAGGCAAGAGTATA</residues>') f.write('</seq><map_position><arm>seq3</arm><span><start>1</start><end>120</end></span></map_position></game>') f.close() f = open("exp_seq4.gamexml", 'w') f.write('<?xml version="1.0" ?><game><seq focus="true" id="seq4"><name>seq4</name>') f.write('<residues>TGTTCATATTCATAGGATGGAGCTAGTAAGCGATGTCGGCTTAGCTCATCCACATGAATGCAGGAATCATGAAGGGTACGACTGTTCG</residues>') f.write('</seq><map_position><arm>seq4</arm><span><start>1</start><end>88</end></span></map_position></game>') f.close() def _createStep2Tables(self): iDb = DbFactory.createInstance() iDb.createTable("Test_F_GameXmlMaker_set", "set", "Test_F_GameXmlMaker_set.set", True) iDb.createTable("Test_F_GameXmlMaker_chk_map", "map", "Test_F_GameXmlMaker_chk_map.map", True) iDb.createTable("Test_F_GameXmlMaker_path", "path", "Test_F_GameXmlMaker_path.path", True) iDb.close() def _writeStep2InputXmls(self): f = open("seq1.gamexml", 'w') f.write('<?xml version="1.0" ?><game><seq focus="true" id="seq1"><name>seq1</name>') f.write('<residues>TGTTCATATTCATAGGATGGAGCTAGTAAGCGATGTCGGCTTAGCTCATCCACATGAATGCAGGAATCATGAAGGGTACGACTGTTCGTCGATTAAAGAGCTACACGAGCTGGGTTAAATCAGGAATCATGAAGGGTACGACTGTTCGTCGATTAAAGAGCTACA</residues>') f.write('</seq><map_position><arm>seq1</arm><span><start>1</start><end>165</end></span></map_position></game>') f.close() f = open("seq2.gamexml", 'w') f.write('<?xml version="1.0" ?><game><seq focus="true" id="seq2"><name>seq2</name>') f.write('<residues>TGTTCATATTCATAGGATGGAGCTAGTAAGCGATGTCGGCTTAGCTCATCCACATGAATGCAGGAATCATGAAGGGTACGACTGTTCGTCGATTAAAGAGCTACACGAGCTGGGTTAAATCAGGAATCATGAAGGGTACGACTGTTCGTCGATTAAAGAGCTACACGAGCTGGGTTAAAT</residues>') f.write('</seq><map_position><arm>seq2</arm><span><start>1</start><end>180</end></span></map_position></game>') f.close() f = open("seq3.gamexml", 'w') f.write('<?xml version="1.0" ?><game><seq focus="true" id="seq3"><name>seq3</name>') f.write('<residues>CCTAGACAATTAATTATAATAATTAATAAACTATTAGGCTAGTAGTAGGTAATAATAAAAGGATTACTACTAAGCTGCGCTATGTAGATATTTAAAACATGTGGCTTAGGCAAGAGTATA</residues>') f.write('</seq><map_position><arm>seq3</arm><span><start>1</start><end>120</end></span></map_position></game>') f.close() f = open("seq4.gamexml", 'w') f.write('<?xml version="1.0" ?><game><seq focus="true" id="seq4"><name>seq4</name>') f.write('<residues>TGTTCATATTCATAGGATGGAGCTAGTAAGCGATGTCGGCTTAGCTCATCCACATGAATGCAGGAATCATGAAGGGTACGACTGTTCG</residues>') f.write('</seq><map_position><arm>seq4</arm><span><start>1</start><end>88</end></span></map_position></game>') f.close() def _writeStep2InputPathFile(self): f = open("Test_F_GameXmlMaker_path.path", 'w') f.write("1\tseq1\t1\t10\tTE1\t1\t10\t0\t550\t80.7\n") f.write("2\tseq1\t15\t50\tTE1\t12\t47\t0\t770\t90.8\n") f.write("2\tseq1\t55\t70\tTE1\t50\t65\t0\t5410\t97.7\n") f.write("3\tseq1\t75\t80\tTE2\t10\t15\t0\t8710\t60.0\n") f.write("4\tseq2\t1\t10\tTE2\t20\t30\t0\t5410\t75.7\n") f.write("5\tseq3\t1\t120\tTE2\t450\t550\t0\t5410\t75.7\n") f.close() def _writeStep2InputSetFile(self): f = open("Test_F_GameXmlMaker_set.set", 'w') f.write("1\tseq1\tseq1\t1\t10\n") f.write("2\tseq1\tseq1\t15\t50\n") f.write("3\tseq1\tseq1\t75\t80\n") f.write("4\tseq2\tseq2\t1\t10\n") f.write("5\tseq3\tseq3\t1\t120\n") f.close() def _writeStep2InputMapFile(self): f = open("Test_F_GameXmlMaker_chk_map.map", 'w') f.write("chunk1\tseq1\t1\t200000\n") f.write("chunk2\tseq1\t190001\t390000\n") f.write("chunk3\tseq3\t380001\t580000\n") f.write("chunk4\tseq4\t570001\t770000\n") f.write("chunk5\tseq5\t760001\t960000\n") f.write("chunk6\tseq6\t950001\t1150000\n") f.write("chunk7\tseq7\t1140001\t1281640\n") f.close() def _writeStep2ExpXmls(self): f = open("exp_seq1.gamexml", 'w') f.write('<?xml version="1.0" ?><game><seq focus="true" id="seq1"><name>seq1</name>') f.write('<residues>TGTTCATATTCATAGGATGGAGCTAGTAAGCGATGTCGGCTTAGCTCATCCACATGAATGCAGGAATCATGAAGGGTACGACTGTTCGTCGATTAAAGAGCTACACGAGCTGGGTTAAATCAGGAATCATGAAGGGTACGACTGTTCGTCGATTAAAGAGCTACA</residues>') f.write('</seq><map_position><arm>seq1</arm><span><start>1</start><end>165</end></span></map_position>') f.write('<computational_analysis><program>Test_F_GameXmlMaker_path</program><database>db</database><result_set id="1"><name>TE1::1</name>') f.write('<result_span><seq_relationship seq="seq1" type="query"><span><start>1</start><end>10</end></span></seq_relationship><seq_relationship seq="TE1::1" type="subject"><span>') f.write('<start>1</start><end>10</end></span></seq_relationship><score>80.7</score></result_span></result_set><result_set id="2"><name>TE1::2</name><result_span>') f.write('<seq_relationship seq="seq1" type="query"><span><start>15</start><end>50</end></span></seq_relationship><seq_relationship seq="TE1::2" type="subject"><span><start>12</start>') f.write('<end>47</end></span></seq_relationship><score>90.8</score></result_span><result_span><seq_relationship seq="seq1" type="query"><span><start>55</start><end>70</end></span></seq_relationship>') f.write('<seq_relationship seq="TE1::2" type="subject"><span><start>50</start><end>65</end></span></seq_relationship><score>97.7</score></result_span></result_set><result_set id="3"><name>TE2::3</name>') f.write('<result_span><seq_relationship seq="seq1" type="query"><span><start>75</start><end>80</end></span></seq_relationship><seq_relationship seq="TE2::3" type="subject"><span><start>10</start><end>15</end></span></seq_relationship>') f.write('<score>60.0</score></result_span></result_set></computational_analysis>') f.write('<computational_analysis><program>Test_F_GameXmlMaker_set</program><database>db</database>') f.write('<result_set id="1"><name>seq1::1</name><result_span>') f.write('<seq_relationship seq="seq1" type="query"><span><start>1</start><end>10</end></span></seq_relationship>') f.write('<seq_relationship seq="seq1::1" type="subject"><span><start>-1</start><end>-1</end></span></seq_relationship>') f.write('<score>0</score></result_span></result_set>') f.write('<result_set id="2"><name>seq1::2</name><result_span>') f.write('<seq_relationship seq="seq1" type="query"><span><start>15</start><end>50</end></span></seq_relationship>') f.write('<seq_relationship seq="seq1::2" type="subject"><span><start>-1</start><end>-1</end></span></seq_relationship>') f.write('<score>0</score></result_span></result_set>') f.write('<result_set id="3"><name>seq1::3</name><result_span>') f.write('<seq_relationship seq="seq1" type="query"><span><start>75</start><end>80</end></span></seq_relationship>') f.write('<seq_relationship seq="seq1::3" type="subject"><span><start>-1</start><end>-1</end></span></seq_relationship>') f.write('<score>0</score></result_span></result_set></computational_analysis>') f.write('<computational_analysis><program>Test_F_GameXmlMaker_chk_map</program><database>db</database>') f.write('<result_set id="-1"><name>chunk1::-1</name>') f.write('<result_span><seq_relationship seq="seq1" type="query"><span><start>1</start><end>200000</end></span></seq_relationship>') f.write('<seq_relationship seq="chunk1::-1" type="subject"><span><start>-1</start><end>-1</end></span></seq_relationship>') f.write('<score>0</score></result_span></result_set>') f.write('<result_set id="-1"><name>chunk2::-1</name>') f.write('<result_span><seq_relationship seq="seq1" type="query"><span><start>190001</start><end>390000</end></span></seq_relationship>') f.write('<seq_relationship seq="chunk2::-1" type="subject"><span><start>-1</start><end>-1</end></span></seq_relationship><score>0</score></result_span></result_set></computational_analysis></game>') f.close() f = open("exp_seq2.gamexml", 'w') f.write('<?xml version="1.0" ?><game><seq focus="true" id="seq2"><name>seq2</name>') f.write('<residues>TGTTCATATTCATAGGATGGAGCTAGTAAGCGATGTCGGCTTAGCTCATCCACATGAATGCAGGAATCATGAAGGGTACGACTGTTCGTCGATTAAAGAGCTACACGAGCTGGGTTAAATCAGGAATCATGAAGGGTACGACTGTTCGTCGATTAAAGAGCTACACGAGCTGGGTTAAAT</residues>') f.write('</seq><map_position><arm>seq2</arm><span><start>1</start><end>180</end></span></map_position>') f.write('<computational_analysis><program>Test_F_GameXmlMaker_path</program><database>db</database><result_set id="4"><name>TE2::4</name>') f.write('<result_span><seq_relationship seq="seq2" type="query"><span><start>1</start><end>10</end></span>') f.write('</seq_relationship><seq_relationship seq="TE2::4" type="subject"><span><start>20</start><end>30</end></span></seq_relationship>') f.write('<score>75.7</score></result_span></result_set></computational_analysis>') f.write('<computational_analysis><program>Test_F_GameXmlMaker_set</program><database>db</database><result_set id="4"><name>seq2::4</name>') f.write('<result_span><seq_relationship seq="seq2" type="query"><span><start>1</start><end>10</end></span></seq_relationship>') f.write('<seq_relationship seq="seq2::4" type="subject"><span><start>-1</start><end>-1</end></span></seq_relationship>') f.write('<score>0</score></result_span></result_set></computational_analysis>') f.write('<computational_analysis><program>Test_F_GameXmlMaker_chk_map</program><database>db</database></computational_analysis></game>') f.close() f = open("exp_seq3.gamexml", 'w') f.write('<?xml version="1.0" ?><game><seq focus="true" id="seq3"><name>seq3</name>') f.write('<residues>CCTAGACAATTAATTATAATAATTAATAAACTATTAGGCTAGTAGTAGGTAATAATAAAAGGATTACTACTAAGCTGCGCTATGTAGATATTTAAAACATGTGGCTTAGGCAAGAGTATA</residues>') f.write('</seq><map_position><arm>seq3</arm><span><start>1</start><end>120</end></span></map_position>') f.write('<computational_analysis><program>Test_F_GameXmlMaker_path</program><database>db</database><result_set id="5"><name>TE2::5</name>') f.write('<result_span><seq_relationship seq="seq3" type="query"><span><start>1</start><end>120</end></span>') f.write('</seq_relationship><seq_relationship seq="TE2::5" type="subject"><span><start>450</start><end>550</end></span></seq_relationship>') f.write('<score>75.7</score></result_span></result_set></computational_analysis>') f.write('<computational_analysis><program>Test_F_GameXmlMaker_set</program><database>db</database><result_set id="5"><name>seq3::5</name>') f.write('<result_span><seq_relationship seq="seq3" type="query"><span><start>1</start><end>120</end></span></seq_relationship>') f.write('<seq_relationship seq="seq3::5" type="subject"><span><start>-1</start><end>-1</end></span></seq_relationship>') f.write('<score>0</score></result_span></result_set></computational_analysis>') f.write('<computational_analysis><program>Test_F_GameXmlMaker_chk_map</program><database>db</database>') f.write('<result_set id="-1"><name>chunk3::-1</name>') f.write('<result_span><seq_relationship seq="seq3" type="query"><span><start>380001</start><end>580000</end></span></seq_relationship>') f.write('<seq_relationship seq="chunk3::-1" type="subject"><span><start>-1</start><end>-1</end></span></seq_relationship>') f.write('<score>0</score></result_span></result_set></computational_analysis></game>') f.close() f = open("exp_seq4.gamexml", 'w') f.write('<?xml version="1.0" ?><game><seq focus="true" id="seq4"><name>seq4</name>') f.write('<residues>TGTTCATATTCATAGGATGGAGCTAGTAAGCGATGTCGGCTTAGCTCATCCACATGAATGCAGGAATCATGAAGGGTACGACTGTTCG</residues>') f.write('</seq><map_position><arm>seq4</arm><span><start>1</start><end>88</end></span></map_position>') f.write('<computational_analysis><program>Test_F_GameXmlMaker_path</program><database>db</database></computational_analysis>') f.write('<computational_analysis><program>Test_F_GameXmlMaker_set</program><database>db</database></computational_analysis>') f.write('<computational_analysis><program>Test_F_GameXmlMaker_chk_map</program><database>db</database>') f.write('<result_set id="-1"><name>chunk4::-1</name>') f.write('<result_span><seq_relationship seq="seq4" type="query"><span><start>570001</start><end>770000</end></span></seq_relationship>') f.write('<seq_relationship seq="chunk4::-1" type="subject"><span><start>-1</start><end>-1</end></span></seq_relationship>') f.write('<score>0</score></result_span></result_set></computational_analysis></game>') f.close() def _writeStep2InputTableFile(self): f = open(self._tableFileName,'w') f.write("Test_F_GameXmlMaker_path\tpath\tTest_F_GameXmlMaker_path\n") f.write("Test_F_GameXmlMaker_set\tset\tTest_F_GameXmlMaker_set\n") f.write("Test_F_GameXmlMaker_chk_map\tmap\tTest_F_GameXmlMaker_chk_map") f.close() if __name__ == "__main__": unittest.main()