comparison fastx_barcode_splitter_galaxy_wrapper.sh @ 0:84bbf4fd24c3 draft

Initial toolshed version with support for separate index reads and automatic loading of results into Galaxy history.
author lparsons
date Fri, 08 Nov 2013 09:53:39 -0500
parents
children b7b3d008e2d3
comparison
equal deleted inserted replaced
-1:000000000000 0:84bbf4fd24c3
1 #!/bin/bash
2
3 # FASTX-toolkit - FASTA/FASTQ preprocessing tools.
4 # Copyright (C) 2009 A. Gordon (gordon@cshl.edu)
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as
8 # published by the Free Software Foundation, either version 3 of the
9 # License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
15 #
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 # Modified by Lance Parsons (lparsons@princeton.edu)
20 # 2011-03-15 Adapted to allow galaxy to determine filetype
21 #
22 #This is a shell script wrapper for 'fastx_barcode_splitter.pl'
23 #
24 # 1. Output files are saved at the dataset's files_path directory.
25 #
26 # 2. 'fastx_barcode_splitter.pl' outputs a textual table.
27 # This script turns it into pretty HTML with working URL
28 # (so lazy users can just click on the URLs and get their files)
29
30 if [ "$1x" = "x" ]; then
31 echo "Usage: $0 [BARCODE FILE] [FASTQ FILE] [LIBRARY_NAME] [OUTPUT_PATH] [FILETYPE]" >&2
32 exit 1
33 fi
34
35 BARCODE_FILE="$1"
36 FASTQ_FILE="$2"
37 LIBNAME="$3"
38 OUTPUT_PATH="$4"
39 FILETYPE="$5"
40 shift 5
41 # The rest of the parameters are passed to the split program
42
43 if [ "${OUTPUT_PATH}x" = "x" ]; then
44 echo "Usage: $0 [BARCODE FILE] [FASTQ FILE] [LIBRARY_NAME] [OUTPUT_PATH] [FILETYPE]" >&2
45 exit 1
46 fi
47
48 #Sanitize library name, make sure we can create a file with this name
49 LIBNAME=${LIBNAME%.gz}
50 LIBNAME=${LIBNAME%.txt}
51 LIBNAME=$(echo "$LIBNAME" | tr -cd '[:alnum:]_')
52
53 if [ ! -r "$FASTQ_FILE" ]; then
54 echo "Error: Input file ($FASTQ_FILE) not found!" >&2
55 exit 1
56 fi
57 if [ ! -r "$BARCODE_FILE" ]; then
58 echo "Error: barcode file ($BARCODE_FILE) not found!" >&2
59 exit 1
60 fi
61 mkdir -p "$OUTPUT_PATH"
62 if [ ! -d "$OUTPUT_PATH" ]; then
63 echo "Error: failed to create output path '$OUTPUT_PATH'" >&2
64 exit 1
65 fi
66
67 PUBLICURL=""
68 BASEPATH="$OUTPUT_PATH/"
69 #PREFIX="$BASEPATH"`date "+%Y-%m-%d_%H%M__"`"${LIBNAME}__"
70 PREFIX="$BASEPATH""${LIBNAME}_"
71 SUFFIX="_visible_$FILETYPE"
72 DIRECTORY=$(cd `dirname $0` && pwd)
73
74 RESULTS=`gzip -cdf "$FASTQ_FILE" | $DIRECTORY/fastx_barcode_splitter.pl --bcfile "$BARCODE_FILE" --prefix "$PREFIX" --suffix "$SUFFIX" "$@"`
75 if [ $? != 0 ]; then
76 echo "error"
77 fi
78
79 #
80 # Convert the textual tab-separated table into simple HTML table,
81 # with the local path replaces with a valid URL
82 #HTMLSUMMARY=${PREFIX}stats_visible_html
83 echo "<html><body><table border=1>"
84 echo "$RESULTS" | sed -r "s|$BASEPATH(.*)|\\1|" | sed '
85 i<tr><td>
86 s|\t|</td><td>|g
87 a<\/td><\/tr>
88 '
89 echo "<p>"
90 echo "</table></body></html>"