##################################################
#
# README splice_sites
#
# This README runs as a shell script.
# Here you can find the commands
# we used to produce all the figures for:
#
#   ""
#
# USAGE: bash README > .log 2>&1
#
# $Id: README,v 1.2 2003/03/04 19:06:09 jabril Exp $
#
##################################################
#
SECONDS=0 ;
#

#
# Original Files
#
# KCRB.AG.hs.gff KCRB.AG.mm.gff KCRB.AG.hs-mm.gff_tmp
# KCRB.GT.hs.gff KCRB.GT.mm.gff KCRB.GT.hs-mm.gff

# 
# Fixing GFF input files
#
# gawk '{$6=sprintf("%.2f",$6);
#        $9=$6;
#        print $0}' KCRB.AG.hs-mm.gff_tmp > KCRB.AG.hs-mm.gff
# cp KCRB.AG.hs.gff KCRB.hs.gff~
# cp KCRB.AG.mm.gff KCRB.mm.gff~
# 
# sort +3n -4 KCRB.hs.gff~ KCRB.hs_utr.gff > KCRB.hs.gff
# sort +3n -4 KCRB.mm.gff~ KCRB.mm_utr.gff > KCRB.mm.gff

#
echo "# Getting the PostScripts with GFF2APLOT" ;
#
echo "#  ->  GT - DONORS" ;
# GT - DONORS
gff2aplot -v -t "DONOR SITES" \
                  -- KCRB.hs.gff \
                     KCRB.mm.gff \
                     KCRB.GT.hs-mm.gff \
                   > KCRB.GT.hs-mm.ps \
                  2> KCRB.GT.hs-mm.log;
#
echo "#  ->  AG - ACCEPTORS" ;
# AG - ACCEPTORS
gff2aplot -v -t "ACCEPTOR SITES" \
                  -- KCRB.hs.gff \
                     KCRB.mm.gff \
                     KCRB.AG.hs-mm.gff \
                   > KCRB.AG.hs-mm.ps \
                  2> KCRB.AG.hs-mm.log;
#
echo "#  ->  GT + AG" ;
# GT + AG
gff2aplot -v -t "DONOR + ACCEPTOR SITES" \
                  -- KCRB.hs.gff \
                     KCRB.mm.gff \
                     KCRB.GT.hs-mm.gff \
                     KCRB.AG.hs-mm.gff \
                   > KCRB.GT-AG.hs-mm.ps \
                  2> KCRB.GT-AG.hs-mm.log;

# Extra customization
cat > GT-AG.rc <<'+++EOF+++'
#
# L #
# percent_box_label=SIMILARITY
# percent_box_label_fontsize=10pt
show_percent_box=on
percent_box_score_range=0.0..1.0
major_tickmark_score=0.25
minor_tickmark_score=0.05
x_label=Homo sapiens
x_label_font=helvetica-boldoblique
y_label=Mus musculus
y_label_font=helvetica-boldoblique
ribbon_color_merge=on
color_merge_factor=0.5
aplot_score_range=0..1
#
# G #
*::group_shape=arrow
#
# F #
utr::feature_color=lightgrey
exon::feature_color=darkorange
exon::show_ribbons=on
utr::show_ribbons=on
exon::ribbon_style=both
utr::ribbon_style=ribbons
exon::ribbon_color=lightyellow
utr::ribbon_color=palegrey
# GT - Donors
alignGT::alignment_color=darkred
# AG - Acceptors
alignAG::alignment_color=darkblue
*::alignment_scale_color=on
+++EOF+++
#
echo "#  -> GT + AG ... CUSTOMIZED" ;
# GT + AG
gff2aplot -v -t "DONOR + ACCEPTOR SITES (Color Version)" \
                  --x-sequence-coords 0..4200 \
                  --y-sequence-coords 0..4600 \
                  --custom-filename GT-AG.rc \
                  -- KCRB.hs.gff \
                     KCRB.mm.gff \
                     KCRB.GT.hs-mm.gff \
                     KCRB.AG.hs-mm.gff \
                   > KCRB.GT-AG.hs-mm.color.ps \
                  2> KCRB.GT-AG.hs-mm.color.log;

# Extra customization
cat > GT-AG_sm.rc <<'+++EOF+++'
# L #
color_merge_factor=1
+++EOF+++
#
echo "#  -> GT + AG ... MORE CUSTOMIZED" ;
# GT + AG
gff2aplot -v -t "DONOR + ACCEPTOR SITES (Color Version)" \
                  --x-sequence-coords 0..4200 \
                  --y-sequence-coords 0..4600 \
                  --custom-filename GT-AG.rc \
                  --custom-filename GT-AG_sm.rc \
                  -- KCRB.hs.gff \
                     KCRB.mm.gff \
                     KCRB.GT.hs-mm.gff \
                     KCRB.AG.hs-mm.gff \
                   > KCRB.GT-AG.hs-mm.color_small.ps \
                  2> KCRB.GT-AG.hs-mm.color_small.log;

#
# Preparing web images
#
filenames () {
       ls *.ps | sed 's/\.ps//'
};
#
# echo "# Using \"ghostscript\" to obtain JPEG images from PS files" ;
echo "# Using \"ghostscript\" to obtain PNG images from PS files" ;
#
GS="gs -q" ;
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'  splicesites.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 splicesites.tex;
# dvips splicesites.dvi -o splicesites.ps;
#
#
echo "###" ;
echo "### TOTAL TIME: $SECONDS seconds..." ; 
#
#
# That's all folks... ;^D
#
#        >> Copyleft (C) 2002/2003 - Josep F. Abril <<
#
