Mercurial > repos > yufei-luo > s_mart
comparison commons/core/writer/test/Test_Gff3Writer.py @ 6:769e306b7933
Change the repository level.
author | yufei-luo |
---|---|
date | Fri, 18 Jan 2013 04:54:14 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
5:ea3082881bf8 | 6:769e306b7933 |
---|---|
1 from commons.core.writer.Gff3Writer import Gff3Writer | |
2 from SMART.Java.Python.structure.Transcript import Transcript | |
3 from SMART.Java.Python.structure.Interval import Interval | |
4 import unittest | |
5 import os | |
6 from SMART.Java.Python.misc import Utils | |
7 | |
8 class Test_Gff3Writer(unittest.TestCase): | |
9 | |
10 def test_writer(self): | |
11 obsFileName = "testGffWriter1.gff3" | |
12 writer = Gff3Writer(obsFileName) | |
13 | |
14 transcript = Transcript() | |
15 transcript.setName("test1.1") | |
16 transcript.setChromosome("arm_X") | |
17 transcript.setStart(1000) | |
18 transcript.setEnd(4000) | |
19 transcript.setDirection("+") | |
20 transcript.setTagValue("ID", "test1.1-1") | |
21 transcript.setTagValue("occurrence", 1) | |
22 transcript.setTagValue("nbOccurrences", 2) | |
23 | |
24 exon1 = Interval() | |
25 exon1.setChromosome("arm_X") | |
26 exon1.setStart(1000) | |
27 exon1.setEnd(2000) | |
28 exon1.setDirection("+") | |
29 | |
30 exon2 = Interval() | |
31 exon2.setChromosome("arm_X") | |
32 exon2.setStart(3000) | |
33 exon2.setEnd(4000) | |
34 exon2.setDirection("+") | |
35 | |
36 transcript.addExon(exon1) | |
37 transcript.addExon(exon2) | |
38 | |
39 writer.addTranscript(transcript) | |
40 writer.write() | |
41 writer.close() | |
42 | |
43 expFileName = "expFile.gff3" | |
44 f = open(expFileName, "w") | |
45 f.write("arm_X\tS-MART\ttranscript\t1000\t4000\t.\t+\t.\tnbOccurrences=2;ID=test1.1-1;occurrence=1;Name=test1.1\n") | |
46 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") | |
47 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") | |
48 f.close() | |
49 | |
50 self.assertTrue(Utils.diff(expFileName, obsFileName)) | |
51 | |
52 os.remove(expFileName) | |
53 os.remove(obsFileName) | |
54 | |
55 def test_writerAltNames(self): | |
56 obsFileName = "testGffWriter1.gff3" | |
57 writer = Gff3Writer(obsFileName,title="ALTSOURCE", feature="Match", featurePart="Match-Part") | |
58 | |
59 transcript = Transcript() | |
60 transcript.setName("test1.1") | |
61 transcript.setChromosome("arm_X") | |
62 transcript.setStart(1000) | |
63 transcript.setEnd(4000) | |
64 transcript.setDirection("+") | |
65 transcript.setTagValue("ID", "test1.1-1") | |
66 transcript.setTagValue("occurrence", 1) | |
67 transcript.setTagValue("nbOccurrences", 2) | |
68 | |
69 exon1 = Interval() | |
70 exon1.setChromosome("arm_X") | |
71 exon1.setStart(1000) | |
72 exon1.setEnd(2000) | |
73 exon1.setDirection("+") | |
74 | |
75 exon2 = Interval() | |
76 exon2.setChromosome("arm_X") | |
77 exon2.setStart(3000) | |
78 exon2.setEnd(4000) | |
79 exon2.setDirection("+") | |
80 | |
81 transcript.addExon(exon1) | |
82 transcript.addExon(exon2) | |
83 | |
84 writer.addTranscript(transcript) | |
85 writer.write() | |
86 writer.close() | |
87 | |
88 expFileName = "expFile.gff3" | |
89 f = open(expFileName, "w") | |
90 f.write("arm_X\tALTSOURCE\tMatch\t1000\t4000\t.\t+\t.\tnbOccurrences=2;ID=test1.1-1;occurrence=1;Name=test1.1\n") | |
91 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") | |
92 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") | |
93 f.close() | |
94 | |
95 self.assertTrue(Utils.diff(expFileName, obsFileName)) | |
96 | |
97 os.remove(expFileName) | |
98 os.remove(obsFileName) | |
99 | |
100 if __name__ == '__main__': | |
101 unittest.main() |