| 1 | #!/bin/bash |
| 2 | |
| 3 | usage(){ |
| 4 | echo " |
| 5 | Written by Brian Bushnell |
| 6 | Last modified September 1, 2016 |
| 7 | |
| 8 | Description: Filters reads by name. |
| 9 | |
| 10 | Usage: filterbyname.sh in=<file> in2=<file2> out=<outfile> out2=<outfile2> names=<string,string,string> include=<t/f> |
| 11 | |
| 12 | in2 and out2 are for paired reads and are optional. |
| 13 | If input is paired and there is only one output file, it will be written interleaved. |
| 14 | Important! Leading > and @ symbols are NOT part of sequence names; they are part of |
| 15 | the fasta, fastq, and sam specifications. Therefore, this is correct: |
| 16 | names=e.coli_K12 |
| 17 | And these are incorrect: |
| 18 | names=>e.coli_K12 |
| 19 | [email protected]_K12 |
| 20 | |
| 21 | Parameters: |
| 22 | include=f Set to 'true' to include the filtered names rather than excluding them. |
| 23 | substring=f Allow one name to be a substring of the other, rather than a full match. |
| 24 | f: No substring matching. |
| 25 | t: Bidirectional substring matching. |
| 26 | header: Allow input read headers to be substrings of names in list. |
| 27 | name: Allow names in list to be substrings of input read headers. |
| 28 | prefix=f Allow names to match read header prefixes. |
| 29 | case=t (casesensitive) Match case also. |
| 30 | ow=t (overwrite) Overwrites files that already exist. |
| 31 | app=f (append) Append to files that already exist. |
| 32 | zl=4 (ziplevel) Set compression level, 1 (low) to 9 (max). |
| 33 | int=f (interleaved) Determines whether INPUT file is considered interleaved. |
| 34 | names= A list of strings or files. The files can have one name per line, or |
| 35 | be a standard read file (fasta, fastq, or sam). |
| 36 | minlen=0 Do not output reads shorter than this. |
| 37 | ths=f (truncateheadersymbol) Ignore a leading @ or > symbol in the names file. |
| 38 | tws=f (truncatewhitespace) Ignore leading or trailing whitespace in the names file. |
| 39 | truncate=f Set both ths and tws at the same time. |
| 40 | |
| 41 | Positional parameters: |
| 42 | These optionally allow you to output only a portion of a sequence. Zero-based, inclusive. |
| 43 | Intended for a single sequence and include=t mode. |
| 44 | from=-1 Only print bases starting at this position. |
| 45 | to=-1 Only print bases up to this position. |
| 46 | range= Set from and to with a single flag. |
| 47 | |
| 48 | |
| 49 | Java Parameters: |
| 50 | -Xmx This will set Java's memory usage, overriding autodetection. |
| 51 | -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will specify 200 megs. |
| 52 | The max is typically 85% of physical memory. |
| 53 | -eoom This flag will cause the process to exit if an out-of-memory |
| 54 | exception occurs. Requires Java 8u92+. |
| 55 | -da Disable assertions. |
| 56 | |
| 57 | To read from stdin, set 'in=stdin'. The format should be specified with an extension, like 'in=stdin.fq.gz' |
| 58 | To write to stdout, set 'out=stdout'. The format should be specified with an extension, like 'out=stdout.fasta' |
| 59 | |
| 60 | Please contact Brian Bushnell at [email protected] if you encounter any problems. |
| 61 | " |
| 62 | } |
| 63 | |
| 64 | #This block allows symlinked shellscripts to correctly set classpath. |
| 65 | pushd . > /dev/null |
| 66 | DIR="${BASH_SOURCE[0]}" |
| 67 | while [ -h "$DIR" ]; do |
| 68 | cd "$(dirname "$DIR")" |
| 69 | DIR="$(readlink "$(basename "$DIR")")" |
| 70 | done |
| 71 | cd "$(dirname "$DIR")" |
| 72 | DIR="$(pwd)/" |
| 73 | popd > /dev/null |
| 74 | |
| 75 | #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/" |
| 76 | CP="$DIR""current/" |
| 77 | |
| 78 | z="-Xmx800m" |
| 79 | set=0 |
| 80 | |
| 81 | if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then |
| 82 | usage |
| 83 | exit |
| 84 | fi |
| 85 | |
| 86 | calcXmx () { |
| 87 | source "$DIR""/calcmem.sh" |
| 88 | setEnvironment |
| 89 | parseXmx "$@" |
| 90 | if [[ $set == 1 ]]; then |
| 91 | return |
| 92 | fi |
| 93 | freeRam 800m 84 |
| 94 | z="-Xmx${RAM}m" |
| 95 | z2="-Xms${RAM}m" |
| 96 | } |
| 97 | calcXmx "$@" |
| 98 | |
| 99 | function filterbyname() { |
| 100 | local CMD="java $EA $EOOM $z -cp $CP driver.FilterReadsByName $@" |
| 101 | echo $CMD >&2 |
| 102 | eval $CMD |
| 103 | } |
| 104 | |
| 105 | filterbyname "$@" |