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