#!/bin/bash
#PBS -N 06_feature_counts
#PBS -l select=1:ncpus=12:mem=150gb:scratch_local=40gb
#PBS -l walltime=12:00:00 
#PBS -m ae
# The 4 lines above are options for scheduling system: job will run 1 hour at maximum, 1 machine with 4 processors + 4gb RAM memory + 10gb scratch memory are requested, email notification will be sent when the job aborts (a) or ends (e)

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


### Variables

USERNAME="bartonv"
cd /storage/brno2/home/${USERNAME}/
THREADS=$PBS_NUM_PPN
INPUT_DIR=/storage/brno2/home/${USERNAME}/RNASeq/data/mapped
OUTPUT_DIR=/storage/brno2/home/${USERNAME}/RNASeq/results/feature_counts
OUTPUT_DIR_QC=/storage/brno2/home/${USERNAME}/RNASeq/results/qc/feature_counts

mkdir -p $OUTPUT_DIR
mkdir -p $OUTPUT_DIR_QC

# Binaries
module add subread

####################################################################################################
### Genome and annotation preparation
GTF=/storage/brno2/home/${USERNAME}/RNASeq/data/genomic.gtf
COUNT_OVER="exon"

####################################################################################################
### feature counts
featureCounts \
    -t $COUNT_OVER \
    -g gene_id \
    -p -P \
    -C \
    -s 0 \
    -T $THREADS \
    -Q 0 -d 1 -D 25000 \
    -a $GTF \
    -o $OUTPUT_DIR/Unstranded.featureCounts \
    $INPUT_DIR/*.Aligned.sortedByCoord.out.bam

####################################################################################################
### multi QC

module unload subread
module add python27-modules-gcc # multiqc

multiqc -o $OUTPUT_DIR_QC $OUTPUT_DIR
