| 1 | #!/bin/bash |
| 2 | |
| 3 | usage(){ |
| 4 | echo " |
| 5 | Written by Brian Bushnell |
| 6 | Last modified March 10, 2025 |
| 7 | |
| 8 | Description: Generates synthetic reads from a set of fasta assemblies. |
| 9 | Each assembly is assigned a random coverage level. |
| 10 | |
| 11 | Usage: randomreadsmg.sh *.fa out=reads.fq.gz |
| 12 | |
| 13 | File parameters: |
| 14 | in=<file,file> Assembly input. Can be a single file, a directory of files, |
| 15 | or comma-delimited list. Unrecognized arguments with no '=' |
| 16 | sign will also be treated as input files. |
| 17 | out=<file> Synthetic read output destination. |
| 18 | out2=<file> Read 2 output if twin files are desired for paired reads. |
| 19 | |
| 20 | Processing parameters: |
| 21 | paired=true Generate paired reads. |
| 22 | mindepth=1 Minimum assembly average depth. |
| 23 | maxdepth=256 Maximum assembly average depth. |
| 24 | depth= Sets minimum and maximum to the same level. |
| 25 | variance=0.4 Coverage within an assembly will vary by up to this much; |
| 26 | one region can be up to this fraction deeper than another. |
| 27 | length=150 Read length. |
| 28 | avginsert=300 Average insert size; only affects paired reads. |
| 29 | threads= Set the number of threads; default is logical core count. |
| 30 | seed=-1 If positive, use the specified RNG seed. This will cause |
| 31 | deterministic output if threads=1. |
| 32 | |
| 33 | Java Parameters: |
| 34 | -Xmx This will set Java's memory usage, overriding autodetection. |
| 35 | -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will |
| 36 | specify 200 megs. The max is typically 85% of physical memory. |
| 37 | -eoom This flag will cause the process to exit if an out-of-memory |
| 38 | exception occurs. Requires Java 8u92+. |
| 39 | -da Disable assertions. |
| 40 | |
| 41 | Please contact Brian Bushnell at [email protected] if you encounter any problems. |
| 42 | " |
| 43 | } |
| 44 | |
| 45 | #This block allows symlinked shellscripts to correctly set classpath. |
| 46 | pushd . > /dev/null |
| 47 | DIR="${BASH_SOURCE[0]}" |
| 48 | while [ -h "$DIR" ]; do |
| 49 | cd "$(dirname "$DIR")" |
| 50 | DIR="$(readlink "$(basename "$DIR")")" |
| 51 | done |
| 52 | cd "$(dirname "$DIR")" |
| 53 | DIR="$(pwd)/" |
| 54 | popd > /dev/null |
| 55 | |
| 56 | #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/" |
| 57 | CP="$DIR""current/" |
| 58 | |
| 59 | z="-Xmx4g" |
| 60 | z2="-Xms4g" |
| 61 | set=0 |
| 62 | |
| 63 | if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then |
| 64 | usage |
| 65 | exit |
| 66 | fi |
| 67 | |
| 68 | calcXmx () { |
| 69 | source "$DIR""/calcmem.sh" |
| 70 | setEnvironment |
| 71 | parseXmx "$@" |
| 72 | if [[ $set == 1 ]]; then |
| 73 | return |
| 74 | fi |
| 75 | freeRam 4000m 84 |
| 76 | z="-Xmx${RAM}m" |
| 77 | z2="-Xms${RAM}m" |
| 78 | } |
| 79 | calcXmx "$@" |
| 80 | |
| 81 | generate() { |
| 82 | local CMD="java $EA $EOOM $z -cp $CP bin.RandomReadsMG $@" |
| 83 | echo $CMD >&2 |
| 84 | eval $CMD |
| 85 | } |
| 86 | |
| 87 | generate "$@" |