view commons/core/writer/test/Test_Gff3Writer.py @ 31:0ab839023fe4

Uploaded
author m-zytnicki
date Tue, 30 Apr 2013 14:33:21 -0400
parents 769e306b7933
children
line wrap: on
line source

from commons.core.writer.Gff3Writer import Gff3Writer
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

class Test_Gff3Writer(unittest.TestCase):
  
    def test_writer(self):
        obsFileName = "testGffWriter1.gff3"
        writer = Gff3Writer(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()
        
        expFileName = "expFile.gff3"
        f = open(expFileName, "w")
        f.write("arm_X\tS-MART\ttranscript\t1000\t4000\t.\t+\t.\tnbOccurrences=2;ID=test1.1-1;occurrence=1;Name=test1.1\n")
        f.write("arm_X\tS-MART\texon\t1000\t2000\t.\t+\t.\tID=test1.1-1-exon1;Name=test1.1-exon1;Parent=test1.1-1\n")
        f.write("arm_X\tS-MART\texon\t3000\t4000\t.\t+\t.\tID=test1.1-1-exon2;Name=test1.1-exon2;Parent=test1.1-1\n")
        f.close()
        
        self.assertTrue(Utils.diff(expFileName, obsFileName))
        
        os.remove(expFileName)
        os.remove(obsFileName)
        
    def test_writerAltNames(self):
        obsFileName = "testGffWriter1.gff3"
        writer = Gff3Writer(obsFileName,title="ALTSOURCE", feature="Match", featurePart="Match-Part")
        
        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()
        
        expFileName = "expFile.gff3"
        f = open(expFileName, "w")
        f.write("arm_X\tALTSOURCE\tMatch\t1000\t4000\t.\t+\t.\tnbOccurrences=2;ID=test1.1-1;occurrence=1;Name=test1.1\n")
        f.write("arm_X\tALTSOURCE\tMatch-Part\t1000\t2000\t.\t+\t.\tID=test1.1-1-Match-Part1;Name=test1.1-Match-Part1;Parent=test1.1-1\n")
        f.write("arm_X\tALTSOURCE\tMatch-Part\t3000\t4000\t.\t+\t.\tID=test1.1-1-Match-Part2;Name=test1.1-Match-Part2;Parent=test1.1-1\n")
        f.close()
        
        self.assertTrue(Utils.diff(expFileName, obsFileName))
        
        os.remove(expFileName)
        os.remove(obsFileName)

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