erange 4.0a dev release with integrated cistematic
[erange.git] / cistematic / programs / locator.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 # locator.py
31 from cistematic.programs import Program
32 from cistematic.core.motif import Motif
33
34 class Locator(Program):
35     motifs = []
36     consensus = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
37     identifier = "DEFAULT"
38     PWM = []
39     seqs = []
40     motFile = ""
41
42
43     def getSettings(self):
44         return (self.consensus, self.identifier, self.PWM, self.seqs, self.motFile)
45
46
47     def setSettings(self, settings):
48         self.motifs = []
49         progsettings = ""
50         commSettings = "progsettings = %s" % str(settings)
51         exec commSettings
52         (self.consensus, self.identifier, self.PWM, self.seqs, self.motFile) = progsettings
53
54
55     def setGenExpOptions(self, optionArray):
56         for option in optionArray:
57             (optionTag, optionValue) = option.split(":")
58             if optionTag == "consensus":
59                 self.setConsensus(optionValue)
60
61             if optionTag == "identifier":
62                 self.setID(optionValue)
63
64
65     def setConsensus(self, cons):
66         self.consensus = cons
67
68
69     def setID(self, ident):
70         self.identifier = ident
71
72
73     def setPWM(self, aPWM):
74         self.PWM[self.identifier] = aPWM
75
76
77     def useMotifFile(self, mFile):
78         self.motFile = mFile
79
80
81     def run(self):
82         pass
83
84
85     def getMotifs(self):
86         self.motifs = []
87         if self.motFile != "":
88             motif = Motif("%s-LOC-%s" % (self.tagID, self.identifier), motifFile=self.motFile)
89             self.motifs.append(motif)
90         else:
91             motif = Motif("%s-LOC-%s" % (self.tagID, self.identifier), self.consensus, self.PWM, self.seqs)
92             self.motifs.append(motif)
93
94         return self.motifs