###Supplemental Data 1: Pipelines for QIIME2, PICRUSt2, and generation of the SILVA 16S rRNA gene taxonomy database
#QIIME2 is run on a Linux-based virtual machine on the command line

##Main QIIME2 pipeline

##import using manifest
qiime tools import \
  --type 'SampleData[SequencesWithQuality]' \
  --input-path manifest.tsv \
  --output-path demux-single-end.qza \
  --input-format SingleEndFastqManifestPhred33V2
#summarize
qiime demux summarize \
--i-data demux-single-end.qza \
--o-visualization demux.qzv

##dada2 cleanup
qiime dada2 denoise-single \
--i-demultiplexed-seqs demux-single-end.qza \
--p-n-threads 16 \
--p-trim-left 13 \
--p-trunc-len 181 \
--o-representative-sequences unfiltered-rep-seqs.qza \
--o-table unfiltered-table.qza \
--o-denoising-stats unfilter-denoise-stats.qza
#tabulate results of dada2
qiime metadata tabulate \
--m-input-file unfilter-denoise-stats.qza \
--o-visualization unfilter-denoise-stats.qzv

##filter low-depth seqs
qiime feature-table filter-samples \
--i-table unfiltered-table.qza \
--p-min-frequency 1500 \
--o-filtered-table filtered-table.qza

qiime feature-table filter-seqs \
--i-data unfiltered-rep-seqs.qza \
--i-table filtered-table.qza \
--o-filtered-data filtered-rep-seqs.qza
#summarize results
qiime feature-table summarize \
--i-table filtered-table.qza \
--m-sample-metadata-file metadata.tsv \
--o-visualization filtered-table.qzv
qiime feature-table tabulate-seqs \
--i-data filtered-rep-seqs.qza \
--o-visualization filtered-rep-seqs.qzv


##creation of SILVA database
#Downloaded Silva release 138.1 - fasta files of database and taxonomy file
#138.1-SSURef-trunc.fasta - seqs
#pre-aligned and truncated version (unaligned regions cut out)

#importing SILVA sequences
qiime tools import \
--type 'FeatureData[AlignedSequence]' \
--input-path SILVA138.fasta \
--input-format AlignedRNAFASTAFormat \
--output-path silva_138.qza
#importing Silva taxonomy
qiime tools import \
--type 'FeatureTable[Taxonomy]' \
--input-format HeaderlessTSVTaxonomyFormat \
--input-path tax_silva_138.txt \
--output-path silva-138-taxonomy.qza

#trimmed the database reads by 515F/806R primers
qiime feature-classifier extract-reads \
--i-sequences silva_138.qza \
--p-f-primer GTGCCAGCMGCCGCGGTAA \
--p-r-primer GGACTACHVGGGTWTCTAAT \
--p-trunc-len 120 \
--p-min-length 100 \
--p-max-length 400 \
--o-reads silva-138-ref-seqs.qza

#then trained the Qiime classifier on this database
qiime feature-classifier fit-classifier-naive-bayes \
--i-reference-reads silva-138-ref-seqs.qza \
--i-reference-taxonomy silva-138-taxonomy.qza \
--o-classifier silva-classifier-qza


##QIIME2 taxonomy classification
qiime feature-classifier classify-sklearn \
--i-classifier silva-classifier.qza \
--i-reads filtered-rep-seqs.qza \
--o-classification taxonomy.qza
#view results
qiime metadata tabulate \
--m-input-file taxonomy.qza \
--o-visualization taxonomy.qzv

##taxa barplots
qiime taxa barplot \
--i-table filtered-table.qza \
--i-taxonomy taxonomy.qza \
--m-metadata-file metadata.tsv \
--o-visualization taxa-bar-plots.qzv


##PICRUSt2 pipeline
qiime picrust2 full-pipeline \
--i-table filtered-table.qza \
--i-seq filtered-rep-seqs.qza \
--output-dir picrust2_out \
--p-threads 1 \
--p-hsp-method mp \
--p-max-nsti 2 \
--verbose

#export
qiime tools export \
--input-path ko_metagenome.qza \
--output-path ko_metagenome
#convert BIOM to TSV
biom convert -i feature-table.biom -o feature-table.tsv --to-tsv