comparison cpo_galaxy_tree.py @ 12:4b2738bc81ed draft

planemo upload
author jjjjia
date Fri, 24 Aug 2018 19:10:42 -0400
parents 8aaa4001383b
children a14b12a71a53
comparison
equal deleted inserted replaced
11:8aaa4001383b 12:4b2738bc81ed
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.6.0">pyqt</requirement> 20 # <requirement type="package" version="5.6.0">pyqt</requirement>
21 # <requirement type="package" version="5.6.2">qt</requirement>
21 # </requirements> 22 # </requirements>
22 23
23 import subprocess 24 import subprocess
24 import pandas #conda pandas 25 import pandas #conda pandas
25 import optparse 26 import optparse
51 #define some objects to store values from results 52 #define some objects to store values from results
52 #//TODO this is not the proper way of get/set private object variables. every value has manually assigned defaults intead of specified in init(). Also, use property(def getVar, def setVar). 53 #//TODO this is not the proper way of get/set private object variables. every value has manually assigned defaults intead of specified in init(). Also, use property(def getVar, def setVar).
53 class workflowResult(object): 54 class workflowResult(object):
54 def __init__(self): 55 def __init__(self):
55 self.new = False 56 self.new = False
56 self.ID = "" 57 self.ID = "?"
57 self.ExpectedSpecies = "" 58 self.ExpectedSpecies = "?"
58 self.MLSTSpecies = "" 59 self.MLSTSpecies = "?"
59 self.SequenceType = "" 60 self.SequenceType = "?"
60 self.MLSTScheme = "" 61 self.MLSTScheme = "?"
61 self.CarbapenemResistanceGenes ="" 62 self.CarbapenemResistanceGenes ="?"
62 self.OtherAMRGenes="" 63 self.OtherAMRGenes="?"
63 self.TotalPlasmids = 0 64 self.TotalPlasmids = -1
64 self.plasmids = [] 65 self.plasmids = []
65 self.DefinitelyPlasmidContigs ="" 66 self.DefinitelyPlasmidContigs ="?"
66 self.LikelyPlasmidContigs="" 67 self.LikelyPlasmidContigs="?"
67 self.row = "" 68 self.row = ""
68 class plasmidObj(object): 69 class plasmidObj(object):
69 def __init__(self): 70 def __init__(self):
70 self.PlasmidsID = 0 71 self.PlasmidsID = 0
71 self.Num_Contigs = 0 72 self.Num_Contigs = 0
126 #region functions to parse result files 127 #region functions to parse result files
127 def ParseWorkflowResults(pathToResult): 128 def ParseWorkflowResults(pathToResult):
128 _worflowResult = {} 129 _worflowResult = {}
129 r = pandas.read_csv(pathToResult, delimiter='\t', header=0) 130 r = pandas.read_csv(pathToResult, delimiter='\t', header=0)
130 r = r.replace(numpy.nan, '', regex=True) 131 r = r.replace(numpy.nan, '', regex=True)
132 _naResult = workflowResult()
133 _worflowResult["na"] = _naResult
131 for i in range(len(r.index)): 134 for i in range(len(r.index)):
132 _results = workflowResult() 135 _results = workflowResult()
133 if(str(r.loc[r.index[i], 'new']).lower() == "new"): 136 if(str(r.loc[r.index[i], 'new']).lower() == "new"):
134 _results.new = True 137 _results.new = True
135 else: 138 else:
136 _results.new = False 139 _results.new = False
137 _results.ID = str(r.loc[r.index[i], 'ID']) 140 _results.ID = str(r.loc[r.index[i], 'ID']).replace(".fa","")
138 _results.ExpectedSpecies = str(r.loc[r.index[i], 'Expected Species']) 141 _results.ExpectedSpecies = str(r.loc[r.index[i], 'Expected Species'])
139 _results.MLSTSpecies = str(r.loc[r.index[i], 'MLST Species']) 142 _results.MLSTSpecies = str(r.loc[r.index[i], 'MLST Species'])
140 _results.SequenceType = str(r.loc[r.index[i], 'Sequence Type']) 143 _results.SequenceType = str(r.loc[r.index[i], 'Sequence Type'])
141 _results.MLSTScheme = (str(r.loc[r.index[i], 'MLST Scheme'])) 144 _results.MLSTScheme = (str(r.loc[r.index[i], 'MLST Scheme']))
142 _results.CarbapenemResistanceGenes = (str(r.loc[r.index[i], 'Carbapenem Resistance Genes'])) 145 _results.CarbapenemResistanceGenes = (str(r.loc[r.index[i], 'Carbapenem Resistance Genes']))
175 t = e.Tree(treeFile) 178 t = e.Tree(treeFile)
176 t.set_outgroup(t&"Reference") 179 t.set_outgroup(t&"Reference")
177 180
178 #set the tree style 181 #set the tree style
179 ts = e.TreeStyle() 182 ts = e.TreeStyle()
180 ts.show_leaf_name = False 183 ts.show_leaf_name = True
181 ts.show_branch_length = True 184 ts.show_branch_length = True
182 ts.scale = 2000 #pixel per branch length unit 185 ts.scale = 2000 #pixel per branch length unit
183 ts.branch_vertical_margin = 15 #pixel between branches 186 ts.branch_vertical_margin = 15 #pixel between branches
184 style2 = e.NodeStyle() 187 style2 = e.NodeStyle()
185 style2["fgcolor"] = "#000000" 188 style2["fgcolor"] = "#000000"
226 (t&"Reference").add_face(addFace(distanceDict[list(distanceDict.keys())[0]][i]), index + i, "aligned") 229 (t&"Reference").add_face(addFace(distanceDict[list(distanceDict.keys())[0]][i]), index + i, "aligned")
227 index = index + len(distanceDict[list(distanceDict.keys())[0]]) 230 index = index + len(distanceDict[list(distanceDict.keys())[0]])
228 elif (n.is_leaf() and not n.name == "Reference"): 231 elif (n.is_leaf() and not n.name == "Reference"):
229 #not reference branches, populate with metadata 232 #not reference branches, populate with metadata
230 index = 0 233 index = 0
231 mData = metadata[n.name.replace(".fa","")] 234 if (n.name.replace(".fa","") in metadata.keys()):
235 mData = metadata[n.name.replace(".fa","")]
236 else:
237 mData = metadata["na"]
232 n.add_face(addFace(mData.ID), index, "aligned") 238 n.add_face(addFace(mData.ID), index, "aligned")
233 index = index + 1 239 index = index + 1
234 if (metadata[n.name.replace(".fa","")].new == True): #new column 240 if (mData.new == True): #new column
235 face = e.RectFace(30,30,"green","green") # TextFace("Y",fsize=10,tight_text=True) 241 face = e.RectFace(30,30,"green","green") # TextFace("Y",fsize=10,tight_text=True)
236 face.border.margin = 5 242 face.border.margin = 5
237 face.margin_right = 5 243 face.margin_right = 5
238 face.margin_left = 5 244 face.margin_left = 5
239 face.vt_align = 1 245 face.vt_align = 1