#!/bin/bash

# The bicycle command
alias bicycle="/path/to/bicycle/cmd/bicycle"

#
# Paths to the directories containing bowtie and samtools binaries
#
# Please, nothe that bicycle requires:
#  - bowtie 2.3.2 or higher .
#  - samtools 0.1.8 or higher
BOWTIE2="/path/to/bowtie-2.3.2"
SAMTOOLS="/path/to/samtools-0.1.8"

# Local data directory
DATA_DIR=`pwd`/"data-case-study"

# Download data
mkdir -p $DATA_DIR

cd $DATA_DIR

if [ ! -d "raw_data" ]; then
  wget http://static.sing-group.org/software/bicycle/data/case_study/raw_data.zip && unzip raw_data.zip && rm raw_data.zip
fi

if [ ! -d "referenceGenome" ]; then
  wget http://static.sing-group.org/software/bicycle/data/case_study/reference_genome.zip && unzip reference_genome.zip && rm reference_genome.zip
fi

if [ ! -f "target_regions.bed" ]; then
  wget http://static.sing-group.org/software/bicycle/data/case_study/target_regions.bed
fi

cd ..

# Declare the Docker data directories
REFERENCE_GENOME=$DATA_DIR"/referenceGenome"
TARGET_REGIONS=$DATA_DIR"/target_regions.bed"
SAMPLES_DIR=$DATA_DIR"/raw_data"
PROJECT_DIR=$DATA_DIR"/bicycle-case-study-project"

# Create a new bicycle project
bicycle create-project -p $PROJECT_DIR -r $REFERENCE_GENOME -f $SAMPLES_DIR -b2 $BOWTIE2 -s $SAMTOOLS --paired-mate1-regexp _1.fastq

# Reads alignment
bicycle align -p $PROJECT_DIR -t 4 --bowtie2-quals phred33 --bowtie2-I 0 --bowtie2-X 500

# Analyze methilation
bicycle analyze-methylation -p $PROJECT_DIR -t 4 -n 1 --remove-ambiguous --only-with-one-alignment -b $TARGET_REGIONS

# Analyze differnetial metilation 
bicycle analyze-differential-methylation -p $PROJECT_DIR  -c SRR2052487,SRR2052488,SRR2052489,SRR2052490,SRR2052491 -t SRR2052492,SRR2052493,SRR2052494,SRR2052495,SRR2052496 -b $TARGET_REGIONS
