| 1 | #!/bin/bash |
| 2 | #SBATCH -J sketch_refseq |
| 3 | #SBATCH -q genepool |
| 4 | #SBATCH -A gtrqc |
| 5 | #SBATCH -N 1 |
| 6 | #SBATCH -C haswell |
| 7 | #SBATCH -t 71:00:00 |
| 8 | #SBATCH --error=log_%j.err |
| 9 | #SBATCH --output=log_%j.out |
| 10 | #SBATCH --exclusive |
| 11 | |
| 12 | set -e |
| 13 | |
| 14 | #Written by Brian Bushnell |
| 15 | #Last updated August 7, 2019 |
| 16 | |
| 17 | #Sketches RefSeq. |
| 18 | #Be sure taxonomy is updated first! |
| 19 | #To use this script outside of NERSC, modify $TAXPATH to point to your directory with the BBTools taxonomy data, |
| 20 | #e.g. TAXPATH="/path/to/taxonomy_directory/" |
| 21 | |
| 22 | TAXPATH="auto" |
| 23 | |
| 24 | #Ensure necessary executables are in your path |
| 25 | #module load pigz |
| 26 | |
| 27 | #Sort by taxonomy. |
| 28 | #This makes sketching by taxa use much less memory because sketches can be written to disk as soon as they are finished. |
| 29 | #If this stage still runs out of memory please increase the -Xmx flag or add the flag 'maxfiles=4'. |
| 30 | #Or you can just skip it; sorting should no longer be necessary. |
| 31 | time sortbyname.sh -Xmx100g in=renamed.fa.gz memmult=0.33 out=sorted.fa.gz zl=9 pigz=64 bgzip taxa tree=auto gi=ignore fastawrap=1023 minlen=60 readbufferlen=2 readbuffers=1 taxpath=$TAXPATH |
| 32 | |
| 33 | #If sortbyname runs out of memory in the last stage (when sorted.fa.gz is being written), you can usually run this: |
| 34 | #mergesorted.sh -Xmx100g sort_temp* bgzip unbgzip zl=8 out=sorted.fa.gz taxa tree=auto fastawrap=1023 minlen=60 readbufferlen=2 readbuffers=1 ow taxpath=$TAXPATH |
| 35 | |
| 36 | |
| 37 | #Make a blacklist of kmers occuring in at least 140 different genuses. |
| 38 | time sketchblacklist.sh -Xmx63g in=sorted.fa.gz prepasses=1 tree=auto taxa taxlevel=species ow out=blacklist_refseq_genus_140.sketch mincount=140 k=32,24 sizemult=2 taxpath=$TAXPATH |
| 39 | |
| 40 | #Generate 31 sketch files, with one sketch per species. |
| 41 | time bbsketch.sh -Xmx63g in=sorted.fa.gz out=taxa#.sketch mode=taxa tree=auto accession=null gi=null files=31 ow unpigz minsize=400 prefilter autosize blacklist=blacklist_refseq_genus_140.sketch k=32,24 depth sizemult=2 taxpath=$TAXPATH |
| 42 | |
| 43 | #A query such as contigs.fa can now be compared to the new reference sketches like this: |
| 44 | #comparesketch.sh in=contigs.fa k=32,24 tree=auto taxa*.sketch blacklist=blacklist_refseq_genus_140 taxpath=$TAXPATH |
| 45 | |
| 46 | #On NERSC systems, you can then set the default path to nt by pointing /global/projectb/sandbox/gaag/bbtools/refseq/current at the path to the new sketches. |
| 47 | #Then you can use the default set of refseq sketches like this: |
| 48 | #comparesketch.sh in=contigs.fa refseq tree=auto |
| 49 | #That command automatically adds the default path to the sketches, the blacklist, and the correct values for K. |