0
|
1 #!/bin/sh
|
|
2 #
|
|
3 # Wrapper script to run RnaChipIntegrator as a Galaxy tool
|
|
4 #
|
|
5 # usage: sh rnachipintegrator_wrapper.sh [OPTIONS] <rnaseq_in> <chipseq_in> --output_xls <xls_out>
|
|
6 #
|
1
|
7 echo RnaChipIntegrator: analyse gene and peak data
|
0
|
8 #
|
|
9 # Collect command line options
|
|
10 opts=
|
1
|
11 xlsx_file=
|
0
|
12 zip_file=
|
1
|
13 gene_centric=
|
|
14 peak_centric=
|
|
15 gene_centric_summary=
|
|
16 peak_centric_summary=
|
0
|
17 while [ ! -z "$1" ] ; do
|
|
18 case $1 in
|
1
|
19 --xlsx_file)
|
|
20 shift; xlsx_file=$1
|
|
21 opts="$opts --xlsx"
|
0
|
22 ;;
|
1
|
23 --output_files)
|
|
24 shift; gene_centric=$1
|
|
25 shift; peak_centric=$1
|
0
|
26 ;;
|
1
|
27 --summary_files)
|
|
28 shift; gene_centric_summary=$1
|
|
29 shift; peak_centric_summary=$1
|
|
30 opts="$opts --summary"
|
0
|
31 ;;
|
|
32 --zip_file)
|
|
33 shift; zip_file=$1
|
|
34 ;;
|
|
35 *)
|
|
36 opts="$opts $1"
|
|
37 ;;
|
|
38 esac
|
|
39 shift
|
|
40 done
|
|
41 #
|
|
42 # Run RnaChipIntegrator
|
|
43 # NB append stderr to stdout otherwise Galaxy job will fail
|
|
44 # Direct output to a temporary directory
|
1
|
45 outdir=$(mktemp -d)
|
0
|
46 base_name=galaxy
|
1
|
47 cmd="RnaChipIntegrator --name=${outdir}/${base_name} $opts"
|
0
|
48 echo $cmd
|
|
49 $cmd 2>&1
|
|
50 #
|
|
51 # Check exit code
|
|
52 exit_status=$?
|
|
53 if [ "$exit_status" -ne "0" ] ; then
|
|
54 echo RnaChipIntegrator exited with non-zero status >&2
|
|
55 # Clean up and exit
|
|
56 /bin/rm -rf $outdir
|
|
57 exit $exit_status
|
|
58 fi
|
|
59 #
|
1
|
60 # Deal with output XLSX file
|
|
61 if [ -f "${outdir}/${base_name}.xlsx" ] ; then
|
|
62 /bin/mv ${outdir}/${base_name}.xlsx $xlsx_file
|
0
|
63 else
|
1
|
64 echo No file ${outdir}/${base_name}.xlsx >&2
|
0
|
65 # Clean up and exit
|
|
66 /bin/rm -rf $outdir
|
|
67 exit 1
|
|
68 fi
|
|
69 #
|
1
|
70 # Generate zip file
|
0
|
71 if [ ! -z "$zip_file" ] ; then
|
1
|
72 for ext in \
|
|
73 gene_centric \
|
|
74 gene_centric_summary \
|
|
75 peak_centric \
|
|
76 peak_centric_summary ; do
|
0
|
77 txt_file=${outdir}/${base_name}_${ext}.txt
|
|
78 if [ -f "$txt_file" ] ; then
|
|
79 zip -j -g ${outdir}/archive.zip $txt_file
|
|
80 fi
|
|
81 done
|
|
82 /bin/mv ${outdir}/archive.zip $zip_file
|
|
83 fi
|
|
84 #
|
1
|
85 # Collect tab delimited files
|
|
86 for ext in \
|
|
87 gene_centric \
|
|
88 gene_centric_summary \
|
|
89 peak_centric \
|
|
90 peak_centric_summary ; do
|
|
91 eval dest=\$$ext
|
|
92 if [ ! -z "$dest" ] ; then
|
|
93 outfile=${outdir}/${base_name}_${ext}.txt
|
|
94 if [ -f "$outfile" ] ; then
|
|
95 /bin/mv $outfile $dest
|
|
96 else
|
|
97 echo ERROR missing output file $outfile >&2
|
|
98 fi
|
0
|
99 fi
|
1
|
100 done
|
0
|
101 #
|
|
102 # Clean up
|
|
103 /bin/rm -rf $outdir
|
|
104 #
|
|
105 # Done
|