! Example of mutation plot.
! Author: Francois Tonneau

size 18.5 12.5

include muta.gle

set font ss

! Before drawing a mutation plot, we must specify a color for each type of
! mutation. Each color should be a string variable of the form:

! MUTATIONTYPE$

! where MUTATIONTYPE appears (without the final '$') in the datafile for the
! plot. Each line of the datafile should read as:

! row, column, mutation count, mutation types (with underscores, no spaces).

! For example:

! 13 37 2 nonsense missense
! 14 59 3 nonsense missense splice_site
! 28 97 1 nonsense

! See the accompaying datafile, mutation.dat, for an example of datafile in the
! correct format.

missense$        = "#1f98b4"  ! blue
nonsense$        = "#bc8f8f"  ! rosy brown
frame_shift_del$ = "#a6cee3"  ! pale blue
frame_shift_ins$ = "#fb9a99"  ! pale magenta
in_frame_del$    = "#ff7f00"  ! orange
splice_site$     = "#fdbf6f"  ! page orange
splice_site_del$ = "#e31a1c"  ! red

! We prepare the plot area with a begin graph ... end graph block. The axes
! range from 0.5 to 95.5 and from 0.5 to 20.5 because we want a mutation plot
! with 95 patients (columns) and 20 genes (rows). Also, we invert the y axis
! ('negate') to draw the plot from top to bottom.

amove 2 2
begin graph
    size 12 8
    fullsize

    xaxis min 0.5 max 95.5 ftick 1 dticks 1
    yaxis min 0.5 max 20.5 ftick 1 dticks 1
    yaxis negate

    lightgray$ = "#c0c0c0"
    side color lightgray$ lwidth 0.01
    ticks off

    xplaces 1 10 30 50 70 90 95
    xtitle Patient hei 0.30 dist 0.4
    ynames KMT2D      CREBBP    TNFRSF14   BCL2    BCL7A    &
           EP300      EZH2      MUC4       IRF8    HIST1H1E &
           PIM1       STAT6     CARD11     ZNF608  ATP6V1B2 &
           HIST1H1C   TP53      BTG2       BTK     CCDC129  &
           GNA13      HIST1H1D  HVCN1      MEF2B   LRRN3    &
           POU2AF1    POU2F2    HIST1H3G   HNRNPU  TPTE2    &
           CD79B      HIST1H1B  HIST1H2AM  VMA21   CXCR4    &
           HIST1H2BK  DEFB115   DUXA       HIST2H2AC
    labels color black hei 0.3 dist 0.2

end graph

! We draw the grid and the plot outside of the graph block to avoid clipping
! by axis boundaries. The grid is drawn first so that it does not obscure the
! plot. Cell borders are drawn in the pseudo-color, 'cell', to make the cells
! appear borderless. See the 'muta.gle' library file for more information.

mutagrid lightgray$ 0.01
mutaplot "mutation.dat" cell

! We add annotations and a plot legend.

set hei 0.30
amove xg(-1.5) yg(-0.5)
set just cr
write Gene

begin key
    pos tl offset 0.8 -0.5 dist 0.3 nobox
    hei 0.3
    coldist 1
    marker fsquare msize 0.2 color frame_shift_del$  text "Frame Shift Deletion"
    marker fsquare msize 0.2 color frame_shift_ins$  text "Frame Shift Insertion"
    marker fsquare msize 0.2 color in_frame_del$     text "In Frame Deletion"
    separator
    marker fsquare msize 0.2 color missense$         text "Missense"
    marker fsquare msize 0.2 color nonsense$         text "Nonsense"
    separator
    marker fsquare msize 0.2 color splice_site$      text "Splice Site"
    marker fsquare msize 0.2 color splice_site_del$  text "Splice Site Deletion"
end key

! We end with a horizontal bar chart on the right of the mutation plot.

hue_1$ = frame_shift_del$
hue_2$ = frame_shift_ins$
hue_3$ = in_frame_del$
hue_4$ = missense$
hue_5$ = nonsense$
hue_6$ = splice_site$
hue_7$ = splice_site_del$

amove 14.2 2.0

sum_first_row = 96

begin graph
    size 3 8
    fullsize
    xaxis min 0 max sum_first_row dticks sum_first_row
    yaxis min 0.5 max 20.5
    yaxis negate
    side   off
    ticks  off
    labels off
    data "mutationsums.dat"
    for num = 2 to 7
        let d[num] = d[num-1]+d[num]
    next num
    set lwidth 0.01
    bar d1 horiz width 1.0 color hue_1$ fill hue_1$
    for num = 2 to 7
        hue$= eval("hue_" + num + "$")
        bar d[num] from d[num-1] horiz width 1.0 color hue$ fill hue$
    next num
end graph

set hei 0.25 just cc
amove xg(0) yg(0)
write 0
amove xg(sum_first_row) yg(0)
write sum_first_row

amove xg(sum_first_row/2) yg(-0.75)
set hei 0.3 just cc
write Samples