0
|
1 #!/bin/bash
|
|
2
|
|
3 clonalType=${@:(-6):1}
|
|
4 html=${@:(-5):1}
|
|
5 imageDir=${@:(-4):1}
|
|
6 species=${@:(-3):1}
|
|
7 locus=${@:(-2):1}
|
|
8 selection=${@:(-1):1}
|
|
9 dataCount=`expr $# - 6`
|
|
10 inputData=${@:(1):dataCount}
|
|
11 echo ${inputData[@]}
|
|
12 dir="$(cd "$(dirname "$0")" && pwd)"
|
|
13 array=("$@")
|
|
14 echo "<html><h3>Progress</h3><table><tr><td>info</td></tr>" > $html
|
|
15 echo "<tr><td>-----------------------------------</td></tr>" >> $html
|
|
16
|
|
17 mkdir $PWD/igblastdatabase
|
|
18 unzip $dir/database.zip -d $PWD/igblastdatabase/
|
|
19 export IGDATA=$PWD/igblastdatabase/
|
|
20
|
|
21 function blastAndParse {
|
|
22 echo "<tr><td>Starting blast of sample $3 of patient $2</td></tr>" >> $html
|
|
23 echo "igblastn -germline_db_V $PWD/igblastdatabase/database/human_gl_V -germline_db_J $PWD/igblastdatabase/database/human_gl_J -germline_db_D $PWD/igblastdatabase/database/human_gl_D -domain_system imgt -query $1 -auxiliary_data $PWD/igblastdatabase/optional_file/human_gl.aux -show_translation -outfmt 3 > $PWD/$4"
|
|
24 /home/galaxy/galaxy/igblast/igblastn -germline_db_V $PWD/igblastdatabase/database/human_gl_V -germline_db_J $PWD/igblastdatabase/database/human_gl_J -germline_db_D $PWD/igblastdatabase/database/human_gl_D -domain_system imgt -query $1 -auxiliary_data $PWD/igblastdatabase/optional_file/human_gl.aux -show_translation -outfmt 3 > $PWD/$4
|
|
25 echo "<tr><td>Finished blast of sample $3 of patient $2</td></tr>" >> $html
|
|
26
|
|
27 echo "<tr><td>Starting parse of sample $3 of patient $2</td></tr>" >> $html
|
|
28 perl $dir/igparse.pl $PWD/$4 0 | grep -v "D:" | cut -f2- > $5
|
|
29 echo "<tr><td>Finished parse of sample $3 of patient $2</td></tr>" >> $html
|
|
30 }
|
|
31
|
|
32 function imgtConvert {
|
|
33 echo "<tr><td>Starting imgt convert of sample $3 of patient $2</td></tr>" >> $html
|
|
34 bash $dir/imgtconvert.sh $1 $2 $3 $4
|
|
35 echo "<tr><td>Finished conversion of sample $3 of patient $2</td></tr>" >> $html
|
|
36
|
|
37 }
|
|
38
|
|
39 id=${inputData[0]}
|
|
40 forwardSlash="/"
|
|
41 mergerInput=()
|
|
42 count=0
|
|
43 for current in $inputData; do
|
|
44 if [[ "$current" != *"$forwardSlash"* ]]; then
|
|
45 id=$current
|
|
46 count=0
|
|
47 mergerInput+=($id)
|
|
48 continue
|
|
49 fi
|
|
50 fileName=$(basename $current)
|
|
51 parsedFileName="${fileName%.*}"
|
|
52 parsedFileName="$PWD/$parsedFileName.parsed"
|
|
53 f=$(file $current)
|
|
54 zipType="Zip archive"
|
|
55 if [[ "$f" == *"$zipType"* ]]
|
|
56 then
|
|
57 echo "<tr><td>Sample $count of patient $id is a zip file, using IMGT Loader</td></tr>" >> $html
|
|
58 fileName=$(basename $current)
|
|
59 imgtConvert $current $id $count $parsedFileName &
|
|
60 else
|
|
61 echo "<tr><td>Sample $count of patient $id is not a zip file, using igBLASTn</td></tr>" >> $html
|
|
62 blastAndParse $current $id $count $fileName $parsedFileName &
|
|
63 fi
|
|
64 mergerInput+=($parsedFileName)
|
|
65 count=$((count+1))
|
|
66 done
|
|
67 wait
|
|
68
|
|
69
|
|
70
|
|
71 echo "<tr><td>-----------------------------------</td></tr>" >> $html
|
|
72 echo "<tr><td>merging</td></tr>" >> $html
|
|
73
|
|
74 python $dir/igblastmerge.py ${mergerInput[*]} --output $PWD/merged.txt
|
|
75
|
|
76 echo "<tr><td>done</td></tr>" >> $html
|
|
77 echo "<tr><td>-----------------------------------</td></tr>" >> $html
|
|
78 echo "<tr><td>plotting</td></tr>" >> $html
|
|
79
|
|
80
|
|
81 inputFile=$PWD/merged.txt
|
|
82 outputDir=$imageDir
|
|
83 outputFile=$outputDir/index.html
|
|
84 mkdir $outputDir
|
|
85 Rscript --verbose $dir/RScript.r $inputFile $outputDir $outputDir $clonalType $species $locus $selection 2>&1
|
|
86 cp $dir/tabber.js $outputDir
|
|
87 cp $dir/style.css $outputDir
|
|
88 cp $dir/script.js $outputDir
|
|
89 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)</center></html>" > $html
|
|
90 echo "<html><head><title>Report on:" >> $outputFile
|
|
91 for sample in $samples; do
|
|
92 echo " $sample" >> $outputFile
|
|
93 done
|
|
94 echo "</title><script type='text/javascript' src='jquery-1.11.0.min.js'></script>" >> $outputFile
|
|
95 echo "<script type='text/javascript' src='tabber.js'></script>" >> $outputFile
|
|
96 echo "<script type='text/javascript' src='script.js'></script>" >> $outputFile
|
|
97 echo "<script type='text/javascript' src='jquery.tablesorter.min.js'></script>" >> $outputFile
|
|
98 echo "<link rel='stylesheet' type='text/css' href='style.css'></head>" >> $outputFile
|
|
99
|
|
100 echo "<div class='tabber'><div class='tabbertab' title='Gene frequencies'>" >> $outputFile
|
|
101 echo "<img src='CDR3LengthPlot.png'/><br />" >> $outputFile
|
|
102 echo "<img src='VFPlot.png'/>" >> $outputFile
|
|
103 echo "<img src='DFPlot.png'/>" >> $outputFile
|
|
104 echo "<img src='JFPlot.png'/>" >> $outputFile
|
|
105 echo "<img src='VPlot.png'/>" >> $outputFile
|
|
106 echo "<img src='DPlot.png'/>" >> $outputFile
|
|
107 echo "<img src='JPlot.png'/></div>" >> $outputFile
|
|
108
|
|
109 samples=`cat $outputDir/samples.txt`
|
|
110 count=1
|
|
111 echo "<div class='tabbertab' title='Heatmaps'><div class='tabber'>" >> $outputFile
|
|
112 for sample in $samples; do
|
|
113 echo "<div class='tabbertab' title='$sample'><table border='1'><tr>" >> $outputFile
|
|
114
|
|
115 mv "$outputDir/HeatmapVD_$sample.png" "$outputDir/VD_$sample.png"
|
|
116 echo "<td><img src='VD_$sample.png'/></td>" >> $outputFile
|
|
117 mv "$outputDir/HeatmapVJ_$sample.png" "$outputDir/VJ_$sample.png"
|
|
118 echo "<td><img src='VJ_$sample.png'/></td>" >> $outputFile
|
|
119 mv "$outputDir/HeatmapDJ_$sample.png" "$outputDir/DJ_$sample.png"
|
|
120 echo "<td><img src='DJ_$sample.png'/></td></tr></table></div>" >> $outputFile
|
|
121 count=$((count+1))
|
|
122 done
|
|
123 echo "</div></div>" >> $outputFile
|
|
124
|
|
125
|
|
126 hasReplicateColumn="$(if head -n 1 $inputFile | grep -q 'Replicate'; then echo 'Yes'; else echo 'No'; fi)"
|
|
127 #if its a 'new' merged file with replicate info
|
|
128 if [[ "$hasReplicateColumn" == "Yes" ]] ; then
|
|
129 echo "<div class='tabbertab' title='Clonality'><div class='tabber'>" >> $outputFile
|
|
130 for sample in $samples; do
|
|
131 clonalityScore="$(cat $outputDir/ClonalityScore_$sample.csv)"
|
|
132 echo "<div class='tabbertab' title='$sample'><table border='1'>" >> $outputFile
|
|
133 echo "<tr><td colspan='4'>Clonality Score: $clonalityScore</td></tr>" >> $outputFile
|
|
134
|
|
135 #replicate,reads,squared
|
|
136 echo "<tr><td>Replicate ID</td><td>Number of Reads</td><td>Reads Squared</td><td></td></tr>" >> $outputFile
|
|
137 while IFS=, read replicate reads squared
|
|
138 do
|
|
139
|
|
140 echo "<tr><td>$replicate</td><td>$reads</td><td>$squared</td><td></td></tr>" >> $outputFile
|
|
141 done < $outputDir/ReplicateReads_$sample.csv
|
|
142
|
|
143 #sum of reads and reads squared
|
|
144 while IFS=, read readsSum squaredSum
|
|
145 do
|
|
146 echo "<tr><td>Sum</td><td>$readsSum</td><td>$squaredSum</td></tr>" >> $outputFile
|
|
147 done < $outputDir/ReplicateSumReads_$sample.csv
|
|
148
|
|
149 #overview
|
|
150 echo "<tr><td>Coincidence Type</td><td>Raw Coincidence Freq</td><td>Coincidence Weight</td><td>Coincidences, Weighted</td></tr>" >> $outputFile
|
|
151 while IFS=, read type count weight weightedCount
|
|
152 do
|
|
153 echo "<tr><td>$type</td><td>$count</td><td>$weight</td><td>$weightedCount</td></tr>" >> $outputFile
|
|
154 done < $outputDir/ClonalityOverView_$sample.csv
|
|
155 echo "</table></div>" >> $outputFile
|
|
156 done
|
|
157 echo "</div></div>" >> $outputFile
|
|
158 fi
|
|
159
|
|
160 hasJunctionData="$(if head -n 1 $inputFile | grep -q '3V-REGION trimmed-nt nb'; then echo 'Yes'; else echo 'No'; fi)"
|
|
161
|
|
162 if [[ "$hasJunctionData" == "Yes" ]] ; then
|
|
163 echo "<div class='tabbertab' title='Junction Analysis'><table border='1' id='junction_table' class='tablesorter'><thead><tr><th>Sample</th><th>unique</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
|
|
164 while IFS=, read Sample unique VHDEL P1 N1 P2 DELDH DHDEL P3 N2 P4 DELJH TotalDel TotalN TotalP
|
|
165 do
|
|
166 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
|
|
167 done < $outputDir/junctionAnalysis.csv
|
|
168 echo "</tbody></table></div>" >> $outputFile
|
|
169 fi
|
|
170
|
|
171 echo "<div class='tabbertab' title='Comparison'><table border='1'><tr><th>ID</th><th>Include</th></tr>" >> $outputFile
|
|
172 for sample in $samples; do
|
|
173 echo "<tr><td>$sample</td><td><input type='checkbox' onchange=\"javascript:compareAdd('$sample')\" id='compare_checkbox_$sample'/></td></tr>" >> $outputFile
|
|
174 done
|
|
175 echo "</table><div name='comparisonarea'>" >> $outputFile
|
|
176 echo "<table><tr id='comparison_table_vd'></tr></table>" >> $outputFile
|
|
177 echo "<table><tr id='comparison_table_vj'></tr></table>" >> $outputFile
|
|
178 echo "<table><tr id='comparison_table_dj'></tr></table>" >> $outputFile
|
|
179 echo "</div></div>" >> $outputFile
|
|
180
|
|
181 echo "<div class='tabbertab' title='Downloads'>" >> $outputFile
|
|
182 echo "<table border='1'>" >> $outputFile
|
|
183 echo "<tr><th>Description</th><th>Link</th></tr>" >> $outputFile
|
|
184 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
|
|
185 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
|
|
186
|
|
187 echo "<tr><td>The dataset used to generate the CDR3 length frequency graph</td><td><a href='CDR3LengthPlot.csv'>Download</a></td></tr>" >> $outputFile
|
|
188
|
|
189 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
|
|
190 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
|
|
191 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
|
|
192
|
|
193 echo "<tr><td>The dataset used to generate the V gene frequency graph</td><td><a href='VFrequency.csv'>Download</a></td></tr>" >> $outputFile
|
|
194 echo "<tr><td>The dataset used to generate the D gene frequency graph</td><td><a href='DFrequency.csv'>Download</a></td></tr>" >> $outputFile
|
|
195 echo "<tr><td>The dataset used to generate the J gene frequency graph</td><td><a href='JFrequency.csv'>Download</a></td></tr>" >> $outputFile
|
|
196
|
|
197 for sample in $samples; do
|
|
198 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
|
|
199 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
|
|
200 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
|
|
201 done
|
|
202
|
|
203 echo "</table>" >> $outputFile
|
|
204 echo "</div></html>" >> $outputFile
|