annotate Tryp_V.py @ 20:26ec953069b3 draft

Uploaded
author johnheap
date Mon, 03 Jun 2019 16:02:02 -0400
parents e7da2274c9f6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
1 """
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
2 * Copyright 2018 University of Liverpool
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
3 * Author: John Heap, Computational Biology Facility, UoL
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
4 * Based on original scripts of Sara Silva Pereira, Institute of Infection and Global Health, UoL
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
5 *
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
6 * Licensed under the Apache License, Version 2.0 (the "License");
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
7 * you may not use this file except in compliance with the License.
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
8 * You may obtain a copy of the License at
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
9 *
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
10 * http://www.apache.org/licenses/LICENSE-2.0
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
11 *
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
12 * Unless required by applicable law or agreed to in writing, software
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
13 * distributed under the License is distributed on an "AS IS" BASIS,
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
15 * See the License for the specific language governing permissions and
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
16 * limitations under the License.
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
17 *
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
18 """
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
19
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
20 import matplotlib as mpl
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
21 mpl.use('Agg')
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
22
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
23 import subprocess
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
24 import shutil
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
25 import re
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
26 import pandas as pd
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
27 import os
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
28
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
29 import sys
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
30
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
31 import matplotlib.pyplot as plt
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
32 from matplotlib.patches import Patch
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
33 import seaborn as sns
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
34
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
35 def assembleWithVelvet(name, kmers, inslen, covcut, fastq1name,fastq2name):
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
36 #argString = "velveth " + name + "_k65 65 -shortPaired -fastq " + name + "_R1.fastq " + name + "_R2.fastq"
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
37 argString = "velveth " + name + "_k"+ kmers+" "+ kmers + " -shortPaired -fastq " + fastq1name+" "+fastq2name
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
38 print(argString)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
39 returncode = subprocess.call(argString, shell=True)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
40 if returncode != 0:
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
41 return "Error in velveth"
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
42 argString = "velvetg " + name + "_k"+kmers+" -exp_cov auto -ins_length "+inslen+" -clean yes -ins_length_sd 50 -min_pair_count 20"
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
43 #argString = "velvetg " + name + "_k"+kmers+" -exp_cov auto -ins_length "+inslen+" -cov_cutoff "+covcut+" -clean yes -ins_length_sd 50 -min_pair_count 20"
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
44 #argString = "velvetg " + name + "_k65 -exp_cov auto -ins_length 400 -cov_cutoff 5 -clean yes -ins_length_sd 50 -min_pair_count 20"+quietString
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
45 print(argString)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
46 returncode = subprocess.call(argString, shell = True)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
47 if returncode != 0:
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
48 return "Error in velvetg"
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
49 shutil.copyfile(name + "_k"+kmers+"//contigs.fa",name + ".fa") # my $namechange = "mv ".$input."_k65/contigs.fa ".$input.".fa";
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
50 return "ok"
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
51
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
52
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
53 def blastContigs(test_name,database):
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
54 print(test_name)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
55 print(database)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
56 #db_path = os.path.dirname(os.path.realpath(__file__))+database
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
57 db_path = database
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
58 argString = "blastn -db "+db_path+" -query "+test_name+".fa -outfmt 10 -out "+test_name+"_blast.txt"
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
59 print(argString)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
60 returncode = subprocess.call(argString, shell = True)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
61 if returncode != 0:
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
62 return "Error in blastall"
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
63 blast_df = pd.read_csv(""+test_name+"_blast.txt")
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
64 #print (blast_df)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
65 #if ($temp[2] >= 98 & & $temp[3] > 100 & & $temp[10] < 0.001){
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
66 #'qaccver saccver pident length mismatch gapopen qstart qend sstart send evalue bitscore'
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
67 blast_df.columns = ['qaccver', 'saccver', 'pident', 'length', 'mismatch', 'gapopen', 'qstart', 'qend', 'sstart', 'send', 'evalue','bitscore']
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
68 blastResult_df = blast_df[(blast_df['pident']>=98) & (blast_df['length'] > 100) & (blast_df['evalue']<0.001) ]
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
69 blastResult_df = blastResult_df[['qaccver', 'saccver', 'pident']] #query accession.version, subject accession.version, Percentage of identical matches
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
70
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
71 return blastResult_df
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
72
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
73
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
74
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
75 def getCogsPresent(blastResult_df,strain,cogOrBinList):
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
76 blastResult_df.sort_values('pident',axis = 0, ascending=False, inplace=True)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
77 nodeList = blastResult_df['qaccver'].tolist()
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
78 cogList = blastResult_df['saccver'].tolist()
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
79 cogSet = set(cogList) #get unique values
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
80 cogList = sorted(cogSet) #sort them
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
81
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
82 #print (cogList)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
83 #print (len(cogList))
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
84
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
85 thereList = []
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
86 dataList = []
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
87 #dir_path = os.path.dirname(os.path.realpath(__file__))
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
88 fname = cogOrBinList
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
89 cnt = 0
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
90 with open (fname) as f:
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
91 for line in f:
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
92 dataList.append(line.rstrip('\n\r '))
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
93 if line.rstrip('\n\r ') in cogList:
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
94 thereList.append('1')
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
95 cnt = cnt+1
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
96 else:
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
97 thereList.append('0')
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
98
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
99 #print (thereList)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
100 #print (cnt)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
101 data = {'Cog': dataList, strain: thereList}
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
102 presence_df = pd.DataFrame(data)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
103 #print (presence_df)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
104 return presence_df
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
105
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
106 def addToCurrentData(cog_df, name):
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
107 dir_path = os.path.dirname(os.path.realpath(__file__))
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
108 j_fname = dir_path + r"/data/vivax/TvDatabase.csv"
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
109 tv_df = pd.read_csv(j_fname)
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
110
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
111 cogList = cog_df[name].tolist()
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
112 #cogList.insert(0,'Test')
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
113 #print (len(tv_df))
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
114 #print(len(cogList))
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
115
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
116 #print(cogList)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
117 tv_df.loc[:,name]=cogList
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
118 return tv_df
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
119
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
120
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
121
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
122
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
123 def createClusterMap(tv_df,name,html_path,pdfExport):
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
124 #Retrieve Data
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
125 dir_path = os.path.dirname(os.path.realpath(__file__))
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
126 j_fname = dir_path+r"/data/vivax/geoTv.csv"
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
127 geo_df = pd.read_csv(j_fname)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
128 geo_df.loc[len(geo_df)] =[name,name,'k']
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
129 print(geo_df)
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
130
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
131 myStrains = tv_df.columns.values.tolist() #beware first entry is COG
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
132 myStrains = myStrains[1:]
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
133 print(myStrains)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
134 myPal = []
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
135 for s in myStrains:
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
136 col = geo_df[(geo_df['Strain'] == s)]['colour'].tolist()
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
137 myPal.append(col[0])
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
138 print(myPal)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
139 mycogmap = ['skyblue', 'orangered'] # blue absent,red present
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
140 tv_df.set_index('COG', inplace=True)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
141 tv_df = tv_df[tv_df.columns].astype(float)
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
142
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
143 cg = sns.clustermap(tv_df, method='ward', col_colors=myPal, cmap=mycogmap, yticklabels = 1500, row_cluster=False, linewidths = 0)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
144 #cg = sns.clustermap(tv_df, method='ward', row_cluster=False, linewidths = 0)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
145 ax = cg.ax_heatmap
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
146 #xasix ticks and labels.
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
147 ax.xaxis.tick_top() #set ticks at top
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
148 newlabs = []
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
149
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
150 labs = ax.xaxis.get_ticklabels()
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
151 for i in range(0, len(labs)):
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
152 print(labs[i])
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
153 # labs[i].set_text(" "+labs[i].get_text()) #make enough room so label sits atop of col_color bars
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
154 newlabs.append(" " + labs[i].get_text())
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
155 ax.xaxis.set_ticklabels(newlabs)
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
156
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
157 #labs = ax.xaxis.get_ticklabels()
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
158 #for i in range(0, len(labs)):
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
159 # print(labs[i])
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
160 # labs[i].set_text(" "+labs[i].get_text()) #make enough room so label sits atop of col_color bars
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
161 # print(labs[i])
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
162 #ax.xaxis.set_ticklabels(labs)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
163 plt.setp(cg.ax_heatmap.xaxis.get_ticklabels(), rotation=90) # get x labels printed vertically
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
164
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
165 cg.cax.set_visible(False)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
166 ax = cg.ax_heatmap
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
167 ax.set_yticklabels("")
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
168 ax.set_ylabel("")
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
169 ax = cg.ax_heatmap
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
170 # ax.set_title("Variant antigen profiles of T. vivax genomes.\nDendrogram reflects the VSG repertoire relationships of each strain inferred by the presence and absence of non-universal T. vivax VSG orthologs.", va = "top", wrap = "True")
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
171 b = len(tv_df)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
172 print(b)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
173 title = "Figure Legend: The Variant Antigen Profiles of $\itTrypanosoma$ $\itvivax$ " \
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
174 "showing the \ncombination of present and absent diagnostic cluster of VSG orthologs " \
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
175 "across the sample cohort. \nDendrogram reflects the relationships amongst the VSG" \
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
176 " repertoires of each strain. " \
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
177 "Strains were isolated \nfrom multiple African countries as shown in the key.\nData was produced with the " \
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
178 "'Variant Antigen Profiler' (Silva Pereira et al., 2019)."
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
179
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
180 ax.text(-1.5, len(tv_df) + 8,
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
181 title,
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
182 ha="left", va="top", wrap="True")
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
183 col = cg.ax_col_dendrogram.get_position()
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
184 cg.ax_col_dendrogram.set_position([col.x0, col.y0*1.08, col.width, col.height*1.1])
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
185
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
186 countryList = pd.unique(geo_df['Location'])
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
187 colourList = pd.unique(geo_df['colour'])
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
188 legend_elements = [Patch(facecolor='orangered', label='COG Present'),
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
189 Patch(facecolor='skyblue', label='COG Absent')]
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
190
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
191 for i in range(0, len(colourList)):
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
192 print("country = %s, colour = %s" % (countryList[i], colourList[i]))
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
193 p = Patch(facecolor=str(colourList[i]), label=countryList[i])
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
194 legend_elements.append(p)
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
195
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
196 ax.legend(handles = legend_elements, bbox_to_anchor=(-0.3,1.2),loc = 'upper left')
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
197
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
198
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
199
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
200
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
201
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
202
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
203
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
204 #plt.setp(cg.ax_heatmap.yaxis.get_ticklabels(), rotation=0 ) # get y labels printed horizontally
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
205 # cg.dendrogram_col.linkage # linkage matrix for columns
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
206 # cg.dendrogram_row.linkage # linkage matrix for rows
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
207 # plt.savefig(r"results/" + name + "_heatmap.png")
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
208 #plt.savefig(htmlresource + "/heatmap.png")
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
209 #if pdf == 'PDF_Yes':
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
210 # plt.savefig(htmlresource + "/heatmap.pdf")
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
211 # shutil.copyfile("heatmap.pdf",heatmapfn) #
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
212 #plt.legend()
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
213 fname = html_path+"/"+name+"_clustermap.png"
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
214 cg.savefig(fname)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
215 if pdfExport == 'PDF_Yes':
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
216 fname = html_path + "/" + name + "_clustermap.pdf"
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
217 cg.savefig(fname)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
218 #plt.show()
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
219
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
220 def createHTML(name,htmlfn,htmlPath):
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
221 #assumes imgs are heatmap.png, dheatmap.png, vapPCA.png and already in htmlresource
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
222 htmlString = r"<html><title>T.vivax VAP</title><body><div style='text-align:center'><h2><i>Trypanosoma vivax</i> Variant Antigen Profile</h2><h3>"
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
223 htmlString += name
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
224
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
225
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
226 htmlString += r'<p> <h3>The Heat Map and Dendrogram</h3></p>'
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
227 imgString = r"<img src = '"+name+"_clustermap.png' alt='Cog Clustermap' style='max-width:100%'><br><br>"
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
228 htmlString += imgString
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
229 print(htmlString)
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
230
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
231 with open(htmlfn, "w") as htmlfile:
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
232 htmlfile.write(htmlString)
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
233
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
234
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
235 def vivax_assemble(args,dict):
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
236 #argdict = {'name': 2, 'pdfexport': 3, 'kmers': 4, 'inslen': 5, 'covcut': 6, 'forward': 7, 'reverse': 8, 'html_file': 9,'html_resource': 10}
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
237 #assembleWithVelvet("V2_Test", '65', '400', '5', "data/TviBrRp.1.clean", "data/TviBrRp.2.clean")
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
238
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
239 vivaxPath = os.path.dirname(os.path.realpath(__file__))+r"/data/vivax"
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
240 assembleWithVelvet(args[dict['name']], args[dict['kmers']], args[dict['inslen']], args[dict['covcut']],
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
241 args[dict['forward']], args[dict['reverse']])
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
242 blastResult_df = blastContigs(args[dict['name']], vivaxPath+r"/Database/COGs.fas")
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
243 orthPresence_df = getCogsPresent(blastResult_df, args[dict['name']], vivaxPath+r"/Database/COGlist.txt")
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
244
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
245 binBlastResult_df = blastContigs(args[dict['name']], vivaxPath+r"/Database/Bin_2.fas")
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
246 binPresence_df = getCogsPresent(binBlastResult_df, args[dict['name']], vivaxPath+r"/Database/binlist.txt")
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
247 cogPresence_df = orthPresence_df.append(binPresence_df, ignore_index=True)
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
248
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
249 fname = args[dict['html_resource']] +args[dict['name']]+"_cogspresent.csv"
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
250 cogPresence_df.to_csv(fname)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
251 current_df = addToCurrentData(cogPresence_df,args[dict['name']]) # load in Tvdatabase and add cogPresence column to it.
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
252 createClusterMap(current_df, args[dict['name']],args[dict['html_resource']],args[dict['pdfexport']])
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
253 createHTML(args[dict['name']],args[dict['html_file']],args[dict['html_resource']])
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
254
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
255 def test_cluster(args,dict):
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
256 print ("name: %s",args[dict['name']])
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
257 cogPresence_df = pd.read_csv("test_cogspresent.csv")
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
258 print(cogPresence_df)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
259 current_df = addToCurrentData(cogPresence_df,args[dict['name']]) # load in Tvdatabase and add cogPresence column to it.
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
260 createClusterMap(current_df, args[dict['name']], args[dict['html_resource']], args[dict['pdfexport']])
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
261
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
262 def vivax_contigs(args,dict):
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
263 # argdict = {'name': 2, 'pdfexport': 3, 'contigs': 4, 'html_file': 5, 'html_resource': 6}
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
264
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
265 #test_cluster(args,dict)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
266 #return;
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
267
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
268 #subprocess.call('echo $PATH',shell = True)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
269 #sys.exit(1)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
270
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
271 vivaxPath = os.path.dirname(os.path.realpath(__file__))+r"/data/vivax"
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
272 shutil.copyfile(args[dict['contigs']], args[dict['name']]+".fa")
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
273 blastResult_df = blastContigs(args[dict['name']], vivaxPath+r"/Database/COGs.fas")
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
274 orthPresence_df = getCogsPresent(blastResult_df, args[dict['name']], vivaxPath+r"/Database/COGlist.txt")
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
275
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
276 binBlastResult_df = blastContigs(args[dict['name']], vivaxPath+r"/Database/Bin_2.fas")
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
277 binPresence_df = getCogsPresent(binBlastResult_df, args[dict['name']], vivaxPath+r"/Database/binlist.txt")
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
278 cogPresence_df = orthPresence_df.append(binPresence_df, ignore_index=True)
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
279
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
280 fname = args[dict['html_resource']]+r"/"+ args[dict['name']]+"_cogspresent.csv"
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
281 cogPresence_df.to_csv(fname)
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
282 current_df = addToCurrentData(cogPresence_df,args[dict['name']]) # load in Tvdatabase and add cogPresence column to it.
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
283 createClusterMap(current_df, args[dict['name']], args[dict['html_resource']], args[dict['pdfexport']])
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
284 createHTML(args[dict['name']],args[dict['html_file']],args[dict['html_resource']])
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
285
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
286
18
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
287 if __name__ == "__main__":
e7da2274c9f6 Uploaded
johnheap
parents: 8
diff changeset
288 sys.exit()
8
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
289
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
290
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
291
e75a85590041 Uploaded
johnheap
parents: 3
diff changeset
292