annotate src/MaaslinToGraphlanAnnotation.py @ 0:e0b5980139d9

maaslin
author george-weingart
date Tue, 13 May 2014 22:00:40 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
1 #!/usr/bin/env python
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
2 #####################################################################################
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
3 #Copyright (C) <2012>
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
4 #
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
5 #Permission is hereby granted, free of charge, to any person obtaining a copy of
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
6 #this software and associated documentation files (the "Software"), to deal in the
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
7 #Software without restriction, including without limitation the rights to use, copy,
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
8 #modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
9 #and to permit persons to whom the Software is furnished to do so, subject to
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
10 #the following conditions:
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
11 #
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
12 #The above copyright notice and this permission notice shall be included in all copies
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
13 #or substantial portions of the Software.
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
14 #
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
15 #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
16 #INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
17 #PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
18 #HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
19 #OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
20 #SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
21 #
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
22 # This file is a component of the MaAsLin (Multivariate Associations Using Linear Models),
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
23 # authored by the Huttenhower lab at the Harvard School of Public Health
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
24 # (contact Timothy Tickle, ttickle@hsph.harvard.edu).
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
25 #####################################################################################
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
26
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
27 __author__ = "Timothy Tickle"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
28 __copyright__ = "Copyright 2012"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
29 __credits__ = ["Timothy Tickle"]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
30 __license__ = ""
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
31 __version__ = ""
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
32 __maintainer__ = "Timothy Tickle"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
33 __email__ = "ttickle@sph.harvard.edu"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
34 __status__ = "Development"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
35
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
36 import argparse
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
37 import csv
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
38 import math
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
39 from operator import itemgetter
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
40 import re
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
41 import string
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
42 import sys
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
43
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
44 #def funcGetColor(fNumeric,fMax):
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
45 # if fNumeric>0:
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
46 # return("#"+str(int(99*fNumeric/fMax)).zfill(2)+"0000")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
47 # if fNumeric<0:
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
48 # return("#00"+str(int(99*abs(fNumeric/fMax))).zfill(2)+"00")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
49 # return("#000000")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
50
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
51 def funcGetColor(fNumeric):
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
52 if fNumeric>0:
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
53 return sRingPositiveColor
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
54 else:
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
55 return sRingNegativeColor
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
56
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
57 def funcGetAlpha(fNumeric,fMax):
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
58 return max(abs(fNumeric/fMax),dMinAlpha)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
59
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
60 #Constants
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
61 sAnnotation = "annotation"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
62 sAnnotationColor = "annotation_background_color"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
63 sClass = "class"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
64 sRingAlpha = "ring_alpha"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
65 dMinAlpha = .075
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
66 sRingColor = "ring_color"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
67 sRingHeight = "ring_height"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
68 #sRingHeightMin = 0.5
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
69 sStandardizedRingHeight = "1.01"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
70 sRingLabel = "ring_label"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
71 sRingLabelSizeWord = "ring_label_font_size"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
72 sRingLabelSize = 10
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
73 sRingLineColor = "#999999"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
74 sRingPositiveWord = "Positive"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
75 sRingPositiveColor = "#990000"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
76 sRingNegativeWord = "Negative"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
77 sRingNegativeColor = "#009900"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
78 sRingLineColorWord = "ring_separator_color"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
79 sRingLineThickness = "0.5"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
80 sRingLineThicknessWord = "ring_internal_separator_thickness"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
81 sCladeMarkerColor = "clade_marker_color"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
82 sCladeMarkerSize = "clade_marker_size"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
83 sHighlightedMarkerSize = "10"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
84 c_dMinDoubleValue = 0.00000000001
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
85
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
86 #Set up arguments reader
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
87 argp = argparse.ArgumentParser( prog = "MaaslinToGraphlanAnnotation.py",
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
88 description = """Converts summary files to graphlan annotation files.""" )
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
89
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
90 #### Read in information
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
91 #Arguments
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
92 argp.add_argument("strInputSummary", metavar = "SummaryFile", type = argparse.FileType("r"), help ="Input summary file produced by maaslin")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
93 argp.add_argument("strInputCore", metavar = "CoreFile", type = argparse.FileType("r"), help ="Core file produced by Graphlan from the maaslin pcl")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
94 argp.add_argument("strInputHeader", metavar = "HeaderFile", type = argparse.FileType("r"), help ="Input header file to append to the generated annotation file.")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
95 argp.add_argument("strOutputAnnotation", metavar = "AnnotationFile", type = argparse.FileType("w"), help ="Output annotation file for graphlan")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
96
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
97 args = argp.parse_args( )
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
98
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
99 #Read in the summary file and transform to class based descriptions
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
100 csvSum = open(args.strInputSummary,'r') if isinstance(args.strInputSummary, str) else args.strInputSummary
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
101 fSum = csv.reader(csvSum, delimiter="\t")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
102 #Skip header (until i do this a better way)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
103 fSum.next()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
104
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
105 #Extract associations (Metadata,taxon,coef,qvalue)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
106 lsAssociations = [[sLine[1],sLine[2],sLine[4],sLine[7]] for sLine in fSum]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
107 csvSum.close()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
108
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
109 #### Read in default graphlan settings provided by maaslin
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
110 #Read in the annotation header file
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
111 csvHdr = open(args.strInputHeader,'r') if isinstance(args.strInputHeader, str) else args.strInputHeader
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
112 fHdr = csv.reader(csvHdr, delimiter="\t")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
113
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
114 #Begin writting the output
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
115 #Output annotation file
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
116 csvAnn = open(args.strOutputAnnotation,'w') if isinstance(args.strOutputAnnotation, str) else args.strOutputAnnotation
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
117 fAnn = csv.writer(csvAnn, delimiter="\t")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
118 fAnn.writerows(fHdr)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
119 csvHdr.close()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
120
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
121 #If no associatiosn were found
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
122 if(len(lsAssociations)==0):
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
123 csvAnn.close()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
124
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
125 else:
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
126 #### Fix name formats
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
127 #Manipulate names to graphlan complient names (clades seperated by .)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
128 lsAssociations = sorted(lsAssociations, key=itemgetter(1))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
129 lsAssociations = [[sBug[0]]+[re.sub("^[A-Za-z]__","",sBug[1])]+sBug[2:] for sBug in lsAssociations]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
130 lsAssociations = [[sBug[0]]+[re.sub("\|*[A-Za-z]__|\|",".",sBug[1])]+sBug[2:] for sBug in lsAssociations]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
131
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
132 #If this is an OTU, append the number and the genus level together for a more descriptive termal name
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
133 lsAssociationsModForOTU = []
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
134 for sBug in lsAssociations:
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
135 lsBug = sBug[1].split(".")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
136 if(len(lsBug))> 1:
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
137 if(lsBug[-1].isdigit()):
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
138 lsBug[-2]=lsBug[-2]+"_"+lsBug[-1]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
139 lsBug = lsBug[0:-1]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
140 lsAssociationsModForOTU.append([sBug[0]]+[".".join(lsBug)]+sBug[2:])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
141 else:
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
142 lsAssociationsModForOTU.append([sBug[0]]+[lsBug[0]]+sBug[2:])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
143
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
144 #Extract just class info
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
145 #lsClassData = [[sLine[2],sClass,sLine[1]] for sLine in fSum]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
146
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
147 ### Make rings
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
148 #Setup rings
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
149 dictRings = dict([[enumData[1],enumData[0]] for enumData in enumerate(set([lsData[0] for lsData in lsAssociationsModForOTU]))])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
150
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
151 #Ring graphlan setting: rings represent a metadata that associates with a feature
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
152 #Rings have a line to help differetiate them
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
153 lsRingSettings = [[sRingLabel,lsPair[1],lsPair[0]] for lsPair in dictRings.items()]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
154 lsRingLineColors = [[sRingLineColorWord,lsPair[1],sRingLineColor] for lsPair in dictRings.items()]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
155 lsRingLineThick = [[sRingLineThicknessWord,lsPair[1],sRingLineThickness] for lsPair in dictRings.items()]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
156 lsRingLineLabelSize = [[sRingLabelSizeWord,lsPair[1], sRingLabelSize] for lsPair in dictRings.items()]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
157
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
158 #Create coloring for rings color represents the directionality of the relationship
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
159 dMaxCoef = max([abs(float(sAssociation[2])) for sAssociation in lsAssociationsModForOTU])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
160 lsRingColors = [[lsAssociation[1], sRingColor, dictRings[lsAssociation[0]], funcGetColor(float(lsAssociation[2]))] for lsAssociation in lsAssociationsModForOTU]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
161 lsRingAlpha = [[lsAssociation[1], sRingAlpha, dictRings[lsAssociation[0]], funcGetAlpha(float(lsAssociation[2]), dMaxCoef)] for lsAssociation in lsAssociationsModForOTU]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
162
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
163 #Create height for rings representing the log tranformed q-value?
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
164 dMaxQValue = max([-1*math.log(max(float(sAssociation[3]), c_dMinDoubleValue)) for sAssociation in lsAssociationsModForOTU])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
165 #lsRingHeights = [[lsAssociation[1], sRingHeight, dictRings[lsAssociation[0]], ((-1*math.log(max(float(lsAssociation[3]), c_dMinDoubleValue)))/dMaxQValue)+sRingHeightMin] for lsAssociation in lsAssociationsModForOTU]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
166 lsRingHeights = [[lsAssociation[1], sRingHeight, dictRings[lsAssociation[0]], sStandardizedRingHeight] for lsAssociation in lsAssociationsModForOTU]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
167
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
168 #### Marker
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
169 # Marker colors (mainly to make legend
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
170 lsMarkerColors = [[lsAssociation[1], sCladeMarkerColor, funcGetColor(float(lsAssociation[2]))] for lsAssociation in lsAssociationsModForOTU]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
171 lsMarkerSizes = [[lsAssociation[1], sCladeMarkerSize, sHighlightedMarkerSize] for lsAssociation in lsAssociationsModForOTU]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
172
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
173 #### Make internal highlights
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
174 #Highlight the associated clades
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
175 lsUniqueAssociatedTaxa = sorted(list(set([lsAssociation[1] for lsAssociation in lsAssociationsModForOTU])))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
176
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
177 lsHighlights = []
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
178 sABCPrefix = ""
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
179 sListABC = string.ascii_lowercase
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
180 iListABCIndex = 0
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
181 for lsHighlight in lsUniqueAssociatedTaxa:
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
182 lsTaxa = lsHighlight.split(".")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
183 sLabel = sABCPrefix+sListABC[iListABCIndex]+":"+lsTaxa[-1] if len(lsTaxa) > 2 else lsTaxa[-1]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
184 lsHighlights.append([lsHighlight, sAnnotation, sLabel])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
185 iListABCIndex = iListABCIndex + 1
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
186 if iListABCIndex > 25:
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
187 iListABCIndex = 0
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
188 sABCPrefix = sABCPrefix + sListABC[len(sABCPrefix)]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
189
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
190 #Read in the core file
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
191 csvCore = open(args.strInputCore,'r') if isinstance(args.strInputCore, str) else args.strInputCore
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
192 fSum = csv.reader(csvCore, delimiter="\t")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
193
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
194 #Add in all phylum just incase they were not already included here
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
195 lsAddSecondLevel = list(set([sUnique[0].split(".")[1] for sUnique in fSum if len(sUnique[0].split(".")) > 1]))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
196 lsHighlights.extend([[sSecondLevel, sAnnotation, sSecondLevel] for sSecondLevel in lsAddSecondLevel])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
197 lsHighlightColor = [[lsHighlight[0], sAnnotationColor,"b"] for lsHighlight in lsHighlights]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
198
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
199 #### Write the remaining output annotation file
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
200 fAnn.writerows(lsRingSettings)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
201 fAnn.writerows(lsRingLineColors)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
202 fAnn.writerows(lsRingColors)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
203 fAnn.writerows(lsRingAlpha)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
204 fAnn.writerows(lsRingLineThick)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
205 fAnn.writerows(lsRingLineLabelSize)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
206 fAnn.writerows(lsRingHeights)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
207 fAnn.writerows(lsMarkerColors)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
208 fAnn.writerows(lsMarkerSizes)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
209 fAnn.writerows([[sRingPositiveWord, sCladeMarkerColor, sRingPositiveColor]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
210 fAnn.writerows([[sRingNegativeWord, sCladeMarkerColor, sRingNegativeColor]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
211 fAnn.writerows(lsHighlights)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
212 fAnn.writerows(lsHighlightColor)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
213 csvAnn.close()