#! /bin/bash
## This code is invented to test NanoporeSanger pipeline, in which we use barrnap to extract 16S ribosomal of bacteria, and use it for taxonomy 
set -ux
export THREADS=20
export nextflow='/media/kt/data/0.Tools/nextflow/nextflow'
export nanoclust_main='/media/kt/data/TRUNG/2.Tool/NanoCLUST/main.nf'
export seqtk='/media/kt/data/anaconda3/envs/kt/bin/seqtk'
export outdir='/media/kt/data/TRUNG/0.Projects/13.NANOPORE-SANGER/3.Output/NanoClust/16SNCBI_REFFSEQ'
export db16Sncbi='/media/kt/data/TRUNG/2.Tool/NanoCLUST/db/16S_ribosomal_RNA'
export db16Ssilva_nr_ref='/media/kt/data/TRUNG/3.Database/database_sliva/Nonredundant_Ref/SILVA_138-1_nr_ref'
export taxdbncbi="/media/kt/data/TRUNG/2.Tool/NanoCLUST/db/taxdb/"


longread='/media/kt/data/TRUNG/0.Projects/13.NANOPORE-SANGER/3.Output/Nanopore_reads_of_GCF_000196035.1_ASM19603v1_genomic.trimmed.fastq.gz'
allreads=''
for nread in {100,500,1000,1500,2000}; do
	prefix=$(basename -s .fastq.gz $longread)
	#capacity=$(awk "BEGIN {print int($nread*1500/10**6+0.5)}")
	mkdir -p $outdir/${prefix}
	outread=$outdir/${prefix}/${prefix}_${nread}_reads.fastq.gz
	$seqtk sample -s50 $longread $nread | gzip > $outread
    $nextflow $nanoclust_main -profile docker --reads $outread --outdir $outdir/$prefix/${prefix}_${nread}_reads \
    --db $db16Sncbi --tax $taxdbncbi
done