0
|
1 #!/bin/bash
|
4
|
2 set -e
|
0
|
3 dir="$(cd "$(dirname "$0")" && pwd)"
|
|
4 input=$1
|
19
|
5 method=$2
|
|
6 output=$3
|
|
7 outdir=$4
|
|
8 title=$5
|
22
|
9 include_fr1=$6
|
0
|
10 mkdir $outdir
|
|
11
|
|
12 unzip $input -d $PWD/files/ > $PWD/unziplog.log
|
|
13 cat $PWD/files/*/1_* > $PWD/summary.txt
|
|
14 cat $PWD/files/*/7_* > $PWD/mutationanalysis.txt
|
|
15 cat $PWD/files/*/8_* > $PWD/mutationstats.txt
|
|
16 cat $PWD/files/*/10_* > $PWD/hotspots.txt
|
3
|
17
|
22
|
18 BLASTN_DIR="/home/galaxy/tmp/blast/ncbi-blast-2.2.30+/bin"
|
19
|
19
|
|
20 echo "${BLASTN_DIR}"
|
|
21
|
|
22
|
15
|
23
|
4
|
24
|
19
|
25 echo "identification ($method)"
|
|
26
|
|
27 if [[ "${method}" == "custom" ]] ; then
|
|
28 python $dir/gene_identification.py --input $PWD/summary.txt --output $outdir/identified_genes.txt
|
|
29 else
|
|
30 ID_index=$(cat $PWD/summary.txt | grep -o -P ".+Sequence ID" | grep -o -P "\t" | wc -l)
|
|
31 ID_index=$((ID_index+1))
|
|
32 sequence_index=$(cat $PWD/summary.txt | grep -o -P ".+\tSequence" | grep -o -P "\t" | wc -l)
|
|
33 sequence_index=$((sequence_index+1))
|
|
34
|
|
35 echo "$ID_index ${sequence_index}"
|
|
36
|
|
37 cat $PWD/summary.txt | tail -n+2 | cut -f ${ID_index},${sequence_index} | awk '{print ">" $1 "\n" $2}' > $PWD/sequences.fasta
|
|
38
|
|
39 echo -e "qseqid\tsseqid\tpident\tlength\tmismatch\tgapopen\tqstart\tqend\tsstart\tsend\tevalue\tbitscore" > $outdir/identified_genes.txt
|
|
40 ${BLASTN_DIR}/blastn -task blastn -db $dir/subclass_definition.db -query $PWD/sequences.fasta -outfmt 6 >> $outdir/identified_genes.txt
|
|
41 fi
|
|
42
|
|
43
|
|
44
|
4
|
45 echo "merging"
|
19
|
46 Rscript $dir/merge_and_filter.r $PWD/summary.txt $PWD/mutationanalysis.txt $PWD/mutationstats.txt $PWD/hotspots.txt $outdir/identified_genes.txt $outdir/merged.txt $outdir/unmatched.txt $method
|
0
|
47
|
4
|
48 genes="ca,ca1,ca2,cg,cg1,cg2,cg3,cg4,cm"
|
|
49 echo "R mutation analysis"
|
22
|
50 Rscript $dir/mutation_analysis.r $outdir/merged.txt $genes $outdir ${include_fr1} 2>&1
|
4
|
51 echo "python mutation analysis"
|
|
52 python $dir/mutation_analysis.py --input $outdir/merged.txt --genes $genes --output $outdir/hotspot_analysis.txt
|
|
53
|
|
54 cat $outdir/mutations.txt $outdir/hotspot_analysis.txt > $outdir/result.txt
|
|
55
|
0
|
56 genes=(ca ca1 ca2 cg cg1 cg2 cg3 cg4 cm)
|
|
57
|
|
58
|
1
|
59 echo "<html><center><h1>$title</h1></center><table border='1'>" > $output
|
0
|
60 echo "<tr><th>info</th>" >> $output
|
4
|
61 for gene in ${genes[@]}
|
|
62 do
|
|
63 tmp=`cat $outdir/${gene}_n.txt`
|
|
64 echo "<th><a href='matched_${gene}.txt'>${gene} (N = $tmp)</a></th>" >> $output
|
|
65 done
|
|
66 tmp=`cat $outdir/total_n.txt`
|
|
67 echo "<th><a href='matched_all.txt'>all (N = $tmp)</a></th>" >> $output
|
|
68
|
0
|
69 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
|
|
70 do
|
|
71 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
|
4
|
72 done < $outdir/result.txt
|
0
|
73 echo "</table>" >> $output
|
21
|
74 echo "<a href='unmatched.txt'>unmatched</a><br /><a href='motif_per_seq.txt'>motif per sequence</a><br />" >> $output
|
2
|
75
|
|
76
|
4
|
77 echo "<img src='all.png'/><br />" >> $output
|
|
78 if [ -a $outdir/ca.png ]
|
|
79 then
|
|
80 echo "<img src='ca.png'/><br />" >> $output
|
|
81 fi
|
|
82 if [ -a $outdir/cg.png ]
|
|
83 then
|
|
84 echo "<img src='cg.png'/><br />" >> $output
|
|
85 fi
|
22
|
86 if [ -a $outdir/scatter.png ]
|
|
87 then
|
|
88 echo "<img src='scatter.png'/><br />" >> $output
|
|
89 fi
|
2
|
90
|
0
|
91 for gene in ${genes[@]}
|
|
92 do
|
|
93 echo "<table border='1'><caption>$gene transition table</caption>" >> $output
|
|
94 while IFS=, read from a c g t
|
|
95 do
|
|
96 echo "<tr><td>$from</td><td>$a</td><td>$c</td><td>$g</td><td>$t</td></tr>" >> $output
|
4
|
97 done < $outdir/transitions_${gene}.txt
|
0
|
98 echo "</table>" >> $output
|
|
99 done
|
|
100
|
|
101 echo "<table border='1'><caption>All transition table</caption>" >> $output
|
|
102 while IFS=, read from a c g t
|
|
103 do
|
|
104 echo "<tr><td>$from</td><td>$a</td><td>$c</td><td>$g</td><td>$t</td></tr>" >> $output
|
|
105 done < $outdir/transitions.txt
|
|
106 echo "</table>" >> $output
|
|
107
|
|
108 echo "</html>" >> $output
|
2
|
109
|
|
110 #rm $outdir/HS12RSS.txt
|
|
111 #rm $outdir/HS23RSS.txt
|