annotate SMART/Java/Python/getSizes.py @ 6:769e306b7933

Change the repository level.
author yufei-luo
date Fri, 18 Jan 2013 04:54:14 -0500
parents
children 94ab73e8a190
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
1 #! /usr/bin/env python
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 # Copyright INRA-URGI 2009-2010
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
4 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
5 # This software is governed by the CeCILL license under French law and
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
6 # abiding by the rules of distribution of free software. You can use,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
7 # modify and/ or redistribute the software under the terms of the CeCILL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
8 # license as circulated by CEA, CNRS and INRIA at the following URL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
9 # "http://www.cecill.info".
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
10 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
11 # As a counterpart to the access to the source code and rights to copy,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
12 # modify and redistribute granted by the license, users are provided only
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
13 # with a limited warranty and the software's author, the holder of the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
14 # economic rights, and the successive licensors have only limited
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
15 # liability.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
16 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
17 # In this respect, the user's attention is drawn to the risks associated
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
18 # with loading, using, modifying and/or developing or reproducing the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
19 # software by the user in light of its specific status of free software,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
20 # that may mean that it is complicated to manipulate, and that also
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
21 # therefore means that it is reserved for developers and experienced
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
22 # professionals having in-depth computer knowledge. Users are therefore
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
23 # encouraged to load and test the software's suitability as regards their
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
24 # requirements in conditions enabling the security of their systems and/or
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
25 # data to be ensured and, more generally, to use and operate it in the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26 # same conditions as regards security.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28 # The fact that you are presently reading this means that you have had
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29 # knowledge of the CeCILL license and that you accept its terms.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31 import os, sys
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 from optparse import OptionParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 from commons.core.parsing.FastaParser import FastaParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 from commons.core.parsing.FastqParser import FastqParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 from SMART.Java.Python.structure.TranscriptContainer import TranscriptContainer
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 from commons.core.parsing.GffParser import GffParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37 from SMART.Java.Python.misc.Progress import Progress
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 from SMART.Java.Python.misc.RPlotter import RPlotter
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 from SMART.Java.Python.misc import Utils
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41 from commons.core.LoggerFactory import LoggerFactory
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42 from commons.core.utils.RepetOptionParser import RepetOptionParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 LOG_DEPTH = "smart"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 class GetSizes(object):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 def __init__(self, inFileName = None, inFormat=None, outFileName = None, query=None,xMax=None, xMin=None, csv=False, verbosity = 0):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 self.inFileName = inFileName
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 self.inFormat= inFormat
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 self.outFileName = outFileName
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 self.query = query
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 self.xMax = xMax
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 self.xMin = xMin
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 self.xLab = "Size"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 self.yLab = "# reads"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 self.barplot = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 self.csv = csv
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 self._verbosity = verbosity
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 self.parser = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 self._log = LoggerFactory.createLogger("%s.%s" % (LOG_DEPTH, self.__class__.__name__), self._verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 def setAttributesFromCmdLine(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 description = "Usage: getSizes.py [options]\n\nGet Sizes v1.0.2: Get the sizes of a set of genomic coordinates. [Category: Visualization]\n"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 epilog = ""
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 parser = RepetOptionParser(description = description, epilog = epilog)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 parser.add_option("-i", "--input", dest="inputFileName", action="store", default=None, type="string", help="input file [compulsory] [format: file in transcript or sequence format given by -f]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 parser.add_option("-f", "--format", dest="format", action="store", default=None, type="string", help="format of the input [compulsory] [format: transcript or sequence file format]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 parser.add_option("-q", "--query", dest="query", action="store", default=None, type="string", help="type to mesure [default: size] [format: choice (size, intron size, exon size, 1st exon size)]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 parser.add_option("-o", "--output", dest="outputFileName", action="store", default=None, type="string", help="output file [format: output file in PNG format]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 parser.add_option("-x", "--xMax", dest="xMax", action="store", default=None, type="int", help="maximum value on the x-axis to plot [format: int]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 parser.add_option("-X", "--xMin", dest="xMin", action="store", default=None, type="int", help="minimum value on the x-axis to plot [format: int]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 parser.add_option("-v", "--verbosity", dest="verbosity", action="store", default=1, type="int", help="trace level [format: int]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74 parser.add_option("-c", "--csv", dest="csv", action="store", type="string", help="write a .csv file [format: bool] [default: false]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75 parser.add_option("-a", "--xLabel", dest="xLab", action="store", default="Size", type="string", help="x absis label name [format: string] [default: Size]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 parser.add_option("-b", "--yLabel", dest="yLab", action="store", default="# reads", type="string", help="y absis label name [format: string] [default: Reads]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 parser.add_option("-B", "--barplot", dest="barplot", action="store_true", default=False, help="use barplot representation [format: bool] [default: false]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 options = parser.parse_args()[0]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79 self._setAttributesFromOptions(options)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 def _setAttributesFromOptions(self, options):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82 self.setInFileName(options.inputFileName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83 self.setInFormat(options.format)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84 self.setQuery(options.query)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85 self.setOutFileName(options.outputFileName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 self.setXMax(options.xMax)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87 self.setXMin(options.xMin)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88 self.setxLab(options.xLab)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89 self.setyLab(options.yLab)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90 self.setBarplot(options.barplot)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 self.setVerbosity(options.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93 def setInFileName(self, inputFileName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94 self.inFileName = inputFileName
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96 def setInFormat(self, inFormat):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97 self.inFormat = inFormat
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 def setQuery(self, query):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 self.query = query
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102 def setOutFileName(self, outFileName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103 self.outFileName = outFileName
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105 def setXMax(self, xMax):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106 self.xMax = xMax
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108 def setXMin(self, xMin):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109 self.xMin = xMin
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111 def setxLab(self, xLab):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112 self.xLab = xLab
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114 def setyLab(self, yLab):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115 self.yLab = yLab
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117 def setBarplot(self, barplot):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118 self.barplot = barplot
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120 def setCsv(self, csv):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121 self.csv = csv
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123 def setVerbosity(self, verbosity):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124 self._verbosity = verbosity
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
126 def _checkOptions(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
127 if self.inFileName == None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
128 self._logAndRaise("ERROR: Missing input file name")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
129 if self.inFormat == "fasta":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
130 self.parser = FastaParser(self.inFileName, self._verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
131 elif self.inFormat == "fastq":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
132 self.parser = FastqParser(self.inFileName, self._verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
133 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
134 self.parser = TranscriptContainer(self.inFileName, self.inFormat, self._verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
135
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
136 def _logAndRaise(self, errorMsg):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
137 self._log.error(errorMsg)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
138 raise Exception(errorMsg)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
139
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
140 def run(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
141 LoggerFactory.setLevel(self._log, self._verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
142 self._checkOptions()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
143 self._log.info("START getsizes")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
144 self._log.debug("Input file name: %s" % self.inFileName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
145
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
146 nbItems = self.parser.getNbItems()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
147 self._log.info( "%i items found" % (nbItems))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
148
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
149 # treat items
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
150 progress = Progress(nbItems, "Analyzing sequences of %s" % (self.inFileName), self._verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
151 sizes = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
152 names = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
153 minimum = 1000000000000
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
154 maximum = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
155 sum = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
156 number = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
157 nbSubItems = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
158 for item in self.parser.getIterator():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
159 items = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
160 if self.query == "exon":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
161 items = item.getExons()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
162 elif self.query == "exon1":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
163 if len(item.getExons()) > 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
164 item.sortExons()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
165 items = [item.getExons()[0]]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
166 elif self.query == "intron":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
167 items = item.getIntrons()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
168 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
169 items = [item, ]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
170
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
171 for thisItem in items:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
172 try:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
173 nbElements = int(float(thisItem.getTagValue("nbElements")))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
174 if nbElements == None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
175 nbElements = 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
176 except:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
177 nbElements = 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
178 size = thisItem.getSize()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
179 minimum = min(minimum, size)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
180 maximum = max(maximum, size)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
181 name = thisItem.name.split()[0]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
182
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
183 if size not in sizes:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
184 sizes[size] = nbElements
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
185 if self.csv:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
186 names[size] = [name, ]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
187 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
188 sizes[size] += nbElements
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
189 if self.csv:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
190 names[size].append(name)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
191 sum += size
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
192 nbSubItems += nbElements
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
193 number += 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
194 progress.inc()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
195 progress.done()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
196
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
197 if self.outFileName != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
198 plotter = RPlotter(self.outFileName, self._verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
199 plotter.setFill(0)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
200 plotter.setMinimumX(self.xMin)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
201 plotter.setMaximumX(self.xMax)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
202 plotter.setXLabel(self.xLab)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
203 plotter.setYLabel(self.yLab)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
204 plotter.setBarplot(self.barplot)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
205 plotter.addLine(sizes)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
206 plotter.plot()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
207
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
208 if nbSubItems == 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
209 self._logAndRaise("No item found")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
210
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
211 if self.csv:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
212 csvHandle = open(self.csv, "w")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
213 for size in range(min(sizes.keys()), max(sizes.keys())+1):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
214 if size not in sizes:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
215 csvHandle.write("%d,0,\n" % (size))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
216 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
217 csvHandle.write("%d,%d,%s\n" % (size, sizes[size], ";".join(names[size])))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
218 csvHandle.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
219
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
220 self.items = number
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
221 self.subItems = nbSubItems
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
222 self.nucleotides = sum
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
223 self.minAvgMedMax = Utils.getMinAvgMedMax(sizes)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
224
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
225 print "%d items" % (number)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
226 print "%d sub-items" % (nbSubItems)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
227 print "%d nucleotides" % (sum)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
228 print "min/avg/med/max transcripts: %d/%.2f/%.1f/%d" % Utils.getMinAvgMedMax(sizes)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
229
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
230 self._log.info("END getsizes")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
231
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
232
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
233 if __name__ == "__main__":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
234 iGetSizes = GetSizes()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
235 iGetSizes.setAttributesFromCmdLine()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
236 iGetSizes.run()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
237
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
238 #TODO: add two more options!!!!!!