##################################################
#
# README wublast
#
# This README runs as a shell script.
# Here you can find the commands
# we used to produce all the figures for:
#
#   "WU-BLAST Analysis of two Homologous Genes"
# 
# USAGE: bash README > .log 2>&1
#
# $Id: README,v 1.1 2003/03/04 18:55:02 jabril Exp $
#
##################################################

#
# Original Files
#
# ANNOTATION: taf6.hs.gene.gff  taf6.mm.gene.gff
# ALIGNMENT:  taf6.mmhs.genomic.blastn  taf6.mmhs.genomic.tblastx
#

#
echo "#  -> Running parseblast: BLAST -> GFF" ;
#
$BIN/parseblast.pl --verbose --no-frame --aplot             \
                   -- taf6.mmhs.genomic.blastn              \
                    > taf6.mmhs.genomic.blastn.aplot.gff    \
                   2> taf6.mmhs.genomic.blastn.aplotgff.log ;
#
$BIN/parseblast.pl --verbose --no-frame            \
                   --fullgff --compact-tags        \
                   -- taf6.mmhs.genomic.blastn     \
                    > taf6.mmhs.genomic.blastn.gff \
                   2> taf6.mmhs.genomic.blastn.log ;
#
$BIN/parseblast.pl --verbose --no-frame --fullgff       \
                   -- taf6.mmhs.genomic.blastn          \
                    > taf6.mmhs.genomic.blastn.full.gff \
                   2> taf6.mmhs.genomic.blastn.full.log ;
#
$BIN/parseblast.pl --verbose --no-frame --aplot              \
                   -- taf6.mmhs.genomic.tblastx              \
                    > taf6.mmhs.genomic.tblastx.aplot.gff    \
                   2> taf6.mmhs.genomic.tblastx.aplotgff.log ;
#
$BIN/parseblast.pl --verbose --no-frame --fullgff   \
                   -- taf6.mmhs.genomic.tblastx     \
                    > taf6.mmhs.genomic.tblastx.gff \
                   2> taf6.mmhs.genomic.tblastx.log ;

#
echo "#  -> Running gff2aplot: GFF -> PS" ;
#
$BIN/gff2aplot.pl                   \
    --verbose                       \
    -- taf6.mmhs.genomic.blastn.gff \
       taf6.mm.gene.gff             \
       taf6.hs.gene.gff             \
     > taf6.mmhs.genomic.blastn.ps  \
    2> taf6.mmhs.genomic.blastn.log ;
#
$BIN/gff2aplot.pl                         \
    --verbose                             \
    -- taf6.mmhs.genomic.blastn.aplot.gff \
       taf6.mm.gene.gff                   \
       taf6.hs.gene.gff                   \
     > taf6.mmhs.genomic.blastn.aplot.ps  \
    2> taf6.mmhs.genomic.blastn.aplot.log ;
#
$BIN/gff2aplot.pl                    \
    --verbose                        \
    --show-percent-box               \
    -- taf6.mmhs.genomic.tblastx.gff \
       taf6.mm.gene.gff              \
       taf6.hs.gene.gff              \
     > taf6.mmhs.genomic.tblastx.ps  \
    2> taf6.mmhs.genomic.tblastx.log ;
#
$BIN/gff2aplot.pl                          \
    --verbose                              \
    --show-percent-box                     \
    -- taf6.mmhs.genomic.tblastx.aplot.gff \
       taf6.mm.gene.gff                    \
       taf6.hs.gene.gff                    \
     > taf6.mmhs.genomic.tblastx.aplot.ps  \
    2> taf6.mmhs.genomic.tblastx.aplot.log ;

# Extra customization
cat > taf6.tblastx.rc <<'+++EOF+++'
#
# L #
percent_box_label=SIMILARITY
percent_box_label_fontsize=10pt
percent_box_score_range=0..1000
major_tickmark_score=250
ribbon_color_merge=on
color_merge_factor=2
# group_y_label_angle=315
#
# G #
/.*M.musculus.*/::group_label=taf6 (M.musculus)
/.*H.sapiens.*/::group_label=taf6 (H.sapiens)
#
# F #
/[it].*exon/::feature_color=darkred
utrexon::feature_color=lightgrey
initialexon::feature_shape=half_arrow_end
terminalexon::feature_shape=half_arrow
/.*exon/::show_ribbons=on
/.*exon/::ribbon_style=ribbons
/[it].*exon/::ribbon_color=verylightred
utrexon::ribbon_color=verylightgrey
+++EOF+++
#
echo "#  -> Running gff2aplot + customization" ;
#
$BIN/gff2aplot.pl                              \
    --verbose                                  \
    --title 'Hsap/Mmus taf6 Orthologous Gene'  \
    --subtitle 'Figure displays BLASTN results for this genomic region.' \
    --show-percent-box                         \
    --custom-filename taf6.tblastx.rc          \
    -- taf6.mmhs.genomic.blastn.aplot.gff      \
       taf6.mm.gene.gff                        \
       taf6.hs.gene.gff                        \
     > taf6.mmhs.genomic.blastn.aplot_conf.ps  \
    2> taf6.mmhs.genomic.blastn.aplot_conf.log ;
#
$BIN/gff2aplot.pl                               \
    --verbose                                   \
    --title 'Hsap/Mmus taf6 Orthologous Gene'   \
    --subtitle 'Figure displays TBLASTX results for this genomic region.' \
    --show-percent-box                          \
    --custom-filename taf6.tblastx.rc           \
    -- taf6.mmhs.genomic.tblastx.aplot.gff      \
       taf6.mm.gene.gff                         \
       taf6.hs.gene.gff                         \
     > taf6.mmhs.genomic.tblastx.aplot_conf.ps  \
    2> taf6.mmhs.genomic.tblastx.aplot_conf.log ;
#
echo "#  -> Merging data..." ;
#
$BIN/gff2aplot.pl                          \
    --verbose                              \
    --title 'Hsap/Mmus taf6 Orthologous Gene'           \
    --subtitle 'Merging BLASTN and TBLASTX alignments.' \
    --show-percent-box                     \
    --custom-filename taf6.tblastx.rc      \
    -- taf6.mmhs.genomic.blastn.aplot.gff  \
       taf6.mmhs.genomic.tblastx.aplot.gff \
       taf6.mm.gene.gff                    \
       taf6.hs.gene.gff                    \
     > taf6.mmhs.genomic.blast.merge.ps    \
    2> taf6.mmhs.genomic.blast.merge.log ;
#
$BIN/gff2aplot.pl                                    \
    --verbose                                        \
    --title 'Hsap/Mmus taf6 Orthologous Gene'        \
    --subtitle 'BLASTN alignments shown in green, TBLASTX results in blue.' \
    --show-percent-box                               \
    --custom-filename taf6.tblastx.rc                \
    --source-var 'BLASTN::alignment_color=darkgreen' \
    --source-var 'TBLASTX::alignment_color=darkblue' \
    -- taf6.mmhs.genomic.blastn.aplot.gff            \
       taf6.mmhs.genomic.tblastx.aplot.gff           \
       taf6.mm.gene.gff                              \
       taf6.hs.gene.gff                              \
     > taf6.mmhs.genomic.blast.merge_conf.ps         \
    2> taf6.mmhs.genomic.blast.merge_conf.log ;

#
#
# Preparing web images
#
filenames () {
  cat << 'EOF';
taf6.mmhs.genomic.blastn
taf6.mmhs.genomic.tblastx
taf6.mmhs.genomic.blastn.aplot
taf6.mmhs.genomic.tblastx.aplot
taf6.mmhs.genomic.blastn.aplot_conf
taf6.mmhs.genomic.tblastx.aplot_conf
taf6.mmhs.genomic.blast.merge
taf6.mmhs.genomic.blast.merge_conf
EOF
};
#
# echo "# Using \"ghostscript\" to obtain JPEG images from PS files" ;
echo "# Using \"ghostscript\" to obtain PNG images from PS files" ;
#
GS=`which gs || echo "gs"`;
MG=`which mogrify || echo "mogrify"`;
CV=`which convert || echo "convert"`;
#
filenames | while read n ;
  do {
    echo "# -> $n" ;
    $GS -dBATCH -dNOPAUSE -r300        \
        -sPAPERSIZE=a4 -sDEVICE=png16m \
        -sOutputFile=$n.png $n.ps      ;
    cp -v $n.png $n.s.png ;
    # mogrify is a ImageMagick tool that allow us to transform images on batch,
    # large high-resolution jpeg files are scaled down to thumbnail resolution (2479x3508=>123x175)
    # it overwrites original file (so that we previously get a renamed copy for each jpeg to process).
    $MG -verbose -geometry 5% $n.s.png ;
    #
    # $GS -dBATCH -dNOPAUSE -r300      \
    #     -sPAPERSIZE=a4 -sDEVICE=jpeg \
    #     -sOutputFile=$n.jpg $n.ps    ;
    # png large version is pretty smaller than jpeg
    # cp -v $n.jpg $n.s.jpg ;
    # $MG -verbose -geometry 5% $n.s.jpg ;
    };
  done ;
$CV 'vid:*.s.png'  wublast.summary.png
#
echo "# Using \"ghostscript\" to obtain PDF documents from PS files" ;
#
filenames | while read n ;
  do {
    echo "# -> $n" ;
    $GS -dBATCH -dNOPAUSE -r300          \
        -sPAPERSIZE=a4 -sDEVICE=pdfwrite \
        -sOutputFile=$n.pdf $n.ps        ;
    };
  done ;
#
#
# echo "# LaTeXing all figures together..." ;
#
# latex wublast.tex;
# dvips wublast.dvi -o wublast.ps;
#
#
echo "###" ;
echo "### TOTAL TIME: $SECONDS seconds..." ;
#
#
# That's all folks... ;^D
#
#        >> Copyleft (C) 2002/2003 - Josep F. Abril <<
#
