#!/bin/bash
#
# Prepare STAR alignment index
#
# Requires STAR
#
############################################################################################
qsub -l walltime=6:0:0 -q default -l select=1:ncpus=12:mem=100gb:scratch_local=20gb -I

### Variables
USERNAME="bartonv"
GENOME=/storage/brno2/home/${USERNAME}/RNASeq/data/GCF_000001405.40_GRCh38.p14_genomic.fna
GTF=/storage/brno2/home/${USERNAME}/RNASeq/data/genomic.gtf


INDEX_OUTPUT_DIR=/storage/brno2/home/$USERNAME/RNASeq/results/STAR_index # Where you want to copy created index?
THREADS=$PBS_NUM_PPN # Number of threads to use

# Read length for sjdbOverhang; --sjdbOverhang 100 should work fine for most of the data, but more specific setting based on the real read length should be more sensitive https://groups.google.com/forum/#!msg/rna-star/h9oh10UlvhI/BfSPGivUHmsJ

RD_LENGTH=75 # Read length from the sequencing. Illumina sometimes reports N+1 http://seqanswers.com/forums/archive/index.php/t-31154.html; 

# Binaries
module add star


############################################################################################
### Indexing - RUN ONLY ONCE FOR ONE GENOME AND STAR VERSION AND READ LENGTH 
mkdir -p $INDEX_OUTPUT_DIR

STAR \
	--runMode genomeGenerate \
	--runThreadN $THREADS \
	--genomeDir $INDEX_OUTPUT_DIR \
	--genomeFastaFiles $GENOME \
	--sjdbGTFfile $GTF \
	--sjdbOverhang $RD_LENGTH # --sjdbOverhang 100 should work fine for most of the data, but more specific setting based on the real read length should be more sensitive
