#!/bin/bash
#SBATCH -t 4:00:00
#SBATCH --nodes=1 --ntasks-per-node=1
#SBATCH --mem=24g
#SBATCH --export=NONE
#SBATCH --mail-user=alex_labossiere@uri.edu
#SBATCH --mail-type=BEGIN,END,FAIL

module load QIIME2/2019.7

rawdir=/data/mramseylab/raw_reads/AL_v1v2_test
visdir=/data/mramseylab/visualizations/AL_2022
metadata=/data/mramseylab/metadata/plaque_meta_3.5.tsv
# table summarize will give info on how many sequences are associated with each sample. This has useful graphs and info w/ sum. stats.
# table tabulate-seqs will map feature IDs to sequences and BLAST that to NCBI. this stuff will be used later on

  qiime dada2 denoise-paired \
    --i-demultiplexed-seqs $rawdir/demux-v1v2.qza \
    --p-trim-left-f 8 \
    --p-trim-left-r 6 \
    --p-trunc-len-f 230 \
    --p-trunc-len-r 202 \
    --o-table $rawdir/denoise-table-paired-v1v2.qza \
    --o-representative-sequences $rawdir/rep-seqs-paired-v1v2.qza \
    --o-denoising-stats $rawdir/denoising-stats-paired-v1v2.qza


# I think FeatureTables and Feature data summaries are next. Mix from perera and qiime moving pictures.
# table summarize will give info on how many sequences are associated with each sample. This has useful graphs and info w/ sum. stats.
# table tabulate-seqs will map feature IDs to sequences and BLAST that to NCBI. this stuff will be used later on
#will likely be the slowest script to run

qiime feature-table summarize \
  --i-table $rawdir/denoise-table-paired-v1v2.qza \
  --o-visualization $visdir/table_sum-paired-v1v2.qzv \
  --m-sample-metadata-file $metadata \

qiime feature-table tabulate-seqs \
  --i-data $rawdir/rep-seqs-paired-v1v2.qza \
  --o-visualization $visdir/rep-seqs-paired-v1v2.qzv

#now it seems that phylogeny is next
#qiime2021.11 code is shorter and gives us same artifacts

qiime phylogeny align-to-tree-mafft-fasttree \
  --i-sequences $rawdir/rep-seqs-paired-v1v2.qza \
  --o-alignment $rawdir/aligned-rep-seqs-paired-v1v2.qza \
  --o-masked-alignment $rawdir/masked-aligned-rep-seqs-paired-v1v2.qza \
  --o-tree $rawdir/unrooted-tree-paired-v1v2.qza \
  --o-rooted-tree $rawdir/rooted-tree-paired-v1v2.qza
