1 ###########################################################################
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 #
7 # All Rights Reserved. #
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: #
17 # The above copyright notice and this permission notice shall be #
18 # included in all copies or substantial portions of the Software. #
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 #
28 ###########################################################################
31 from cistematic.programs import Program
33 import cistematic.programs.gibbs as Gibbs
34 from cistematic.core.motif import Motif
37 class CisSampler(Program):
40 def getSettings(self):
41 return (self.model, self.nmotifs, self.minwidth, self.maxwidth, self.bON, self.iterations,self.bfile, self.percID,self.MarkovSize,self.findBest)
44 def setSettings(self, settings):
46 (self.model, self.nmotifs, self.minwidth, self.maxwidth, self.bON, self.iterations, self.bfile,self.percID,self.MarkovSize,self.findBest) = settings
49 def setGenExpOptions(self, optionArray):
50 self.setModel("zoops")
51 self.setNumMotifs("10")
52 self.setMaxWidth("15")
53 self.setIterations("1000")
58 self.setMarkovSize("2")
59 self.setFindBest("100")
60 for option in optionArray:
61 (optionTag, optionValue) = option.split(":")
62 if optionTag == "Markov size":
63 self.setMarkovSize(optionValue)
65 if optionTag == "percentID":
66 self.setPercID(optionValue)
68 if optionTag == "founderPercentID":
69 self.setFounderPID(optionValue)
71 if optionTag == "model":
72 self.setModel(optionValue)
74 if optionTag == "nmotifs":
75 self.setNumMotifs(optionValue)
77 if optionTag == "width":
78 self.setMinWidth(optionValue)
79 self.setMaxWidth(optionValue)
81 if optionTag == "minWidth":
82 self.setMinWidth(optionValue)
84 if optionTag == "maxWidth":
85 self.setMaxWidth(optionValue)
87 if optionTag == "reverse":
88 self.setBON(optionValue)
90 if optionTag == "iterations":
91 self.setIterations(optionValue)
93 if optionTag == "background":
94 self.setBackground(optionValue)
96 if optionTag == "founder":
99 #if no background file is provided the default setting
100 #is to use the input sequences as a background
104 def setMarkovSize(self,val):
105 self.MarkovSize = int(str(val))
108 def setFindBest(self,val):
109 self.findBest = int(str(val))
112 def setFounderPID(self,val):
113 self.founderPercID = int(str(val))
116 def setFounder(self, boolVal):
123 def setPercID(self, percVal):
124 self.percID = int(str(percVal))
127 def setModel(self, modelType):
128 if modelType in ["oops", "zoops", "tcm"]:
129 self.model = str(modelType)
131 self.model = "zoops";
134 def setIterations(self, number):
135 self.iterations = int(str(number))
138 def setNumMotifs(self, motifNum):
139 self.nmotifs = int(str(motifNum))
142 def setBON(self, B_val):
143 if str(B_val) == "False":
149 def getSequences(self, infile):
150 seqFiles = open(infile, "r")
151 Lines = seqFiles.readlines()
156 self.sequences.append(line[:-1])
159 def setMinWidth(self, width):
160 self.minwidth = int(str(width))
163 def setMaxWidth(self, width):
164 self.maxwidth = int(str(width))
167 ##willlikley satr to use this but not yet
168 # set background frequency file
169 def setBackground(self, backFile):
170 self.bfile = str(backFile)
175 startTime = time.time()
176 if self.bfile == "None":
177 self.bfile = Gibbs.Markov(self.sequences, self.bON,self.MarkovSize)
178 print "geting consensus score"
179 self.contents = Gibbs.MotifFinder(self.sequences, self.minwidth, self.maxwidth, self.nmotifs,
180 self.MarkovSize, self.bON, self.bfile, False, self.percID,
181 self.iterations, self.findBest)
182 stopTime = time.time()
184 print "right here!\n \n\n"
185 print "\nThis run took %.3f - %.3f = %.3f seconds and produced %d motifs" % (startTime, stopTime, stopTime - startTime, len(self.contents))
191 for motif in range(len(self.contents)):
193 self.motifs.append(Motif("%s-cisSampler-%s" % (self.tagID, str(motif + 1)), "", self.contents[motif], [], 0.0, info))
195 print "error returning motifs"