view smart_toolShed/commons/core/writer/test/Test_MapWriter.py @ 0:e0f8dcca02ed

Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
author yufei-luo
date Thu, 17 Jan 2013 10:52:14 -0500
parents
children
line wrap: on
line source

from SMART.Java.Python.structure.Transcript import Transcript
from SMART.Java.Python.structure.Interval import Interval
import unittest
import os
from SMART.Java.Python.misc import Utils
from commons.core.writer.MapWriter import MapWriter
from commons.core.utils.FileUtils import FileUtils

class Test_MapWriter(unittest.TestCase):
    
    def setUp(self):
        self.expFileName = "expMapWriter.map"
        self.obsFileName = "testMapWriter1.map"
        
    def tearDown(self):
        os.remove(self.expFileName)
        os.remove(self.obsFileName)
        
    def test_writer(self):
        self.write_ExpMapFileName()
        writer = MapWriter(self.obsFileName)
        
        transcript = Transcript()
        transcript.setName("test1.1")
        transcript.setChromosome("arm_X")
        transcript.setStart(1000)
        transcript.setEnd(4000)
        transcript.setDirection("+")
        transcript.setTagValue("ID", "test1.1-1")
        transcript.setTagValue("occurrence", 1)
        transcript.setTagValue("nbOccurrences", 2)
        
        exon1 = Interval()
        exon1.setChromosome("arm_X")
        exon1.setStart(1000)
        exon1.setEnd(2000)
        exon1.setDirection("+")
        
        exon2 = Interval()
        exon2.setChromosome("arm_X")
        exon2.setStart(3000)
        exon2.setEnd(4000)
        exon2.setDirection("+")
        
        transcript.addExon(exon1)
        transcript.addExon(exon2)
        
        writer.addTranscript(transcript)
        writer.write()
        writer.close()
        
        self.assertTrue(FileUtils.are2FilesIdentical(self.expFileName, self.obsFileName))
        

    def write_ExpMapFileName(self):
        f = open(self.expFileName, "w")
        f.write("test1.1\tarm_X\t1000\t4001\n")
        f.close()

if __name__ == '__main__':
    unittest.main()