annotate wrapper.sh @ 1:cbce7f35f8b0 draft

Uploaded
author davidvanzessen
date Wed, 21 Dec 2016 10:07:42 -0500
parents cb08a27e5fc2
children 44ec2a1009fc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
1 #!/bin/bash
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
2 input="$1"
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
3 output="$2"
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
4 outDir="$3"
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
5 mkdir "$outDir"
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
6 EOL="$4"
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
7 mismatches="$5"
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
8 partial="$6"
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
9 name=$(basename "$7")
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
10 ext="${name##*.}"
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
11 name="${name%.*}"
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
12 name="${name// /_}"
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
13 prefix="${name}_"
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
14 dir="$(cd "$(dirname "$0")" && pwd)"
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
15
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
16 unzip $dir/fastqc_v0.11.2.zip -d $PWD/ > $PWD/unziplog.log
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
17 chmod 755 $PWD/FastQC/fastqc
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
18
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
19 declare -A trim_start
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
20 declare -A trim_end
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
21 for ((i=8;i<=$#;i=i+4))
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
22 do
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
23 j=$((i+1))
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
24 start_int=$((i+2))
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
25 end_int=$((i+3))
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
26 id="${!i}"
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
27 echo "$id, ${start_int}, ${end_int}"
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
28 trim_start[$id]=${!start_int}
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
29 trim_end[$id]=${!end_int}
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
30 echo -e "$id\t${!j}" >> $outDir/barcodes.txt
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
31
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
32 done
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
33 trim_start["unmatched"]=0
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
34 trim_end["unmatched"]=0
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
35
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
36 echo "trim_start = ${trim_start[@]}"
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
37 echo "trim_end = ${trim_end[@]}"
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
38
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
39 workdir=$PWD
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
40 cd $outDir
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
41 echo "$3"
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
42 filetype=`file $input`
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
43 result=""
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
44 if [[ $filetype == *ASCII* ]]
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
45 then
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
46 result=`cat $input | $dir/fastx_barcode_splitter.pl --bcfile $outDir/barcodes.txt --prefix "$prefix" --suffix ".fastq" --$EOL --mismatches $mismatches --partial $partial`
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
47 else
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
48 result=`$dir/sff2fastq $input | $dir/fastx_barcode_splitter.pl --bcfile $outDir/barcodes.txt --prefix "$prefix" --suffix ".fastq" --$EOL --mismatches $mismatches --partial $partial`
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
49 fi
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
50
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
51 echo "$result" | tail -n +2 | sed 's/\t/,/g' > output.txt
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
52 echo "<html><head><title>$name demultiplex</title></head><body><table border='1'><thead><tr><th>ID</th><th>Count</th><th>FASTQ</th><th>FASTA</th><th>Trimmed FASTA</th><th>FASTQC</th></tr></thead><tbody>" >> $output
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
53 while IFS=, read barcode count location
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
54 do
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
55 if [ "total" == "$barcode" ]
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
56 then
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
57 echo "<tr><td>$barcode</td><td>$count</td><td></td><td></td><td></td><td></td><td></td><td></td></tr>" >> $output
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
58 break
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
59 fi
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
60 file="${name}_${barcode}"
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
61 mkdir "$outDir/fastqc_$barcode"
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
62 $workdir/FastQC/fastqc "$file.fastq" -o "$outDir" 2> /dev/null
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
63 cat "$file.fastq" | awk 'NR%4==1{printf ">%s\n", substr($0,2)}NR%4==2{print}' > "$file.fasta"
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
64 python $dir/trim.py --input "$file.fasta" --output "${file}_trimmed.fasta" --start "${trim_start[$barcode]}" --end "${trim_end[$barcode]}"
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
65 echo "<tr><td>$barcode</td><td>$count</td><td><a href='$file.fastq'>$file.fastq</a></td><td><a href='$file.fasta'>$file.fasta</a></td><td><a href='${file}_trimmed.fasta'>${file}_trimmed.fasta</a></td><td><a href='${name}_${barcode}_fastqc.html'>Report</a></td></tr>" >> $output
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
66 done < output.txt
cb08a27e5fc2 Uploaded
davidvanzessen
parents:
diff changeset
67 echo "</tbody></body></html>" >> $output