Mercurial > repos > jjjjia > cpo_prediction
comparison cpo_galaxy_tree.py @ 8:93c25036d3b9 draft
planemo upload
author | jjjjia |
---|---|
date | Thu, 23 Aug 2018 19:40:12 -0400 |
parents | 4d2777aa99db |
children | b7e9a3be2b11 |
comparison
equal
deleted
inserted
replaced
7:4d2777aa99db | 8:93c25036d3b9 |
---|---|
15 | 15 |
16 # <requirements> | 16 # <requirements> |
17 # <requirement type="package" version="0.23.4">pandas</requirement> | 17 # <requirement type="package" version="0.23.4">pandas</requirement> |
18 # <requirement type="package" version="3.6">python</requirement> | 18 # <requirement type="package" version="3.6">python</requirement> |
19 # <requirement type="package" version="3.1.1">ete3</requirement> | 19 # <requirement type="package" version="3.1.1">ete3</requirement> |
20 # <requirement type="package" version="5.9.3">pyqt</requirement> | 20 # <requirement type="package" version="5.6.0">pyqt</requirement> |
21 # </requirements> | 21 # </requirements> |
22 | 22 |
23 import subprocess | 23 import subprocess |
24 import pandas #conda pandas | 24 import pandas #conda pandas |
25 import optparse | 25 import optparse |
26 import os | 26 import os |
27 os.environ['QT_QPA_PLATFORM']='offscreen' | |
27 import datetime | 28 import datetime |
28 import sys | 29 import sys |
29 import time | 30 import time |
30 import urllib.request | 31 import urllib.request |
31 import gzip | 32 import gzip |
165 | 166 |
166 distanceDict = {} #store the distance matrix as rowname:list<string> | 167 distanceDict = {} #store the distance matrix as rowname:list<string> |
167 for i in range(len(distance)): | 168 for i in range(len(distance)): |
168 temp = distance[i].split("\t") | 169 temp = distance[i].split("\t") |
169 distanceDict[temp[0]] = temp[1:] | 170 distanceDict[temp[0]] = temp[1:] |
170 #region step5: tree construction | 171 |
171 | |
172 ''' | |
173 #region create detailed tree | |
174 | |
175 plasmidCount = 0 | |
176 for n in t.traverse(): | |
177 if (n.is_leaf() and not n.name == "Reference"): | |
178 mData = metadata[n.name.replace(".fa","")] | |
179 face = faces.TextFace(mData.MLSTSpecies,fsize=10,tight_text=True) | |
180 face.border.margin = 5 | |
181 face.margin_left = 10 | |
182 face.margin_right = 10 | |
183 n.add_face(face, 0, "aligned") | |
184 face = faces.TextFace(mData.SequenceType,fsize=10,tight_text=True) | |
185 face.border.margin = 5 | |
186 face.margin_right = 10 | |
187 n.add_face(face, 1, "aligned") | |
188 face = faces.TextFace(mData.CarbapenemResistanceGenes,fsize=10,tight_text=True) | |
189 face.border.margin = 5 | |
190 face.margin_right = 10 | |
191 n.add_face(face, 2, "aligned") | |
192 index = 3 | |
193 if (mData.TotalPlasmids > plasmidCount): | |
194 plasmidCount = mData.TotalPlasmids | |
195 for i in range(0, mData.TotalPlasmids): | |
196 face = faces.TextFace(mData.plasmids[i].PlasmidRepType,fsize=10,tight_text=True) | |
197 face.border.margin = 5 | |
198 face.margin_right = 10 | |
199 n.add_face(face, index, "aligned") | |
200 index+=1 | |
201 face = faces.TextFace(mData.plasmids[i].PlasmidMobility,fsize=10,tight_text=True) | |
202 face.border.margin = 5 | |
203 face.margin_right = 10 | |
204 n.add_face(face, index, "aligned") | |
205 index+=1 | |
206 | |
207 face = faces.TextFace("Species",fsize=10,tight_text=True) | |
208 face.border.margin = 5 | |
209 face.margin_right = 10 | |
210 face.margin_left = 10 | |
211 (t&"Reference").add_face(face, 0, "aligned") | |
212 face = faces.TextFace("Sequence Type",fsize=10,tight_text=True) | |
213 face.border.margin = 5 | |
214 face.margin_right = 10 | |
215 (t&"Reference").add_face(face, 1, "aligned") | |
216 face = faces.TextFace("Carbapenamases",fsize=10,tight_text=True) | |
217 face.border.margin = 5 | |
218 face.margin_right = 10 | |
219 (t&"Reference").add_face(face, 2, "aligned") | |
220 index = 3 | |
221 for i in range(0, plasmidCount): | |
222 face = faces.TextFace("plasmid " + str(i) + " replicons",fsize=10,tight_text=True) | |
223 face.border.margin = 5 | |
224 face.margin_right = 10 | |
225 (t&"Reference").add_face(face, index, "aligned") | |
226 index+=1 | |
227 face = faces.TextFace("plasmid " + str(i) + " mobility",fsize=10,tight_text=True) | |
228 face.border.margin = 5 | |
229 face.margin_right = 10 | |
230 (t&"Reference").add_face(face, index, "aligned") | |
231 index+=1 | |
232 | |
233 t.render("./pipelineTest/tree.png", w=5000,units="mm", tree_style=ts) | |
234 | |
235 #endregion | |
236 ''' | |
237 #region create box tree | 172 #region create box tree |
238 #region step5: tree construction | 173 #region step5: tree construction |
239 treeFile = "".join(read(treePath)) | 174 treeFile = "".join(read(treePath)) |
240 t = e.Tree(treeFile) | 175 t = e.Tree(treeFile) |
241 t.set_outgroup(t&"Reference") | 176 t.set_outgroup(t&"Reference") |
322 n.add_face(addFace(mData.CarbapenemResistanceGenes), index, "aligned") | 257 n.add_face(addFace(mData.CarbapenemResistanceGenes), index, "aligned") |
323 index = index + 1 | 258 index = index + 1 |
324 for i in range(len(distanceDict[list(distanceDict.keys())[0]])): #this loop adds distance matrix | 259 for i in range(len(distanceDict[list(distanceDict.keys())[0]])): #this loop adds distance matrix |
325 n.add_face(addFace(list(distanceDict[n.name])[i]), index + i, "aligned") | 260 n.add_face(addFace(list(distanceDict[n.name])[i]), index + i, "aligned") |
326 | 261 |
327 t.render("./tree.png", w=5000,units="mm", tree_style=ts) #save it as a png. or an phyloxml | 262 t.render("./tree.pdf", w=5000,units="mm", tree_style=ts) #save it as a png. or an phyloxml |
328 | 263 |
329 #endregion | 264 #endregion |
330 #endregion | 265 #endregion |
331 | 266 |
332 | 267 |