comparison wrapper.sh @ 0:cb08a27e5fc2 draft

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