1#!/usr/local/bin/bash
2
3usage(){
4echo "
5Written by Shijie Yao
6Last modified March 22, 2018
7
8Description: Read QC pipeline
9
10Usage:        readqc.sh in=<file> out=<dir>
11
12Parameters:
13in=file         Specify the input fastq or fastq.gz file
14out=dir         The output directory
15
16Please contact Shijie Yao at syao @lbl.gov if you encounter any problems.
17"
18}
19
20
21pushd . > /dev/null         # save current dir in directory stack
22DIR="${BASH_SOURCE[0]}"     # script file, even by source (vs $0)
23
24while [ -h "$DIR" ]; do     # if a link, follow the link to path
25  cd "$(dirname "$DIR")"
26  DIR="$(readlink "$(basename "$DIR")")"
27done
28
29cd "$(dirname "$DIR")"      # obtain the abspath of where the script live
30DIR="$(pwd)"
31
32popd > /dev/null            # move back to invocation dir
33
34PYDIR="$DIR/pytools"        # abs path to pytools
35
36set=0                       #?
37
38if [ $# -ne 2 ] || [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then    # -z tells if null
39    usage
40    exit
41fi
42
43fastq=""
44out=""
45
46parse_arg() {
47    IFS='=' read -ra toks <<< "$1"    #Convert string to array
48    if [ ${#toks[@]} -eq 2 ]; then
49        if [ ${toks[0]} == "in" ]; then
50            fastq=${toks[1]}
51        elif [ ${toks[0]} == "out" ]; then
52            out=${toks[1]}
53        fi
54    fi
55}
56
57parse_arg $1
58parse_arg $2
59
60if [ -z $fastq ] || [ -z $out ]; then
61    usage
62    exit
63fi
64
65if [ ! -e $fastq ]; then
66    echo "ERROR - The file not found : $fastq !!"
67    exit
68fi
69
70CMD="$PYDIR/readqc.py -f $fastq -o $out --html --skip-blast"
71echo "$CMD"
72eval $CMD
73