#!/bin/bash
filename='metadata2.csv'

genomedir=/data/mramseylab/genomes/
# cmat1=$genomedir"cmat_atcc14266/"
cmat1path=/data/mramseylab/genomes/cmat_atcc14266/
hpara1path=/data/mramseylab/genomes/hpara_392/
EL1path=/data/mramseylab/genomes/hpara_EL1/

fq_dir=/data/mramseylab/raw_reads/YOURDIRHERE
# 


while read line
do
    fastq=$(echo "$line" | cut -f1)
    #below prefix1 change trailing zeroes when metadata updated
    PREFIX1="${fastq%R1_000.fastq.gz}"
    category=$(echo "$line" | cut -f2) 
    #below defines genome prefix name from tsv
    index=$(echo "$line" | cut -f3)
    #below defines path to genome folder var from tsv (didnt work yet)
    #genomepath=$(echo "$line" | cut -f4)
    
    #below if-then statement to link genome prefix with genome folder path, entry needed for all genomes here
    #if [ "$index" = "cmatr" ]; then indexpath=$cmat1path;
    #elif [ "$index" = "hpara" ]; then indexpath=$hpara1path;
    #elif [ "$index" = "EL1" ]; then indexpath=$EL1path; 
    #else echo "ouch"; fi

    #trying out case for replacement of if-then
    case $index in
        cmatr)
            indexpath=$cmat1path
            ;;
        hpara)
            indexpath=$hpara1path
            ;;
        EL1)
            indexpath=$EL1path
            ;;
        *)
            indexpath=$nope
            echo "invalid genome prefix"
            ;;
    esac 


echo $indexpath
#echo $index
# genomeprefix="cmatr" 


    #echo bowtie2 -x $index_path/$index -1 $DIRFASTQ"$CONDITION1"1_R1.fastq -2 $DIRFASTQ"$CONDITION1"1_R2.fastq -S "$CONDITION1"_SAMPLES1.sam
# for below line "-s reverse -t CDS" may not be correct
# htseq-count -s reverse -t CDS -a 1 -m intersection-nonempty -i ID "$CONDITION1"_SAMPLES1.sam "$INDEX".gff > condition1_"$CONDITION1"_counts1.txt

done < "$filename"

# mkdir alignment
# mv *.sam ./alignment

# mkdir figures
# mkdir kegg_analysis
# mkdir rnaseq_analysis

# Rscript deseq_tablesandkegg.R

#paired_end_duplicate_analysis.sh -d /path/to/fastq/files/ -1 FastqCondition1Prefix -2 FastqCondition2Prefix -i BowTieIndexName -p /path/to/bowtie/indexes/ -s reverse -f CDS”
