annotate SMART/Java/Python/getRandomRegions.py @ 44:5f796c5c579f

Uploaded
author m-zytnicki
date Wed, 18 Sep 2013 08:32:38 -0400
parents 769e306b7933
children 169d364ddd91
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 """Find random regions in a genome"""
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 import random, math
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 commons.core.parsing.FastaParser import *
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 from commons.core.writer.Gff3Writer import *
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37 from commons.core.writer.MySqlTranscriptWriter import *
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 from SMART.Java.Python.misc.Progress import *
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 from SMART.Java.Python.structure.Transcript import Transcript
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40 from SMART.Java.Python.structure.TranscriptContainer import TranscriptContainer
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42 repetitions = 100
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 class RandomRegionsGenerator(object):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 def __init__(self, verbosity):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 self.verbosity = verbosity
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 self.strands = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 self.distribution = "uniform"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 self.transcripts = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 self.sequenceParser = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 random.seed()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 def setInput(self, fileName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 self.sequenceParser = FastaParser(fileName, self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 def setGenomeSize(self, size):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 self.genomeSize = size
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 def setChromosomeName(self, name):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 self.chromosomeName = name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 def setAnnotation(self, fileName, format):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 parser = TranscriptContainer(fileName, format, self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 self.transcripts = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 for transcript in parser.getIterator():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 self.transcripts.append(transcript)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 self.setNumber(len(self.transcripts))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74 self.setSize(0)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 def setOutputFile(self, fileName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 self.outputFileName = fileName
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 setSize(self, size):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82 self.minSize = size
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83 self.maxSize = size
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 setMinSize(self, size):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87 self.minSize = size
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90 def setMaxSize(self, size):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 self.maxSize = size
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94 def setNumber(self, number):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95 self.number = number
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98 def setStrands(self, strands):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 self.strands = strands
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102 def setMaxDistribution(self, maxElements):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103 if maxElements == None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104 return
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105 self.maxElements = maxElements
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106 self.distribution = "gaussian"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109 def setDeviationDistribution(self, deviation):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110 if deviation == None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111 return
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112 self.deviation = deviation
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113 self.distribution = "gaussian"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116 def getSizes(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117 if self.sequenceParser == None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118 self.chromosomes = [self.chromosomeName]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119 self.sizes = {self.chromosomeName: self.genomeSize}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120 self.cumulatedSize = self.genomeSize
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121 self.cumulatedSizes = {self.chromosomeName: self.genomeSize}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122 return
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123 self.chromosomes = self.sequenceParser.getRegions()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124 self.sizes = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125 self.cumulatedSize = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
126 self.cumulatedSizes = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
127 for chromosome in self.chromosomes:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
128 self.sizes[chromosome] = self.sequenceParser.getSizeOfRegion(chromosome)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
129 self.cumulatedSize += self.sizes[chromosome]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
130 self.cumulatedSizes[chromosome] = self.cumulatedSize
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
131
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
132
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
133 def findPosition(self, size = None):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
134 if size == None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
135 size = random.randint(self.minSize, self.maxSize)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
136 integer = random.randint(0, self.cumulatedSize)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
137 for chromosome in self.chromosomes:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
138 if self.cumulatedSizes[chromosome] > integer:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
139 break
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
140 start = random.randint(1, self.sizes[chromosome] - size)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
141 return (chromosome, start, size)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
142
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
143
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
144 def createTranscript(self, chromosome, start, size, strand, cpt):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
145 transcript = Transcript()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
146 transcript.setChromosome(chromosome)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
147 transcript.setStart(start)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
148 transcript.setEnd(start + size-1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
149 transcript.setDirection(strand)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
150 transcript.setName("rand_%d" % (cpt))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
151 return transcript
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
152
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
153
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
154 def moveTranscript(self, chromosome, start, transcript):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
155 while transcript.getEnd() + start - transcript.getStart() > self.cumulatedSizes[chromosome]:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
156 chromosome, start, size = self.findPosition(transcript.getEnd() - transcript.getStart())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
157 transcript.setChromosome(chromosome)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
158 oldStart, oldEnd = transcript.getStart(), transcript.getEnd()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
159 if transcript.getNbExons() > 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
160 for exon in transcript.getNbExons():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
161 oldExonStart, oldExonEnd = exon.getStart(), exon.getEnd()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
162 exon.setStart(oldExonStart + start - oldStart)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
163 exon.setEnd(oldExonEnd + start - oldStart)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
164 transcript.setStart(start)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
165 transcript.setEnd(oldEnd + start - oldStart)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
166 return [transcript]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
167
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
168
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
169 def createUniformCluster(self, chromosome, start, size, strand, cpt):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
170 transcript = self.createTranscript(chromosome, start, size, strand, cpt)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
171 return [transcript]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
172
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
173
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
174 def findNbTranscripts(self, cpt):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
175 return min(int(round(math.exp(random.random() * math.log(self.maxElements)))), self.number - cpt + 1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
176
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
177
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
178 def getDev(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
179 deviation = 0.0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
180 for j in range(repetitions):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
181 deviation += random.randint(-self.deviation, self.deviation)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
182 deviation /= repetitions
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
183 deviation = int(round(deviation))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
184 return deviation
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
185
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
186
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
187 def createGaussianCluster(self, chromosome, start, size, strand, cpt):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
188 transcripts = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
189 nbTranscripts = self.findNbTranscripts(cpt)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
190 for i in range(nbTranscripts):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
191 transcript = self.createTranscript(chromosome, start + self.getDev(), size + self.getDev(), strand, cpt + i)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
192 transcripts.append(transcript)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
193 return transcripts
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
194
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
195
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
196 def writeRegions(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
197 writer = Gff3Writer(self.outputFileName, self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
198 outputFile = open(self.outputFileName, "w")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
199 progress = Progress(self.number, "Writing to %s" % (self.outputFileName), self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
200 i = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
201 while i < self.number:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
202 chromosome, start, size = self.findPosition()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
203 strand = random.choice([-1, 1]) if self.strands else 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
204 if self.transcripts != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
205 transcripts = self.moveTranscript(chromosome, start, self.transcripts[i])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
206 elif self.distribution == "uniform":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
207 transcripts = self.createUniformCluster(chromosome, start, size, strand, i+1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
208 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
209 transcripts = self.createGaussianCluster(chromosome, start, size, strand, i+1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
210 for transcript in transcripts:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
211 writer.addTranscript(transcript)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
212 i += 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
213 progress.inc()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
214 progress.done()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
215 outputFile.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
216 writer.write()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
217 writer.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
218
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
219
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
220 def run(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
221 self.getSizes()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
222 self.writeRegions()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
223
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
224
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
225 if __name__ == "__main__":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
226
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
227 # parse command line
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
228 description = "Get Random Regions v1.0.2: Get some random coordinates on a genome. May use uniform or gaussian distribution (in gaussion distribution, # of element per cluster follows a power law). [Category: Other]"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
229
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
230 parser = OptionParser(description = description)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
231 parser.add_option("-r", "--reference", dest="reference", action="store", default=None, type="string", help="file that contains the sequences [format: file in FASTA format]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
232 parser.add_option("-S", "--referenceSize", dest="referenceSize", action="store", default=None, type="int", help="size of the chromosome (when no reference is given) [format: int]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
233 parser.add_option("-c", "--chromosome", dest="chromosome", action="store", default=None, type="string", help="name of the chromosome (when no reference is given) [format: string]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
234 parser.add_option("-o", "--output", dest="outputFileName", action="store", type="string", help="output file [compulsory] [format: output file in FASTA format]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
235 parser.add_option("-i", "--input", dest="inputFileName", action="store", default=None, type="string", help="optional file containing regions to shuffle [format: file in transcript format given by -f]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
236 parser.add_option("-f", "--format", dest="format", action="store", default=None, type="string", help="format of the previous file [format: transcript file format]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
237 parser.add_option("-s", "--size", dest="size", action="store", default=None, type="int", help="size of the regions (if no region set is provided) [format: int]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
238 parser.add_option("-z", "--minSize", dest="minSize", action="store", default=None, type="int", help="minimum size of the regions (if no region set nor a fixed size are provided) [format: int]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
239 parser.add_option("-Z", "--maxSize", dest="maxSize", action="store", default=None, type="int", help="maximum size of the regions (if no region set nor a fixed size are provided) [format: int]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
240 parser.add_option("-n", "--number", dest="number", action="store", default=None, type="int", help="number of regions (if no region set is provided) [format: int]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
241 parser.add_option("-t", "--strands", dest="strands", action="store_true", default=False, help="use both strands (if no region set is provided) [format: boolean]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
242 parser.add_option("-m", "--max", dest="max", action="store", default=None, type="int", help="max. # reads in a cluster (for Gaussian dist.) [format: int]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
243 parser.add_option("-d", "--deviation", dest="deviation", action="store", default=None, type="int", help="deviation around the center of the cluster (for Gaussian dist.) [format: int]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
244 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
245 (options, args) = parser.parse_args()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
246
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
247 rrg = RandomRegionsGenerator(options.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
248 if options.reference == None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
249 rrg.setGenomeSize(options.referenceSize)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
250 rrg.setChromosomeName(options.chromosome)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
251 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
252 rrg.setInput(options.reference)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
253 rrg.setOutputFile(options.outputFileName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
254 if options.inputFileName == None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
255 if options.size != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
256 rrg.setSize(options.size)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
257 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
258 rrg.setMinSize(options.minSize)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
259 rrg.setMaxSize(options.maxSize)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
260 rrg.setNumber(options.number)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
261 rrg.setStrands(options.strands)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
262 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
263 rrg.setAnnotation(options.inputFileName, options.format)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
264 rrg.setMaxDistribution(options.max)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
265 rrg.setDeviationDistribution(options.deviation)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
266 rrg.run()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
267