annotate BAMqc.sh @ 17:161866cee2a2

wrapper rename
author youngkim
date Wed, 30 Mar 2016 13:28:47 -0400
parents b4ff32b63fcd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
1 #!/bin/sh
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
2
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
3 ### Galaxy Wrapper for BAMqc ###
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
4
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
5 alignment_files=""
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
6 refgene=""
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
7 attrID=""
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
8 rRNA=""
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
9 outputHTML=""
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
10 stranded=""
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
11 mapq="30"
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
12 lowBound="-250"
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
13 upperBound="250"
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
14 stepSize="5"
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
15 labels=""
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
16 cores="1"
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
17
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
18 ARGS=$(getopt -o "r:f:R:o:s:p:q:" -- "$@")
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
19
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
20 if [ $? -ne 0 ]; then
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
21 echo "Invalid command-line parameters. Do not use this script outside of Galaxy" >&2
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
22 exit 1
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
23 fi
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
24
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
25 eval set -- "$ARGS"
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
26
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
27 while [ $# -gt 0 ]; do
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
28 case "$1" in
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
29 -r)
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
30 refgene="$2"
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
31 shift 2
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
32 ;;
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
33 -f)
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
34 attrID="$2"
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
35 shift 2
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
36 ;;
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
37 -R)
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
38 rRNA="$2"
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
39 shift 2
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
40 ;;
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
41 -o)
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
42 outputHTML=$2
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
43 shift 2
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
44 ;;
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
45 -s)
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
46 stranded=$2
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
47 shift 2
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
48 ;;
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
49 -q)
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
50 mapq=$2
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
51 shift 2
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
52 ;;
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
53
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
54 -p)
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
55 cores=$2
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
56 shift 2
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
57 ;;
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
58 --)
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
59 shift
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
60 break
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
61 ;;
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
62 esac
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
63 done
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
64
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
65 if [ "$cores" -gt 10 ];then
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
66 cores="10"
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
67 fi
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
68
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
69 outputDir=`echo $outputHTML | sed 's/\.dat$/_files/'`
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
70 if [ ! -d "$outputDir" ]; then
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
71 mkdir $outputDir
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
72 fi
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
73
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
74 touch bamqc.log
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
75
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
76 while [ "$#" -ne 0 ];
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
77 do
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
78 FILE="$1"
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
79 LABEL=`echo $2 | sed 's/ /-/g; s/\[//; s/\]//;'`
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
80 shift 2
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
81 QNAME_SORTED=`samtools view -H ${FILE} | grep "SO:queryname"`
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
82 if [ $? -ne 0 ]; then
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
83 BASE=`basename ${FILE} \.dat`
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
84 echo "Sorting BAM file (${LABEL}." >>samtools.log
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
85 samtools sort -@ 5 -n ${FILE} ${BASE} 2>>samtools.log
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
86 if [ $? -ne 0 ]; then
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
87 echo "Error with samtools sorting for BAM file (${LABEL})." >&2
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
88 cat samtools.log >&2
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
89 exit 1
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
90 fi
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
91 echo "BAM file (${LABEL}) was re-sorted by query name." >>bamqc.log
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
92 FILELIST="$FILELIST ${BASE}.bam"
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
93 else
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
94 FILELIST="$FILELIST $FILE"
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
95 fi
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
96 LABELLIST="$LABELLIST $LABEL"
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
97 done
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
98
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
99 CMD="ezBAMQC -i $FILELIST -l $LABELLIST -f $attrID -r $refgene -o Galaxy_BAMqc_output --stranded $stranded -q $mapq --rRNA $rRNA -t $cores"
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
100
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
101 echo "BAMqc command: $CMD" >> bamqc.log
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
102 echo >> bamqc.log
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
103
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
104 $CMD 2>> bamqc.log
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
105
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
106 if [ $? -ne 0 ]; then
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
107 echo "BAMqc ran with errors" >&2
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
108 cat bamqc.log >&2
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
109 exit 1
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
110 fi
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
111
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
112 sed -i "s/\.\.\/Galaxy_BAMqc_output\///g;" Galaxy_BAMqc_output/bamqc_output.html
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
113
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
114 cp -r Galaxy_BAMqc_output/data "$outputDir"
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
115 cp -r Galaxy_BAMqc_output/figs "$outputDir"
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
116 cp Galaxy_BAMqc_output/bamqc_output.html "$outputHTML"
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
117
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
118 if [ $? -ne 0 ]; then
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
119 echo "Copying BAMqc results failed" >&2
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
120 fi
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
121
b4ff32b63fcd Uploaded
cshl-bsr
parents:
diff changeset
122 echo "BAMqc results copied to $outputDir" >>bamqc.log