annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
1 #!/bin/bash
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
3 # FASTX-toolkit - FASTA/FASTQ preprocessing tools.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
4 # Copyright (C) 2009 A. Gordon (gordon@cshl.edu)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
5 #
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8 # published by the Free Software Foundation, either version 3 of the
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9 # License, or (at your option) any later version.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10 #
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14 # GNU Affero General Public License for more details.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15 #
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
19 #
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
20 #This is a shell script wrapper for 'fastx_barcode_splitter.pl'
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
21 #
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
22 # 1. Output files are saved at the dataset's files_path directory.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
23 #
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
24 # 2. 'fastx_barcode_splitter.pl' outputs a textual table.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
25 # This script turns it into pretty HTML with working URL
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
26 # (so lazy users can just click on the URLs and get their files)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
27
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
28 BARCODE_FILE="$1"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
29 FASTQ_FILE="$2"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
30 LIBNAME="$3"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
31 OUTPUT_PATH="$4"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
32 shift 4
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
33 # The rest of the parameters are passed to the split program
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
34
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
35 if [ "$OUTPUT_PATH" == "" ]; then
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
36 echo "Usage: $0 [BARCODE FILE] [FASTQ FILE] [LIBRARY_NAME] [OUTPUT_PATH]" >&2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
37 exit 1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
38 fi
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
39
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
40 #Sanitize library name, make sure we can create a file with this name
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
41 LIBNAME=${LIBNAME//\.gz/}
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
42 LIBNAME=${LIBNAME//\.txt/}
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
43 LIBNAME=${LIBNAME//[^[:alnum:]]/_}
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
44
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
45 if [ ! -r "$FASTQ_FILE" ]; then
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
46 echo "Error: Input file ($FASTQ_FILE) not found!" >&2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
47 exit 1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
48 fi
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
49 if [ ! -r "$BARCODE_FILE" ]; then
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
50 echo "Error: barcode file ($BARCODE_FILE) not found!" >&2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
51 exit 1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
52 fi
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
53 mkdir -p "$OUTPUT_PATH"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
54 if [ ! -d "$OUTPUT_PATH" ]; then
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
55 echo "Error: failed to create output path '$OUTPUT_PATH'" >&2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
56 exit 1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
57 fi
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
58
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
59 PUBLICURL=""
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
60 BASEPATH="$OUTPUT_PATH/"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
61 #PREFIX="$BASEPATH"`date "+%Y-%m-%d_%H%M__"`"${LIBNAME}__"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
62 PREFIX="$BASEPATH""${LIBNAME}__"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
63 SUFFIX=".txt"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
64
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
65 RESULTS=`zcat -f "$FASTQ_FILE" | fastx_barcode_splitter.pl --bcfile "$BARCODE_FILE" --prefix "$PREFIX" --suffix "$SUFFIX" "$@"`
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
66 if [ $? != 0 ]; then
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
67 echo "error"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
68 fi
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
69
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
70 #
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
71 # Convert the textual tab-separated table into simple HTML table,
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
72 # with the local path replaces with a valid URL
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
73 echo "<html><body><table border=1>"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
74 echo "$RESULTS" | sed -r "s|$BASEPATH(.*)|<a href=\"\\1\">\\1</a>|" | sed '
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
75 i<tr><td>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
76 s|\t|</td><td>|g
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
77 a<\/td><\/tr>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
78 '
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
79 echo "<p>"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
80 echo "</table></body></html>"