| 1 | #!/bin/bash |
| 2 | set -e |
| 3 | |
| 4 | #Written by Brian Bushnell |
| 5 | #Last updated August 6, 2019 |
| 6 | |
| 7 | #Fetches and sketches Silva. |
| 8 | #Be sure taxonomy is updated first! |
| 9 | #To use this script outside of NERSC, modify $TAXPATH to point to your directory with the BBTools taxonomy data, |
| 10 | #e.g. TAXPATH="/path/to/taxonomy_directory/" |
| 11 | #Also, check Silva's archive (https://www.arb-silva.de/no_cache/download/archive/) for a newer version. |
| 12 | |
| 13 | TAXPATH="auto" |
| 14 | |
| 15 | #Fetch files. |
| 16 | |
| 17 | #"_tax_silva_trunc" means it has taxonomic information, and it is truncated to retain only alignable 16S bases, not additional sequence. |
| 18 | wget -nv http://ftp.arb-silva.de/release_132/Exports/SILVA_132_SSURef_tax_silva_trunc.fasta.gz |
| 19 | wget -nv http://ftp.arb-silva.de/release_132/Exports/SILVA_132_LSURef_tax_silva_trunc.fasta.gz |
| 20 | |
| 21 | |
| 22 | #Process SSU |
| 23 | |
| 24 | #This transforms U to T, trims leading or trailing Ns, discards sequences under 80bp, and changes the line wrap to 4000 to save space. |
| 25 | time reformat.sh in=SILVA_132_SSURef_tax_silva_trunc.fasta.gz out=ssu_utot.fa.gz fastawrap=4000 utot zl=9 qtrim=rl trimq=1 ow minlen=80 pigz=20 |
| 26 | |
| 27 | #Clumpify step is not strictly necessary |
| 28 | time clumpify.sh in=ssu_utot.fa.gz reorder groups=1 -Xmx31g fastawrap=4000 out=ssu_clumped.fa.gz zl=9 pigz=20 bgzip |
| 29 | |
| 30 | #Prefix with the subunit identifier to allow unique names when SSU and LSU are merged |
| 31 | time rename.sh addprefix prefix="lcl\|SSU" in=ssu_clumped.fa.gz out=ssu_prefix.fa.gz pigz=20 bgzip zl=9 fastawrap=4000 |
| 32 | |
| 33 | #Rename with the prefix tid|number based on the TaxID. |
| 34 | time gi2taxid.sh -Xmx8g tree=auto gi=null accession=null in=ssu_prefix.fa.gz out=ssu_renamed.fa.gz silva zl=9 pigz=20 bgzip taxpath=$TAXPATH |
| 35 | |
| 36 | #Sort by taxonomy to put records from the same organism together,a nd increase compression |
| 37 | time sortbyname.sh -Xmx31g in=ssu_renamed.fa.gz out=ssu_sorted.fa.gz ow taxa tree=auto fastawrap=4000 zl=9 pigz=20 bgzip allowtemp=f taxpath=$TAXPATH |
| 38 | |
| 39 | #Remove duplicate or contained sequences |
| 40 | time dedupe.sh in=ssu_sorted.fa.gz out=ssu_deduped_sorted.fa.gz zl=9 pigz=20 bgzip ordered fastawrap=4000 |
| 41 | |
| 42 | |
| 43 | #Process LSU |
| 44 | |
| 45 | time reformat.sh in=SILVA_132_LSURef_tax_silva_trunc.fasta.gz out=lsu_utot.fa.gz fastawrap=4000 utot zl=9 qtrim=rl trimq=1 ow minlen=80 pigz=20 bgzip |
| 46 | time clumpify.sh in=lsu_utot.fa.gz reorder groups=1 -Xmx31g fastawrap=4000 out=lsu_clumped.fa.gz zl=9 pigz=20 bgzip |
| 47 | time rename.sh addprefix prefix="lcl\|LSU" in=lsu_clumped.fa.gz out=lsu_prefix.fa.gz pigz=20 bgzip zl=9 fastawrap=4000 |
| 48 | time gi2taxid.sh -Xmx8g tree=auto gi=null accession=null in=lsu_prefix.fa.gz out=lsu_renamed.fa.gz silva zl=9 pigz=20 bgzip taxpath=$TAXPATH |
| 49 | time sortbyname.sh -Xmx31g in=lsu_renamed.fa.gz out=lsu_sorted.fa.gz ow taxa tree=auto fastawrap=4000 zl=9 pigz=20 bgzip allowtemp=f |
| 50 | time dedupe.sh in=lsu_sorted.fa.gz out=lsu_deduped100pct.fa.gz zl=9 pigz=20 bgzip ordered fastawrap=4000 |
| 51 | #time sortbyname.sh -Xmx31g in=lsu_deduped_sorted.fa.gz out=lsu_deduped_sorted.fa.gz ow taxa tree=auto fastawrap=4000 zl=9 pigz=20 bgzip allowtemp=f taxpath=$TAXPATH |
| 52 | |
| 53 | |
| 54 | #Merge SSU and LSU |
| 55 | |
| 56 | mergesorted.sh -Xmx31g ssu_sorted.fa.gz lsu_sorted.fa.gz bgzip unbgzip zl=9 out=both_sorted.fa.gz taxa tree=auto fastawrap=4000 minlen=60 ow taxpath=$TAXPATH |
| 57 | mergesorted.sh -Xmx31g ssu_deduped_sorted.fa.gz lsu_deduped_sorted.fa.gz bgzip unbgzip zl=9 out=both_deduped_sorted.fa.gz taxa tree=auto fastawrap=4000 minlen=60 ow taxpath=$TAXPATH |
| 58 | |
| 59 | #Old version of merge |
| 60 | #cat ssu_sorted.fa.gz lsu_sorted.fa.gz > both_sorted_temp.fa.gz |
| 61 | #time sortbyname.sh -Xmx31g in=both_sorted_temp.fa.gz out=both_sorted.fa.gz ow taxa tree=auto fastawrap=4000 zl=9 pigz=20 bgzip allowtemp=f taxpath=$TAXPATH |
| 62 | #rm both_sorted_temp.fa.gz |
| 63 | #cat ssu_deduped_sorted.fa.gz lsu_deduped_sorted.fa.gz > both_deduped_sorted_temp.fa.gz |
| 64 | #time sortbyname.sh -Xmx31g in=both_deduped_sorted_temp.fa.gz out=both_deduped_sorted.fa.gz ow taxa tree=auto fastawrap=4000 zl=9 pigz=20 bgzip allowtemp=f taxpath=$TAXPATH |
| 65 | #rm both_deduped_sorted_temp.fa.gz |
| 66 | |
| 67 | |
| 68 | #Sketch steps |
| 69 | |
| 70 | #Make a blacklist of kmers occuring in at least 500 different species. |
| 71 | #A blacklist is HIGHLY recommended for Silva or any ribo database. |
| 72 | #This needs to be copied to bbmap/resources/ |
| 73 | time sketchblacklist.sh -Xmx31g in=both_deduped_sorted.fa.gz prefilter=f tree=auto taxa silva taxlevel=species ow out=blacklist_silva_species_500.sketch mincount=500 taxpath=$TAXPATH |
| 74 | |
| 75 | #Make one sketch per sequence |
| 76 | time sketch.sh files=31 out=both_seq#.sketch in=both_deduped_sorted.fa.gz size=200 maxgenomefraction=0.1 -Xmx8g tree=auto mode=sequence ow silva blacklist=blacklist_silva_species_500.sketch autosize ow parsesubunit taxpath=$TAXPATH |
| 77 | |
| 78 | #Make one sketch per TaxID |
| 79 | time sketch.sh files=31 out=both_taxa#.sketch in=both_deduped_sorted.fa.gz size=200 maxgenomefraction=0.1 -Xmx8g tree=auto mode=taxa ow silva blacklist=blacklist_silva_species_500.sketch autosize ow taxpath=$TAXPATH |