#!/bin/bash
#PBS -N hic-te
#PBS -q default
#PBS -l select=1:ncpus=8:mem=200gb:scratch_local=200gb
#PBS -l walltime=16:00:00
#PBS -m ae

BASE="/storage/brno2/home/matej_lexa/hic-te/"

trap 'clean_scratch' TERM EXIT # clean scratch

module add nextflow-21.04.3
export SINGULARITY_CACHEDIR=$SCRATCHDIR
export SINGULARITY_LOCALCACHEDIR=$SCRATCHDIR
export SINGULARITY_TMPDIR=$SCRATCHDIR
export NXF_SINGULARITY_CACHEDIR=$SCRATCHDIR
export NXF_SINGULARITY_LOCALCACHEDIR=$SCRATCHDIR
export NXF_SINGULARITY_TMPDIR=$SCRATCHDIR

cd $BASE
mkdir -p $SCRATCHDIR/run
mkdir -p $SCRATCHDIR/tmp
cp -r * $SCRATCHDIR/run/
rm -rf $SCRATCHDIR/run/output
#rm -rf $SCRATCHDIR/run/work
rm -rf $SCRATCHDIR/run/.nextflow*
cd $SCRATCHDIR/run

plant_path="/storage/brno2/home/matej_lexa/hic-te_test_inputs/Solanum_lycopersicum"

nextflow run main_TE_2.nf -profile test,singularity --data_dir "output" --skip_align false --sra_run "SRR5748734" --reference ${plant_path}"/Slyc_SL40.fa" --exons_gff3 ${plant_path}"/Slycopersicum_691_ITAG4.0.gene_exons.gff3" --skip_bow_index false --skip_re false --plantsat ${plant_path}"/PlantSat_Solanum.fa" --input_nester ${plant_path}"/data" -resume 

mkdir -p $BASE/output-$PBS_JOBID
cp -r $SCRATCHDIR/run/output/* $BASE/output-$PBS_JOBID/

echo "Done."
