###############################
#Step I: Make reference genome 
#Run cell ranger with the output of this script 
#The library will be aligned to both the sgRNAs and the transcriptome 

#############################
#Step Ia:sgRNA oligo sequence 
#############################
#get .csv file with the following columns 
sgRNA_Name,Gene,Sequence,Oligo 

#############################################################
#Step Ib: Builds a custom reference FASTA and GTF for CROP-seq
##############################################################
#Use buildReference.py to generate custom CROP-seq reference files for the sgRNA library and CROP-seq backbone.

#expected inputs: 
-i guides.csv #from step Ia with sgRNA names and sequences
-c cropseq_components.csv  #CROP-seq backbone and component sequences.
-o  cropseq_components #defines the output basename

#command 
python buildReference.py \
  -i guides.csv \
  -c cropseq_components.csv \
  -o cropseq_components

##############################################
#Step Ic: Concatenate FASTA and GTF with mm10 
##############################################

cat ~/path/to/mm10.fa cropseq_components.fa > file_name_with_cropseq.fa
cat ~/path/to/mm10.refGene.gtf cropseq_components.gtf > file_name_with_cropseq.gtf

#####################################################
#Step Id: Make cellranger reference by submitting job
#####################################################

#Create a SLURM submission script called mkref_cropseq.sh.
#!/bin/bash
#SBATCH --job-name=mkref # Job name
#SBATCH --mail-type=ALL # Mail events (NONE, BEGIN, END, FAIL, ALL)
#SBATCH --mail-user=Ayushi.Patel@nyulangone.org # Where to send mail
#SBATCH --nodes=1 # Run on a single node
#SBATCH --cpus-per-task=16
#SBATCH --mem=32gb # Job memory request
#SBATCH --time=048:00:00 # Time limit hrs:min:sec
#SBATCH --output=mkref%j.log # Standard output and error log
#SBATCH -p cpu_short # Specifies location to submit job

module load cellranger/6.0.1

cellranger mkref --genome=mm10_cropseq --fasta=file_name_with_cropseq.fa --genes=file_name_with_cropseq.gtf|| exit 1
#################################################
