| 1 | #!/bin/bash |
| 2 | |
| 3 | usage(){ |
| 4 | echo " |
| 5 | Written by Brian Bushnell |
| 6 | Last modified March 21, 2018 |
| 7 | |
| 8 | Description: Converts sam/bam to fastq rapidly with multiple threads. |
| 9 | bam files require samtools or sambamba in the path. |
| 10 | |
| 11 | Usage: streamsam.sh in=<file> out=<file> |
| 12 | |
| 13 | Filtering parameters: |
| 14 | minpos= Ignore alignments not overlapping this range. |
| 15 | maxpos= Ignore alignments not overlapping this range. |
| 16 | minmapq= Ignore alignments with mapq below this. |
| 17 | maxmapq= Ignore alignments with mapq above this. |
| 18 | contigs= Comma-delimited list of contig names to include. These |
| 19 | should have no spaces, or underscores instead of spaces. |
| 20 | mapped=t Include mapped reads. |
| 21 | unmapped=t Include unmapped reads. |
| 22 | secondary=f Include secondary alignments. |
| 23 | supplimentary=t Include supplimentary alignments. |
| 24 | lengthzero=f Include alignments without bases. |
| 25 | invert=f Invert sam filters. |
| 26 | ordered=t Keep reads in input order. False is faster. |
| 27 | ref=<file> Optional reference file. |
| 28 | |
| 29 | Please contact Brian Bushnell at [email protected] if you encounter any problems. |
| 30 | " |
| 31 | } |
| 32 | |
| 33 | #This block allows symlinked shellscripts to correctly set classpath. |
| 34 | pushd . > /dev/null |
| 35 | DIR="${BASH_SOURCE[0]}" |
| 36 | while [ -h "$DIR" ]; do |
| 37 | cd "$(dirname "$DIR")" |
| 38 | DIR="$(readlink "$(basename "$DIR")")" |
| 39 | done |
| 40 | cd "$(dirname "$DIR")" |
| 41 | DIR="$(pwd)/" |
| 42 | popd > /dev/null |
| 43 | |
| 44 | #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/" |
| 45 | CP="$DIR""current/" |
| 46 | |
| 47 | z="-Xmx1g" |
| 48 | set=0 |
| 49 | |
| 50 | if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then |
| 51 | usage |
| 52 | exit |
| 53 | fi |
| 54 | |
| 55 | calcXmx () { |
| 56 | source "$DIR""/calcmem.sh" |
| 57 | setEnvironment |
| 58 | parseXmx "$@" |
| 59 | } |
| 60 | calcXmx "$@" |
| 61 | |
| 62 | streamsam() { |
| 63 | local CMD="java $EA $EOOM $z -cp $CP stream.SamStreamerWrapper $@" |
| 64 | echo $CMD >&2 |
| 65 | eval $CMD |
| 66 | } |
| 67 | |
| 68 | streamsam "$@" |