erange 4.0a dev release with integrated cistematic
[erange.git] / cistematic / experiments / varyLength.py
1 ###########################################################################
2 #                                                                         #
3 # C O P Y R I G H T   N O T I C E                                         #
4 #  Copyright (c) 2003-10 by:                                              #
5 #    * California Institute of Technology                                 #
6 #                                                                         #
7 #    All Rights Reserved.                                                 #
8 #                                                                         #
9 # Permission is hereby granted, free of charge, to any person             #
10 # obtaining a copy of this software and associated documentation files    #
11 # (the "Software"), to deal in the Software without restriction,          #
12 # including without limitation the rights to use, copy, modify, merge,    #
13 # publish, distribute, sublicense, and/or sell copies of the Software,    #
14 # and to permit persons to whom the Software is furnished to do so,       #
15 # subject to the following conditions:                                    #
16 #                                                                         #
17 # The above copyright notice and this permission notice shall be          #
18 # included in all copies or substantial portions of the Software.         #
19 #                                                                         #
20 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,         #
21 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF      #
22 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND                   #
23 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS     #
24 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN      #
25 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN       #
26 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE        #
27 # SOFTWARE.                                                               #
28 ###########################################################################
29 #
30 # a simple use of the experiment class
31 from experiment import Experiment
32 from analyzeMotifs import AnalyzeMotifs
33
34 class VaryLength(Experiment, AnalyzeMotifs):
35     experimentType = "varyLength"
36
37
38     def setRange(self, step, uMin=0, uMax=0, dMin=0, dMax=0):
39         self.stepSize      = step
40         self.upstreamMin   = uMin
41         self.upstreamMax   = uMax + 1
42         self.downstreamMin = dMin
43         self.downstreamMax = dMax + 1
44
45
46     def run(self):
47         Experiment.run(self)
48
49         for downP in range(self.downstreamMin, self.downstreamMax, self.stepSize):
50             for upP in range(self.upstreamMin, self.upstreamMax, self.stepSize):
51                 self.setSeqParameters(upP, downP)
52                 # force reloading of the genepool
53                 self.loadGenepool()
54                 datasetID = self.genepoolID
55                 fastaFile = self.createDataFile()
56                 for (prog, settingsID) in self.programs:
57                     prog.inputFile(fastaFile)
58                     # reset setttings to orig settings, set new length, save settings
59                     prog.setSettings(self.settings[settingsID])
60                     prog.setSeqLength(str(upP + downP))
61                     newestSettingsID = self.setSettings(prog.getSettings())
62                     runID = self.setRun(prog.name(), datasetID, newestSettingsID)
63                     tag = str(runID)
64                     prog.setTagID(tag)
65                     prog.run()
66                     theMotifs = prog.getMotifs()
67                     for mot in theMotifs:
68                         self.results.append(mot)