comparison report_clonality/r_wrapper.sh @ 0:f90fbc15b35a draft

Uploaded
author davidvanzessen
date Thu, 16 Jul 2015 08:30:43 -0400
parents
children ee1bda8c27c8
comparison
equal deleted inserted replaced
-1:000000000000 0:f90fbc15b35a
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 dir="$(cd "$(dirname "$0")" && pwd)"
12 useD="false"
13 if grep -q "$species.*${locus}D" "$dir/genes.txt" ; then
14 echo "species D region in reference db"
15 useD="true"
16 fi
17 echo "$species"
18 if [[ "$species" == *"custom"* ]] ; then
19 loci=(${locus//;/ })
20 useD="true"
21 echo "${loci[@]}"
22 if [[ "${#loci[@]}" -eq "2" ]] ; then
23 useD="false"
24 fi
25 fi
26 mkdir $3
27 cp $dir/genes.txt $outputDir
28 Rscript --verbose $dir/RScript.r $inputFile $outputDir $outputDir $clonalType "$species" "$locus" $filterproductive ${clonality_method} 2>&1
29 cp $dir/tabber.js $outputDir
30 cp $dir/style.css $outputDir
31 cp $dir/script.js $outputDir
32 cp $dir/jquery-1.11.0.min.js $outputDir
33 samples=`cat $outputDir/samples.txt`
34 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
35 echo "<table border = 1>" >> $2
36 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
37 while IFS=, read sample all productive perc_prod productive_unique perc_prod_un unproductive perc_unprod unproductive_unique perc_unprod_un
38 do
39 echo "<tr><td>$sample</td>" >> $2
40 echo "<td>$all</td>" >> $2
41 echo "<td>$productive (${perc_prod}%)</td>" >> $2
42 echo "<td>$productive_unique (${perc_prod_un}%)</td>" >> $2
43 echo "<td>$unproductive (${perc_unprod}%)</td>" >> $2
44 echo "<td>$unproductive_unique (${perc_unprod_un}%)</td></tr>" >> $2
45 done < $outputDir/productive_counting.txt
46 echo "</table border></center></html>" >> $2
47
48 echo "productive_counting.txt"
49 echo "<html><head><title>Report on:" >> $outputFile
50 for sample in $samples; do
51 echo " $sample" >> $outputFile
52 done
53 echo "</title><script type='text/javascript' src='jquery-1.11.0.min.js'></script>" >> $outputFile
54 echo "<script type='text/javascript' src='tabber.js'></script>" >> $outputFile
55 echo "<script type='text/javascript' src='script.js'></script>" >> $outputFile
56 echo "<link rel='stylesheet' type='text/css' href='style.css'></head>" >> $outputFile
57 echo "<div class='tabber'><div class='tabbertab' title='Gene frequencies'>" >> $outputFile
58
59 echo "<img src='CDR3LengthPlot.png'/><br />" >> $outputFile
60 echo "<img src='VFPlot.png'/>" >> $outputFile
61 if [[ "$useD" == "true" ]] ; then
62 echo "<img src='DFPlot.png'/>" >> $outputFile
63 fi
64 echo "<img src='JFPlot.png'/>" >> $outputFile
65 echo "<img src='VPlot.png'/>" >> $outputFile
66 if [[ "$useD" == "true" ]] ; then
67 echo "<img src='DPlot.png'/>" >> $outputFile
68 fi
69 echo "<img src='JPlot.png'/>" >> $outputFile
70 echo "<img src='AAComposition.png'/></div>" >> $outputFile
71
72 count=1
73 echo "<div class='tabbertab' title='Heatmaps'><div class='tabber'>" >> $outputFile
74 for sample in $samples; do
75 echo "<div class='tabbertab' title='$sample'><table border='1'><tr>" >> $outputFile
76 if [[ "$useD" == "true" ]] ; then
77 echo "<td><img src='HeatmapVD_$sample.png'/></td>" >> $outputFile
78 fi
79 echo "<td><img src='HeatmapVJ_$sample.png'/></td>" >> $outputFile
80 if [[ "$useD" == "true" ]] ; then
81 echo "<td><img src='HeatmapDJ_$sample.png'/></td>" >> $outputFile
82 fi
83 echo "</tr></table></div>" >> $outputFile
84 count=$((count+1))
85 done
86 echo "</div></div>" >> $outputFile
87
88 #echo "<div class='tabbertab' title='Interactive'><svg class='chart'></svg><script src='http://d3js.org/d3.v3.min.js'></script></div>" >> $outputFile
89
90 hasReplicateColumn="$(if head -n 1 $inputFile | grep -q 'Replicate'; then echo 'Yes'; else echo 'No'; fi)"
91 echo "$hasReplicateColumn"
92 #if its a 'new' merged file with replicate info
93 if [[ "$hasReplicateColumn" == "Yes" && "$clonalType" != "none" ]] ; then
94 echo "<div class='tabbertab' title='Clonality'><div class='tabber'>" >> $outputFile
95 for sample in $samples; do
96 echo "${clonality_method}"
97 if [[ "${clonality_method}" == "old" ]] ; then
98 echo "in old"
99 clonalityScore="$(cat $outputDir/ClonalityScore_$sample.csv)"
100 echo "<div class='tabbertab' title='$sample'><table border='1'>" >> $outputFile
101 echo "<tr><td colspan='4'>Clonality Score: $clonalityScore</td></tr>" >> $outputFile
102
103 #replicate,reads,squared
104 echo "<tr><td>Replicate ID</td><td>Number of Reads</td><td>Reads Squared</td><td></td></tr>" >> $outputFile
105 while IFS=, read replicate reads squared
106 do
107
108 echo "<tr><td>$replicate</td><td>$reads</td><td>$squared</td><td></td></tr>" >> $outputFile
109 done < $outputDir/ReplicateReads_$sample.csv
110
111 #sum of reads and reads squared
112 while IFS=, read readsSum squaredSum
113 do
114 echo "<tr><td>Sum</td><td>$readsSum</td><td>$squaredSum</td></tr>" >> $outputFile
115 done < $outputDir/ReplicateSumReads_$sample.csv
116
117 #overview
118 echo "<tr><td>Coincidence Type</td><td>Raw Coincidence Freq</td><td>Coincidence Weight</td><td>Coincidences, Weighted</td></tr>" >> $outputFile
119 while IFS=, read type count weight weightedCount
120 do
121 echo "<tr><td>$type</td><td>$count</td><td>$weight</td><td>$weightedCount</td></tr>" >> $outputFile
122 done < $outputDir/ClonalityOverView_$sample.csv
123 echo "</table></div>" >> $outputFile
124 else
125 echo "in new"
126 clonalityScore="$(cat $outputDir/lymphclon_clonality_${sample}.csv)"
127 echo "<div class='tabbertab' title='$sample'>" >> $outputFile
128 echo "Lymphclon clonality score: <br />$clonalityScore<br /><br />" >> $outputFile
129 echo "<table border = 1>" >> $outputFile
130 while IFS=, read type count
131 do
132 echo "<tr><td>$type</td><td>$count</td></tr>" >> $outputFile
133 done < $outputDir/lymphclon_coincidences_$sample.csv
134 echo "</table></div>" >> $outputFile
135 fi
136 done
137 echo "</div></div>" >> $outputFile
138 fi
139
140 hasJunctionData="$(if head -n 1 $inputFile | grep -q '3V-REGION trimmed-nt nb'; then echo 'Yes'; else echo 'No'; fi)"
141
142 if [[ "$hasJunctionData" == "Yes" ]] ; then
143 echo "<div class='tabbertab' title='Junction Analysis'>" >> $outputFile
144 echo "<table border='1' id='junction_table'> <caption>Productive</caption><thead><tr><th>Sample</th><th>count</th><th>VH.DEL</th><th>P1</th><th>N1</th><th>P2</th><th>DEL.DH</th><th>DH.DEL</th><th>P3</th><th>N2</th><th>P4</th><th>DEL.JH</th><th>Total.Del</th><th>Total.N</th><th>Total.P</th><thead></tr><tbody>" >> $outputFile
145 while IFS=, read Sample unique VHDEL P1 N1 P2 DELDH DHDEL P3 N2 P4 DELJH TotalDel TotalN TotalP
146 do
147 echo "<tr><td>$Sample</td><td>$unique</td><td>$VHDEL</td><td>$P1</td><td>$N1</td><td>$P2</td><td>$DELDH</td><td>$DHDEL</td><td>$P3</td><td>$N2</td><td>$P4</td><td>$DELJH</td><td>$TotalDel</td><td>$TotalN</td><td>$TotalP</td></tr>" >> $outputFile
148 done < $outputDir/junctionAnalysisProd.csv
149 echo "</tbody></table>" >> $outputFile
150
151 echo "<table border='1' id='junction_table'> <caption>Unproductive</caption><thead><tr><th>Sample</th><th>count</th><th>VH.DEL</th><th>P1</th><th>N1</th><th>P2</th><th>DEL.DH</th><th>DH.DEL</th><th>P3</th><th>N2</th><th>P4</th><th>DEL.JH</th><th>Total.Del</th><th>Total.N</th><th>Total.P</th><thead></tr><tbody>" >> $outputFile
152 while IFS=, read Sample unique VHDEL P1 N1 P2 DELDH DHDEL P3 N2 P4 DELJH TotalDel TotalN TotalP
153 do
154 echo "<tr><td>$Sample</td><td>$unique</td><td>$VHDEL</td><td>$P1</td><td>$N1</td><td>$P2</td><td>$DELDH</td><td>$DHDEL</td><td>$P3</td><td>$N2</td><td>$P4</td><td>$DELJH</td><td>$TotalDel</td><td>$TotalN</td><td>$TotalP</td></tr>" >> $outputFile
155 done < $outputDir/junctionAnalysisUnProd.csv
156 echo "</tbody></table>" >> $outputFile
157
158 echo "</div>" >> $outputFile
159 fi
160
161 echo "<div class='tabbertab' title='Comparison'><table border='1'><tr><th>ID</th><th>Include</th></tr>" >> $outputFile
162 for sample in $samples; do
163 echo "<tr><td>$sample</td><td><input type='checkbox' onchange=\"javascript:compareAdd('$sample')\" id='compare_checkbox_$sample'/></td></tr>" >> $outputFile
164 done
165 echo "</table><div name='comparisonarea'>" >> $outputFile
166 echo "<table><tr id='comparison_table_vd'></tr></table>" >> $outputFile
167 echo "<table><tr id='comparison_table_vj'></tr></table>" >> $outputFile
168 echo "<table><tr id='comparison_table_dj'></tr></table>" >> $outputFile
169 echo "</div></div>" >> $outputFile
170
171 echo "<div class='tabbertab' title='Downloads'>" >> $outputFile
172 echo "<table border='1'>" >> $outputFile
173 echo "<tr><th>Description</th><th>Link</th></tr>" >> $outputFile
174 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
175 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
176
177 echo "<tr><td>The dataset used to generate the CDR3 length frequency graph</td><td><a href='CDR3LengthPlot.csv'>Download</a></td></tr>" >> $outputFile
178
179 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
180 if [[ "$useD" == "true" ]] ; then
181 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
182 fi
183 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
184
185 echo "<tr><td>The dataset used to generate the V gene frequency graph</td><td><a href='VFrequency.csv'>Download</a></td></tr>" >> $outputFile
186 if [[ "$useD" == "true" ]] ; then
187 echo "<tr><td>The dataset used to generate the D gene frequency graph</td><td><a href='DFrequency.csv'>Download</a></td></tr>" >> $outputFile
188 fi
189 echo "<tr><td>The dataset used to generate the J gene frequency graph</td><td><a href='JFrequency.csv'>Download</a></td></tr>" >> $outputFile
190 echo "<tr><td>The dataset used to generate the AA composition graph</td><td><a href='AAComposition.csv'>Download</a></td></tr>" >> $outputFile
191
192 for sample in $samples; do
193 if [[ "$useD" == "true" ]] ; then
194 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
195 fi
196 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
197 if [[ "$useD" == "true" ]] ; then
198 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
199 fi
200 done
201
202 echo "</table>" >> $outputFile
203 echo "</div></html>" >> $outputFile