main(){
    PYTHON_PATH=python3.4
    RSCRIPT_PATH=Rscript
    READEMPTION_PATH=../bin/reademption
    SEGEMEHL_PATH=../bin/segemehl.x
    LACK_PATH=../bin/lack.x
    FASTQ_TRIMMER_PATH=../bin/fastq_quality_trimmer
    FASTQ_TO_FASTA_PATH=../bin/fastq_to_fasta
    FASTQ_DUMP_PATH=../bin/fastq-dump

    SRA_FOLDER=Libs_as_SRA
    FASTQ_FOLDER=Libs_as_FASTQ
    READEMPTION_HUMAN_FOLDER=READemption_analysis_Human
    READEMPTION_PIG_FOLDER=READemption_analysis_Pig
    READEMPTION_MOUSE_FOLDER=READemption_analysis_Mouse

    ACCURACY=90
    MIN_MAPPING_LEN=20
    EDGER_SALMONELLA_FOLDER=edgeR_Salmonella
    PROCESSORS_MAPPING=40
    PROCESSORS_GENE_QUANTI=5
    PLOT_FOLDER=plots

    create_folders
    download_sra
    convert_to_fastq

    set_up_analysis_folder_human
    link_reference_sequences_human
    link_annotations_human
    convert_to_quality_trimmed_fasta_human
    run_read_alignment_human
    run_gene_quantification_human

    set_up_analysis_folder_pig
    link_reference_sequences_pig
    link_annotations_pig
    convert_to_quality_trimmed_fasta_pig
    run_read_alignment_pig
    run_gene_quantification_pig

    set_up_analysis_folder_mouse
    link_reference_sequences_mouse
    link_annotations_mouse
    convert_to_quality_trimmed_fasta_mouse
    run_read_alignment_mouse
    run_gene_quantification_mouse

    run_salmonella_edger
    plot_srna_kinetics
}

create_folders(){
    mkdir -p bin $SRA_FOLDER $FASTQ_FOLDER $EDGER_SALMONELLA_FOLDER \
	$PLOT_FOLDER
}

download_sra(){
    BASE_URL="ftp://ftp-trace.ncbi.nlm.nih.gov/sra/sra-instant/reads/ByExp/sra/SRX/"
    for LIB in \
	GSM1967278,SRX146/SRX1469627/SRR2980047/SRR2980047.sra,CaCo-2:WT:00_h:R1 \
	GSM1967280,SRX146/SRX1469629/SRR2980049/SRR2980049.sra,CaCo-2:WT:04_h:R1 \
	GSM1967282,SRX146/SRX1469631/SRR2980051/SRR2980051.sra,CaCo-2:WT:24_h:R1 \
	GSM1967279,SRX146/SRX1469628/SRR2980048/SRR2980048.sra,CaCo-2:WT:00_h:R2 \
	GSM1967281,SRX146/SRX1469630/SRR2980050/SRR2980050.sra,CaCo-2:WT:04_h:R2 \
	GSM1967283,SRX146/SRX1469632/SRR2980052/SRR2980052.sra,CaCo-2:WT:24_h:R2 \
	GSM1967290,SRX146/SRX1469639/SRR2980059/SRR2980059.sra,HT29:WT:00_h:R1 \
	GSM1967292,SRX146/SRX1469641/SRR2980061/SRR2980061.sra,HT29:WT:02_h:R1 \
	GSM1967294,SRX146/SRX1469643/SRR2980063/SRR2980063.sra,HT29:WT:20_h:R1 \
	GSM1967291,SRX146/SRX1469640/SRR2980060/SRR2980060.sra,HT29:WT:00_h:R2 \
	GSM1967293,SRX146/SRX1469642/SRR2980062/SRR2980062.sra,HT29:WT:02_h:R2 \
	GSM1967295,SRX146/SRX1469644/SRR2980064/SRR2980064.sra,HT29:WT:20_h:R2 \
	GSM1967264,SRX146/SRX1469613/SRR2980033/SRR2980033.sra,AGS:WT:00_h:R1 \
	GSM1967266,SRX146/SRX1469615/SRR2980035/SRR2980035.sra,AGS:WT:04_h:R1 \
	GSM1967268,SRX146/SRX1469617/SRR2980037/SRR2980037.sra,AGS:WT:24_h:R1 \
	GSM1967265,SRX146/SRX1469614/SRR2980034/SRR2980034.sra,AGS:WT:00_h:R2 \
	GSM1967267,SRX146/SRX1469616/SRR2980036/SRR2980036.sra,AGS:WT:04_h:R2 \
	GSM1967269,SRX146/SRX1469618/SRR2980038/SRR2980038.sra,AGS:WT:24_h:R2 \
	GSM1967326,SRX146/SRX1469675/SRR2980095/SRR2980095.sra,THP-1_without_PMA:WT:00_h:R1 \
	GSM1967328,SRX146/SRX1469677/SRR2980097/SRR2980097.sra,THP-1_without_PMA:WT:04_h:R1 \
	GSM1967330,SRX146/SRX1469679/SRR2980099/SRR2980099.sra,THP-1_without_PMA:WT:24_h:R1 \
	GSM1967327,SRX146/SRX1469676/SRR2980096/SRR2980096.sra,THP-1_without_PMA:WT:00_h:R2 \
	GSM1967329,SRX146/SRX1469678/SRR2980098/SRR2980098.sra,THP-1_without_PMA:WT:04_h:R2 \
	GSM1967331,SRX146/SRX1469680/SRR2980100/SRR2980100.sra,THP-1_without_PMA:WT:24_h:R2 \
	GSM1967332,SRX146/SRX1469681/SRR2980101/SRR2980101.sra,THP-1_with_PMA:WT:00_h:R1 \
	GSM1967334,SRX146/SRX1469683/SRR2980103/SRR2980103.sra,THP-1_with_PMA:WT:04_h:R1 \
	GSM1967336,SRX146/SRX1469685/SRR2980105/SRR2980105.sra,THP-1_with_PMA:WT:24_h:R1 \
	GSM1967333,SRX146/SRX1469682/SRR2980102/SRR2980102.sra,THP-1_with_PMA:WT:00_h:R2 \
	GSM1967335,SRX146/SRX1469684/SRR2980104/SRR2980104.sra,THP-1_with_PMA:WT:04_h:R2 \
	GSM1967337,SRX146/SRX1469686/SRR2980106/SRR2980106.sra,THP-1_with_PMA:WT:24_h:R2 \
	GSM1967308,SRX146/SRX1469657/SRR2980077/SRR2980077.sra,LoVo:WT:00_h:R1 \
	GSM1967310,SRX146/SRX1469659/SRR2980079/SRR2980079.sra,LoVo:WT:02_h:R1 \
	GSM1967312,SRX146/SRX1469661/SRR2980081/SRR2980081.sra,LoVo:WT:20_h:R1 \
	GSM1967309,SRX146/SRX1469658/SRR2980078/SRR2980078.sra,LoVo:WT:00_h:R2 \
	GSM1967311,SRX146/SRX1469660/SRR2980080/SRR2980080.sra,LoVo:WT:02_h:R2 \
	GSM1967313,SRX146/SRX1469662/SRR2980082/SRR2980082.sra,LoVo:WT:20_h:R2 \
	GSM1967284,SRX146/SRX1469633/SRR2980053/SRR2980053.sra,HEK:WT:00_h:R1 \
	GSM1967286,SRX146/SRX1469635/SRR2980055/SRR2980055.sra,HEK:WT:04_h:R1 \
	GSM1967288,SRX146/SRX1469637/SRR2980057/SRR2980057.sra,HEK:WT:24_h:R1 \
	GSM1967285,SRX146/SRX1469634/SRR2980054/SRR2980054.sra,HEK:WT:00_h:R2 \
	GSM1967287,SRX146/SRX1469636/SRR2980056/SRR2980056.sra,HEK:WT:04_h:R2 \
	GSM1967289,SRX146/SRX1469638/SRR2980058/SRR2980058.sra,HEK:WT:24_h:R2 \
	GSM1967270,SRX146/SRX1469619/SRR2980039/SRR2980039.sra,BMDM:WT:00_h:R1 \
	GSM1967272,SRX146/SRX1469621/SRR2980041/SRR2980041.sra,BMDM:WT:02_h:R1 \
	GSM1967274,SRX146/SRX1469623/SRR2980043/SRR2980043.sra,BMDM:WT:06_h:R1 \
	GSM1967276,SRX146/SRX1469625/SRR2980045/SRR2980045.sra,BMDM:WT:20_h:R1 \
	GSM1967271,SRX146/SRX1469620/SRR2980040/SRR2980040.sra,BMDM:WT:00_h:R2 \
	GSM1967273,SRX146/SRX1469622/SRR2980042/SRR2980042.sra,BMDM:WT:02_h:R2 \
	GSM1967275,SRX146/SRX1469624/SRR2980044/SRR2980044.sra,BMDM:WT:06_h:R2 \
	GSM1967277,SRX146/SRX1469626/SRR2980046/SRR2980046.sra,BMDM:WT:20_h:R2 \
	GSM1967320,SRX146/SRX1469669/SRR2980089/SRR2980089.sra,RAW264.7:WT:00_h:R1 \
	GSM1967322,SRX146/SRX1469671/SRR2980091/SRR2980091.sra,RAW264.7:WT:04_h:R1 \
	GSM1967324,SRX146/SRX1469673/SRR2980093/SRR2980093.sra,RAW264.7:WT:24_h:R1 \
	GSM1967321,SRX146/SRX1469670/SRR2980090/SRR2980090.sra,RAW264.7:WT:00_h:R2 \
	GSM1967323,SRX146/SRX1469672/SRR2980092/SRR2980092.sra,RAW264.7:WT:04_h:R2 \
	GSM1967325,SRX146/SRX1469674/SRR2980094/SRR2980094.sra,RAW264.7:WT:24_h:R2 \
	GSM1967302,SRX146/SRX1469651/SRR2980071/SRR2980071.sra,L929:WT:00_h:R1 \
	GSM1967304,SRX146/SRX1469653/SRR2980073/SRR2980073.sra,L929:WT:01_h:R1 \
	GSM1967306,SRX146/SRX1469655/SRR2980075/SRR2980075.sra,L929:WT:06_h:R1 \
	GSM1967303,SRX146/SRX1469652/SRR2980072/SRR2980072.sra,L929:WT:00_h:R2 \
	GSM1967305,SRX146/SRX1469654/SRR2980074/SRR2980074.sra,L929:WT:01_h:R2 \
	GSM1967307,SRX146/SRX1469656/SRR2980076/SRR2980076.sra,L929:WT:06_h:R2 \
	GSM1967314,SRX146/SRX1469663/SRR2980083/SRR2980083.sra,MEF:WT:00_h:R1 \
	GSM1967316,SRX146/SRX1469665/SRR2980085/SRR2980085.sra,MEF:WT:04_h:R1 \
	GSM1967318,SRX146/SRX1469667/SRR2980087/SRR2980087.sra,MEF:WT:20_h:R1 \
	GSM1967315,SRX146/SRX1469664/SRR2980084/SRR2980084.sra,MEF:WT:00_h:R2 \
	GSM1967317,SRX146/SRX1469666/SRR2980086/SRR2980086.sra,MEF:WT:04_h:R2 \
	GSM1967319,SRX146/SRX1469668/SRR2980088/SRR2980088.sra,MEF:WT:20_h:R2 \
	GSM1967296,SRX146/SRX1469645/SRR2980065/SRR2980065.sra,IPEC-J2:WT:00_h:R1 \
	GSM1967298,SRX146/SRX1469647/SRR2980067/SRR2980067.sra,IPEC-J2:WT:02_h:R1 \
	GSM1967300,SRX146/SRX1469649/SRR2980069/SRR2980069.sra,IPEC-J2:WT:20_h:R1 \
	GSM1967297,SRX146/SRX1469646/SRR2980066/SRR2980066.sra,IPEC-J2:WT:00_h:R2 \
	GSM1967299,SRX146/SRX1469648/SRR2980068/SRR2980068.sra,IPEC-J2:WT:02_h:R2 \
	GSM1967301,SRX146/SRX1469650/SRR2980070/SRR2980070.sra,IPEC-J2:WT:20_h:R2 \
	GSM1967249,SRX146/SRX1469598/SRR2980018/SRR2980018.sra,3D4_31:WT:00_h:R1 \
	GSM1967252,SRX146/SRX1469601/SRR2980021/SRR2980021.sra,3D4_31:WT:01_h:R1 \
	GSM1967255,SRX146/SRX1469604/SRR2980024/SRR2980024.sra,3D4_31:WT:02_h:R1 \
	GSM1967258,SRX146/SRX1469607/SRR2980027/SRR2980027.sra,3D4_31:WT:06_h:R1 \
	GSM1967261,SRX146/SRX1469610/SRR2980030/SRR2980030.sra,3D4_31:WT:16_h:R1 \
	GSM1967250,SRX146/SRX1469599/SRR2980019/SRR2980019.sra,3D4_31:WT:00_h:R2 \
	GSM1967253,SRX146/SRX1469602/SRR2980022/SRR2980022.sra,3D4_31:WT:01_h:R2 \
	GSM1967256,SRX146/SRX1469605/SRR2980025/SRR2980025.sra,3D4_31:WT:02_h:R2 \
	GSM1967259,SRX146/SRX1469608/SRR2980028/SRR2980028.sra,3D4_31:WT:06_h:R2 \
	GSM1967262,SRX146/SRX1469611/SRR2980031/SRR2980031.sra,3D4_31:WT:16_h:R2 \
	GSM1967251,SRX146/SRX1469600/SRR2980020/SRR2980020.sra,3D4_31:WT:00_h:R3 \
	GSM1967254,SRX146/SRX1469603/SRR2980023/SRR2980023.sra,3D4_31:WT:01_h:R3 \
	GSM1967257,SRX146/SRX1469606/SRR2980026/SRR2980026.sra,3D4_31:WT:02_h:R3 \
	GSM1967260,SRX146/SRX1469609/SRR2980029/SRR2980029.sra,3D4_31:WT:06_h:R3 \
	GSM1967263,SRX146/SRX1469612/SRR2980032/SRR2980032.sra,3D4_31:WT:16_h:R3
    do
	GEO_ACCESSION=$(echo $LIB | cut -f 1 -d",")
	FILE_PATH=$(echo $LIB | cut -f 2 -d",")
	LIB_NAME=$(echo $LIB | cut -f 3 -d",")

	wget \
	    -O $SRA_FOLDER/${GEO_ACCESSION}_${LIB_NAME}.sra \
	    -c \
	    ${BASE_URL}/${FILE_PATH}
    done
}

convert_to_fastq(){
    for SRA_FILE in $(ls $SRA_FOLDER)
    do
	COMPRESSED_FASTQ_FILE=$(echo $SRA_FILE \
	    | sed -e "s/GSM......._//" -e "s/.sra/.fq.bz2/")
	$FASTQ_DUMP_PATH \
	    --stdout \
	    $SRA_FOLDER/$SRA_FILE \
	    | bzip2 \
	    --stdout - \
	    > ${FASTQ_FOLDER}/$COMPRESSED_FASTQ_FILE &
    done
    wait
}

convert_sra_to_fastq(){
    echo "The SRA files are not yet accessible on GEO. This function will be replaced."
}

set_up_analysis_folder_human(){
    $PYTHON_PATH $READEMPTION_PATH create $READEMPTION_HUMAN_FOLDER
}

convert_to_quality_trimmed_fasta_human(){
    for FASTQ_FILE in \
	AGS:WT:00_h:R1.fq.bz2 \
	AGS:WT:00_h:R2.fq.bz2 \
	AGS:WT:04_h:R1.fq.bz2 \
	AGS:WT:04_h:R2.fq.bz2 \
	AGS:WT:24_h:R1.fq.bz2 \
	AGS:WT:24_h:R2.fq.bz2 \
	CaCo-2:WT:00_h:R1.fq.bz2 \
	CaCo-2:WT:00_h:R2.fq.bz2 \
	CaCo-2:WT:04_h:R1.fq.bz2 \
	CaCo-2:WT:04_h:R2.fq.bz2 \
	CaCo-2:WT:24_h:R1.fq.bz2 \
	CaCo-2:WT:24_h:R2.fq.bz2 \
	HEK:WT:00_h:R1.fq.bz2 \
	HEK:WT:00_h:R2.fq.bz2 \
	HEK:WT:04_h:R1.fq.bz2 \
	HEK:WT:04_h:R2.fq.bz2 \
	HEK:WT:24_h:R1.fq.bz2 \
	HEK:WT:24_h:R2.fq.bz2 \
	HT29:WT:00_h:R1.fq.bz2 \
	HT29:WT:00_h:R2.fq.bz2 \
	HT29:WT:02_h:R1.fq.bz2 \
	HT29:WT:02_h:R2.fq.bz2 \
	HT29:WT:20_h:R1.fq.bz2 \
	HT29:WT:20_h:R2.fq.bz2 \
	LoVo:WT:00_h:R1.fq.bz2 \
	LoVo:WT:00_h:R2.fq.bz2 \
	LoVo:WT:02_h:R1.fq.bz2 \
	LoVo:WT:02_h:R2.fq.bz2 \
	LoVo:WT:20_h:R1.fq.bz2 \
	LoVo:WT:20_h:R2.fq.bz2 \
	THP-1_without_PMA:WT:00_h:R1.fq.bz2 \
	THP-1_without_PMA:WT:00_h:R2.fq.bz2 \
	THP-1_without_PMA:WT:04_h:R1.fq.bz2 \
	THP-1_without_PMA:WT:04_h:R2.fq.bz2 \
	THP-1_without_PMA:WT:24_h:R1.fq.bz2 \
	THP-1_without_PMA:WT:24_h:R2.fq.bz2 \
	THP-1_with_PMA:WT:00_h:R1.fq.bz2 \
	THP-1_with_PMA:WT:00_h:R2.fq.bz2 \
	THP-1_with_PMA:WT:04_h:R1.fq.bz2 \
	THP-1_with_PMA:WT:04_h:R2.fq.bz2 \
	THP-1_with_PMA:WT:24_h:R1.fq.bz2 \
	THP-1_with_PMA:WT:24_h:R2.fq.bz2
    do
	FASTA_FILE=$(echo $FASTQ_FILE | sed "s/.fq.bz2/.fa.bz2/")
	bunzip2 --stdout $FASTQ_FOLDER/$FASTQ_FILE \
	    | $FASTQ_TRIMMER_PATH -t 20 -Q33 -l 1 \
	    | $FASTQ_TO_FASTA_PATH -Q33 \
	    | bzip2 --stdout - > $READEMPTION_HUMAN_FOLDER/input/reads/$FASTA_FILE &
    done
    wait
}

link_reference_sequences_human(){
    ln -s ../../../../reference_sequences_and_annotations/output/hs37d5.fa \
	$READEMPTION_HUMAN_FOLDER/input/reference_sequences/
    ln -s ../../../../reference_sequences_and_annotations/output/NC_016810.fa \
	$READEMPTION_HUMAN_FOLDER/input/reference_sequences/
    ln -s ../../../../reference_sequences_and_annotations/output/NC_017718.fa \
	$READEMPTION_HUMAN_FOLDER/input/reference_sequences/
    ln -s ../../../../reference_sequences_and_annotations/output/NC_017719.fa \
	$READEMPTION_HUMAN_FOLDER/input/reference_sequences/
    ln -s ../../../../reference_sequences_and_annotations/output/NC_017720.fa \
	$READEMPTION_HUMAN_FOLDER/input/reference_sequences/
}

link_annotations_human(){
    # Quantification is only required for Salmonella
    ln -s ../../../../reference_sequences_and_annotations/output/Salmonella.gff \
	$READEMPTION_HUMAN_FOLDER/input/annotations/
}

run_read_alignment_human(){
    HUMAN_SEQ_ID_STRING=$(grep ">" $READEMPTION_HUMAN_FOLDER/input/reference_sequences/hs37d5.fa \
	| cut -f 1 -d" " | sed "s/>//" | tr "\n" "," | sed "s/,$//")
    CROSSMAPPING_PARAMETERS="-x Salmonella:NC_016810.1,NC_017718.1,NC_017719.1,NC_017720.1;Human:$HUMAN_SEQ_ID_STRING"
    
    $PYTHON_PATH $READEMPTION_PATH \
        align \
    	--split \
    	-r \
        -p ${PROCESSORS_MAPPING} \
        -a $ACCURACY \
        -l $MIN_MAPPING_LEN \
    	--poly_a_clipping \
    	--progress \
    	$CROSSMAPPING_PARAMETERS \
        $READEMPTION_HUMAN_FOLDER
}

run_gene_quantification_human(){
    $PYTHON_PATH $READEMPTION_PATH \
        gene_quanti \
        -p ${PROCESSORS_GENE_QUANTI} \
    	--unique_only \
    	--no_count_splitting_by_gene_no \
    	--no_count_split_by_alignment_no \
        $READEMPTION_HUMAN_FOLDER
}

set_up_analysis_folder_pig(){
    $PYTHON_PATH $READEMPTION_PATH create $READEMPTION_PIG_FOLDER
}

convert_to_quality_trimmed_fasta_pig(){
    # The following additional samples are taken from data set
    # 05-Comparative_Dual_RNA-seq_in_pig_macrophages:
    # - 3D4_31:WT:06_h:R2
    # - 3D4_31:WT:06_h:R1
    for FASTQ_FILE in \
	3D4_31:WT:00_h:R1.fq.bz2 \
	3D4_31:WT:00_h:R2.fq.bz2 \
	3D4_31:WT:00_h:R3.fq.bz2 \
	3D4_31:WT:01_h:R1.fq.bz2 \
	3D4_31:WT:01_h:R2.fq.bz2 \
	3D4_31:WT:01_h:R3.fq.bz2 \
	3D4_31:WT:02_h:R1.fq.bz2 \
	3D4_31:WT:02_h:R2.fq.bz2 \
	3D4_31:WT:02_h:R3.fq.bz2 \
	3D4_31:WT:06_h:R1.fq.bz2 \
	3D4_31:WT:06_h:R2.fq.bz2 \
	3D4_31:WT:06_h:R3.fq.bz2 \
	3D4_31:WT:16_h:R1.fq.bz2 \
	3D4_31:WT:16_h:R2.fq.bz2 \
	3D4_31:WT:16_h:R3.fq.bz2 \
	IPEC-J2:WT:00_h:R1.fq.bz2 \
	IPEC-J2:WT:00_h:R2.fq.bz2 \
	IPEC-J2:WT:02_h:R1.fq.bz2 \
	IPEC-J2:WT:02_h:R2.fq.bz2 \
	IPEC-J2:WT:20_h:R1.fq.bz2 \
	IPEC-J2:WT:20_h:R2.fq.bz2 
    do
	FASTA_FILE=$(echo $FASTQ_FILE | sed "s/.fq.bz2/.fa.bz2/")
	bunzip2 --stdout $FASTQ_FOLDER/$FASTQ_FILE \
	    | $FASTQ_TRIMMER_PATH -t 20 -Q33 -l 1 \
	    | $FASTQ_TO_FASTA_PATH -Q33 \
	    | bzip2 --stdout - > $READEMPTION_PIG_FOLDER/input/reads/$FASTA_FILE &
    done
    wait
}

link_reference_sequences_pig(){
    ln -s ../../../../reference_sequences_and_annotations/output/Pig.fa \
	$READEMPTION_PIG_FOLDER/input/reference_sequences/
    ln -s ../../../../reference_sequences_and_annotations/output/NC_016810.fa \
	$READEMPTION_PIG_FOLDER/input/reference_sequences/
    ln -s ../../../../reference_sequences_and_annotations/output/NC_017718.fa \
	$READEMPTION_PIG_FOLDER/input/reference_sequences/
    ln -s ../../../../reference_sequences_and_annotations/output/NC_017719.fa \
	$READEMPTION_PIG_FOLDER/input/reference_sequences/
    ln -s ../../../../reference_sequences_and_annotations/output/NC_017720.fa \
	$READEMPTION_PIG_FOLDER/input/reference_sequences/
}

link_annotations_pig(){
    # Quantification is only required for Salmonella
    ln -s ../../../../reference_sequences_and_annotations/output/Salmonella.gff \
	$READEMPTION_PIG_FOLDER/input/annotations/
}

run_read_alignment_pig(){
    PIG_SEQ_ID_STRING=$(grep ">" $READEMPTION_PIG_FOLDER/input/reference_sequences/Pig.fa \
	| cut -f 1 -d" " | sed "s/>//" | tr "\n" "," | sed "s/,$//")
    CROSSMAPPING_PARAMETERS="-x Salmonella:NC_016810.1,NC_017718.1,NC_017719.1,NC_017720.1;Pig:$PIG_SEQ_ID_STRING"

    $PYTHON_PATH $READEMPTION_PATH \
        align \
    	--split \
    	-r \
        -p ${PROCESSORS_MAPPING} \
        -a $ACCURACY \
        -l $MIN_MAPPING_LEN \
    	--poly_a_clipping \
    	--progress \
    	$CROSSMAPPING_PARAMETERS \
        $READEMPTION_PIG_FOLDER
}

run_gene_quantification_pig(){
    $PYTHON_PATH $READEMPTION_PATH \
        gene_quanti \
        -p ${PROCESSORS_GENE_QUANTI} \
    	--unique_only \
    	--no_count_splitting_by_gene_no \
    	--no_count_split_by_alignment_no \
        $READEMPTION_PIG_FOLDER
}

set_up_analysis_folder_mouse(){
    $PYTHON_PATH $READEMPTION_PATH create $READEMPTION_MOUSE_FOLDER
}

convert_to_quality_trimmed_fasta_mouse(){
    for FASTQ_FILE in \
	BMDM:WT:00_h:R1.fq.bz2 \
	BMDM:WT:00_h:R2.fq.bz2 \
	BMDM:WT:02_h:R1.fq.bz2 \
	BMDM:WT:02_h:R2.fq.bz2 \
	BMDM:WT:06_h:R1.fq.bz2 \
	BMDM:WT:06_h:R2.fq.bz2 \
	BMDM:WT:20_h:R1.fq.bz2 \
	BMDM:WT:20_h:R2.fq.bz2 \
	L929:WT:00_h:R1.fq.bz2 \
	L929:WT:00_h:R2.fq.bz2 \
	L929:WT:01_h:R1.fq.bz2 \
	L929:WT:01_h:R2.fq.bz2 \
	L929:WT:06_h:R1.fq.bz2 \
	L929:WT:06_h:R2.fq.bz2 \
	MEF:WT:00_h:R1.fq.bz2 \
	MEF:WT:00_h:R2.fq.bz2 \
	MEF:WT:04_h:R1.fq.bz2 \
	MEF:WT:04_h:R2.fq.bz2 \
	MEF:WT:20_h:R1.fq.bz2 \
	MEF:WT:20_h:R2.fq.bz2 \
	RAW264.7:WT:00_h:R1.fq.bz2 \
	RAW264.7:WT:00_h:R2.fq.bz2 \
	RAW264.7:WT:04_h:R1.fq.bz2 \
	RAW264.7:WT:04_h:R2.fq.bz2 \
	RAW264.7:WT:24_h:R1.fq.bz2 \
	RAW264.7:WT:24_h:R2.fq.bz2
    do
	FASTA_FILE=$(echo $FASTQ_FILE | sed "s/.fq.bz2/.fa.bz2/")
	bunzip2 --stdout $FASTQ_FOLDER/$FASTQ_FILE \
	    | $FASTQ_TRIMMER_PATH -t 20 -Q33 -l 1 \
	    | $FASTQ_TO_FASTA_PATH -Q33 \
	    | bzip2 --stdout - > $READEMPTION_MOUSE_FOLDER/input/reads/$FASTA_FILE &
    done
    wait
}

link_reference_sequences_mouse(){
    ln -s ../../../../reference_sequences_and_annotations/output/Mouse.fa \
	$READEMPTION_MOUSE_FOLDER/input/reference_sequences/
    ln -s ../../../../reference_sequences_and_annotations/output/NC_016810.fa \
	$READEMPTION_MOUSE_FOLDER/input/reference_sequences/
    ln -s ../../../../reference_sequences_and_annotations/output/NC_017718.fa \
	$READEMPTION_MOUSE_FOLDER/input/reference_sequences/
    ln -s ../../../../reference_sequences_and_annotations/output/NC_017719.fa \
	$READEMPTION_MOUSE_FOLDER/input/reference_sequences/
    ln -s ../../../../reference_sequences_and_annotations/output/NC_017720.fa \
	$READEMPTION_MOUSE_FOLDER/input/reference_sequences/
}

link_annotations_mouse(){
    # Quantification is only required for Salmonella
    ln -s ../../../../reference_sequences_and_annotations/output/Salmonella.gff \
	$READEMPTION_MOUSE_FOLDER/input/annotations/
}

run_read_alignment_mouse(){
    MOUSE_SEQ_ID_STRING=$(grep ">" $READEMPTION_MOUSE_FOLDER/input/reference_sequences/Mouse.fa \
	| cut -f 1 -d" " | sed "s/>//" | tr "\n" "," | sed "s/,$//")
    CROSSMAPPING_PARAMETERS="-x Salmonella:NC_016810.1,NC_017718.1,NC_017719.1,NC_017720.1;Mouse:$MOUSE_SEQ_ID_STRING"

    $PYTHON_PATH $READEMPTION_PATH \
        align \
    	--split \
    	-r \
        -p ${PROCESSORS_MAPPING} \
        -a $ACCURACY \
        -l $MIN_MAPPING_LEN \
    	--poly_a_clipping \
    	--progress \
    	$CROSSMAPPING_PARAMETERS \
        $READEMPTION_MOUSE_FOLDER
}

run_gene_quantification_mouse(){
    $PYTHON_PATH $READEMPTION_PATH \
        gene_quanti \
        -p ${PROCESSORS_GENE_QUANTI} \
    	--unique_only \
    	--no_count_splitting_by_gene_no \
    	--no_count_split_by_alignment_no \
        $READEMPTION_MOUSE_FOLDER
}

run_salmonella_edger(){
    # Extract gene names and locus tag colums
    grep -Pv "\trRNA\t|\ttRNA\t" ../reference_sequences_and_annotations/output/Salmonella.csv \
    	| cut -f 10,11 \
    	> tmp_names_and_locus_tags

    GENE_QUANTI_SUBPATH=output/gene_quanti/gene_quanti_combined/gene_wise_quantifications_combined.csv
    paste \
    	$READEMPTION_HUMAN_FOLDER/$GENE_QUANTI_SUBPATH \
    	$READEMPTION_MOUSE_FOLDER/$GENE_QUANTI_SUBPATH \
    	$READEMPTION_PIG_FOLDER/$GENE_QUANTI_SUBPATH \
    	tmp_names_and_locus_tags  \
    	| grep -P "^Orienta|\tNC_01"  \
    	| grep -v "^anti-sense" \
    	| grep -Pv "\trRNA\t|\ttRNA\t" \
    	| cut -f 1-52,63-88,99- \
    	> $EDGER_SALMONELLA_FOLDER/Salmonella_gene_wise_read_countings.csv
    rm tmp_names_and_locus_tags

    $RSCRIPT_PATH bin/edgeR_Salmonella.R \
    	$EDGER_SALMONELLA_FOLDER/Salmonella_gene_wise_read_countings.csv \
    	$EDGER_SALMONELLA_FOLDER
}

plot_srna_kinetics(){
    $PYTHON_PATH \
	../bin/plot_srna_kinetics.py \
	--output_pdf $PLOT_FOLDER/sRNA_kinetics_AGS_time_course.pdf \
	--mark_only_pinT \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-AGS_WT_04_h_vs_AGS_WT_00_h.csv \
    $EDGER_SALMONELLA_FOLDER/edgeR-comparison-AGS_WT_24_h_vs_AGS_WT_00_h.csv
	
    $PYTHON_PATH \
	../bin/plot_srna_kinetics.py \
	--output_pdf $PLOT_FOLDER/sRNA_kinetics_BMDM_time_course.pdf \
	--mark_only_pinT \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-BMDM_WT_02_h_vs_BMDM_WT_00_h.csv \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-BMDM_WT_06_h_vs_BMDM_WT_00_h.csv \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-BMDM_WT_20_h_vs_BMDM_WT_00_h.csv \

    $PYTHON_PATH \
	../bin/plot_srna_kinetics.py \
	--output_pdf $PLOT_FOLDER/sRNA_kinetics_CaCo-2_time_course.pdf \
	--mark_only_pinT \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-CaCo_2_WT_04_h_vs_CaCo_2_WT_00_h.csv \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-CaCo_2_WT_24_h_vs_CaCo_2_WT_00_h.csv

    $PYTHON_PATH \
	../bin/plot_srna_kinetics.py \
	--output_pdf $PLOT_FOLDER/sRNA_kinetics_HEK_time_course.pdf \
	--mark_only_pinT \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-HEK_WT_04_h_vs_HEK_WT_00_h.csv \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-HEK_WT_24_h_vs_HEK_WT_00_h.csv

    $PYTHON_PATH \
	../bin/plot_srna_kinetics.py \
	--output_pdf $PLOT_FOLDER/sRNA_kinetics_HT29_time_course.pdf \
	--mark_only_pinT \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-HT29_WT_02_h_vs_HT29_WT_00_h.csv \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-HT29_WT_20_h_vs_HT29_WT_00_h.csv

    $PYTHON_PATH \
	../bin/plot_srna_kinetics.py \
	--output_pdf $PLOT_FOLDER/sRNA_kinetics_IPEC-J2_time_course.pdf \
	--mark_only_pinT \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-IPEC.J2_WT_02_h_vs_IPEC.J2_WT_00_h.csv \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-IPEC.J2_WT_20_h_vs_IPEC.J2_WT_00_h.csv

    $PYTHON_PATH \
	../bin/plot_srna_kinetics.py \
	--output_pdf $PLOT_FOLDER/sRNA_kinetics_L929_time_course.pdf \
	--mark_only_pinT \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-L929_WT_01_h_vs_L929_WT_00_h.csv \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-L929_WT_06_h_vs_L929_WT_00_h.csv

    $PYTHON_PATH \
	../bin/plot_srna_kinetics.py \
	--output_pdf $PLOT_FOLDER/sRNA_kinetics_LoVo_time_course.pdf \
	--mark_only_pinT \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-LoVo_WT_02_h_vs_LoVo_WT_00_h.csv \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-LoVo_WT_20_h_vs_LoVo_WT_00_h.csv

    $PYTHON_PATH \
	../bin/plot_srna_kinetics.py \
	--output_pdf $PLOT_FOLDER/sRNA_kinetics_MEF_time_course.pdf \
	--mark_only_pinT \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-MEF_WT_04_h_vs_MEF_WT_00_h.csv \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-MEF_WT_20_h_vs_MEF_WT_00_h.csv

    $PYTHON_PATH \
	../bin/plot_srna_kinetics.py \
	--output_pdf $PLOT_FOLDER/sRNA_kinetics_RAW264.7_time_course.pdf \
	--mark_only_pinT \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-RAW264.7_WT_04_h_vs_RAW264.7_WT_00_h.csv \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-RAW264.7_WT_24_h_vs_RAW264.7_WT_00_h.csv

    $PYTHON_PATH \
	../bin/plot_srna_kinetics.py \
	--output_pdf $PLOT_FOLDER/sRNA_kinetics_THP-1_time_course.pdf \
	--mark_only_pinT \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-THP.1_without_PMA_WT_04_h_vs_THP.1_without_PMA_WT_00_h.csv \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-THP.1_without_PMA_WT_24_h_vs_THP.1_without_PMA_WT_00_h.csv \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-THP.1_with_PMA_WT_04_h_vs_THP.1_with_PMA_WT_00_h.csv \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-THP.1_with_PMA_WT_24_h_vs_THP.1_with_PMA_WT_00_h.csv

    $PYTHON_PATH \
	../bin/plot_srna_kinetics.py \
	--output_pdf $PLOT_FOLDER/sRNA_kinetics_3D4-31_time_course.pdf \
	--mark_only_pinT \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-X3D4_31_WT_01_h_vs_X3D4_31_WT_00_h.csv \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-X3D4_31_WT_02_h_vs_X3D4_31_WT_00_h.csv \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-X3D4_31_WT_06_h_vs_X3D4_31_WT_00_h.csv \
	$EDGER_SALMONELLA_FOLDER/edgeR-comparison-X3D4_31_WT_16_h_vs_X3D4_31_WT_00_h.csv
}

main
