/tools/fastx_toolkit/fastx_barcode_splitter_galaxy_wrapper.sh

https://bitbucket.org/cistrome/cistrome-harvard/ · Shell · 80 lines · 41 code · 9 blank · 30 comment · 7 complexity · 8a923b8288c6cffc061819f0defa6aad MD5 · raw file

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