annotate TEisotools-1.1.a/commons/core/utils/Classif.py @ 15:255c852351c5 draft

Uploaded
author urgi-team
date Thu, 21 Jul 2016 07:36:44 -0400
parents feef9a0db09d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
1 import re
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
2 import os
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
3 from collections import OrderedDict
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
4
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
5 DWICKERCODE = {
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
6 "ClassI":"RXX",
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
7 "ClassII":"DXX",
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
8 "LTR":"RLX",
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
9 "DIRS":"RYX",
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
10 "PLE":"RPX",
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
11 "LINE":"RIX",
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
12 "SINE":"RSX",
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
13 "TIR":"DTX",
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
14 "Crypton":"DYX",
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
15 "Helitron":"DHX",
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
16 "Maverick":"DMX",
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
17
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
18 "TIR-MITE":"DTX",
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
19 "LTR-LARD":"RLX",
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
20 "LTR-TRIM":"RLX"
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
21 }
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
22
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
23 class Classif(object):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
24 """ The class Classif is a object what determine a line in classif file.
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
25 """
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
26
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
27 def __init__(self, consensusName = "", code = "NA", outConfuseness = "", outCompleteness = "", projectName = "", isShorten = False, consensusLength = "NA", consensusStrand = "NA", consensusClass = "NA", consensusOrder = "NA", consensusSuperFam = "NA", consensusCI = "NA"):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
28 self._consensusName = consensusName
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
29 self._confusness = outConfuseness
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
30 self._completeness = outCompleteness
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
31 self._projectName = projectName
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
32 self._isShorten = isShorten
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
33 self._consensusLength = consensusLength
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
34 self._consensusStrand = consensusStrand
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
35 self._consensusClass = consensusClass
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
36 self._consensusOrder = consensusOrder
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
37 self._consensusSuperFam = consensusSuperFam
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
38 self._consensusCI = consensusCI
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
39 self._consensusCoding = ""
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
40 self._consensusStruct = ""
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
41 self._consensusOther = ""
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
42 self._isNoChim = ""
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
43 self._hasCodingPart = False
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
44 self._hasStructPart = False
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
45 self._hasOtherPart = False
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
46 self._code = code
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
47 self._evidence = {}
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
48
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
49 def __eq__(self, o):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
50 if type(o) is type(self):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
51 return self._consensusName == o._consensusName and self._code == o._code \
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
52 and self._confusness == o._confusness and self._completeness == o._completeness
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
53 return False
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
54
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
55 def __ne__(self, o):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
56 return not self.__eq__(o)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
57
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
58 def getConsensusName(self):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
59 return self._consensusName
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
60
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
61 def getCode(self):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
62 return self._code
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
63
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
64 def getconfusness(self):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
65 return self._confusness
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
66
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
67 def getcompleteness(self):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
68 return self._completeness
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
69
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
70 def getprojectName(self):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
71 return self._projectName
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
72
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
73 def getConsensusLength(self):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
74 return self._consensusLength
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
75
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
76 def getConsensusStrand(self):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
77 return self._consensusStrand
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
78
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
79 def getConsensusClass(self):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
80 return self._consensusClass
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
81
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
82 def getConsensusOrder(self):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
83 return self._consensusOrder
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
84
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
85 def getConsensusSuperFamily(self):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
86 return self._consensusSuperFam
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
87
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
88 def getConsensusCI(self):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
89 return str(self._consensusCI)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
90
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
91 def getInfoEvidence(self):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
92 return self._evidence
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
93
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
94 def getConsensusCoding(self):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
95 if self._confusness == 'ok':
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
96 coding = self.writeCodingFeaturesLine(self._evidence)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
97 else:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
98 lOrder = self.getConsensusOrder().split("|")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
99 coding = self.writeCodingFeaturesLine(self._evidence[lOrder[0]])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
100 for order in lOrder[1:]:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
101 if self._evidence[order].keys() != ['other']:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
102 coding = coding + "|" + self.writeCodingFeaturesLine(self._evidence[order])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
103 return "coding=" + coding
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
104
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
105 def getConsensusStructure(self):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
106 if self._confusness == 'ok':
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
107 Structure = self.writeStructFeaturesLine(self._evidence)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
108 else:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
109 lOrder = self.getConsensusOrder().split("|")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
110 Structure = self.writeStructFeaturesLine(self._evidence[lOrder[0]])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
111 for order in lOrder[1:]:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
112 if self._evidence[order].keys() != ['other']:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
113 Structure = Structure + "|" + self.writeStructFeaturesLine(self._evidence[order])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
114 return "struct=" + Structure
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
115
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
116 def getConsensusOther(self):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
117 if self._confusness == 'ok':
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
118 Other = self.writeOtherFeaturesLine(self._evidence)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
119 else:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
120 lOrder = self.getConsensusOrder().split("|")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
121 Other = self.writeOtherFeaturesLine(self._evidence[lOrder[0]])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
122 for order in lOrder[1:]:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
123 Other = Other + "|" + self.writeOtherFeaturesLine(self._evidence[order])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
124 return "other=" + Other
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
125
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
126 def setConsensusName(self, consensusName):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
127 self._consensusName = consensusName
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
128
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
129 def setInfoEvidence(self, evidence):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
130 self._evidence = evidence
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
131
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
132 def setCode(self):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
133 self._code = self._decisionRuleForWickerCode(self.getConsensusClass(), self.getConsensusOrder())
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
134
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
135 def setConfusness(self, Confusness):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
136 self._confusness = Confusness
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
137
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
138 def setCompleteness(self, completeness):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
139 self._completeness = completeness
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
140
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
141 def setProjectName(self, projectName):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
142 self._projectName = projectName
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
143
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
144 def setConsensusLength(self, cLength):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
145 self._consensusLength = cLength
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
146
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
147 def setConsensusStrand(self, cStrand):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
148 self._consensusStrand = cStrand
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
149
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
150 def setConsensusClass(self, cClass):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
151 self._consensusClass = cClass
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
152
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
153 def setConsensusOrder(self, cOrder):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
154 self._consensusOrder = cOrder
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
155
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
156 def setConsensusSuperFamily(self, cSuperFamily):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
157 self._consensusSuperFamily = cSuperFamily
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
158
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
159 def setConsensusCI(self, CI):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
160 self._consensusCI = CI
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
161
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
162 def setConsensusCoding(self, coding):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
163 self._consensusCoding = coding
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
164
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
165 def setConsensusStructure(self, structure):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
166 self._consensusStruct = structure
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
167
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
168 def setConsensusOther(self, other):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
169 self._consensusOther = other
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
170
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
171 def setCodStrOthFromMessage(self, dico):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
172 self._consensusCoding = "coding="+self.writeCodingFeaturesLine(dico)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
173 self._consensusStruct = "struct="+self.writeStructFeaturesLine(dico)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
174 self._consensusOther = "other="+self.writeOtherFeaturesLine(dico)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
175
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
176 def setCodStrOthFromMessage2(self, dico, cOrder):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
177 if 'rDNA' in cOrder:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
178 cOrder = cOrder.replace('rDNA', 'RDNA')
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
179 lOrder = cOrder.split("|")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
180 lDicoKeys = dico.keys()
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
181 if lOrder[0] not in lDicoKeys:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
182 self._consensusCoding = "coding="+self.writeCodingFeaturesLine(dico)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
183 self._consensusStruct = "struct="+self.writeStructFeaturesLine(dico)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
184 self._consensusOther = "other="+self.writeOtherFeaturesLine(dico)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
185 else:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
186 self._consensusCoding = "coding="+self.writeCodingFeaturesLine(dico[lDicoKeys[0]])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
187 self._consensusStruct = "struct="+self.writeStructFeaturesLine(dico[lDicoKeys[0]])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
188 self._consensusOther = "other="+self.writeOtherFeaturesLine(dico[lDicoKeys[0]])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
189 if len(lDicoKeys) != 1:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
190 for order in lDicoKeys[1:]:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
191 if dico[order].keys() == ['other']:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
192 self._consensusOther = self._consensusOther+"|"+self.writeOtherFeaturesLine(dico[order])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
193 else:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
194 self._consensusCoding = self._consensusCoding+"|"+self.writeCodingFeaturesLine(dico[order])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
195 self._consensusStruct = self._consensusStruct+"|"+self.writeStructFeaturesLine(dico[order])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
196 self._consensusOther = self._consensusOther+"|"+self.writeOtherFeaturesLine(dico[order])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
197
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
198 def createNewConsensusName(self):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
199 pastecClassif = "%s" % self._code
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
200 if self._completeness != "":
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
201 pastecClassif += "-%s" % self._completeness
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
202 if self._confusness != "":
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
203 pastecClassif += "-%s" % self._confusness
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
204 if self._isShorten:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
205 pattern = "%s_[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9_]+" % self._projectName
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
206 if re.match(pattern, self._consensusName) and not "%s_RS_" % self._projectName in self._consensusName:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
207 header = self.shortenConsensusName()
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
208 header = "%s_%s" % (pastecClassif, header)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
209 else:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
210 header = "%s_%s" % (pastecClassif, self._consensusName)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
211 else:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
212 header = "%s_%s" % (pastecClassif, self._consensusName)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
213
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
214 return header
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
215
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
216 def shortenConsensusName(self):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
217 desc = self._consensusName.split(self._projectName)[1]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
218 palignMeth = desc.split("_")[1]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
219 clustMeth = desc.split("_")[2]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
220 clustID = desc.split("_")[3]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
221 lmalignMeth = desc.split("_")[4:]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
222 if len(lmalignMeth) > 2:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
223 malignMeth = "%s%s_%s" % (lmalignMeth[0], lmalignMeth[1], lmalignMeth[2])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
224 else:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
225 malignMeth = "".join(lmalignMeth)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
226 consensusShorten = "%s-%s-%s%s-%s" % (self._projectName, palignMeth[0], clustMeth[0], clustID, malignMeth)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
227
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
228 return consensusShorten
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
229
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
230 def renameHeaderInConsensusFastaFile(self, fileName = ""):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
231 newFileName = fileName.split(".")[0]+"New.fa"
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
232
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
233 oldFile = open(fileName, "r")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
234 newFile = open(newFileName, "w")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
235
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
236 inputLine = oldFile.readline()
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
237 while inputLine != "" :
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
238 if ">" in inputLine:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
239 self.setConsensusName(inputLine)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
240 outputLine = ">%s" % self.shortenConsensusName()
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
241 newFile.write(outputLine)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
242 else:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
243 newFile.write(inputLine)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
244
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
245 inputLine = oldFile.readline()
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
246
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
247 oldFile.close()
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
248 newFile.close()
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
249
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
250 os.system("mv %s.fa %sOld.fa" % (fileName.split(".")[0], fileName.split(".")[0]))
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
251 os.system("mv %sNew.fa %s.fa" % (fileName.split(".")[0], fileName.split(".")[0]))
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
252 os.system("rm -f %sOld.fa" % fileName.split(".")[0])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
253
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
254 def writeOtherFeaturesLine(self, dEvidence):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
255 other = "(NA)"
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
256 if dEvidence.has_key('other'):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
257 lResults = []
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
258 dOtherResults = dEvidence['other']
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
259 lResultsWithCoding = self.formatCodingFeatures(dOtherResults, lResults)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
260 lResultsFilled = self.formatStructFeatures(dOtherResults, lResultsWithCoding)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
261 if len(lResultsFilled) != 0:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
262 subOther = "; ".join(lResultsFilled)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
263 other = '(%s)' % subOther
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
264 self._hasOtherPart = True
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
265 return other
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
266
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
267 def writeCodingFeaturesLine(self, dEvidence):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
268 lResults = []
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
269 lResultsFilled = self.formatCodingFeatures(dEvidence, lResults)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
270 if len(lResultsFilled) != 0:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
271 subCoding = "; ".join(lResultsFilled)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
272 coding = '(%s)' % subCoding
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
273 else:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
274 coding = "(NA)"
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
275 return coding
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
276
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
277 def writeStructFeaturesLine(self, dEvidence):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
278 lResults = []
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
279 lResultsFilled = self.formatStructFeatures(dEvidence, lResults)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
280 if len(lResultsFilled) != 0:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
281 subStruct = "; ".join(lResultsFilled)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
282 struct = '(%s)' % subStruct
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
283 else:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
284 struct = "(NA)"
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
285 return struct
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
286
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
287 def formatCodingFeatures(self, dEvidence, lResults):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
288 if dEvidence.has_key('Repbase_tbx') and dEvidence['Repbase_tbx'] != []:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
289 lResults.append("TE_BLRtx: %s" % ", ".join(map(str, dEvidence['Repbase_tbx'])))
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
290
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
291 if dEvidence.has_key('Repbase_bx') and dEvidence['Repbase_bx'] != []:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
292 lResults.append("TE_BLRx: %s" % ", ".join(map(str, dEvidence['Repbase_bx'])))
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
293
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
294 if (dEvidence.has_key('te_hmmer')) and (dEvidence['te_hmmer'] != None):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
295 lResults.append('profiles: %s' % self.formatProfilesResults(dEvidence['te_hmmer']))
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
296
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
297 if dEvidence.has_key('Other_profiles'):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
298 lResults.append('Other_profiles: %s' % self.formatProfilesResults(dEvidence['Other_profiles']))
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
299
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
300 if dEvidence.has_key("rDNA") and (dEvidence["rDNA"] != None):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
301 lResults.append("rDNA_BLRn: %s" % dEvidence["rDNA"])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
302
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
303 if dEvidence.has_key("HG") and (dEvidence["HG"] != None):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
304 lResults.append("HG_BLRn: %s" % dEvidence["HG"])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
305
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
306 if len(lResults) != 0:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
307 self._hasCodingPart = True
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
308 return lResults
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
309
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
310 def formatProfilesResults(self, dProfilesResults):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
311 if len(dProfilesResults.keys()) == 0:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
312 return ""
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
313 lResults = []
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
314 for key in dProfilesResults.keys():
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
315 iPDM = dProfilesResults[key]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
316 cov = "%.2f%%" % iPDM.getCoverageOnSubject()
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
317 profilesResult = '%s: %s' % (key, cov)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
318 lResults.append(profilesResult)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
319 return ", ".join(lResults)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
320
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
321 def formatStructFeatures(self, dEvidence, lResults):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
322 if dEvidence.has_key('length') and (dEvidence['length']!= None):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
323 lResults.append('TElength: %s' % dEvidence['length'])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
324
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
325 if dEvidence.has_key('TR') and (dEvidence['TR'] != None):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
326 lResults.append('TermRepeats: %s' % ", ".join(map(str, dEvidence['TR'])))
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
327
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
328 if dEvidence.has_key('ORF') and (dEvidence['ORF'] != None):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
329 lResults.append('ORF: %s' % ", ".join(dEvidence['ORF']))
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
330
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
331 if dEvidence.has_key('SSR') and (dEvidence['SSR'] != None):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
332 lResults.append('SSR: %s' % ", ".join(dEvidence['SSR']))
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
333
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
334 if dEvidence.has_key('SSRCoverage') and (dEvidence['SSRCoverage'] != None) :
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
335 lResults.append('SSRCoverage=%s' % dEvidence['SSRCoverage'])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
336
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
337 if dEvidence.has_key('polyAtail'):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
338 lResults.append('polyAtail')
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
339
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
340 if dEvidence.has_key('helitronExtremities') and (dEvidence['helitronExtremities'] != None):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
341 lResults.append('helitronExtremities: %s' % ", ".join(map(str, dEvidence['helitronExtremities'])))
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
342 if len(lResults) != 0:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
343 self._hasStructPart = True
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
344 return lResults
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
345
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
346 def _decisionRuleForWickerCode(self, teClass, order):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
347 code = 'NA'
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
348 if order in DWICKERCODE.keys():
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
349 code = DWICKERCODE[order]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
350 elif teClass in DWICKERCODE.keys():
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
351 code = DWICKERCODE[teClass]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
352 elif order == "Unclassified" and teClass == "Unclassified":
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
353 code = "NA"
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
354 elif re.search("\|", order) and teClass == "Unclassified":
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
355 code = "XXX"
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
356 elif re.search("\|", order) and re.search("\|",teClass):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
357 lClass = teClass.split("|")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
358 for iC in lClass[1:]:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
359 if lClass[0] != iC:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
360 code = "XXX"
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
361 return code
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
362 code = DWICKERCODE[lClass[0]]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
363 return code
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
364
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
365 def renameLARDTRIMAndMITE(self):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
366 order = self.getConsensusOrder()
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
367 order = order.replace("MITE", "TIR-MITE")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
368 order = order.replace("LARD", "LTR-LARD")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
369 order = order.replace("TRIM", "LTR-TRIM")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
370 self.setConsensusOrder(order)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
371 dEvidence = self.getInfoEvidence()
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
372 if 'LARD' in dEvidence.keys():
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
373 dEvidence["LTR-LARD"] = dEvidence["LARD"]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
374 del dEvidence["LARD"]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
375 if 'TRIM' in dEvidence.keys():
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
376 dEvidence["LTR-TRIM"] = dEvidence["TRIM"]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
377 del dEvidence["TRIM"]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
378 if 'MITE' in dEvidence.keys():
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
379 dEvidence["TIR-MITE"] = dEvidence["MITE"]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
380 del dEvidence["MITE"]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
381 self.setInfoEvidence(dEvidence)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
382
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
383
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
384
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
385