annotate SMART/Java/Python/CountLoci.py @ 18:94ab73e8a190

Uploaded
author m-zytnicki
date Mon, 29 Apr 2013 03:20:15 -0400
parents
children 0ab839023fe4 169d364ddd91
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
1 #! /usr/bin/env python
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
2 #
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
3 # Copyright INRA-URGI 2009-2012
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
4 #
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
5 # This software is governed by the CeCILL license under French law and
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
6 # abiding by the rules of distribution of free software. You can use,
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
7 # modify and/ or redistribute the software under the terms of the CeCILL
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
8 # license as circulated by CEA, CNRS and INRIA at the following URL
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
9 # "http://www.cecill.info".
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
10 #
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
11 # As a counterpart to the access to the source code and rights to copy,
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
12 # modify and redistribute granted by the license, users are provided only
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
13 # with a limited warranty and the software's author, the holder of the
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
14 # economic rights, and the successive licensors have only limited
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
15 # liability.
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
16 #
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
17 # In this respect, the user's attention is drawn to the risks associated
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
18 # with loading, using, modifying and/or developing or reproducing the
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
19 # software by the user in light of its specific status of free software,
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
20 # that may mean that it is complicated to manipulate, and that also
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
21 # therefore means that it is reserved for developers and experienced
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
22 # professionals having in-depth computer knowledge. Users are therefore
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
23 # encouraged to load and test the software's suitability as regards their
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
24 # requirements in conditions enabling the security of their systems and/or
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
25 # data to be ensured and, more generally, to use and operate it in the
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
26 # same conditions as regards security.
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
27 #
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
28 # The fact that you are presently reading this means that you have had
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
29 # knowledge of the CeCILL license and that you accept its terms.
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
30 #
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
31 import os, os.path, random
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
32 from optparse import OptionParser
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
33 from SMART.Java.Python.structure.TranscriptContainer import TranscriptContainer
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
34 from commons.core.parsing.GffParser import GffParser
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
35 from commons.core.writer.Gff3Writer import Gff3Writer
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
36 from commons.core.writer.TranscriptWriter import TranscriptWriter
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
37 from SMART.Java.Python.misc.Progress import Progress
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
38 from SMART.Java.Python.misc.RPlotter import RPlotter
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
39 from SMART.Java.Python.cleanGff import CleanGff
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
40 from SMART.Java.Python.CompareOverlappingSmallRef import CompareOverlappingSmallRef
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
41 from SMART.Java.Python.structure.TranscriptListsComparator import TranscriptListsComparator
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
42 from SMART.Java.Python.GetUpDownStream import GetUpDownStream
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
43
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
44 REFERENCE = 0
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
45 QUERY = 1
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
46
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
47 class CountLoci(object):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
48
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
49 def __init__(self, verbosity = 1):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
50 self.verbosity = verbosity
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
51 self.tmpFileNames = []
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
52
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
53 def __del__(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
54 for fileName in self.tmpFileNames:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
55 if os.path.exists(fileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
56 os.remove(fileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
57
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
58 def setInputFile(self, fileName, format):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
59 self.inputFileName = fileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
60 self.inputFormat = format
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
61 self.parser = TranscriptContainer(fileName, format, self.verbosity-1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
62 if self.verbosity > 0:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
63 print "%d elements in input" % (self.parser.getNbTranscripts())
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
64
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
65 def setReference(self, fileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
66 self.referenceFileName = fileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
67
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
68 def setDistance(self, distance):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
69 self.distance = distance
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
70
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
71 def setOutputFileName(self, fileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
72 self.outputFileName = fileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
73 self.writer = Gff3Writer(fileName, self.verbosity-1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
74 self.outputBase = "%s_%d_" % (os.path.splitext(fileName)[0], random.randint(0, 10000))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
75
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
76 def _writeTmpRef(self, tags, outputFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
77 cleanGff = CleanGff(self.verbosity-1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
78 cleanGff.setInputFileName(self.referenceFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
79 cleanGff.setOutputFileName(outputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
80 cleanGff.setAcceptedTypes(tags)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
81 cleanGff.run()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
82
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
83 def _getReferenceFiles(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
84 self.referenceFiles = {"CDS": "%scds.gff3" % (self.outputBase), \
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
85 "five_prime_UTR": "%sfive.gff3" % (self.outputBase), \
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
86 "three_prime_UTR": "%sthree.gff3" % (self.outputBase), \
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
87 "mRNA": "%smrna.gff3" % (self.outputBase), \
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
88 "ncRNA": "%sncRNA.gff3" % (self.outputBase), \
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
89 "transposable_element_gene": "%sTE.gff3" % (self.outputBase), \
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
90 "vic": "%svicinity.gff3" % (self.outputBase)}
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
91 self.tmpFileNames.extend(self.referenceFiles.values())
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
92 for tag, fileName in self.referenceFiles.iteritems():
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
93 if tag == "ncRNA":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
94 self._writeTmpRef(["miRNA", "ncRNA", "rRNA", "snoRNA", "snRNA", "tRNA"], fileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
95 elif tag == "vic":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
96 continue
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
97 else:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
98 self._writeTmpRef([tag], fileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
99
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
100 def _compare(self, queryFileName, queryFormat, referenceFileName, referenceFormat, outputFileName, exclusion = False):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
101 co = CompareOverlappingSmallRef(self.verbosity-1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
102 co.setQueryFile(queryFileName, queryFormat)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
103 co.setReferenceFile(referenceFileName, referenceFormat)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
104 co.setOutputFile(outputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
105 if exclusion:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
106 co.setInvert(True)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
107 co.run()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
108 return co.nbWritten
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
109
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
110 def _copy(self, inputFile, tag):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
111 parser = GffParser(inputFile, self.verbosity-1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
112 for transcript in parser.getIterator():
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
113 transcript.setTagValue("locus", tag)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
114 self.writer.addTranscript(transcript)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
115
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
116 def _getCds(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
117 outputFileName = "%sin_cds.gff3" % (self.outputBase)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
118 outputNoFileName = "%sin_nocds.gff3" % (self.outputBase)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
119 self.tmpFileNames.extend([outputFileName, outputNoFileName])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
120 nbOverlaps = self._compare(self.inputFileName, self.inputFormat, self.referenceFiles["CDS"], "gff3", outputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
121 self._compare(self.inputFileName, self.inputFormat, self.referenceFiles["CDS"], "gff3", outputNoFileName, True)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
122 self._copy(outputFileName, "CDS")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
123 if self.verbosity > 0:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
124 print "%d overlaps in CDS" % (nbOverlaps)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
125 return outputNoFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
126
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
127 def _getFivePrime(self, inputFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
128 outputFileName = "%sin_five.gff3" % (self.outputBase)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
129 outputNoFileName = "%sin_nofive.gff3" % (self.outputBase)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
130 self.tmpFileNames.extend([outputFileName, outputNoFileName])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
131 nbOverlaps = self._compare(inputFileName, "gff3", self.referenceFiles["five_prime_UTR"], "gff3", outputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
132 self._compare(inputFileName, "gff3", self.referenceFiles["five_prime_UTR"], "gff3", outputNoFileName, True)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
133 self._copy(outputFileName, "five_prime_UTR")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
134 if self.verbosity > 0:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
135 print "%d overlaps in 5' UTR" % (nbOverlaps)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
136 return outputNoFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
137
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
138 def _getThreePrime(self, inputFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
139 outputFileName = "%sin_three.gff3" % (self.outputBase)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
140 outputNoFileName = "%sin_nothree.gff3" % (self.outputBase)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
141 self.tmpFileNames.extend([outputFileName, outputNoFileName])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
142 nbOverlaps = self._compare(inputFileName, "gff3", self.referenceFiles["three_prime_UTR"], "gff3", outputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
143 self._compare(inputFileName, "gff3", self.referenceFiles["three_prime_UTR"], "gff3", outputNoFileName, True)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
144 self._copy(outputFileName, "three_prime_UTR")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
145 if self.verbosity > 0:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
146 print "%d overlaps in 3' UTR" % (nbOverlaps)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
147 return outputNoFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
148
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
149 def _getNcRna(self, inputFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
150 outputFileName = "%sin_ncRna.gff3" % (self.outputBase)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
151 outputNoFileName = "%sin_noNcRna.gff3" % (self.outputBase)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
152 self.tmpFileNames.extend([outputFileName, outputNoFileName])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
153 nbOverlaps = self._compare(inputFileName, "gff3", self.referenceFiles["ncRNA"], "gff3", outputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
154 self._compare(inputFileName, "gff3", self.referenceFiles["ncRNA"], "gff3", outputNoFileName, True)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
155 self._copy(outputFileName, "ncRNA")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
156 if self.verbosity > 0:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
157 print "%d overlaps in ncRNA" % (nbOverlaps)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
158 return outputNoFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
159
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
160 def _getTe(self, inputFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
161 outputFileName = "%sin_te.gff3" % (self.outputBase)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
162 outputNoFileName = "%sin_noTe.gff3" % (self.outputBase)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
163 self.tmpFileNames.extend([outputFileName, outputNoFileName])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
164 nbOverlaps = self._compare(inputFileName, "gff3", self.referenceFiles["transposable_element_gene"], "gff3", outputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
165 self._compare(inputFileName, "gff3", self.referenceFiles["transposable_element_gene"], "gff3", outputNoFileName, True)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
166 self._copy(outputFileName, "TE")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
167 if self.verbosity > 0:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
168 print "%d overlaps in TE" % (nbOverlaps)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
169 return outputNoFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
170
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
171 def _getIntron(self, inputFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
172 outputFileName = "%sin_intron.gff3" % (self.outputBase)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
173 outputNoFileName = "%sin_nointron.gff3" % (self.outputBase)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
174 self.tmpFileNames.extend([outputFileName, outputNoFileName])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
175 nbOverlaps = self._compare(inputFileName, "gff3", self.referenceFiles["mRNA"], "gff3", outputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
176 self._compare(inputFileName, "gff3", self.referenceFiles["mRNA"], "gff3", outputNoFileName, True)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
177 self._copy(outputFileName, "intron")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
178 if self.verbosity > 0:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
179 print "%d overlaps in introns" % (nbOverlaps)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
180 return outputNoFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
181
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
182 def _getVicinity(self, inputFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
183 guds = GetUpDownStream(self.verbosity-1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
184 guds.setInputFile(self.referenceFiles["mRNA"], "gff3")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
185 guds.setOutputFile(self.referenceFiles["vic"])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
186 guds.setDistances(self.distance, self.distance)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
187 guds.run()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
188 outputFileName = "%sout_vicinity.gff3" % (self.outputBase)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
189 outputNoFileName = "%sout_novicinity.gff3" % (self.outputBase)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
190 self.tmpFileNames.extend([outputFileName, outputNoFileName])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
191 nbOverlaps = self._compare(inputFileName, "gff3", self.referenceFiles["vic"], "gff3", outputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
192 nbNoOverlaps = self._compare(inputFileName, "gff3", self.referenceFiles["vic"], "gff3", outputNoFileName, True)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
193 self._copy(outputFileName, "vicinity")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
194 self._copy(outputNoFileName, "intergenic")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
195 if self.verbosity > 0:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
196 print "%d overlaps in vicinity" % (nbOverlaps)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
197 print "%d elsewhere" % (nbNoOverlaps)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
198
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
199 def run(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
200 self._getReferenceFiles()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
201 outputFileName = self._getCds()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
202 outputFileName = self._getFivePrime(outputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
203 outputFileName = self._getThreePrime(outputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
204 outputFileName = self._getNcRna(outputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
205 outputFileName = self._getTe(outputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
206 outputFileName = self._getIntron(outputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
207 self._getVicinity(outputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
208
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
209
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
210
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
211 if __name__ == "__main__":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
212
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
213 # parse command line
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
214 description = "Count Loci v1.0.0: Count input elements with respect to CDS, 5' UTR, 3' UTR, intron, downstream, upstream. [Category: Personal]"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
215
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
216 parser = OptionParser(description = description)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
217 parser.add_option("-i", "--input", dest="inputFileName", action="store", type="string", help="input file [compulsory] [format: file in transcript format given by -f]")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
218 parser.add_option("-f", "--format", dest="format", action="store", type="string", help="format of the input [compulsory] [format: transcript file format]")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
219 parser.add_option("-r", "--reference", dest="reference", action="store", type="string", help="reference file [compulsory] [format: file in GFF format]")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
220 parser.add_option("-o", "--output", dest="outputFileName", action="store", type="string", help="output file [compulsory] [format: output file in GFF3 format]")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
221 parser.add_option("-d", "--distance", dest="distance", action="store", type="int", help="distance up/down stream [compulsory] [format: output file in GFF3 format]")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
222 parser.add_option("-v", "--verbosity", dest="verbosity", action="store", default=1, type="int", help="trace level [format: int]")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
223 (options, args) = parser.parse_args()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
224
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
225 cl = CountLoci(options.verbosity)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
226 cl.setInputFile(options.inputFileName, options.format)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
227 cl.setDistance(options.distance)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
228 cl.setReference(options.reference)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
229 cl.setOutputFileName(options.outputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
230 cl.run()