Mercurial > repos > pjbriggs > ceas
comparison ceas_wrapper.sh @ 4:4e2883bb058d draft
Synchronise version with one on main toolshed (version of 30/06/2015)
author | pjbriggs |
---|---|
date | Wed, 10 Aug 2016 11:04:42 -0400 |
parents | 82df5af2995f |
children |
comparison
equal
deleted
inserted
replaced
3:82df5af2995f | 4:4e2883bb058d |
---|---|
4 # | 4 # |
5 # This runs the Cistrome versions of CEAS, which provides two executables: | 5 # This runs the Cistrome versions of CEAS, which provides two executables: |
6 # - ceas (same as the "official" version) | 6 # - ceas (same as the "official" version) |
7 # - ceasBW (modified version that accepts a bigwig file as input) | 7 # - ceasBW (modified version that accepts a bigwig file as input) |
8 # | 8 # |
9 # Usage: ceas_wrapper.sh $BED_IN $GDB_IN $EXTRA_BED_IN $LOG_OUT $PDF_OUT $XLS_OUT $DBKEY | 9 # Usage: ceas_wrapper.sh $BED_IN $GDB_IN $LOG_OUT $PDF_OUT $XLS_OUT [OPTIONS] |
10 # | |
11 # Initialise | |
12 CEAS=ceas | |
10 # | 13 # |
11 # Process command line | 14 # Process command line |
12 echo $* | 15 echo $* |
13 BED_IN=$1 | 16 BED_IN=$1 |
14 GDB_IN=$2 | 17 GDB_IN=$2 |
15 EXTRA_BED_IN=$3 | 18 LOG_OUT=$3 |
16 LOG_OUT=$4 | 19 PDF_OUT=$4 |
17 PDF_OUT=$5 | 20 XLS_OUT=$5 |
18 XLS_OUT=$6 | 21 # |
22 # Initialise other variables | |
23 EXTRA_BED_IN= | |
19 # | 24 # |
20 # Collect remaining args | 25 # Collect remaining args |
21 CEAS=ceas | |
22 OPTIONS= | 26 OPTIONS= |
23 while [ ! -z "$7" ] ; do | 27 while [ ! -z "$6" ] ; do |
24 if [ "$7" == "--bigwig" ] ; then | 28 if [ "$6" == "--bigwig" ] ; then |
29 # Bigwig input, need to use 'ceasBW' | |
25 CEAS=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" | |
26 fi | 64 fi |
27 if [ "$7" == "--length" ] ; then | |
28 chrom_sizes=$8 | |
29 if [ ! -f "$chrom_sizes" ] ; then | |
30 echo "ERROR no file $chrom_sizes" >&2 | |
31 echo "Please update your Galaxy instance to include this file" | |
32 exit 1 | |
33 fi | |
34 fi | |
35 OPTIONS="$OPTIONS $7" | |
36 shift | 65 shift |
37 done | 66 done |
38 # | 67 # |
39 # Convenience variables for local files | 68 # Convenience variables for local files |
40 base_name="ceas" | 69 base_name="ceas" |
41 log_file=${base_name}.log | 70 log_file=${base_name}.log |
42 r_script=${base_name}.R | |
43 pdf_report=${base_name}.pdf | 71 pdf_report=${base_name}.pdf |
44 xls_file=${base_name}.xls | 72 xls_file=${base_name}.xls |
45 # | 73 # |
46 # Get CEAS version | 74 # Get CEAS version |
47 echo Running $CEAS | 75 echo Running $CEAS |
48 $CEAS --version >$log_file 2>/dev/null | 76 $CEAS --version >$log_file 2>/dev/null |
49 # | 77 # |
50 # Construct and run CEAS command line | 78 # Construct and run CEAS command line |
51 ceas_cmd="$CEAS --name $base_name $OPTIONS -g $GDB_IN -b $BED_IN" | 79 ceas_cmd="$CEAS --name $base_name $OPTIONS -g $GDB_IN -b $BED_IN" |
52 if [ "$EXTRA_BED_IN" != "None" ] ; then | |
53 ceas_cmd="$ceas_cmd -e $EXTRA_BED_IN" | |
54 fi | |
55 echo "Running $ceas_cmd" | 80 echo "Running $ceas_cmd" |
56 $ceas_cmd >>$log_file 2>&1 | 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 | |
57 # | 89 # |
58 # Move outputs to final destination | 90 # Move outputs to final destination |
59 if [ -e $log_file ] ; then | 91 if [ -e $log_file ] ; then |
60 echo "Moving $log_file to $LOG_OUT" | 92 echo "Moving $log_file to $LOG_OUT" |
61 /bin/mv $log_file $LOG_OUT | 93 /bin/mv $log_file $LOG_OUT |
68 /bin/mv $xls_file $XLS_OUT | 100 /bin/mv $xls_file $XLS_OUT |
69 else | 101 else |
70 echo ERROR failed to generate XLS file >&2 | 102 echo ERROR failed to generate XLS file >&2 |
71 exit 1 | 103 exit 1 |
72 fi | 104 fi |
73 # | 105 if [ -e $pdf_report ] ; then |
74 # Run the R script to generate the PDF report | 106 echo "Moving $pdf_report to $PDF_OUT" |
75 if [ -e $r_script ] ; then | 107 /bin/mv $pdf_report $PDF_OUT |
76 echo "Running $r_script to generate $pdf_report" | |
77 R --vanilla < $r_script | |
78 if [ -e $pdf_report ] ; then | |
79 echo "Moving $xls_file to $XLS_OUT" | |
80 /bin/mv $pdf_report $PDF_OUT | |
81 else | |
82 echo ERROR failed to generate PDF report >&2 | |
83 exit 1 | |
84 fi | |
85 else | 108 else |
86 echo ERROR no R script to generate PDF report >&2 | 109 echo ERROR failed to generate PDF report >&2 |
87 exit 1 | 110 exit 1 |
88 fi | 111 fi |
89 # | 112 # |
90 # Done | 113 # Done |