# Print commands to standard output.
set -uex

# The R code in this recipe assumes
# that the Deseq1, Deseq2 and edgeR methods have been
# installed with Bioconductor.

# Obtain the three data analysis scripts.
wget -q -nc http://data.biostarhandbook.com/rnaseq/code/deseq1.r
wget -q -nc http://data.biostarhandbook.com/rnaseq/code/deseq2.r
wget -q -nc http://data.biostarhandbook.com/rnaseq/code/edger.r

# Get the RNA-Seq count table as input data.
wget -q -nc http://data.biostarhandbook.com/rnaseq/code/counts.txt

# Analyze the counts with DESeq1.
cat counts.txt | Rscript deseq1.r 3x3 > results_deseq1.txt 2>> log.txt

# Analyze the counts with DESeq2.
cat counts.txt | Rscript deseq2.r 3x3 > results_deseq2.txt  2>> log.txt

# Analyze the counts with EdgeR.
cat counts.txt | Rscript edger.r 3x3 > results_edger.txt  2>> log.txt

# Download the script to draw the heatmaps (requires the glplots package).
wget -q -nc http://data.biostarhandbook.com/rnaseq/code/draw-heatmap.r

# Generate heatmap from the deseq1 normalized matrix.
cat norm-matrix-deseq1.txt | Rscript draw-heatmap.r > heatmap-norm-matrix-deseq1.pdf  2>> log.txt

# Generate heatmap from the deseq2 normalized matrix.
cat norm-matrix-deseq2.txt | Rscript draw-heatmap.r > heatmap-norm-matrix-deseq2.pdf  2>> log.txt

# Generate heatmap from the edgeR normalized matrix.
cat norm-matrix-edgeR.txt | Rscript draw-heatmap.r > heatmap-norm-matrix-edgeR.pdf  2>> log.txt