annotate fastx_barcode_splitter_galaxy_wrapper.sh @ 7:06ebd94d80ae draft default tip

planemo upload for repository https://github.com/lparsons/galaxy_tools/tree/master/tools/fastx_barcode_splitter_enhanced commit c3b0be52079831f6ae58ff64e42d8ff54ce501e4
author lparsons
date Fri, 13 Nov 2015 12:42:49 -0500
parents 51e098891465
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
1 #!/bin/bash
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
2
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
3 # FASTX-toolkit - FASTA/FASTQ preprocessing tools.
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
4 # Copyright (C) 2009 A. Gordon (gordon@cshl.edu)
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
5 #
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
8 # published by the Free Software Foundation, either version 3 of the
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
9 # License, or (at your option) any later version.
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
10 #
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
14 # GNU Affero General Public License for more details.
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
15 #
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
18
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
19 # Modified by Lance Parsons (lparsons@princeton.edu)
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
20 # 2011-03-15 Adapted to allow galaxy to determine filetype
5
80e84db1c392 planemo upload for repository https://github.com/lparsons/galaxy_tools/tree/master/tools/fastx_barcode_splitter_enhanced commit 9ece31c748369db47d9817066cb91e6f3e8428c8-dirty
lparsons
parents: 4
diff changeset
21 # 2015-10-21 Updated to make compatible with OSX (BSD sed)
7
06ebd94d80ae planemo upload for repository https://github.com/lparsons/galaxy_tools/tree/master/tools/fastx_barcode_splitter_enhanced commit c3b0be52079831f6ae58ff64e42d8ff54ce501e4
lparsons
parents: 6
diff changeset
22 # 2015-11-13 Removed LIBRARY_NAME, no longer needed
06ebd94d80ae planemo upload for repository https://github.com/lparsons/galaxy_tools/tree/master/tools/fastx_barcode_splitter_enhanced commit c3b0be52079831f6ae58ff64e42d8ff54ce501e4
lparsons
parents: 6
diff changeset
23
4
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
24 #This is a shell script wrapper for 'fastx_barcode_splitter.pl'
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
25 #
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
26 # 1. Output files are saved at the dataset's files_path directory.
5
80e84db1c392 planemo upload for repository https://github.com/lparsons/galaxy_tools/tree/master/tools/fastx_barcode_splitter_enhanced commit 9ece31c748369db47d9817066cb91e6f3e8428c8-dirty
lparsons
parents: 4
diff changeset
27 #
4
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
28 # 2. 'fastx_barcode_splitter.pl' outputs a textual table.
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
29 # This script turns it into pretty HTML with working URL
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
30 # (so lazy users can just click on the URLs and get their files)
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
31
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
32 if [ "$1x" = "x" ]; then
7
06ebd94d80ae planemo upload for repository https://github.com/lparsons/galaxy_tools/tree/master/tools/fastx_barcode_splitter_enhanced commit c3b0be52079831f6ae58ff64e42d8ff54ce501e4
lparsons
parents: 6
diff changeset
33 echo "Usage: $0 [BARCODE FILE] [FASTQ FILE] [OUTPUT_PATH] [FILETYPE]" >&2
4
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
34 exit 1
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
35 fi
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
36
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
37 BARCODE_FILE="$1"
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
38 FASTQ_FILE="$2"
7
06ebd94d80ae planemo upload for repository https://github.com/lparsons/galaxy_tools/tree/master/tools/fastx_barcode_splitter_enhanced commit c3b0be52079831f6ae58ff64e42d8ff54ce501e4
lparsons
parents: 6
diff changeset
39 OUTPUT_PATH="$3"
06ebd94d80ae planemo upload for repository https://github.com/lparsons/galaxy_tools/tree/master/tools/fastx_barcode_splitter_enhanced commit c3b0be52079831f6ae58ff64e42d8ff54ce501e4
lparsons
parents: 6
diff changeset
40 FILETYPE="$4"
06ebd94d80ae planemo upload for repository https://github.com/lparsons/galaxy_tools/tree/master/tools/fastx_barcode_splitter_enhanced commit c3b0be52079831f6ae58ff64e42d8ff54ce501e4
lparsons
parents: 6
diff changeset
41 shift 4
4
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
42 # The rest of the parameters are passed to the split program
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
43
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
44 if [ "${OUTPUT_PATH}x" = "x" ]; then
7
06ebd94d80ae planemo upload for repository https://github.com/lparsons/galaxy_tools/tree/master/tools/fastx_barcode_splitter_enhanced commit c3b0be52079831f6ae58ff64e42d8ff54ce501e4
lparsons
parents: 6
diff changeset
45 echo "Usage: $0 [BARCODE FILE] [FASTQ FILE] [OUTPUT_PATH] [FILETYPE]" >&2
4
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
46 exit 1
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
47 fi
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
48
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
49 if [ ! -r "$FASTQ_FILE" ]; then
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
50 echo "Error: Input file ($FASTQ_FILE) not found!" >&2
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
51 exit 1
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
52 fi
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
53 if [ ! -r "$BARCODE_FILE" ]; then
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
54 echo "Error: barcode file ($BARCODE_FILE) not found!" >&2
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
55 exit 1
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
56 fi
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
57 mkdir -p "$OUTPUT_PATH"
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
58 if [ ! -d "$OUTPUT_PATH" ]; then
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
59 echo "Error: failed to create output path '$OUTPUT_PATH'" >&2
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
60 exit 1
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
61 fi
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
62
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
63 BASEPATH="$OUTPUT_PATH/"
7
06ebd94d80ae planemo upload for repository https://github.com/lparsons/galaxy_tools/tree/master/tools/fastx_barcode_splitter_enhanced commit c3b0be52079831f6ae58ff64e42d8ff54ce501e4
lparsons
parents: 6
diff changeset
64 PREFIX="$BASEPATH"
06ebd94d80ae planemo upload for repository https://github.com/lparsons/galaxy_tools/tree/master/tools/fastx_barcode_splitter_enhanced commit c3b0be52079831f6ae58ff64e42d8ff54ce501e4
lparsons
parents: 6
diff changeset
65 SUFFIX=".$FILETYPE"
06ebd94d80ae planemo upload for repository https://github.com/lparsons/galaxy_tools/tree/master/tools/fastx_barcode_splitter_enhanced commit c3b0be52079831f6ae58ff64e42d8ff54ce501e4
lparsons
parents: 6
diff changeset
66 DIRECTORY="$(cd "$(dirname "$0")" && pwd)"
4
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
67
7
06ebd94d80ae planemo upload for repository https://github.com/lparsons/galaxy_tools/tree/master/tools/fastx_barcode_splitter_enhanced commit c3b0be52079831f6ae58ff64e42d8ff54ce501e4
lparsons
parents: 6
diff changeset
68 RESULTS=$(gzip -cdf "$FASTQ_FILE" | "$DIRECTORY/fastx_barcode_splitter.pl" --bcfile "$BARCODE_FILE" --prefix "$PREFIX" --suffix "$SUFFIX" "$@")
4
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
69 if [ $? != 0 ]; then
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
70 echo "error"
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
71 fi
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
72
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
73 #
7
06ebd94d80ae planemo upload for repository https://github.com/lparsons/galaxy_tools/tree/master/tools/fastx_barcode_splitter_enhanced commit c3b0be52079831f6ae58ff64e42d8ff54ce501e4
lparsons
parents: 6
diff changeset
74 # Convert the textual tab-separated table into simple HTML table
5
80e84db1c392 planemo upload for repository https://github.com/lparsons/galaxy_tools/tree/master/tools/fastx_barcode_splitter_enhanced commit 9ece31c748369db47d9817066cb91e6f3e8428c8-dirty
lparsons
parents: 4
diff changeset
75 echo "<html><body><table border=1>"
7
06ebd94d80ae planemo upload for repository https://github.com/lparsons/galaxy_tools/tree/master/tools/fastx_barcode_splitter_enhanced commit c3b0be52079831f6ae58ff64e42d8ff54ce501e4
lparsons
parents: 6
diff changeset
76 echo "$RESULTS" | sed "s|$BASEPATH\\(.*\\)|\\1|" | \
6
51e098891465 planemo upload for repository https://github.com/lparsons/galaxy_tools/tree/master/tools/fastx_barcode_splitter_enhanced commit e6a486662201362134119c0ddc7151b8dd181ebd
lparsons
parents: 5
diff changeset
77 perl -n -e '$_ =~ s|\t|</td><td>|g; print "<tr><td>\n$_</td></tr>\n"'
4
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
78 echo "<p>"
d1a0e6201854 Uploaded
lparsons
parents:
diff changeset
79 echo "</table></body></html>"