Mercurial > repos > davidvanzessen > complete_immunerepertoire_igg
comparison complete.sh @ 1:778a9d130904 draft
Uploaded
author | davidvanzessen |
---|---|
date | Thu, 04 Sep 2014 07:46:23 -0400 |
parents | 7d97fa9a0423 |
children | 3287f7b9c47d |
comparison
equal
deleted
inserted
replaced
0:7d97fa9a0423 | 1:778a9d130904 |
---|---|
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 clonalType=${@:(-6):1} | 3 inputFiles=($1) |
4 html=${@:(-5):1} | 4 outputDir=$3 |
5 imageDir=${@:(-4):1} | 5 outputFile=$3/index.html #$1 |
6 species=${@:(-3):1} | 6 clonalType=$4 |
7 locus=${@:(-2):1} | 7 species=$5 |
8 selection=${@:(-1):1} | 8 locus=$6 |
9 dataCount=`expr $# - 6` | 9 selection=$7 |
10 inputData=${@:(1):dataCount} | 10 |
11 echo ${inputData[@]} | 11 html=$2 |
12 dir="$(cd "$(dirname "$0")" && pwd)" | 12 dir="$(cd "$(dirname "$0")" && pwd)" |
13 array=("$@") | 13 array=("$@") |
14 echo "<html><h3>Progress</h3><table><tr><td>info</td></tr>" > $html | 14 echo "<html><h3>Progress</h3><table><tr><td>info</td></tr>" > $html |
15 echo "<tr><td>-----------------------------------</td></tr>" >> $html | 15 echo "<tr><td>-----------------------------------</td></tr>" >> $html |
16 | 16 |
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" | 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 | 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 | 25 echo "<tr><td>Finished blast of sample $3 of patient $2</td></tr>" >> $html |
26 | 26 |
27 echo "<tr><td>Starting parse of sample $3 of patient $2</td></tr>" >> $html | 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 | 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 | 29 echo "<tr><td>Finished parse of sample $3 of patient $2</td></tr>" >> $html |
30 } | 30 } |
31 | 31 |
32 function imgtConvert { | 32 function imgtConvert { |
33 echo "<tr><td>Starting imgt convert of sample $3 of patient $2</td></tr>" >> $html | 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 | 34 bash $dir/imgtconvert.sh $1 $2 $3 $4 |
35 echo "<tr><td>Finished conversion of sample $3 of patient $2</td></tr>" >> $html | 35 echo "<tr><td>Finished conversion of sample $3 of patient $2</td></tr>" >> $html |
36 | 36 |
37 } | 37 } |
38 | 38 |
39 id=${inputData[0]} | 39 id="" |
40 forwardSlash="/" | 40 forwardSlash="/" |
41 mergerInput=() | 41 mergerInput=() |
42 count=0 | 42 echo "Before loop" |
43 for current in $inputData; do | 43 count=1 |
44 if [[ "$current" != *"$forwardSlash"* ]]; then | 44 for current in "${inputFiles[@]}" |
45 id=$current | 45 do |
46 count=0 | 46 if [[ "$current" != *"$forwardSlash"* ]]; then |
47 mergerInput+=($id) | 47 id="$current" |
48 continue | 48 mergerInput+=($id) |
49 fi | 49 count=1 |
50 continue | |
51 fi | |
52 echo "working on $current" | |
50 fileName=$(basename $current) | 53 fileName=$(basename $current) |
51 parsedFileName="${fileName%.*}" | 54 parsedFileName="${fileName%.*}" |
52 parsedFileName="$PWD/$parsedFileName.parsed" | 55 parsedFileName="$PWD/$parsedFileName.parsed" |
53 f=$(file $current) | 56 f=$(file $current) |
54 zipType="Zip archive" | 57 zipType="Zip archive" |
64 mergerInput+=($parsedFileName) | 67 mergerInput+=($parsedFileName) |
65 count=$((count+1)) | 68 count=$((count+1)) |
66 done | 69 done |
67 wait | 70 wait |
68 | 71 |
69 | 72 echo "after loop" |
70 | 73 |
71 echo "<tr><td>-----------------------------------</td></tr>" >> $html | 74 echo "<tr><td>-----------------------------------</td></tr>" >> $html |
72 echo "<tr><td>merging</td></tr>" >> $html | 75 echo "<tr><td>merging</td></tr>" >> $html |
73 | 76 |
74 python $dir/igblastmerge.py ${mergerInput[*]} --output $PWD/merged.txt | 77 python $dir/experimental_design.py ${mergerInput[*]} --output $PWD/merged.txt |
75 | 78 |
76 echo "<tr><td>done</td></tr>" >> $html | 79 echo "<tr><td>done</td></tr>" >> $html |
77 echo "<tr><td>-----------------------------------</td></tr>" >> $html | 80 echo "<tr><td>-----------------------------------</td></tr>" >> $html |
78 echo "<tr><td>plotting</td></tr>" >> $html | 81 echo "<tr><td>plotting</td></tr>" >> $html |
79 | 82 |
80 | 83 if [ "$locus" == "igh" ] || [ "$locus" == "igk" ] || [ "$locus" == "igl" ]; then |
81 inputFile=$PWD/merged.txt | 84 bash $dir/r_wrapper_b.sh $PWD/merged.txt $2 $outputDir $clonalType $species $locus $selection |
82 outputDir=$imageDir | 85 else |
83 outputFile=$outputDir/index.html | 86 bash $dir/r_wrapper_t.sh $PWD/merged.txt $2 $outputDir $clonalType $species $locus $selection |
84 mkdir $outputDir | 87 fi |
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 | 88 |
125 | 89 |
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 | 90 |
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 | 91 |
160 hasJunctionData="$(if head -n 1 $inputFile | grep -q '3V-REGION trimmed-nt nb'; then echo 'Yes'; else echo 'No'; fi)" | |
161 | 92 |
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 | 93 |
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 | 94 |
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 | 95 |
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 | 96 |
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 |