#!/usr/bin/env bash

#######################################
#### To be replaced by CWL routine #### 
#######################################

# This is supposed to wrap the workflow from kallisto quantification to sleuth diff gene expression
# Execute within <ARC root>/workflows: 
## change rights: `chmod a+x kallisto_sleuth_wrapper.sh`
## execute script: `./kallisto_sleuth_wrapper.sh <run_name> <arc_root>`
## Example: ./kallisto_sleuth_wrapper.sh "run2" "/Users/dominikbrilhaus/03DataPLANT_gitlab/samplearc_rnaseq/"

run_name='kallisto_sleuth/'$1
arc_root=$2

# Note: due to some not well documented change in kallisto development (use of hd5) the kallisto quant part is currently not reproducible and commented out 
# Pointer to `runs/kallisto_sleuth/run1/01_kallisto_results` is thus hard coded into 03_KallistoCollect.R

mkdir -p $arc_root'/runs/'$run_name

# chmod a+x ./kallisto_sleuth/01_KallistoIndex.sh
# ./kallisto_sleuth/01_KallistoIndex.sh $run_name $arc_root
# chmod a+x kallisto_sleuth/01_KallistoQuant.sh 
# ./kallisto_sleuth/01_KallistoQuant.sh $run_name $arc_root

Rscript ./kallisto_sleuth/02_InstallPackages.R
echo "r insallations done"
Rscript ./kallisto_sleuth/03_KallistoCollect.R $run_name $arc_root
echo "kallisto collect done"
Rscript ./kallisto_sleuth/04_Sleuth.R $run_name $arc_root
echo "sleuth done"
Rscript ./kallisto_sleuth/05_plot_shinyPrep.R $run_name $arc_root
echo "shiny prep done"

# store variables for test runs in R
# run_name="kallisto_sleuth/run2"
# arc_root="/Users/dominikbrilhaus/03DataPLANT_gitlab/samplearc_rnaseq/"