annotate ceas_wrapper.sh @ 0:f411ce97a351 draft

Uploaded initial version 1.0.2-2
author pjbriggs
date Tue, 30 Jun 2015 07:08:05 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
1 #!/bin/sh -e
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
2 #
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
3 # Wrapper script to run CEAS as a Galaxy tool
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
4 #
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
5 # This runs the Cistrome versions of CEAS, which provides two executables:
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
6 # - ceas (same as the "official" version)
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
7 # - ceasBW (modified version that accepts a bigwig file as input)
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
8 #
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
9 # Usage: ceas_wrapper.sh $BED_IN $GDB_IN $LOG_OUT $PDF_OUT $XLS_OUT [OPTIONS]
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
10 #
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
11 # Initialise
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
12 CEAS=ceas
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
13 #
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
14 # Process command line
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
15 echo $*
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
16 BED_IN=$1
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
17 GDB_IN=$2
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
18 LOG_OUT=$3
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
19 PDF_OUT=$4
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
20 XLS_OUT=$5
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
21 #
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
22 # Initialise other variables
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
23 EXTRA_BED_IN=
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
24 #
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
25 # Collect remaining args
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
26 OPTIONS=
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
27 while [ ! -z "$6" ] ; do
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
28 if [ "$6" == "--bigwig" ] ; then
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
29 # Bigwig input, need to use 'ceasBW'
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
30 CEAS=ceasBW
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
31 OPTIONS="$OPTIONS --bigwig"
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
32 elif [ "$6" == "--length" ] ; then
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
33 # Need a chrom sizes file
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
34 chrom_sizes=$7
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
35 if [ ! -f "$chrom_sizes" ] ; then
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
36 # If chrom sizes file doesn't already exist then attempt to
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
37 # download the data from UCSC
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
38 echo "WARNING no file $chrom_sizes"
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
39 dbkey=$(echo $(basename $chrom_sizes) | cut -d'.' -f1)
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
40 if [ $dbkey == '?' ] ; then
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
41 # DBkey not set, this is fatal
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
42 echo "ERROR genome build not set, cannot get sizes for '?'" >&2
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
43 echo "Assign a genome build to your input dataset and rerun" >&2
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
44 exit 1
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
45 fi
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
46 # Fetch the sizes using fetchChromSizes
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
47 echo -n "Attempting to download chromosome sizes for $dbkey..."
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
48 chrom_sizes=$(basename $chrom_sizes)
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
49 fetchChromSizes $dbkey >$chrom_sizes 2>/dev/null
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
50 if [ $? -ne 0 ] ; then
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
51 echo "failed"
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
52 echo "ERROR unable to fetch data for ${dbkey}" >&2
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
53 echo "Please check the genome build associated with your input dataset" >&2
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
54 echo "or update your Galaxy instance to include an appropriate .len file" >&2
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
55 exit 1
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
56 else
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
57 echo "ok"
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
58 fi
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
59 fi
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
60 OPTIONS="$OPTIONS --length $chrom_sizes"
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
61 shift
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
62 else
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
63 OPTIONS="$OPTIONS $6"
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
64 fi
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
65 shift
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
66 done
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
67 #
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
68 # Convenience variables for local files
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
69 base_name="ceas"
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
70 log_file=${base_name}.log
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
71 pdf_report=${base_name}.pdf
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
72 xls_file=${base_name}.xls
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
73 #
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
74 # Get CEAS version
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
75 echo Running $CEAS
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
76 $CEAS --version >$log_file 2>/dev/null
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
77 #
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
78 # Construct and run CEAS command line
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
79 ceas_cmd="$CEAS --name $base_name $OPTIONS -g $GDB_IN -b $BED_IN"
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
80 echo "Running $ceas_cmd"
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
81 $ceas_cmd >>$log_file 2>&1
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
82 status=$?
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
83 if [ $status -ne 0 ] ; then
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
84 echo "Error: log file tail:"
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
85 tail $log_file
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
86 echo "ERROR $CEAS exited with non-zero code: $status" >&2
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
87 exit $status
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
88 fi
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
89 #
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
90 # Move outputs to final destination
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
91 if [ -e $log_file ] ; then
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
92 echo "Moving $log_file to $LOG_OUT"
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
93 /bin/mv $log_file $LOG_OUT
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
94 else
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
95 echo ERROR failed to make log file >&2
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
96 exit 1
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
97 fi
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
98 if [ -e $xls_file ] ; then
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
99 echo "Moving $xls_file to $XLS_OUT"
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
100 /bin/mv $xls_file $XLS_OUT
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
101 else
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
102 echo ERROR failed to generate XLS file >&2
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
103 exit 1
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
104 fi
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
105 if [ -e $pdf_report ] ; then
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
106 echo "Moving $pdf_report to $PDF_OUT"
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
107 /bin/mv $pdf_report $PDF_OUT
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
108 else
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
109 echo ERROR failed to generate PDF report >&2
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
110 exit 1
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
111 fi
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
112 #
f411ce97a351 Uploaded initial version 1.0.2-2
pjbriggs
parents:
diff changeset
113 # Done