comparison tools/fastx_toolkit/fastx_barcode_splitter_galaxy_wrapper.sh @ 0:9071e359b9a3

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:37:19 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:9071e359b9a3
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 #
20 #This is a shell script wrapper for 'fastx_barcode_splitter.pl'
21 #
22 # 1. Output files are saved at the dataset's files_path directory.
23 #
24 # 2. 'fastx_barcode_splitter.pl' outputs a textual table.
25 # This script turns it into pretty HTML with working URL
26 # (so lazy users can just click on the URLs and get their files)
27
28 BARCODE_FILE="$1"
29 FASTQ_FILE="$2"
30 LIBNAME="$3"
31 OUTPUT_PATH="$4"
32 shift 4
33 # The rest of the parameters are passed to the split program
34
35 if [ "$OUTPUT_PATH" == "" ]; then
36 echo "Usage: $0 [BARCODE FILE] [FASTQ FILE] [LIBRARY_NAME] [OUTPUT_PATH]" >&2
37 exit 1
38 fi
39
40 #Sanitize library name, make sure we can create a file with this name
41 LIBNAME=${LIBNAME//\.gz/}
42 LIBNAME=${LIBNAME//\.txt/}
43 LIBNAME=${LIBNAME//[^[:alnum:]]/_}
44
45 if [ ! -r "$FASTQ_FILE" ]; then
46 echo "Error: Input file ($FASTQ_FILE) not found!" >&2
47 exit 1
48 fi
49 if [ ! -r "$BARCODE_FILE" ]; then
50 echo "Error: barcode file ($BARCODE_FILE) not found!" >&2
51 exit 1
52 fi
53 mkdir -p "$OUTPUT_PATH"
54 if [ ! -d "$OUTPUT_PATH" ]; then
55 echo "Error: failed to create output path '$OUTPUT_PATH'" >&2
56 exit 1
57 fi
58
59 PUBLICURL=""
60 BASEPATH="$OUTPUT_PATH/"
61 #PREFIX="$BASEPATH"`date "+%Y-%m-%d_%H%M__"`"${LIBNAME}__"
62 PREFIX="$BASEPATH""${LIBNAME}__"
63 SUFFIX=".txt"
64
65 RESULTS=`zcat -f "$FASTQ_FILE" | fastx_barcode_splitter.pl --bcfile "$BARCODE_FILE" --prefix "$PREFIX" --suffix "$SUFFIX" "$@"`
66 if [ $? != 0 ]; then
67 echo "error"
68 fi
69
70 #
71 # Convert the textual tab-separated table into simple HTML table,
72 # with the local path replaces with a valid URL
73 echo "<html><body><table border=1>"
74 echo "$RESULTS" | sed -r "s|$BASEPATH(.*)|<a href=\"\\1\">\\1</a>|" | sed '
75 i<tr><td>
76 s|\t|</td><td>|g
77 a<\/td><\/tr>
78 '
79 echo "<p>"
80 echo "</table></body></html>"