|
58
|
1 #!/bin/bash
|
|
|
2
|
|
|
3 inputFile=$1
|
|
|
4 outputDir=$3
|
|
|
5 outputFile=$3/index.html #$2
|
|
|
6 clonalType=$4
|
|
|
7 species=$5
|
|
|
8 locus=$6
|
|
|
9 filterproductive=$7
|
|
|
10 clonality_method=$8
|
|
|
11
|
|
|
12 dir="$(cd "$(dirname "$0")" && pwd)"
|
|
|
13 useD="false"
|
|
|
14 if grep -q "$species.*${locus}D" "$dir/genes.txt" ; then
|
|
|
15 echo "species D region in reference db"
|
|
|
16 useD="true"
|
|
|
17 fi
|
|
|
18 echo "$species"
|
|
|
19 if [[ "$species" == *"custom"* ]] ; then
|
|
|
20 loci=(${locus//;/ })
|
|
|
21 useD="true"
|
|
|
22 echo "${loci[@]}"
|
|
|
23 if [[ "${#loci[@]}" -eq "2" ]] ; then
|
|
|
24 useD="false"
|
|
|
25 fi
|
|
|
26 fi
|
|
|
27 mkdir $3
|
|
|
28 cp $dir/genes.txt $outputDir
|
|
|
29 Rscript --verbose $dir/RScript.r $inputFile $outputDir $outputDir $clonalType "$species" "$locus" $filterproductive ${clonality_method} 2>&1
|
|
|
30 cp $dir/tabber.js $outputDir
|
|
|
31 cp $dir/style.css $outputDir
|
|
|
32 cp $dir/script.js $outputDir
|
|
|
33 cp $dir/jquery-1.11.0.min.js $outputDir
|
|
|
34 samples=`cat $outputDir/samples.txt`
|
|
|
35
|
|
|
36 echo "<html><center><h1><a href='index.html'>Click here for the results</a></h1>Tip: Open it in a new tab (middle mouse button or right mouse button -> 'open in new tab' on the link above)<br />" > $2
|
|
|
37 echo "<table border = 1>" >> $2
|
|
|
38 echo "<thead><tr><th>Sample/Replicate</th><th>All</th><th>Productive</th><th>Unique Productive</th><th>Unproductive</th><th>Unique Unproductive</th></tr></thead>" >> $2
|
|
|
39 while IFS=, read sample all productive perc_prod productive_unique perc_prod_un unproductive perc_unprod unproductive_unique perc_unprod_un
|
|
|
40 do
|
|
|
41 echo "<tr><td>$sample</td>" >> $2
|
|
|
42 echo "<td>$all</td>" >> $2
|
|
|
43 echo "<td>$productive (${perc_prod}%)</td>" >> $2
|
|
|
44 echo "<td>$productive_unique (${perc_prod_un}%)</td>" >> $2
|
|
|
45 echo "<td>$unproductive (${perc_unprod}%)</td>" >> $2
|
|
|
46 echo "<td>$unproductive_unique (${perc_unprod_un}%)</td></tr>" >> $2
|
|
|
47 done < $outputDir/productive_counting.txt
|
|
|
48 echo "</table border></center></html>" >> $2
|
|
|
49
|
|
|
50 echo "<html><head><title>Report on:" >> $outputFile
|
|
|
51
|
|
|
52 mkdir $outputDir/circos
|
|
|
53 cp $dir/circos/* $outputDir/circos/
|
|
|
54 CIRCOSTOOLS="/data/galaxy/galaxy-dist/toolsheddependencies/circos/0.64/saskia-hiltemann/cg_circos_plots/bbfdd52d64fd/circos-tools-0.21/tools"
|
|
|
55 CIRCOSDIR="/data/galaxy/galaxy-dist/toolsheddependencies/circos/0.64/saskia-hiltemann/cg_circos_plots/bbfdd52d64fd/bin/"
|
|
|
56 USECIRCOS="no"
|
|
|
57 if [ -d "$CIRCOSDIR" ]; then
|
|
|
58 USECIRCOS="yes"
|
|
|
59 fi
|
|
|
60 echo "Using Circos: $USECIRCOS"
|
|
|
61 sed -i "s%DATA_DIR%$outputDir/circos%" $outputDir/circos/circos.conf
|
|
|
62 for sample in $samples; do #output the samples to a file and create the circos plots with the R script output
|
|
|
63 echo " $sample" >> $outputFile
|
|
|
64
|
|
|
65 if [[ "$USECIRCOS" != "yes" ]]; then
|
|
|
66 continue
|
|
|
67 fi
|
|
|
68
|
|
|
69 circos_file="$outputDir/${sample}_VJ_circos.txt"
|
|
|
70 echo -e -n "labels$(cat ${circos_file})" > ${circos_file}
|
|
|
71 cat "${circos_file}" | $CIRCOSTOOLS/tableviewer/bin/parse-table -configfile $dir/circos/parse-table.conf 2>&1 | $CIRCOSTOOLS/tableviewer/bin/make-conf -dir $outputDir/circos/
|
|
|
72 $CIRCOSDIR/circos -conf $outputDir/circos/circos.conf 2>&1
|
|
|
73 mv $outputDir/circos/circos.png $outputDir/circosVJ_${sample}.png
|
|
|
74
|
|
|
75
|
|
|
76 if [[ "$useD" == "true" ]] ; then
|
|
|
77 circos_file="$outputDir/${sample}_VD_circos.txt"
|
|
|
78 echo -e -n "labels$(cat ${circos_file})" > ${circos_file}
|
|
|
79 cat "${circos_file}" | $CIRCOSTOOLS/tableviewer/bin/parse-table -configfile $dir/circos/parse-table.conf 2>&1 | $CIRCOSTOOLS/tableviewer/bin/make-conf -dir $outputDir/circos/
|
|
|
80 $CIRCOSDIR/circos -conf $outputDir/circos/circos.conf 2>&1
|
|
|
81 mv $outputDir/circos/circos.png $outputDir/circosVD_${sample}.png
|
|
|
82
|
|
|
83 circos_file="$outputDir/${sample}_DJ_circos.txt"
|
|
|
84 echo -e -n "labels$(cat ${circos_file})" > ${circos_file}
|
|
|
85 cat "${circos_file}" | $CIRCOSTOOLS/tableviewer/bin/parse-table -configfile $dir/circos/parse-table.conf 2>&1 | $CIRCOSTOOLS/tableviewer/bin/make-conf -dir $outputDir/circos/
|
|
|
86 $CIRCOSDIR/circos -conf $outputDir/circos/circos.conf 2>&1
|
|
|
87 mv $outputDir/circos/circos.png $outputDir/circosDJ_${sample}.png
|
|
|
88
|
|
|
89 fi
|
|
|
90 done
|
|
|
91 echo "</title><script type='text/javascript' src='jquery-1.11.0.min.js'></script>" >> $outputFile
|
|
|
92 echo "<script type='text/javascript' src='tabber.js'></script>" >> $outputFile
|
|
|
93 echo "<script type='text/javascript' src='script.js'></script>" >> $outputFile
|
|
|
94 echo "<link rel='stylesheet' type='text/css' href='style.css'></head>" >> $outputFile
|
|
|
95 echo "<div class='tabber'><div class='tabbertab' title='Gene frequencies'>" >> $outputFile
|
|
|
96
|
|
|
97 echo "<img src='CDR3LengthPlot.png'/><br />" >> $outputFile
|
|
|
98 echo "<img src='VFPlot.png'/>" >> $outputFile
|
|
|
99 if [[ "$useD" == "true" ]] ; then
|
|
|
100 echo "<img src='DFPlot.png'/>" >> $outputFile
|
|
|
101 fi
|
|
|
102 echo "<img src='JFPlot.png'/>" >> $outputFile
|
|
|
103 echo "<img src='VPlot.png'/>" >> $outputFile
|
|
|
104 if [[ "$useD" == "true" ]] ; then
|
|
|
105 echo "<img src='DPlot.png'/>" >> $outputFile
|
|
|
106 fi
|
|
|
107 echo "<img src='JPlot.png'/>" >> $outputFile
|
|
69
|
108 echo "<img src='AAComposition.png'/>" >> $outputFile
|
|
|
109 echo "<img src='DReadingFrame.png'/>" >> $outputFile
|
|
|
110 echo "</div>" >> $outputFile
|
|
58
|
111
|
|
|
112 #Heatmaps
|
|
|
113
|
|
|
114 count=1
|
|
|
115 echo "<div class='tabbertab' title='Heatmaps'><div class='tabber'>" >> $outputFile
|
|
|
116 for sample in $samples; do
|
|
|
117 echo "<div class='tabbertab' title='$sample'><table border='1'><tr>" >> $outputFile
|
|
|
118 if [[ "$useD" == "true" ]] ; then
|
|
|
119 echo "<td><img src='HeatmapVD_$sample.png'/></td>" >> $outputFile
|
|
|
120 fi
|
|
|
121 echo "<td><img src='HeatmapVJ_$sample.png'/></td>" >> $outputFile
|
|
|
122 if [[ "$useD" == "true" ]] ; then
|
|
|
123 echo "<td><img src='HeatmapDJ_$sample.png'/></td>" >> $outputFile
|
|
|
124 fi
|
|
|
125 echo "</tr></table></div>" >> $outputFile
|
|
|
126 count=$((count+1))
|
|
|
127 done
|
|
|
128 echo "</div></div>" >> $outputFile
|
|
|
129
|
|
|
130 #circos
|
|
|
131
|
|
|
132 if [[ "$USECIRCOS" == "yes" ]]; then
|
|
|
133
|
|
|
134 echo "<div class='tabbertab' title='Circos'><div class='tabber'>" >> $outputFile
|
|
|
135 for sample in $samples; do
|
|
|
136 echo "<div class='tabbertab' title='$sample'><table border='1'><center>" >> $outputFile
|
|
|
137 if [[ "$useD" == "true" ]] ; then
|
|
|
138 echo "<tr><td>V-D</td><td><img src='circosVD_${sample}.png' width='700' height='700'/></td></tr>" >> $outputFile
|
|
|
139 fi
|
|
|
140 echo "<tr><td>V-J</td><td><img src='circosVJ_${sample}.png' width='700' height='700'/></td></tr>" >> $outputFile
|
|
|
141 if [[ "$useD" == "true" ]] ; then
|
|
|
142 echo "<tr><td>D-J</td><td><img src='circosDJ_${sample}.png' width='700' height='700'/></td></tr>" >> $outputFile
|
|
|
143 fi
|
|
|
144 echo "<center></table></div>" >> $outputFile
|
|
|
145 count=$((count+1))
|
|
|
146 done
|
|
|
147 echo "</div></div>" >> $outputFile
|
|
|
148 fi
|
|
|
149 #echo "<div class='tabbertab' title='Interactive'><svg class='chart'></svg><script src='http://d3js.org/d3.v3.min.js'></script></div>" >> $outputFile
|
|
|
150
|
|
|
151 hasReplicateColumn="$(if head -n 1 $inputFile | grep -q 'Replicate'; then echo 'Yes'; else echo 'No'; fi)"
|
|
|
152 echo "$hasReplicateColumn"
|
|
|
153 #if its a 'new' merged file with replicate info
|
|
|
154 if [[ "$hasReplicateColumn" == "Yes" ]] ; then
|
|
|
155 echo "<div class='tabbertab' title='Clonality'><div class='tabber'>" >> $outputFile
|
|
|
156 for sample in $samples; do
|
|
|
157 echo "${clonality_method}"
|
|
|
158 if [[ "${clonality_method}" == "old" ]] ; then
|
|
|
159 echo "in old"
|
|
|
160 clonalityScore="$(cat $outputDir/ClonalityScore_$sample.csv)"
|
|
|
161 echo "<div class='tabbertab' title='$sample'><table border='1'>" >> $outputFile
|
|
|
162 echo "<tr><td colspan='4'>Clonality Score: $clonalityScore</td></tr>" >> $outputFile
|
|
|
163
|
|
|
164 #replicate,reads,squared
|
|
|
165 echo "<tr><td>Replicate ID</td><td>Number of Reads</td><td>Reads Squared</td><td></td></tr>" >> $outputFile
|
|
|
166 while IFS=, read replicate reads squared
|
|
|
167 do
|
|
|
168 echo "<tr><td>$replicate</td><td>$reads</td><td>$squared</td><td></td></tr>" >> $outputFile
|
|
|
169 done < $outputDir/ReplicateReads_$sample.csv
|
|
|
170
|
|
|
171 #sum of reads and reads squared
|
|
|
172 while IFS=, read readsSum squaredSum
|
|
|
173 do
|
|
|
174 echo "<tr><td>Sum</td><td>$readsSum</td><td>$squaredSum</td></tr>" >> $outputFile
|
|
|
175 done < $outputDir/ReplicateSumReads_$sample.csv
|
|
|
176
|
|
|
177 #overview
|
|
|
178 echo "<tr><td>Coincidence Type</td><td>Raw Coincidence Freq</td><td>Coincidence Weight</td><td>Coincidences, Weighted</td></tr>" >> $outputFile
|
|
|
179 while IFS=, read type count weight weightedCount
|
|
|
180 do
|
|
64
|
181 if [[ "$type" -eq "1" ]]; then
|
|
|
182 echo "<tr><td>$type</td><td>$count</td><td>$weight</td><td>$weightedCount</td></tr>" >> $outputFile
|
|
|
183 else
|
|
|
184 echo "<tr><td><a href='coincidences_${sample}_${type}.txt'>$type</a></td><td>$count</td><td>$weight</td><td>$weightedCount</td></tr>" >> $outputFile
|
|
|
185 fi
|
|
|
186
|
|
58
|
187 done < $outputDir/ClonalityOverView_$sample.csv
|
|
|
188 echo "</table></div>" >> $outputFile
|
|
|
189 else
|
|
|
190 echo "in new"
|
|
|
191 clonalityScore="$(cat $outputDir/lymphclon_clonality_${sample}.csv)"
|
|
|
192 echo "<div class='tabbertab' title='$sample'>" >> $outputFile
|
|
|
193 echo "Lymphclon clonality score: <br />$clonalityScore<br /><br />" >> $outputFile
|
|
|
194 echo "<table border = 1>" >> $outputFile
|
|
|
195 while IFS=, read type count
|
|
|
196 do
|
|
|
197 echo "<tr><td>$type</td><td>$count</td></tr>" >> $outputFile
|
|
|
198 done < $outputDir/lymphclon_coincidences_$sample.csv
|
|
|
199 echo "</table></div>" >> $outputFile
|
|
|
200 fi
|
|
|
201 done
|
|
|
202 echo "</div></div>" >> $outputFile
|
|
|
203 fi
|
|
|
204
|
|
|
205 #hasJunctionData="$(if head -n 1 $inputFile | grep -qE '3V.REGION.trimmed.nt.nb'; then echo 'Yes'; else echo 'No'; fi)"
|
|
|
206
|
|
|
207 #if [[ "$hasJunctionData" == "Yes" ]] ; then
|
|
|
208 if [ -a "$outputDir/junctionAnalysisProd_mean.csv" ] ; then
|
|
|
209 echo "<div class='tabbertab' title='Junction Analysis'>" >> $outputFile
|
|
68
|
210 echo "<table border='1' id='junction_table'> <caption>Productive mean</caption><thead><tr><th>Sample</th><th>count</th><th>V.DEL</th><th>P1</th><th>N1</th><th>P2</th><th>DEL.D</th><th>D.DEL</th><th>P3</th><th>N2</th><th>P4</th><th>DEL.J</th><th>Total.Del</th><th>Total.N</th><th>Total.P</th><thead></tr><tbody>" >> $outputFile
|
|
|
211 while IFS=, read Sample unique VDEL P1 N1 P2 DELD DDEL P3 N2 P4 DELJ TotalDel TotalN TotalP
|
|
58
|
212 do
|
|
68
|
213 echo "<tr><td>$Sample</td><td>$unique</td><td>$VDEL</td><td>$P1</td><td>$N1</td><td>$P2</td><td>$DELD</td><td>$DDEL</td><td>$P3</td><td>$N2</td><td>$P4</td><td>$DELJ</td><td>$TotalDel</td><td>$TotalN</td><td>$TotalP</td></tr>" >> $outputFile
|
|
58
|
214 done < $outputDir/junctionAnalysisProd_mean.csv
|
|
|
215 echo "</tbody></table>" >> $outputFile
|
|
|
216
|
|
68
|
217 echo "<table border='1' id='junction_table'> <caption>Unproductive mean</caption><thead><tr><th>Sample</th><th>count</th><th>V.DEL</th><th>P1</th><th>N1</th><th>P2</th><th>DEL.D</th><th>D.DEL</th><th>P3</th><th>N2</th><th>P4</th><th>DEL.J</th><th>Total.Del</th><th>Total.N</th><th>Total.P</th><thead></tr><tbody>" >> $outputFile
|
|
|
218 while IFS=, read Sample unique VDEL P1 N1 P2 DELD DDEL P3 N2 P4 DELJ TotalDel TotalN TotalP
|
|
58
|
219 do
|
|
68
|
220 echo "<tr><td>$Sample</td><td>$unique</td><td>$VDEL</td><td>$P1</td><td>$N1</td><td>$P2</td><td>$DELD</td><td>$DDEL</td><td>$P3</td><td>$N2</td><td>$P4</td><td>$DELJ</td><td>$TotalDel</td><td>$TotalN</td><td>$TotalP</td></tr>" >> $outputFile
|
|
58
|
221 done < $outputDir/junctionAnalysisUnProd_mean.csv
|
|
|
222 echo "</tbody></table>" >> $outputFile
|
|
|
223
|
|
68
|
224 echo "<table border='1' id='junction_table'> <caption>Productive median</caption><thead><tr><th>Sample</th><th>count</th><th>V.DEL</th><th>P1</th><th>N1</th><th>P2</th><th>DEL.D</th><th>D.DEL</th><th>P3</th><th>N2</th><th>P4</th><th>DEL.J</th><th>Total.Del</th><th>Total.N</th><th>Total.P</th><thead></tr><tbody>" >> $outputFile
|
|
|
225 while IFS=, read Sample unique VDEL P1 N1 P2 DELD DDEL P3 N2 P4 DELJ TotalDel TotalN TotalP
|
|
58
|
226 do
|
|
68
|
227 echo "<tr><td>$Sample</td><td>$unique</td><td>$VDEL</td><td>$P1</td><td>$N1</td><td>$P2</td><td>$DELD</td><td>$DDEL</td><td>$P3</td><td>$N2</td><td>$P4</td><td>$DELJ</td><td>$TotalDel</td><td>$TotalN</td><td>$TotalP</td></tr>" >> $outputFile
|
|
58
|
228 done < $outputDir/junctionAnalysisProd_median.csv
|
|
|
229 echo "</tbody></table>" >> $outputFile
|
|
|
230
|
|
68
|
231 echo "<table border='1' id='junction_table'> <caption>Unproductive median</caption><thead><tr><th>Sample</th><th>count</th><th>V.DEL</th><th>P1</th><th>N1</th><th>P2</th><th>DEL.D</th><th>D.DEL</th><th>P3</th><th>N2</th><th>P4</th><th>DEL.J</th><th>Total.Del</th><th>Total.N</th><th>Total.P</th><thead></tr><tbody>" >> $outputFile
|
|
|
232 while IFS=, read Sample unique VDEL P1 N1 P2 DELD DDEL P3 N2 P4 DELJ TotalDel TotalN TotalP
|
|
58
|
233 do
|
|
68
|
234 echo "<tr><td>$Sample</td><td>$unique</td><td>$VDEL</td><td>$P1</td><td>$N1</td><td>$P2</td><td>$DELD</td><td>$DDEL</td><td>$P3</td><td>$N2</td><td>$P4</td><td>$DELJ</td><td>$TotalDel</td><td>$TotalN</td><td>$TotalP</td></tr>" >> $outputFile
|
|
58
|
235 done < $outputDir/junctionAnalysisUnProd_median.csv
|
|
|
236 echo "</tbody></table>" >> $outputFile
|
|
|
237
|
|
|
238 echo "</div>" >> $outputFile
|
|
|
239 fi
|
|
|
240
|
|
|
241 echo "<div class='tabbertab' title='Comparison'><table border='1'><tr><th>ID</th><th>Include</th></tr>" >> $outputFile
|
|
|
242 for sample in $samples; do
|
|
|
243 echo "<tr><td>$sample</td><td><input type='checkbox' onchange=\"javascript:compareAdd('$sample')\" id='compare_checkbox_$sample'/></td></tr>" >> $outputFile
|
|
|
244 done
|
|
|
245 echo "</table><div name='comparisonarea'>" >> $outputFile
|
|
|
246 echo "<table><tr id='comparison_table_vd'></tr></table>" >> $outputFile
|
|
|
247 echo "<table><tr id='comparison_table_vj'></tr></table>" >> $outputFile
|
|
|
248 echo "<table><tr id='comparison_table_dj'></tr></table>" >> $outputFile
|
|
|
249 echo "</div></div>" >> $outputFile
|
|
|
250
|
|
|
251 echo "<div class='tabbertab' title='Downloads'>" >> $outputFile
|
|
|
252 echo "<table border='1'>" >> $outputFile
|
|
|
253 echo "<tr><th>Description</th><th>Link</th></tr>" >> $outputFile
|
|
|
254 echo "<tr><td>The dataset used to generate the frequency graphs and the heatmaps (Unique based on clonaltype, $clonalType)</td><td><a href='allUnique.csv'>Download</a></td></tr>" >> $outputFile
|
|
|
255 echo "<tr><td>The dataset used to calculate clonality score (Unique based on clonaltype, $clonalType)</td><td><a href='clonalityComplete.csv'>Download</a></td></tr>" >> $outputFile
|
|
|
256
|
|
|
257 echo "<tr><td>The dataset used to generate the CDR3 length frequency graph</td><td><a href='CDR3LengthPlot.csv'>Download</a></td></tr>" >> $outputFile
|
|
|
258
|
|
|
259 echo "<tr><td>The dataset used to generate the V gene family frequency graph</td><td><a href='VFFrequency.csv'>Download</a></td></tr>" >> $outputFile
|
|
|
260 if [[ "$useD" == "true" ]] ; then
|
|
|
261 echo "<tr><td>The dataset used to generate the D gene family frequency graph</td><td><a href='DFFrequency.csv'>Download</a></td></tr>" >> $outputFile
|
|
|
262 fi
|
|
|
263 echo "<tr><td>The dataset used to generate the J gene family frequency graph</td><td><a href='JFFrequency.csv'>Download</a></td></tr>" >> $outputFile
|
|
|
264
|
|
|
265 echo "<tr><td>The dataset used to generate the V gene frequency graph</td><td><a href='VFrequency.csv'>Download</a></td></tr>" >> $outputFile
|
|
|
266 if [[ "$useD" == "true" ]] ; then
|
|
|
267 echo "<tr><td>The dataset used to generate the D gene frequency graph</td><td><a href='DFrequency.csv'>Download</a></td></tr>" >> $outputFile
|
|
|
268 fi
|
|
|
269 echo "<tr><td>The dataset used to generate the J gene frequency graph</td><td><a href='JFrequency.csv'>Download</a></td></tr>" >> $outputFile
|
|
|
270 echo "<tr><td>The dataset used to generate the AA composition graph</td><td><a href='AAComposition.csv'>Download</a></td></tr>" >> $outputFile
|
|
|
271
|
|
|
272 for sample in $samples; do
|
|
|
273 if [[ "$useD" == "true" ]] ; then
|
|
|
274 echo "<tr><td>The data used to generate the VD heatmap for $sample.</td><td><a href='HeatmapVD_$sample.csv'>Download</a></td></tr>" >> $outputFile
|
|
|
275 fi
|
|
|
276 echo "<tr><td>The data used to generate the VJ heatmap for $sample.</td><td><a href='HeatmapVJ_$sample.csv'>Download</a></td></tr>" >> $outputFile
|
|
|
277 if [[ "$useD" == "true" ]] ; then
|
|
|
278 echo "<tr><td>The data used to generate the DJ heatmap for $sample.</td><td><a href='HeatmapDJ_$sample.csv'>Download</a></td></tr>" >> $outputFile
|
|
|
279 fi
|
|
|
280 done
|
|
|
281
|
|
67
|
282 echo "<tr><td>A frequency count of V Gene + J Gene + CDR3</td><td><a href='VJCDR3_count.txt'>Download</a></td></tr>" >> $outputFile
|
|
|
283
|
|
58
|
284 echo "</table>" >> $outputFile
|
|
|
285 echo "</div></html>" >> $outputFile
|