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