annotate maaslin-4450aa4ecc84/src/MaaslinToGraphlanAnnotation.py @ 1:a87d5a5f2776

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