File: RunRapMap.sh

package info (click to toggle)
rapmap 0.15.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,228 kB
  • sloc: cpp: 48,810; ansic: 4,686; sh: 215; python: 82; makefile: 15
file content (29 lines) | stat: -rwxr-xr-x 1,009 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash

cmd="$@"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
bam_out=`echo $cmd | sed -n 's/.*--bamOut\s\+\(\S\+\)\s*.*/\1/p'`
bam_compress_threads=`echo $cmd | sed -n 's/.*--bamThreads\s\+\([[:digit:]]\+\)\s*.*/\1/p'`

if [ -z "$bam_out" ]
then
    #Run normally in this branch
    $DIR/rapmap ${@}
else
    # from: http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script
    if command -v samtools >/dev/null; then 
        new_cmd=`echo $cmd | sed 's/--bamOut\s\+\(\S\+\)\s*//'`
        execmd=""
        if [ -z "$bam_compress_threads" ]
        then
            execmd="${new_cmd} -o | samtools view -Sb - > ${bam_out}"
        else
            execmd="${new_cmd} -o | samtools view -Sb -@ ${bam_compress_threads} > ${bam_out}"
        fi
        echo "Running command [$DIR/rapmap ${execmd}]"
        $DIR/rapmap ${execmd}
    else
        echo >&2 "samtools is required to convert to BAM, but it's not installed.  Aborting."; 
        exit 1; 
    fi
fi