| 0 | 1 #!/bin/bash | 
|  | 2 dir="$(cd "$(dirname "$0")" && pwd)" | 
|  | 3 input=$1 | 
|  | 4 output=$2 | 
|  | 5 outdir=$3 | 
| 1 | 6 title=$4 | 
| 0 | 7 mkdir $outdir | 
|  | 8 | 
|  | 9 unzip $input -d $PWD/files/ > $PWD/unziplog.log | 
|  | 10 cat $PWD/files/*/1_* > $PWD/summary.txt | 
|  | 11 cat $PWD/files/*/7_* > $PWD/mutationanalysis.txt | 
|  | 12 cat $PWD/files/*/8_* > $PWD/mutationstats.txt | 
|  | 13 cat $PWD/files/*/10_* > $PWD/hotspots.txt | 
| 3 | 14 | 
| 2 | 15 cp $dir/HS12RSS.txt $outdir/ | 
|  | 16 cp $dir/HS23RSS.txt $outdir/ | 
| 0 | 17 | 
|  | 18 mkdir $outdir/identification/ | 
|  | 19 python $dir/gene_identification.py --input $PWD/summary.txt --outdir $outdir/identification/ | 
|  | 20 genes=(ca ca1 ca2 cg cg1 cg2 cg3 cg4 cm) | 
|  | 21 tmp=$PWD/tmp | 
|  | 22 tmp2=$PWD/tmp2 | 
|  | 23 hotspottmp=$PWD/hotspottmp | 
|  | 24 mutationtmp=$PWD/mutationtmp | 
|  | 25 touch $outdir/mutationandhotspot.txt | 
|  | 26 for gene in ${genes[@]} | 
|  | 27 do | 
|  | 28 	echo "Running $gene <br />" >> $output | 
|  | 29 	mkdir $outdir/$gene | 
| 2 | 30 	cp $dir/HS12RSS.txt $outdir/$gene/ | 
|  | 31 	cp $dir/HS23RSS.txt $outdir/$gene/ | 
| 0 | 32 	echo "Filtering input..." >> $output | 
|  | 33 	Rscript $dir/filter.r $PWD/summary.txt $outdir/identification/${gene}.txt $outdir/$gene/summary.txt | 
|  | 34 	Rscript $dir/filter.r $PWD/mutationanalysis.txt $outdir/identification/${gene}.txt $outdir/$gene/mutationanalysis.txt | 
|  | 35 	Rscript $dir/filter.r $PWD/mutationstats.txt $outdir/identification/${gene}.txt $outdir/$gene/mutationstats.txt | 
|  | 36 	Rscript $dir/filter.r $PWD/hotspots.txt $outdir/identification/${gene}.txt $outdir/$gene/hotspots.txt | 
|  | 37 	echo "done <br />" >> $output | 
|  | 38 | 
|  | 39 	echo "Running R script on $gene..." >> $output | 
|  | 40 	Rscript --verbose $dir/mutation_analysis.r $outdir/$gene/mutationstats.txt $outdir/$gene/summary.txt $outdir/$gene/ 2>&1 | 
|  | 41 	echo "done <br />" >> $output | 
|  | 42 | 
|  | 43 	echo "Running Python script..." >> $output | 
|  | 44 	python $dir/mutation_analysis.py --mutationfile $outdir/$gene/mutationanalysis.txt --hotspotfile $outdir/$gene/hotspots.txt --output $outdir/$gene/hotspot_analysis.txt | 
|  | 45 	echo "done <br />" >> $output | 
|  | 46 	echo "Done with $gene <br />" >> $output | 
|  | 47 	cut $outdir/$gene/mutations.txt -d, -f2,3,4 > $mutationtmp | 
|  | 48 	cut $outdir/$gene/hotspot_analysis.txt -d, -f2,3,4 > $hotspottmp | 
|  | 49 	cat $mutationtmp $hotspottmp > $tmp | 
|  | 50 	paste $outdir/mutationandhotspot.txt -d, $tmp > $tmp2 | 
|  | 51 	cat $tmp2 > $outdir/mutationandhotspot.txt | 
| 2 | 52 	rm $outdir/$gene/HS12RSS.txt | 
|  | 53 	rm $outdir/$gene/HS23RSS.txt | 
| 0 | 54 done | 
|  | 55 | 
|  | 56 Rscript --verbose $dir/mutation_analysis.r $PWD/mutationstats.txt $PWD/summary.txt $outdir/ 2>&1 | 
|  | 57 python $dir/mutation_analysis.py --mutationfile $PWD/mutationanalysis.txt --hotspotfile $PWD/hotspots.txt --output $outdir/hotspot_analysis.txt | 
|  | 58 | 
|  | 59 cut $outdir/mutations.txt -d, -f2,3,4 > $mutationtmp | 
|  | 60 cut $outdir/hotspot_analysis.txt -d, -f2,3,4 > $hotspottmp | 
|  | 61 cat $mutationtmp $hotspottmp > $tmp | 
|  | 62 paste $outdir/mutationandhotspot.txt -d, $tmp > $tmp2 | 
|  | 63 cat $tmp2 > $outdir/mutationandhotspot.txt | 
|  | 64 | 
|  | 65 cut $outdir/ca1/mutations.txt -d, -f1 > $mutationtmp | 
|  | 66 cut $outdir/ca1/hotspot_analysis.txt -d, -f1 > $hotspottmp | 
|  | 67 cat $mutationtmp $hotspottmp > $tmp | 
|  | 68 paste $tmp $outdir/mutationandhotspot.txt -d, > $tmp2 | 
|  | 69 cat $tmp2 | tr -s "," > $outdir/mutationandhotspot.txt | 
|  | 70 | 
|  | 71 ca_n=`cat $outdir/ca/n.txt` | 
|  | 72 ca1_n=`cat $outdir/ca1/n.txt` | 
|  | 73 ca2_n=`cat $outdir/ca2/n.txt` | 
|  | 74 cg_n=`cat $outdir/cg/n.txt` | 
|  | 75 cg1_n=`cat $outdir/cg1/n.txt` | 
|  | 76 cg2_n=`cat $outdir/cg2/n.txt` | 
|  | 77 cg3_n=`cat $outdir/cg3/n.txt` | 
|  | 78 cg4_n=`cat $outdir/cg4/n.txt` | 
|  | 79 cm_n=`cat $outdir/cm/n.txt` | 
|  | 80 #all_n=$((ca_n + cg_n + cm_n)) | 
|  | 81 all_n=`cat $outdir/n.txt` | 
|  | 82 | 
|  | 83 | 
| 1 | 84 echo "<html><center><h1>$title</h1></center><table border='1'>" > $output | 
| 0 | 85 echo "<tr><th>info</th>" >> $output | 
|  | 86 echo "<th><a href='identification/ca.txt'>ca (N = $ca_n)</a></th>" >> $output | 
|  | 87 echo "<th><a href='identification/ca1.txt'>ca1 (N = $ca1_n)</a></th>" >> $output | 
|  | 88 echo "<th><a href='identification/ca2.txt'>ca2 (N = $ca2_n)</a></th>" >> $output | 
|  | 89 echo "<th><a href='identification/cg.txt'>cg (N = $cg_n)</a></th>" >> $output | 
|  | 90 echo "<th><a href='identification/cg1.txt'>cg1 (N = $cg1_n)</a></th>" >> $output | 
|  | 91 echo "<th><a href='identification/cg2.txt'>cg2 (N = $cg2_n)</a></th>" >> $output | 
|  | 92 echo "<th><a href='identification/cg3.txt'>cg3 (N = $cg3_n)</a></th>" >> $output | 
|  | 93 echo "<th><a href='identification/cg4.txt'>cg4 (N = $cg4_n)</a></th>" >> $output | 
|  | 94 echo "<th><a href='identification/cm.txt'>cm (N = $cm_n)</a></th>" >> $output | 
|  | 95 echo "<th>all (N = $all_n)</th></tr>" >> $output | 
|  | 96 while IFS=, read name cax cay caz ca1x ca1y ca1z ca2x ca2y ca2z cgx cgy cgz cg1x cg1y cg1z cg2x cg2y cg2z cg3x cg3y cg3z cg4x cg4y cg4z cmx cmy cmz allx ally allz | 
|  | 97 	do | 
|  | 98 		echo "<tr><td>$name</td><td>${cax}/${cay} (${caz}%)</td><td>${ca1x}/${ca1y} (${ca1z}%)</td><td>${ca2x}/${ca2y} (${ca2z}%)</td><td>${cgx}/${cgy} (${cgz}%)</td><td>${cg1x}/${cg1y} (${cg1z}%)</td><td>${cg2x}/${cg2y} (${cg2z}%)</td><td>${cg3x}/${cg3y} (${cg3z}%)</td><td>${cg4x}/${cg4y} (${cg4z}%)</td><td>${cmx}/${cmy} (${cmz}%)</td><td>${allx}/${ally} (${allz}%)</td></tr>" >> $output | 
|  | 99 done < $outdir/mutationandhotspot.txt | 
|  | 100 echo "</table>" >> $output | 
|  | 101 echo "<a href='identification/unmatched.txt'>umatched</a><br />" >> $output | 
|  | 102 | 
|  | 103 Rscript $dir/piechart.r "${ca_n},${cg_n},${cm_n}" "IgA - ${ca_n},IgG - ${cg_n},IgM? - ${cm_n}" "Ig* (N = $all_n)" $outdir/all.png 2>&1 | 
|  | 104 Rscript $dir/piechart.r "${ca1_n},${ca2_n}" "IgA1 - ${ca1_n},IgA2 - ${ca2_n}" "IgA (N = $ca_n)" $outdir/ca.png 2>&1 | 
|  | 105 Rscript $dir/piechart.r "${cg1_n},${cg2_n},${cg3_n},${cg4_n}" "IgG1 - ${cg1_n},IgG2 - ${cg2_n},IgG3 - ${cg3_n},IgG4 - ${cg4_n}" "IgG (N = $cg_n)" $outdir/cg.png 2>&1 | 
|  | 106 | 
| 2 | 107 $dir/seqlogo -t "HS12RSS" -w 20 -h 5 -p -a -c -n -F PNG -f $outdir/weblogo_in_rs12.txt > $outdir/HS12.png 2>&1 | 
|  | 108 $dir/seqlogo -t "HS23RSS" -w 20 -h 5 -p -a -c -n -F PNG -f $outdir/weblogo_in_rs23.txt > $outdir/HS23.png 2>&1 | 
|  | 109 | 
|  | 110 | 
| 0 | 111 echo "<img src='all.png'/>" >> $output | 
|  | 112 echo "<img src='ca.png'/>" >> $output | 
|  | 113 echo "<img src='cg.png'/>" >> $output | 
|  | 114 | 
| 2 | 115 echo "<img src='HS12.png'/>" >> $output | 
|  | 116 echo "<img src='HS23.png'/>" >> $output | 
|  | 117 | 
| 0 | 118 for gene in ${genes[@]} | 
|  | 119 do | 
|  | 120 	echo "<table border='1'><caption>$gene transition table</caption>" >> $output | 
|  | 121 	while IFS=, read from a c g t | 
|  | 122 		do | 
|  | 123 			echo "<tr><td>$from</td><td>$a</td><td>$c</td><td>$g</td><td>$t</td></tr>" >> $output | 
|  | 124 	done < $outdir/$gene/transitions.txt | 
|  | 125 	echo "</table>" >> $output | 
|  | 126 done | 
|  | 127 | 
|  | 128 echo "<table border='1'><caption>All transition table</caption>" >> $output | 
|  | 129 while IFS=, read from a c g t | 
|  | 130 	do | 
|  | 131 		echo "<tr><td>$from</td><td>$a</td><td>$c</td><td>$g</td><td>$t</td></tr>" >> $output | 
|  | 132 done < $outdir/transitions.txt | 
|  | 133 echo "</table>" >> $output | 
|  | 134 | 
|  | 135 echo "</html>" >> $output | 
| 2 | 136 | 
|  | 137 #rm $outdir/HS12RSS.txt | 
|  | 138 #rm $outdir/HS23RSS.txt |