annotate SMART/Java/Python/GetDistribution.py @ 59:2a4884ba3e5c

Uploaded
author m-zytnicki
date Mon, 10 Feb 2014 03:39:09 -0500
parents 169d364ddd91
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
1 #! /usr/bin/env python
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
2 #
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
3 # Copyright INRA-URGI 2009-2012
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
4 #
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
5 # This software is governed by the CeCILL license under French law and
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
6 # abiding by the rules of distribution of free software. You can use,
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
7 # modify and/ or redistribute the software under the terms of the CeCILL
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
8 # license as circulated by CEA, CNRS and INRIA at the following URL
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
9 # "http://www.cecill.info".
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
10 #
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
11 # As a counterpart to the access to the source code and rights to copy,
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
12 # modify and redistribute granted by the license, users are provided only
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
13 # with a limited warranty and the software's author, the holder of the
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
14 # economic rights, and the successive licensors have only limited
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
15 # liability.
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
16 #
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
17 # In this respect, the user's attention is drawn to the risks associated
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
18 # with loading, using, modifying and/or developing or reproducing the
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
19 # software by the user in light of its specific status of free software,
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
20 # that may mean that it is complicated to manipulate, and that also
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
21 # therefore means that it is reserved for developers and experienced
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
22 # professionals having in-depth computer knowledge. Users are therefore
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
23 # encouraged to load and test the software's suitability as regards their
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
24 # requirements in conditions enabling the security of their systems and/or
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
25 # data to be ensured and, more generally, to use and operate it in the
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
26 # same conditions as regards security.
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
27 #
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
28 # The fact that you are presently reading this means that you have had
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
29 # knowledge of the CeCILL license and that you accept its terms.
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
30 #
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
31 import os
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
32 from optparse import OptionParser
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
33 from commons.core.parsing.ParserChooser import ParserChooser
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
34 from commons.core.parsing.FastaParser import FastaParser
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
35 from SMART.Java.Python.structure.Transcript import Transcript
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
36 from commons.core.writer.Gff3Writer import Gff3Writer
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
37 from SMART.Java.Python.misc.RPlotter import RPlotter
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
38 from SMART.Java.Python.misc.MultipleRPlotter import MultipleRPlotter
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
39 from SMART.Java.Python.misc.UnlimitedProgress import UnlimitedProgress
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
40 from SMART.Java.Python.misc.Progress import Progress
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
41
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
42 TWOSTRANDS = {True: [1, -1], False: [0]}
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
43 STRANDTOSTR = {1: "(+)", -1: "(-)", 0: ""}
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
44
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
45 class GetDistribution(object):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
46
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
47 def __init__(self, verbosity):
46
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
48 self.verbosity = verbosity
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
49 self.sizes = None
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
50 self.nbBins = None
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
51 self.sliceSize = None
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
52 self.twoStrands = False
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
53 self.start = 1
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
54 self.names = ["nbElements"]
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
55 self.average = False
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
56 self.nbValues = {}
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
57 self.height = 300
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
58 self.width = 600
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
59 self.dots = False
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
60 self.colors = None
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
61 self.gffFileName = None
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
62 self.csvFileName = None
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
63 self.yMin = None
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
64 self.yMax = None
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
65 self.chromosome = None
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
66 self.merge = False
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
67 self.nbTranscripts = None
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
68 self.factors = None
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
69 self.thicknessCurve = 1
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
70 self.sizePoliceLegend = 1.5
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
71
46
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
72 def setInputFiles(self, fileNames, format):
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
73 self.fileNames = fileNames
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
74 self.format = format
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
75
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
76 def setReferenceFile(self, fileName):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
77 if fileName == None:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
78 return
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
79 fastaParser = FastaParser(fileName, self.verbosity)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
80 self.chromosomes = fastaParser.getRegions()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
81 self.sizes = dict([region, fastaParser.getSizeOfRegion(region)] for region in self.chromosomes)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
82 self.maxSize = max(self.sizes.values())
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
83
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
84 def setRegion(self, chromosome, start, end):
46
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
85 if chromosome == None or start == None or end == None:
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
86 return
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
87 self.maxSize = options.end
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
88 self.sizes = {chromosome: end}
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
89 self.chromosomes = [chromosome]
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
90 self.chromosome = chromosome
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
91 self.start = start
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
92 self.end = end
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
93
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
94 def setOutputFile(self, fileName):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
95 self.outputFileName = fileName
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
96
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
97 def setNbBins(self, nbBins):
46
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
98 if nbBins != None:
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
99 self.nbBins = int(nbBins)
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
100
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
101 def setBinSize(self, binSize):
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
102 if binSize != None:
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
103 self.sliceSize = int(binSize)
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
104
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
105 def set2Strands(self, twoStrands):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
106 self.twoStrands = twoStrands
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
107
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
108 def setNames(self, names):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
109 self.names = names
46
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
110 if len(self.names) == 1 and len(self.fileNames) > 1:
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
111 self.names = ["file %d" % (i+1) for i in range(len(self.fileNames))]
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
112
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
113 def setAverage(self, average):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
114 self.average = average
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
115
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
116 def setNormalization(self, normalization):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
117 self.normalization = normalization
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
118
46
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
119 def setNormalizationFactors(self, factors):
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
120 self.factors = dict([name, 1.0] for name in self.names) if factors == None else dict(zip(self.names, factors))
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
121
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
122 def setImageSize(self, height, width):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
123 self.height = height
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
124 self.width = width
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
125
46
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
126 def setDots(self, dots):
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
127 self.dots = dots
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
128
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
129 def setYLimits(self, yMin, yMax):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
130 self.yMin = yMin
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
131 self.yMax = yMax
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
132
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
133 def setColors(self, colors):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
134 self.colors = colors
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
135
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
136 def writeGff(self, fileName):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
137 self.gffFileName = fileName
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
138
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
139 def writeCsv(self, fileName):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
140 self.csvFileName = fileName
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
141
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
142 def mergePlots(self, merge):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
143 self.merge = merge
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
144
46
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
145 def setThicknessCurve(self, thickness) :
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
146 self.thickness = thickness
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
147
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
148 def setSizePoliceLegend(self, sizePoliceLegend):
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
149 self.sizePoliceLegend = sizePoliceLegend
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
150
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
151 def _estimateSizes(self):
46
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
152 self.sizes = {}
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
153 self.nbTranscripts = {}
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
154 for fileName in self.fileNames:
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
155 progress = UnlimitedProgress(10000, "Reading %s for chromosome size estimate" % (fileName), self.verbosity)
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
156 parserChooser = ParserChooser(self.verbosity)
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
157 parserChooser.findFormat(self.format)
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
158 parser = parserChooser.getParser(fileName)
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
159 for nbTranscripts, transcript in enumerate(parser.getIterator()):
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
160 if transcript.__class__.__name__ == "Mapping":
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
161 transcript = transcript.getTranscript()
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
162 chromosome = transcript.getChromosome()
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
163 start = transcript.getStart()
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
164 self.sizes[chromosome] = max(start, self.sizes.get(chromosome, 0))
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
165 progress.inc()
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
166 progress.done()
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
167 self.nbTranscripts[fileName] = nbTranscripts
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
168
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
169 def _computeSliceSize(self):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
170 if self.nbBins == 0:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
171 return
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
172 tmp1 = int(max(self.sizes.values()) / float(self.nbBins))
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
173 tmp2 = 10 ** (len("%d" % (tmp1))-2)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
174 self.sliceSize = max(1, int((tmp1 / tmp2) * tmp2))
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
175 if self.verbosity > 0:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
176 print "choosing bin size of %d" % (self.sliceSize)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
177
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
178 def _initBins(self):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
179 self.bins = {}
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
180 for chromosome in self.sizes:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
181 self.bins[chromosome] = {}
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
182 for name in self.names:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
183 self.bins[chromosome][name] = {}
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
184 for strand in TWOSTRANDS[self.twoStrands]:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
185 if self.nbBins == 0:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
186 self.bins[chromosome][name][strand] = {}
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
187 else:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
188 self.bins[chromosome][name][strand] = dict([(i * self.sliceSize + 1, 0.0) for i in range(self.start / self.sliceSize, self.sizes[chromosome] / self.sliceSize + 1)])
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
189
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
190 def _populateBins(self):
46
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
191 for id, fileName in enumerate(self.fileNames):
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
192 if self.nbTranscripts == None:
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
193 progress = UnlimitedProgress(10000, "Counting data", self.verbosity)
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
194 else:
46
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
195 progress = Progress(self.nbTranscripts[fileName], "Counting data", self.verbosity)
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
196 parserChooser = ParserChooser(self.verbosity)
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
197 parserChooser.findFormat(self.format)
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
198 parser = parserChooser.getParser(fileName)
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
199 for transcript in parser.getIterator():
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
200 if transcript.__class__.__name__ == "Mapping":
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
201 transcript = transcript.getTranscript()
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
202 progress.inc()
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
203 chromosome = transcript.getChromosome()
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
204 start = transcript.getStart()
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
205 if self.chromosome and (chromosome != self.chromosome or start < self.start or start > self.end):
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
206 continue
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
207 strand = transcript.getDirection() if self.twoStrands else 0
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
208 if self.nbBins != 0:
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
209 bin = (start / self.sliceSize) * self.sliceSize + 1
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
210 else:
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
211 bin = start
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
212 if len(self.fileNames) > 1:
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
213 nbElements = transcript.getTagValue("nbElements") if "nbElements" in transcript.getTagNames() else 1
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
214 name = self.names[id]
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
215 self.bins[chromosome][name][strand][bin] = self.bins[chromosome][name][strand].get(bin, 0) + nbElements
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
216 self.nbValues[name] = self.nbValues.get(name, 0) + nbElements
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
217 else:
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
218 for name in self.names:
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
219 value = float(transcript.tags.get(name, 1))
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
220 self.bins[chromosome][name][strand][bin] = self.bins[chromosome][name][strand].get(bin, 0) + value
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
221 self.nbValues[name] = self.nbValues.get(name, 0) + value
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
222 progress.done()
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
223
46
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
224 def _normalizeFactors(self):
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
225 for chromosome in self.bins:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
226 for name in self.bins[chromosome]:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
227 for strand in self.bins[chromosome][name]:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
228 for bin in self.bins[chromosome][name][strand]:
46
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
229 self.bins[chromosome][name][strand][bin] *= self.factors[name]
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
230
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
231 def _normalize(self):
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
232 average = float(sum(self.nbValues.values())) / len(self.nbValues.keys())
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
233 self.factors = dict([name, float(average) / self.nbValues[name]] for name in self.nbValues)
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
234 self._normalizeFactors()
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
235
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
236 def _computeAverage(self):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
237 for chromosome in self.bins:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
238 for name in self.bins[chromosome]:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
239 for strand in self.bins[chromosome][name]:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
240 for bin in self.bins[chromosome][name][strand]:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
241 self.bins[chromosome][name][strand][bin] = float(self.bins[chromosome][name][strand][bin]) / self.sliceSize
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
242
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
243 def _getPlotter(self, chromosome):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
244 plot = RPlotter("%s_%s.png" % (os.path.splitext(self.outputFileName)[0], chromosome), self.verbosity)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
245 plot.setImageSize(self.width, self.height)
46
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
246 plot.setLineWidth(self.thickness)
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
247 plot.setSizePoliceLegend(self.sizePoliceLegend)
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
248 if self.dots:
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
249 plot.setPoints(True)
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
250 if self.sizes[chromosome] <= 1000:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
251 unit = "nt."
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
252 ratio = 1.0
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
253 elif self.sizes[chromosome] <= 1000000:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
254 unit = "kb"
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
255 ratio = 1000.0
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
256 else:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
257 unit = "Mb"
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
258 ratio = 1000000.0
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
259 if self.yMin != None:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
260 plot.setMinimumY(self.yMin)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
261 if self.yMax != None:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
262 plot.setMaximumY(self.yMax)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
263 plot.setXLabel("Position on %s (in %s)" % (chromosome.replace("_", " "), unit))
46
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
264 if len(self.names) > 1:
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
265 plot.setLegend(True, True)
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
266 for i, name in enumerate(self.bins[chromosome]):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
267 for strand in self.bins[chromosome][name]:
46
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
268 #fullName = "%s %s" % (name.replace("_", " ")[:6], STRANDTOSTR[strand])
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
269 fullName = name.replace("_", " ")[:6]
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
270 factor = 1 if strand == 0 else strand
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
271 correctedLine = dict([(key / ratio, value * factor) for key, value in self.bins[chromosome][name][strand].iteritems()])
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
272 plot.addLine(correctedLine, fullName, self.colors[i] if self.colors else None)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
273 return plot
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
274
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
275 def _plot(self):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
276 if self.merge:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
277 multiplePlot = MultipleRPlotter(self.outputFileName, self.verbosity)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
278 multiplePlot.setImageSize(self.width, self.height * len(self.bins.keys()))
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
279 progress = Progress(len(self.bins.keys()), "Plotting", options.verbosity)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
280 for chromosome in sorted(self.bins.keys()):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
281 plot = self._getPlotter(chromosome)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
282 if self.merge:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
283 multiplePlot.addPlot(plot)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
284 else:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
285 plot.plot()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
286 progress.inc()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
287 if self.merge:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
288 multiplePlot.plot()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
289 progress.done()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
290
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
291 def _writeCsv(self):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
292 if self.verbosity > 1:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
293 print "Writing CSV file..."
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
294 csvHandle = open(self.csvFileName, "w")
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
295 csvHandle.write("chromosome;tag;strand")
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
296 if self.nbBins != 0:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
297 xValues = range(self.start / self.sliceSize, max(self.sizes.values()) / self.sliceSize + 1)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
298 for value in xValues:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
299 csvHandle.write(";%d-%d" % (value * self.sliceSize + 1, (value+1) * self.sliceSize))
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
300 csvHandle.write("\n")
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
301 else:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
302 xValues = []
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
303 for chromosome in self.bins:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
304 for name in self.bins[chromosome]:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
305 for strand in self.bins[chromosome][name]:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
306 for bin in self.bins[chromosome][name][strand]:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
307 xValues.extend(self.bins[chromosome][name][strand].keys())
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
308 xValues = sorted(list(set(xValues)))
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
309 for value in xValues:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
310 csvHandle.write(";%d" % (value))
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
311 csvHandle.write("\n")
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
312 for chromosome in self.bins:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
313 csvHandle.write("%s" % (chromosome))
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
314 for name in self.bins[chromosome]:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
315 csvHandle.write(";%s" % (name))
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
316 for strand in self.bins[chromosome][name]:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
317 csvHandle.write(";%s" % (STRANDTOSTR[strand]))
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
318 for bin in xValues:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
319 csvHandle.write(";%.2f" % (self.bins[chromosome][name][strand].get(bin, 0)))
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
320 csvHandle.write("\n")
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
321 csvHandle.write(";")
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
322 csvHandle.write(";")
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
323 csvHandle.close()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
324 if self.verbosity > 1:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
325 print "...done"
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
326
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
327 def _writeGff(self):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
328 if self.verbosity > 1:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
329 print "Writing GFF file..."
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
330 writer = Gff3Writer(self.gffFileName, self.verbosity)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
331 cpt = 1
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
332 for chromosome in self.bins:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
333 for name in self.bins[chromosome]:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
334 for strand in self.bins[chromosome][name]:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
335 for bin in self.bins[chromosome][name][strand]:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
336 transcript = Transcript()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
337 transcript.setChromosome(chromosome)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
338 transcript.setStart(bin)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
339 if self.nbBins > 0:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
340 transcript.setEnd(bin + self.sliceSize)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
341 else:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
342 transcript.setEnd(self.start)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
343 transcript.setDirection(1 if strand == 0 else strand)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
344 transcript.setTagValue("ID", "region%d" % (cpt))
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
345 cpt += 1
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
346 writer.write()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
347 if self.verbosity > 1:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
348 print "...done"
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
349
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
350 def run(self):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
351 if self.sizes == None:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
352 self._estimateSizes()
46
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
353 if self.sliceSize == None:
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
354 self._computeSliceSize()
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
355 self._initBins()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
356 self._populateBins()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
357 if self.normalization:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
358 self._normalize()
46
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
359 if self.factors != None:
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
360 self._normalizeFactors()
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
361 if self.average:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
362 self._computeAverage()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
363 self._plot()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
364 if self.csvFileName != None:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
365 self._writeCsv()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
366 if self.gffFileName != None:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
367 self._writeGff()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
368
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
369
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
370 if __name__ == "__main__":
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
371
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
372 description = "Get Distribution v1.0.2: Get the distribution of the genomic coordinates on a genome. [Category: Visualization]"
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
373
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
374 parser = OptionParser(description = description)
46
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
375 parser.add_option("-i", "--input", dest="inputFileNames", action="store", type="string", help="input files separated by commas [compulsory] [format: string]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
376 parser.add_option("-f", "--format", dest="format", action="store", type="string", help="format of the input file [compulsory] [format: transcript file format]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
377 parser.add_option("-o", "--output", dest="outputFileName", action="store", type="string", help="output file [compulsory] [format: output file in GFF3 format]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
378 parser.add_option("-r", "--reference", dest="referenceFileName", action="store", default=None, type="string", help="file containing the genome [format: file in FASTA format]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
379 parser.add_option("-b", "--nbBins", dest="nbBins", action="store", default=1000, type="int", help="number of bins [default: 1000] [format: int]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
380 parser.add_option("-B", "--binSize", dest="binSize", action="store", default=None, type="int", help="bin size [default: None] [format: int]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
381 parser.add_option("-2", "--bothStrands", dest="bothStrands", action="store_true", default=False, help="plot one curve per strand [format: bool] [default: false]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
382 parser.add_option("-c", "--chromosome", dest="chromosome", action="store", default=None, type="string", help="plot only a chromosome [format: string]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
383 parser.add_option("-s", "--start", dest="start", action="store", default=None, type="int", help="start from a given region [format: int]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
384 parser.add_option("-e", "--end", dest="end", action="store", default=None, type="int", help="end from a given region [format: int]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
385 parser.add_option("-y", "--yMin", dest="yMin", action="store", default=None, type="int", help="minimum value on the y-axis to plot [format: int]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
386 parser.add_option("-Y", "--yMax", dest="yMax", action="store", default=None, type="int", help="maximum value on the y-axis to plot [format: int]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
387 parser.add_option("-x", "--csv", dest="csv", action="store", default=None, help="write a .csv file [format: output file in CSV format] [default: None]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
388 parser.add_option("-g", "--gff", dest="gff", action="store", default=None, help="also write GFF3 file [format: output file in GFF format] [default: None]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
389 parser.add_option("-H", "--height", dest="height", action="store", default=500, type="int", help="height of the graphics [format: int] [default: 300]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
390 parser.add_option("-W", "--width", dest="width", action="store", default=800, type="int", help="width of the graphics [format: int] [default: 1000]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
391 parser.add_option("-t", "--thickness", dest="lineThickness", action="store", default=1, type="int", help="thickness of the lines [format : int] [default : 1]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
392 parser.add_option("-d", "--policeLegend", dest="sizePoliceLegend", action="store", default=1.5, type="float", help="size of the police of the legend [format : float] [default : 1.5]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
393 parser.add_option("-D", "--dots", dest="dots", action="store_true", default=False, help="plot dots instead of lines [format : bool] [default : false]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
394 parser.add_option("-a", "--average", dest="average", action="store_true", default=False, help="plot average (instead of sum) [default: false] [format: boolean]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
395 parser.add_option("-n", "--names", dest="names", action="store", default="nbElements", type="string", help="name for the tags (separated by commas and no space) [default: None] [format: string]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
396 parser.add_option("-l", "--color", dest="colors", action="store", default=None, type="string", help="color of the lines (separated by commas and no space) [format: string]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
397 parser.add_option("-z", "--normalize", dest="normalize", action="store_true", default=False, help="normalize data (when panels are different) [format: bool] [default: false]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
398 parser.add_option("-Z", "--normalizeFac", dest="normalizeFactors", action="store", default=None, help="normalize data with given factors (when panels are different) [format: string]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
399 parser.add_option("-m", "--merge", dest="mergePlots", action="store_true", default=False, help="merge all plots in one figure [format: bool] [default: false]")
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
400 parser.add_option("-v", "--verbosity", dest="verbosity", action="store", default=1, type="int", help="trace level [default: 1] [format: int]")
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
401 (options, args) = parser.parse_args()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
402
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
403 gt = GetDistribution(options.verbosity)
46
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
404 gt.setInputFiles(options.inputFileNames.split(","), options.format)
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
405 gt.setOutputFile(options.outputFileName)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
406 gt.setReferenceFile(options.referenceFileName)
46
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
407 gt.setNbBins(options.nbBins)
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
408 gt.setBinSize(options.binSize)
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
409 gt.set2Strands(options.bothStrands)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
410 gt.setRegion(options.chromosome, options.start, options.end)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
411 gt.setNormalization(options.normalize)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
412 gt.setAverage(options.average)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
413 gt.setYLimits(options.yMin, options.yMax)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
414 gt.writeCsv(options.csv)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
415 gt.writeGff(options.gff)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
416 gt.setImageSize(options.height, options.width)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
417 gt.setNames(options.names.split(","))
46
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
418 gt.setThicknessCurve(options.lineThickness)
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
419 gt.setSizePoliceLegend(options.sizePoliceLegend)
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
420 gt.setColors(None if options.colors == None else options.colors.split(","))
46
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
421 gt.setDots(options.dots)
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
422 gt.setNormalization(options.normalize)
46
169d364ddd91 Uploaded
m-zytnicki
parents: 36
diff changeset
423 gt.setNormalizationFactors(None if options.normalizeFactors == None else [float(factor) for factor in options.normalizeFactors.split(",")])
36
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
424 gt.mergePlots(options.mergePlots)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
425 gt.run()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
426