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
32 import time, Consensus
33 from cistematic.core.motif import Motif
36 class CisGreedy(Program):
39 def getSettings(self):
40 return (self.model, self.nmotifs, self.minwidth, self.maxwidth, self.bON,
41 self.iterations, self.Founder, self.bfile, self.percID,
42 self.founderPercID, self.MarkovSize)
45 def setSettings(self, settings):
47 (self.model, self.nmotifs, self.minwidth, self.maxwidth, self.bON,
48 self.iterations, self.Founder, self.bfile, self.percID,
49 self.founderPercID, self.MarkovSize) = settings
52 def setGenExpOptions(self, optionArray):
53 self.setModel("zoops")
54 self.setNumMotifs("10")
55 self.setMaxWidth("15")
58 self.setIterations("100")
63 self.setMarkovSize("3")
64 self.setFounderPID("75")
65 self.setBackground("None")
66 for option in optionArray:
67 (optionTag, optionValue) = option.split(":")
69 if optionTag == "Markov size":
70 self.setMarkovSize(optionValue)
72 if optionTag == "percentID":
73 self.setPercID(optionValue)
75 if optionTag == "founderPercentID":
76 self.setFounderPID(optionValue)
78 if optionTag == "model":
79 self.setModel(optionValue)
81 if optionTag == "nmotifs":
82 self.setNumMotifs(optionValue)
84 if optionTag == "width":
85 self.setMinWidth(optionValue)
86 self.setMaxWidth(optionValue)
88 if optionTag == "minWidth":
89 self.setMinWidth(optionValue)
91 if optionTag == "maxWidth":
92 self.setMaxWidth(optionValue)
94 if optionTag == "reverse":
95 self.setBON(optionValue)
97 if optionTag == "iterations":
98 self.setIterations(optionValue)
100 if optionTag == "background":
101 self.setBackground(optionValue)
103 if optionTag == "founder":
104 self.setFounder(True)
106 #if no background file is provided the default setting
107 #is to use the input sequences as a background
112 def setMarkovSize(self, val):
113 self.MarkovSize = int(str(val))
116 def setFounderPID(self, val):
117 self.founderPercID = int(str(val))
120 def setFounder(self, boolVal):
127 def setPercID(self, percVal):
128 self.percID = int(str(percVal))
131 def setModel(self, modelType):
132 if modelType in ["oops", "zoops", "tcm"]:
133 self.model = str(modelType)
135 self.model = "zoops";
138 def setIterations(self, number):
139 self.iterations = int(str(number))
142 def setNumMotifs(self, motifNum):
143 self.nmotifs = int(str(motifNum))
146 def setBON(self, B_val):
147 if str(B_val) == "False":
153 def getSequences(self, infile):
154 seqFiles = open(infile, 'r')
155 Lines = seqFiles.readlines()
160 self.sequences.append(line[:-1])
163 def setMinWidth(self, width):
164 self.minwidth = int(str(width))
167 def setMaxWidth(self, width):
168 self.maxwidth = int(str(width))
171 def setBackground(self, backFile):
172 self.bfile = str(backFile)
177 startTime = time.time()
178 if self.bfile == "None":
179 self.bfile = Consensus.Markov(self.sequences, self.bON,self.MarkovSize)
181 print "geting consensus score"
182 self.contents = Consensus.MotifFinder(self.sequences, self.minwidth, self.maxwidth,
183 self.nmotifs, self.iterations, self.bfile,
184 self.bON, self.Founder,self.percID,
185 self.founderPercID, self.MarkovSize, self.model,
187 stopTime = time.time()
188 print "\nThis run took %.3f - %.3f = %.3f seconds and produced %d motifs" % (startTime, stopTime, stopTime - startTime, len(self.contents[0]))
194 (PWMs, Seqs) = self.contents
195 for index in range(len(Seqs)):
196 self.motifs.append(Motif("%s-cisGreedy-%s" % (self.tagID, str(index + 1)), seqs=Seqs[index]))
198 print "error returning motifs"