#!/bin/sh
#
#   script: Here we run Meta-RNA using HMM models for archaea and bacteria SSU,
#           and the reads of Set 5. The same script can be launched for archaea 
#           and bacteria LSU HMM and all other read sets. 
#
#			Step (1) - 300,000 Roche rRNA reads
#			Step (2) - 1,000,000 Illumina rRNA reads
#			Step (3) - 1,000,000 Roche non-rRNA reads
#			Step (4) - 1,000,000 Illumina non-rRNA
#			Step (5) - SRR106861 filtered reads (for 16S testing)
# 			Step (6) - SRR013513 filtered reads (for 23S testing)
#
#   note:   all fasta files should have .fasta suffix
#
#           Meta-RNA source http://weizhong-lab.ucsd.edu/meta_rna/
#
#   contact: evguenia.kopylova@lifl.fr
#
#   date: July 2012
#

# path to 300,000 Roche 454 rRNA reads (produced by clean-reads.sh)
ROCHERRNA="set5-roche-rrna-reads.fasta"

# path to 1,000,000 Illumina rRNA reads (produced by clean-reads.sh)
ILLUMINARRNA="set5-illumina-rrna-reads.fasta"

# path to 1,000,000 Roche 454 non-rRNA reads
ROCHENONRRNA="roche-non-rrna-reads.fasta"

# path to 1,000,000 Illumina non-rRNA reads
ILLUMINANONRRNA="illumina-non-rrna-reads.fasta"

# path to metatranscriptomic filtered set SRR106861
METAT1="SRR106861-filtered.fasta"

# path to metatranscriptomic filtered set SRR013513
METAT2="SRR013513-filtered.fasta"

# path to Meta-RNA rna_hmm3.py
METARNA="rna_hmm3.py"

# ---------------------------------
# Step (1) 300,000 Roche rRNA reads

echo "300,000 Roche rRNA reads"
time python $METARNA -i $ROCHERRNA -o ./${ROCHERRNA%.fasta}-accepted -k "arc,bac" -m "ssu" -e 0.00001 

# only count accepted read one time (several best hits possible)
sed '1,1d' ./${ROCHERRNA%.fasta}-accepted.coord | awk '{print $1; }' | sort - | uniq -c > ./${ROCHERRNA%.fasta}-accepted.tags 

echo `wc -l ./${ROCHERRNA%.fasta}-accepted.tags`


# --------------------------------------
# Step (2) 1,000,000 Illumina rRNA reads

echo "1,000,000 Illumina rRNA reads"
time python $METARNA -i $ILLUMINARRNA -o ./${ILLUMINARRNA%.fasta}-accepted -k "arc,bac" -m "ssu" -e 0.00001 

# only count accepted read one time (several best hits possible)
sed '1,1d' ./${ILLUMINARRNA%.fasta}-accepted.coord | awk '{print $1; }' | sort - | uniq -c > ./${ILLUMINARRNA%.fasta}-accepted.tags 

echo `wc -l ./${ILLUMINARRNA%.fasta}-accepted.tags`

# ---------------------------------------
# Step (3) 1,000,000 Roche non-rRNA reads

echo "1,000,000 Roche non-rRNA reads"
time python $METARNA -i $ROCHENONRRNA -o ./${ROCHENONRRNA%.fasta}-accepted -k "arc,bac" -m "ssu" -e 0.00001 

# only count accepted read one time (several best hits possible)
sed '1,1d' ./${ROCHENONRRNA%.fasta}-accepted.coord | awk '{print $1; }' | sort - | uniq -c > ./${ROCHENONRRNA%.fasta}-accepted.tags 

echo `wc -l ./${ROCHENONRRNA%.fasta}-accepted.tags`

# ---------------------------------------
# Step (4) 1,000,000 Illumina non-rRNA

echo "1,000,000 Illumina non-rRNA"
time python $METARNA -i $ILLUMINANONRRNA -o ./${ILLUMINANONRRNA%.fasta}-accepted -k "arc,bac" -m "ssu" -e 0.00001 

# only count accepted read one time
sed '1,1d' ./${ILLUMINANONRRNA%.fasta}-accepted.coord | awk '{print $1; }' | sort - | uniq -c > ./${ILLUMINANONRRNA%.fasta}-accepted.tags 

echo `wc -l ./${ILLUMINANONRRNA%.fasta}-accepted.tags`

# ---------------------------------------------------
# Step (5) SRR106861 filtered reads (for 16S testing)

echo "SRR106861 filtered reads (for 16S testing)"
time python $METARNA -i $METAT1 -o ./${METAT1%.fasta}-accepted -k "arc,bac" -m "ssu" -e 0.00001 

# only count accepted read one time (several best hits possible)
sed '1,1d' ./${METAT1%.fasta}-accepted.coord | awk '{print $1; }' | sort - | uniq -c > ./${METAT1%.fasta}-accepted.tags 

echo `wc -l ./${METAT1%.fasta}-accepted.tags`

# ---------------------------------------------------
# Step (6) SRR013513 filtered reads (for 23S testing)

echo "SRR013513 filtered reads (for 23S testing)"
time python $METARNA -i $METAT2 -o ./${METAT2%.fasta}-accepted -k "arc,bac" -m "lsu" -e 0.00001 

# only count accepted read one time (several best hits possible)
sed '1,1d' ./${METAT2%.fasta}-accepted.coord | awk '{print $1; }' | sort - | uniq -c > ./${METAT2%.fasta}-accepted.tags 

echo `wc -l ./${METAT2%.fasta}-accepted.tags`




