#!/bin/bash
#
# This script is continuation of 00_preparation.sh


# please, log in to the metacentrum if you are not already logged in !

ssh user@skirit.ics.muni.cz


# Lets perform quality control of the raw data

# Lets don't forget we are in front end, in the metacentrum "lobby" , we need to ask for a machine to work on! 
qsub -l walltime=3:0:0 -l select=1:ncpus=4:mem=10gb:scratch_local=50gb -I

# Our directory with data has this format: /storage/brno2/home/*username*/RNAseq/data/raw/

USERNAME="bartonv"

#lets make directories in the scratch
mkdir -p $SCRATCH/RNASeq/data/raw
mkdir -p $SCRATCH/RNASeq/scripts
mkdir -p $SCRATCH/RNASeq/results/qc

# Primary QC
#

############################################################################################
### Variables, need to be updated according to actual path to the input and output folder 

# DONT FORGET WE ARE AT A DIFFERENT MACHINE, hence need to put a complete path (please, dont forget to change the username)
INPUT_DIR=/storage/brno2/home/${USERNAME}/E5444/RNASeq/data/raw

APPENDIX="fastq.gz"

THREADS=$PBS_NUM_PPN # we will do the analysis on all the available processors
# how many processors we have?
echo $THREADS


# The analysis requires FastQC and multiQC
module add fastqc

module add python27-modules-gcc #adding multiQC tool


############################################################################################

#enter the scratch
# cd $SCRATCH/


### Copy inputs to the scratch so that we can work there
# cp $INPUT_DIR/*$APPENDIX RNASeq/data/raw/

# ls RNASeq/data/raw/

############################################################################################
### FastQC QC

mkdir -p RNASeq/results/qc/fastqc/raw

#run quality control on raw reads
fastqc -t $THREADS -f fastq -o RNASeq/results/qc/fastqc/raw RNASeq/data/raw/*$APPENDIX
multiqc -o RNASeq/results/qc/fastqc/raw RNASeq/results/qc/fastqc/raw/


############################################################################################
### Copy results

# cp -r RNASeq/results/ /storage/brno2/home/$USERNAME/RNASeq/
# rm -r $SCRATCH/*

# and logout from the machine

exit
