Mercurial > repos > idot > fastx_toolkit2
comparison fastx_barcode_splitter_galaxy_wrapper.sh @ 0:78a7d28f2a15 draft
Uploaded
author | idot |
---|---|
date | Wed, 10 Jul 2013 06:13:48 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:78a7d28f2a15 |
---|---|
1 #!/bin/sh | |
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 if [ "$1x" = "x" ]; then | |
29 echo "Usage: $0 [BARCODE FILE] [FASTQ FILE] [LIBRARY_NAME] [OUTPUT_PATH]" >&2 | |
30 exit 1 | |
31 fi | |
32 | |
33 BARCODE_FILE="$1" | |
34 FASTQ_FILE="$2" | |
35 LIBNAME="$3" | |
36 OUTPUT_PATH="$4" | |
37 shift 4 | |
38 # The rest of the parameters are passed to the split program | |
39 | |
40 if [ "${OUTPUT_PATH}x" = "x" ]; then | |
41 echo "Usage: $0 [BARCODE FILE] [FASTQ FILE] [LIBRARY_NAME] [OUTPUT_PATH]" >&2 | |
42 exit 1 | |
43 fi | |
44 | |
45 #Sanitize library name, make sure we can create a file with this name | |
46 LIBNAME=${LIBNAME%.gz} | |
47 LIBNAME=${LIBNAME%.txt} | |
48 LIBNAME=$(echo "$LIBNAME" | tr -cd '[:alnum:]') | |
49 | |
50 if [ ! -r "$FASTQ_FILE" ]; then | |
51 echo "Error: Input file ($FASTQ_FILE) not found!" >&2 | |
52 exit 1 | |
53 fi | |
54 if [ ! -r "$BARCODE_FILE" ]; then | |
55 echo "Error: barcode file ($BARCODE_FILE) not found!" >&2 | |
56 exit 1 | |
57 fi | |
58 mkdir -p "$OUTPUT_PATH" | |
59 if [ ! -d "$OUTPUT_PATH" ]; then | |
60 echo "Error: failed to create output path '$OUTPUT_PATH'" >&2 | |
61 exit 1 | |
62 fi | |
63 | |
64 PUBLICURL="" | |
65 BASEPATH="$OUTPUT_PATH/" | |
66 #PREFIX="$BASEPATH"`date "+%Y-%m-%d_%H%M__"`"${LIBNAME}__" | |
67 PREFIX="$BASEPATH""${LIBNAME}__" | |
68 SUFFIX=".txt" | |
69 | |
70 RESULTS=`gzip -cdf "$FASTQ_FILE" | fastx_barcode_splitter.pl --bcfile "$BARCODE_FILE" --prefix "$PREFIX" --suffix "$SUFFIX" "$@"` | |
71 if [ $? != 0 ]; then | |
72 echo "error" | |
73 fi | |
74 | |
75 # | |
76 # Convert the textual tab-separated table into simple HTML table, | |
77 # with the local path replaces with a valid URL | |
78 echo "<html><body><table border=1>" | |
79 echo "$RESULTS" | sed -r "s|$BASEPATH(.*)|<a href=\"\\1\">\\1</a>|" | sed ' | |
80 i<tr><td> | |
81 s|\t|</td><td>|g | |
82 a<\/td><\/tr> | |
83 ' | |
84 echo "<p>" | |
85 echo "</table></body></html>" |