annotate SMART/Java/Python/GetDifferentialExpression.py @ 16:6135c3075bc5

Deleted selected files
author m-zytnicki
date Mon, 22 Apr 2013 11:09:41 -0400
parents 769e306b7933
children
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 """Get the differential expression between 2 conditions (2 files), on regions defined by a third file"""
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 import os, re
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 from optparse import OptionParser
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.writer.Gff3Writer import Gff3Writer
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 from SMART.Java.Python.mySql.MySqlConnection import MySqlConnection
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41 from SMART.Java.Python.structure.Transcript import Transcript
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 class GetDifferentialExpression(object):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 def __init__(self, verbosity = 1):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 self.verbosity = verbosity
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 self.mySqlConnection = MySqlConnection(verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 self.inputs = (0, 1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 self.transcriptContainers = [None, None]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 self.transcriptContainerRef = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 self.outputFileName = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 self.writer = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 self.tables = [None, None]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 self.nbElements = [0, 0]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 self.regionsToValues = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 self.regionsToNames = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 self.valuesToPvalues = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 self.oriented = True
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 self.simpleNormalization = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 self.simpleNormalizationParameters = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 self.adjustedNormalization = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 self.fixedSizeFactor = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 self.normalizationSize = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 self.normalizationFactors = [1, 1]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 self.fdr = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 self.fdrPvalue = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 self.plot = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 self.plotter = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 self.plotterName = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 self.points = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 def setInputFile(self, i, fileName, fileFormat):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 self.transcriptContainers[i] = TranscriptContainer(fileName, fileFormat, self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 self.transcriptContainers[i].mySqlConnection = self.mySqlConnection
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 def setReferenceFile(self, fileName, fileFormat):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82 self.transcriptContainerRef = TranscriptContainer(fileName, fileFormat, self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83 self.transcriptContainerRef.mySqlConnection = self.mySqlConnection
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 def setOutputFile(self, fileName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87 self.outputFileName = fileName
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88 self.writer = Gff3Writer(fileName, self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 def setOriented(self, boolean):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92 self.oriented = boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95 def setSimpleNormalization(self, boolean):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96 self.simpleNormalization = boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 def setSimpleNormalizationParameters(self, parameters):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 if parameters != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101 self.simpleNormalization = True
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102 self.simpleNormalizationParameters = [0, 0]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103 for i, splittedParameter in enumerate(parameters.split(",")):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104 self.simpleNormalizationParameters[i] = int(splittedParameter)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107 def setAdjustedNormalization(self, boolean):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108 self.adjustedNormalization = boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111 def setFixedSizeNormalization(self, value):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112 self.fixedSizeFactor = value
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115 def setFdr(self, fdr):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116 self.fdr = fdr
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119 def setPlot(self, boolean):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120 self.plot = boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123 def setPlotterName(self, plotterName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124 self.plotterName = plotterName
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
126 def setPlotter(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
127 self.plot = True
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
128 self.plotter = RPlotter(self.plotterName, self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
129 self.plotter.setPoints(True)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
130 self.plotter.setLog("xy")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
131 self.points = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
132
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
133
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
134 def readInput(self, i):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
135 self.transcriptContainers[i].storeIntoDatabase()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
136 self.tables[i] = self.transcriptContainers[i].getTables()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
137 progress = Progress(len(self.tables[i].keys()), "Adding indices", self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
138 for chromosome in self.tables[i]:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
139 if self.oriented:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
140 self.tables[i][chromosome].createIndex("iStartEndDir_%s_%d" % (chromosome, i), ("start", "end", "direction"))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
141 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
142 self.tables[i][chromosome].createIndex("iStartEnd_%s_%d" % (chromosome, i), ("start", "end"))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
143 progress.inc()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
144 progress.done()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
145
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
146 progress = Progress(self.transcriptContainers[i].getNbTranscripts(), "Reading sample %d" % (i +1), self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
147 for chromosome in self.tables[i]:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
148 for transcript in self.tables[i][chromosome].getIterator():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
149 self.nbElements[i] += 1 if "nbElements" not in transcript.getTagNames() else transcript.getTagValue("nbElements")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
150 progress.inc()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
151 progress.done()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
152 if self.verbosity > 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
153 print "%d elements in sample %d" % (self.nbElements[i], i+1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
154
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
155
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
156 def computeSimpleNormalizationFactors(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
157 nbElements = self.nbElements
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
158 if self.simpleNormalizationParameters != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
159 print "Using provided normalization parameters: %s" % (", ".join([str(parameter) for parameter in self.simpleNormalizationParameters]))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
160 nbElements = self.simpleNormalizationParameters
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
161 avgNbElements = int(float(sum(nbElements)) / len(nbElements))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
162 for i in self.inputs:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
163 self.normalizationFactors[i] = float(avgNbElements) / nbElements[i]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
164 self.nbElements[i] *= self.normalizationFactors[i]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
165 if self.verbosity > 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
166 print "Normalizing to average # reads: %d" % (avgNbElements)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
167 if self.simpleNormalizationParameters != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
168 print "# reads: %s" % (", ".join([str(nbElement) for nbElement in self.nbElements]))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
169
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
170 def __del__(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
171 self.mySqlConnection.deleteDatabase()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
172
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
173 def regionToString(self, transcript):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
174 return "%s:%d-%d(%s)" % (transcript.getChromosome(), transcript.getStart(), transcript.getEnd(), "+" if transcript.getDirection() == 1 else "-")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
175
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
176 def stringToRegion(self, region):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
177 m = re.search(r"^(\S+):(\d+)-(\d+)\((\S)\)$", region)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
178 if m == None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
179 raise Exception("Internal format error: cannot parse region '%s'" % (region))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
180 transcript = Transcript()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
181 transcript.setChromosome(m.group(1))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
182 transcript.setStart(int(m.group(2)))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
183 transcript.setEnd(int(m.group(3)))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
184 transcript.setDirection(m.group(4))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
185 return transcript
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
186
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
187 def computeMinimumSize(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
188 self.normalizationSize = 1000000000
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
189 progress = Progress(self.transcriptContainerRef.getNbTranscripts(), "Getting minimum reference size", self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
190 for transcriptRef in self.transcriptContainerRef.getIterator():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
191 self.normalizationSize = min(self.normalizationSize, transcriptRef.getEnd() - transcriptRef.getStart())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
192 progress.inc()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
193 progress.done()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
194 if self.verbosity > 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
195 print "Minimum reference size: %d" % (self.normalizationSize+1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
196
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
197 def useFixedSizeNormalization(self, start, end, starts):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
198 currentNb = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
199 sum = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
200 if not starts:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
201 return 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
202 for i in range(start - self.normalizationSize, end + 1 + self.normalizationSize):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
203 if i not in starts:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
204 starts[i] = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
205 for i, s in starts.iteritems():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
206 if i < start:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
207 starts[start] += s
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
208 starts[i] = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
209 for i in range(start - self.normalizationSize, end + 1):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
210 currentNb += starts[i+self.normalizationSize] - starts[i]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
211 sum += currentNb
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
212 return (float(sum) / self.normalizationSize) * (self.fixedSizeFactor / (end - start + 1))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
213
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
214 def retrieveCounts(self, transcriptRef, i):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
215 if transcriptRef.getChromosome() not in self.tables[i]:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
216 return (0, 0)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
217 cumulatedCount = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
218 cumulatedNormalizedCount = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
219 for exon in transcriptRef.getExons():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
220 count = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
221 starts = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
222 command = "SELECT start, tags FROM '%s' WHERE start >= %d AND end <= %d" % (self.tables[i][exon.getChromosome()].getName(), exon.getStart(), exon.getEnd())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
223 if self.oriented:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
224 command += " AND direction = %d" % (exon.getDirection())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
225 query = self.mySqlConnection.executeQuery(command)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
226 for line in query.getIterator():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
227 nb = 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
228 tags = line[1].split(";")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
229 for tag in tags:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
230 key, value = tag.split("=")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
231 if key == "nbElements":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
232 nb = int(float(value))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
233 count += nb
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
234 starts[int(line[0])] = nb
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
235 normalizedCount = count if self.fixedSizeFactor == None else self.useFixedSizeNormalization(exon.getStart(), exon.getEnd(), starts)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
236 cumulatedCount += count
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
237 cumulatedNormalizedCount += normalizedCount
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
238 return (cumulatedCount, cumulatedNormalizedCount)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
239
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
240 def getAllCounts(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
241 progress = Progress(self.transcriptContainerRef.getNbTranscripts(), "Getting counts", self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
242 for cpt, transcriptRef in enumerate(self.transcriptContainerRef.getIterator()):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
243 if "ID" in transcriptRef.getTagNames():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
244 self.regionsToNames[self.regionToString(transcriptRef)] = transcriptRef.getTagValue("ID")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
245 elif transcriptRef.getName() != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
246 self.regionsToNames[self.regionToString(transcriptRef)] = transcriptRef.getName()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
247 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
248 self.regionsToNames[self.regionToString(transcriptRef)] = "region_%d" % (cpt)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
249 values = [None, None]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
250 normalizedValues = [None, None]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
251 for i in self.inputs:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
252 values[i], normalizedValues[i] = self.retrieveCounts(transcriptRef, i)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
253 normalizedValues[i] = int(self.normalizationFactors[i] * normalizedValues[i])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
254 if sum(values) != 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
255 self.regionsToValues[self.regionToString(transcriptRef)] = (normalizedValues[0], normalizedValues[1], values[0], values[1])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
256 progress.inc()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
257 progress.done()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
258
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
259 def computeAdjustedNormalizationFactors(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
260 nbElements = len(self.regionsToValues.keys())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
261 avgValues = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
262 progress = Progress(nbElements, "Normalization step 1", self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
263 for values in self.regionsToValues.values():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
264 correctedValues = [values[i] * self.normalizationFactors[i] for i in self.inputs]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
265 avgValues.append(float(sum(correctedValues)) / len(correctedValues))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
266 progress.inc()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
267 progress.done()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
268
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
269 sortedAvgValues = sorted(avgValues)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
270 minAvgValues = sortedAvgValues[nbElements / 4]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
271 maxAvgValues = sortedAvgValues[nbElements * 3 / 4]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
272 sums = [0, 0]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
273 progress = Progress(nbElements, "Normalization step 2", self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
274 for values in self.regionsToValues.values():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
275 correctedValues = [values[i] * self.normalizationFactors[i] for i in self.inputs]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
276 avgValue = float(sum(correctedValues)) / len(correctedValues)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
277 if minAvgValues <= avgValue and avgValue <= maxAvgValues:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
278 for i in self.inputs:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
279 sums[i] += values[i]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
280 progress.inc()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
281 progress.done()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
282
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
283 avgSums = float(sum(sums)) / len(sums)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
284 for i in self.inputs:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
285 if self.verbosity > 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
286 print "Normalizing sample %d: %s to" % ((i+1), self.nbElements[i]),
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
287 self.normalizationFactors[i] *= float(avgSums) / sums[i]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
288 self.nbElements[i] *= self.normalizationFactors[i]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
289 if self.verbosity > 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
290 print "%s" % (int(self.nbElements[i]))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
291
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
292 def getMinimumReferenceSize(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
293 self.normalizationSize = 1000000000
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
294 progress = Progress(self.transcriptContainerRef.getNbTranscripts(), "Reference element sizes", self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
295 for transcriptRef in self.transcriptContainerRef.getIterator():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
296 self.normalizationSize = min(self.normalizationSize, transcriptRef.getEnd() - transcriptRef.getStart() + 1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
297 progress.inc()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
298 progress.done()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
299 if self.verbosity > 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
300 print "Minimum reference size: %d" % (self.normalizationSize)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
301
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
302 def computePvalues(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
303 normalizedValues = set()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
304 progress = Progress(len(self.regionsToValues.keys()), "Normalizing counts", self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
305 for region in self.regionsToValues:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
306 values = self.regionsToValues[region]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
307 normalizedValues0 = int(round(values[0] * self.normalizationFactors[0]))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
308 normalizedValues1 = int(round(values[1] * self.normalizationFactors[1]))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
309 self.regionsToValues[region] = (normalizedValues0, normalizedValues1, self.regionsToValues[region][2], self.regionsToValues[region][3])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
310 normalizedValues.add((normalizedValues0, normalizedValues1, self.nbElements[0] - normalizedValues0, self.nbElements[1] - normalizedValues1, self.regionsToValues[region][2], self.regionsToValues[region][3]))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
311 progress.inc()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
312 progress.done()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
313
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
314 if self.verbosity > 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
315 print "Computing p-values..."
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
316 self.valuesToPvalues = Utils.fisherExactPValueBulk(list(normalizedValues))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
317 if self.verbosity > 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
318 print "... done"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
319
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
320 def setTagValues(self, transcript, values, pValue):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
321 for tag in transcript.getTagNames():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
322 transcript.deleteTag(tag)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
323 transcript.removeExons()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
324 transcript.setTagValue("pValue", str(pValue))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
325 transcript.setTagValue("nbReadsCond1", str(values[0]))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
326 transcript.setTagValue("nbReadsCond2", str(values[1]))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
327 transcript.setTagValue("nbUnnormalizedReadsCond1", str(values[2]))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
328 transcript.setTagValue("nbUnnormalizedReadsCond2", str(values[3]))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
329 if (values[0] == values[1]) or (self.fdr != None and pValue > self.fdrPvalue):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
330 transcript.setTagValue("regulation", "equal")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
331 elif values[0] < values[1]:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
332 transcript.setTagValue("regulation", "up")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
333 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
334 transcript.setTagValue("regulation", "down")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
335 return transcript
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
336
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
337 def computeFdr(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
338 pValues = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
339 nbRegions = len(self.regionsToValues.keys())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
340 progress = Progress(nbRegions, "Computing FDR", self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
341 for values in self.regionsToValues.values():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
342 pValues.append(self.valuesToPvalues[values[0:2]])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
343 progress.inc()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
344 progress.done()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
345
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
346 for i, pValue in enumerate(reversed(sorted(pValues))):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
347 if pValue <= self.fdr * (nbRegions - 1 - i) / nbRegions:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
348 self.fdrPvalue = pValue
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
349 if self.verbosity > 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
350 print "FDR: %f, k: %i, m: %d" % (pValue, nbRegions - 1 - i, nbRegions)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
351 return
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
352
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
353 def writeDifferentialExpression(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
354 if self.plot:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
355 self.setPlotter()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
356
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
357 cpt = 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
358 progress = Progress(len(self.regionsToValues.keys()), "Writing output", self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
359 for region, values in self.regionsToValues.iteritems():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
360 transcript = self.stringToRegion(region)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
361 pValue = self.valuesToPvalues[values[0:2]]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
362 transcript.setName(self.regionsToNames[region])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
363 transcript = self.setTagValues(transcript, values, pValue)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
364 self.writer.addTranscript(transcript)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
365 cpt += 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
366
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
367 if self.plot:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
368 self.points[region] = (values[0], values[1])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
369 progress.done()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
370 self.writer.write()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
371 self.writer.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
372
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
373 if self.plot:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
374 self.plotter.addLine(self.points)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
375 self.plotter.plot()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
376
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
377 def getDifferentialExpression(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
378 for i in self.inputs:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
379 self.readInput(i)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
380
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
381 if self.simpleNormalization:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
382 self.computeSimpleNormalizationFactors()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
383 if self.fixedSizeFactor != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
384 self.computeMinimumSize()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
385
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
386 self.getAllCounts()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
387
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
388 if self.adjustedNormalization:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
389 self.computeAdjustedNormalizationFactors()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
390
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
391 self.computePvalues()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
392
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
393 if self.fdr != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
394 self.computeFdr()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
395
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
396 self.writeDifferentialExpression()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
397
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
398
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
399 if __name__ == "__main__":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
400
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
401 # parse command line
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
402 description = "Get Differential Expression v1.0.1: Get the differential expression between 2 conditions using Fisher's exact test, on regions defined by a third file. [Category: Data Comparison]"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
403
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
404 parser = OptionParser(description = description)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
405 parser.add_option("-i", "--input1", dest="inputFileName1", action="store", type="string", help="input file 1 [compulsory] [format: file in transcript format given by -f]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
406 parser.add_option("-f", "--format1", dest="format1", action="store", type="string", help="format of file 1 [compulsory] [format: transcript file format]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
407 parser.add_option("-j", "--input2", dest="inputFileName2", action="store", type="string", help="input file 2 [compulsory] [format: file in transcript format given by -g]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
408 parser.add_option("-g", "--format2", dest="format2", action="store", type="string", help="format of file 2 [compulsory] [format: transcript file format]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
409 parser.add_option("-k", "--reference", dest="referenceFileName", action="store", type="string", help="reference file [compulsory] [format: file in transcript format given by -l]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
410 parser.add_option("-l", "--referenceFormat", dest="referenceFormat", action="store", type="string", help="format of reference file [compulsory] [format: transcript file format]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
411 parser.add_option("-o", "--output", dest="outputFileName", action="store", type="string", help="output file [format: output file in gff3 format]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
412 parser.add_option("-n", "--notOriented", dest="notOriented", action="store_true", default=False, help="if the reads are not oriented [default: False] [format: bool]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
413 parser.add_option("-s", "--simple", dest="simple", action="store_true", default=False, help="normalize using the number of reads in each condition [format: bool]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
414 parser.add_option("-S", "--simpleParameters", dest="simpleParameters", action="store", default=None, type="string", help="provide the number of reads [format: bool]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
415 parser.add_option("-a", "--adjusted", dest="adjusted", action="store_true", default=False, help="normalize using the number of reads of 'mean' regions [format: bool]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
416 parser.add_option("-x", "--fixedSizeFactor", dest="fixedSizeFactor", action="store", default=None, type="int", help="give the magnification factor for the normalization using fixed size sliding windows in reference regions (leave empty for no such normalization) [format: int]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
417 parser.add_option("-d", "--fdr", dest="fdr", action="store", default=None, type="float", help="use FDR [format: float]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
418 parser.add_option("-p", "--plot", dest="plotName", action="store", default=None, type="string", help="plot cloud plot [format: output file in PNG format]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
419 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
420 (options, args) = parser.parse_args()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
421
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
422
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
423
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
424 differentialExpression = GetDifferentialExpression(options.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
425 differentialExpression.setInputFile(0, options.inputFileName1, options.format1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
426 differentialExpression.setInputFile(1, options.inputFileName2, options.format2)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
427 differentialExpression.setReferenceFile(options.referenceFileName, options.referenceFormat)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
428 differentialExpression.setOutputFile(options.outputFileName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
429 if options.plotName != None :
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
430 differentialExpression.setPlotterName(options.plotName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
431 differentialExpression.setPlotter()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
432 differentialExpression.setOriented(not options.notOriented)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
433 differentialExpression.setSimpleNormalization(options.simple)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
434 differentialExpression.setSimpleNormalizationParameters(options.simpleParameters)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
435 differentialExpression.setAdjustedNormalization(options.adjusted)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
436 differentialExpression.setFixedSizeNormalization(options.fixedSizeFactor)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
437 differentialExpression.setFdr(options.fdr)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
438 differentialExpression.getDifferentialExpression()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
439 differentialExpression.mySqlConnection.deleteDatabase()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
440
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
441