| 1 | #!/bin/bash |
| 2 | |
| 3 | usage(){ |
| 4 | echo " |
| 5 | Written by Brian Bushnell |
| 6 | Last modified April 30, 2019 |
| 7 | |
| 8 | Description: Filters VCF files by position or other attributes. |
| 9 | Filtering by optional fields (such as allele frequency) require VCF files |
| 10 | generated by CallVariants. |
| 11 | |
| 12 | Usage: filtervcf.sh in=<file> out=<file> |
| 13 | |
| 14 | I/O parameters: |
| 15 | in=<file> Input VCF. |
| 16 | out=<file> Output VCF. |
| 17 | ref=<file> Reference fasta (optional). |
| 18 | overwrite=f (ow) Set to false to force the program to abort rather than |
| 19 | overwrite an existing file. |
| 20 | bgzip=f Use bgzip for gzip compression. |
| 21 | splitalleles=f Split multi-allelic lines into multiple lines. |
| 22 | splitsubs=f Split multi-base substitutions into SNPs. |
| 23 | canonize=t Trim variations down to a canonical representation. |
| 24 | |
| 25 | Position-filtering parameters: |
| 26 | minpos= Ignore variants not overlapping this range. |
| 27 | maxpos= Ignore variants not overlapping this range. |
| 28 | contigs= Comma-delimited list of contig names to include. These |
| 29 | should have no spaces, or underscores instead of spaces. |
| 30 | invert=f Invert position filters. |
| 31 | |
| 32 | Type-filtering parameters: |
| 33 | sub=t Keep substitutions. |
| 34 | del=t Keep deletions. |
| 35 | ins=t Keep insertions. |
| 36 | |
| 37 | Variant-quality filtering parameters: |
| 38 | minreads=0 Ignore variants seen in fewer reads. |
| 39 | minqualitymax=0 Ignore variants with lower max base quality. |
| 40 | minedistmax=0 Ignore variants with lower max distance from read ends. |
| 41 | minmapqmax=0 Ignore variants with lower max mapq. |
| 42 | minidmax=0 Ignore variants with lower max read identity. |
| 43 | minpairingrate=0.0 Ignore variants with lower pairing rate. |
| 44 | minstrandratio=0.0 Ignore variants with lower plus/minus strand ratio. |
| 45 | minquality=0.0 Ignore variants with lower average base quality. |
| 46 | minedist=0.0 Ignore variants with lower average distance from ends. |
| 47 | minavgmapq=0.0 Ignore variants with lower average mapq. |
| 48 | minallelefraction=0.0 Ignore variants with lower allele fraction. This |
| 49 | should be adjusted for high ploidies. |
| 50 | minid=0 Ignore variants with lower average read identity. |
| 51 | minscore=0.0 Ignore variants with lower Phred-scaled score. |
| 52 | clearfilters Reset all variant filters to zero. |
| 53 | |
| 54 | There are additionally max filters for score, quality, mapq, allelefraction, |
| 55 | and identity. |
| 56 | |
| 57 | Java Parameters: |
| 58 | -Xmx This will set Java's memory usage, overriding autodetection. |
| 59 | -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will |
| 60 | specify 200 megs. The max is typically 85% of physical memory. |
| 61 | -eoom This flag will cause the process to exit if an out-of-memory |
| 62 | exception occurs. Requires Java 8u92+. |
| 63 | -da Disable assertions. |
| 64 | |
| 65 | Please contact Brian Bushnell at [email protected] if you encounter any problems. |
| 66 | " |
| 67 | } |
| 68 | |
| 69 | #This block allows symlinked shellscripts to correctly set classpath. |
| 70 | pushd . > /dev/null |
| 71 | DIR="${BASH_SOURCE[0]}" |
| 72 | while [ -h "$DIR" ]; do |
| 73 | cd "$(dirname "$DIR")" |
| 74 | DIR="$(readlink "$(basename "$DIR")")" |
| 75 | done |
| 76 | cd "$(dirname "$DIR")" |
| 77 | DIR="$(pwd)/" |
| 78 | popd > /dev/null |
| 79 | |
| 80 | #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/" |
| 81 | CP="$DIR""current/" |
| 82 | |
| 83 | z="-Xmx4g" |
| 84 | z2="-Xms4g" |
| 85 | set=0 |
| 86 | |
| 87 | if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then |
| 88 | usage |
| 89 | exit |
| 90 | fi |
| 91 | |
| 92 | calcXmx () { |
| 93 | source "$DIR""/calcmem.sh" |
| 94 | setEnvironment |
| 95 | parseXmx "$@" |
| 96 | if [[ $set == 1 ]]; then |
| 97 | return |
| 98 | fi |
| 99 | freeRam 4000m 42 |
| 100 | z="-Xmx${RAM}m" |
| 101 | z2="-Xms${RAM}m" |
| 102 | } |
| 103 | calcXmx "$@" |
| 104 | |
| 105 | filtervcf() { |
| 106 | local CMD="java $EA $EOOM $z $z2 -cp $CP var2.FilterVCF $@" |
| 107 | echo $CMD >&2 |
| 108 | eval $CMD |
| 109 | } |
| 110 | |
| 111 | filtervcf "$@" |