{ Overflow-x:scroll;//add horizontal bar option in html Overflow-y:scroll; //add vertical bar option in html }


title: Whole genome/transcriptome sequencing of r params$pair, r paste(ifelse(grepl("^[aeiou]", params$tumor_type, ignore.case = T), "an", "a"), params$tumor_type)


## global code chunk option
knitr::opts_chunk$set(
    collapse = TRUE,
    fig.width = 8,
    fig.height = 8,
    message = FALSE,
    warning = FALSE,
    echo = FALSE)

## hopefully make skidb standard asap
library(gGnome)
library(gTrack)
library(skidb)
library(ggplot2)
library(ggforce)
library(kableExtra)
library(hwriter)
library(htmlwidgets)
library(svglite)
library(slickR)
library(plotly)
library(shiny)
message("Loaded Packages")

summary.list = readRDS(normalizePath(file.path(params$outdir, "summary.rds")))
message("Loaded gGraph")

```{css,echo=FALSE} button.btn.collapsed:before { content:'+' ; display:block; width:15px; } button.btn:before { content:'-' ; display:block; width:15px; }

```r

knitr::knit_hooks$set(dropAboveCol=function(before, options, envir) {
    if (before) {
        paste(
            '<p>',
paste('<button class="btn btn-primary collapsed" id="BT-', options$label,'" data-toggle="collapse" data-target="#',options$label,'">',sep=""),
'</button>',
'</p>',
paste('<div class="collapse" id="',options$label,'">',sep=""), sep = "\n")
    }
})

#For sections to be expanded by default, use this one. 
knitr::knit_hooks$set(dropAboveExp=function(before, options, envir) {
    if (before) {
        paste(
            '<p>',
paste('<button class="btn btn-primary" data-toggle="collapse" data-target="#',options$label,'"aria-expanded="true">',sep=""),
'</button>',
'</p>',
paste('<div class="collapse in" id="',options$label,'">',sep=""),sep = "\n")
    }
})

knitr::knit_hooks$set(dropBelow=function(before, options, envir) {
    if (!before) {
      paste("</div>", sep="\n")
    }
})

r paste(params$pair, params$tumor_type, sep = ", ")


Purity/ploidy

Estimated purity: r format(summary.list$purity, digits = 2)

Estimated ploidy: r format(summary.list$ploidy, digits = 2)

SCNA

Copy number alterations (CNA) are defined as CN at most 0.5 times ploidy (deletions) or at least 1.5 times ploidy (amplifications).

Percent of genome with CNA: r format(round(summary.list$cna_frac * 100, 2), nsmall = 2)%

Total amplifications (Mbp): r format(round(summary.list$amp_mbp, 2), nsmall = 2)

Total deletions (Mbp): r format(round(summary.list$del_mbp, 2), nsmall = 2)

Total CNA (Mbp): r format(round(summary.list$cna_mbp, 2), nsmall = 2)

Junction burden

The total junction burden is r summary.list$junction_burden.

SNV

Total number of somatic SNV/INDELs: r format(round(summary.list$mut_count, 0), nsmall = 0)

Tumor Mutation Burden (TMB): r format(round(summary.list$mut_per_mbp, 2), 2) per Mbp



Summary Driver Table

summary.dt = fread(file.path(params$outdir, "summaryTable.txt"))
expr.hist.dt = fread(file.path(params$outdir, "expr.histograms.txt"))
expr.slickr.dt = fread(file.path(params$outdir, "expr.gallery.txt"))
cn.gallery.dt = fread(file.path(params$outdir, "cn.gallery.txt"))
fusions.gallery.dt = fread(file.path(params$outdir, "fusions.driver.txt"))


basebutton=paste('<input type="button" onclick="openTabset"',';" value="thisValue" />',sep="'")
ExpSequences=c("overexpression","underexpression")
CnvSequences=c("amp","hetdel")
SnvSequences=c("missense")

for(i in 1:nrow(summary.dt)){
  g=gsub(".*/gene/","",summary.dt$gene[i])
  g=gsub(" target.*$","",g)
  if(grepl("expression",summary.dt$type[i])){
    for(val in ExpSequences){
      if(grepl(val,summary.dt$type[i])){
        summary.dt$type[i]=gsub(val,basebutton,summary.dt$type[i])
        summary.dt$type[i]=gsub("thisValue",val,summary.dt$type[i])
        forAction=paste0("showImg('",g,".expr');showImg('",g,".gg')",";showImg('",g,".expt')",";showHeader('expheader')")
        summary.dt$type[i]=gsub('openTabset',forAction,summary.dt$type[i])
      }
    }
  }
  if(grepl("amp|hetdel",summary.dt$type[i])){
    for(val in CnvSequences){
      if(grepl(val,summary.dt$type[i])){
        summary.dt$type[i]=gsub(val,basebutton,summary.dt$type[i])
        summary.dt$type[i]=gsub("thisValue",val,summary.dt$type[i])
        forAction=paste0("showImg('",g,".cnv')",";showImg('",g,".cnvtt')",";showHeader('cnvheader')")
        summary.dt$type[i]=gsub('openTabset',forAction,summary.dt$type[i])
      }
    }
  }
  if(grepl("fusion",summary.dt$type[i])){
        summary.dt$type[i]=gsub("fusion",basebutton,summary.dt$type[i])
        summary.dt$type[i]=gsub("thisValue","fusion",summary.dt$type[i])

        forAction=paste0("showImg('",fusions.gallery.dt[driver.name == g, driver.name],".fus')",";showImg('",g,".fust')",";showHeader('fusheader')")
        summary.dt$type[i]=gsub('openTabset',forAction,summary.dt$type[i])
  }

  if(grepl("missense",summary.dt$type[i])){
        summary.dt$type[i]=gsub("missense",basebutton,summary.dt$type[i])
        summary.dt$type[i]=gsub("thisValue","missense",summary.dt$type[i])
        forAction=paste0("showImg('",driver.mutations.dt[gene == g, gene],".snvt')",";showHeader('snvheader')")
        summary.dt$type[i]=gsub("openTabset",forAction,summary.dt$type[i])
  }
  if(grepl("proximity",summary.dt$type[i])){
        summary.dt$type[i]=gsub("proximity",basebutton,summary.dt$type[i])
        summary.dt$type[i]=gsub("thisValue","proximity",summary.dt$type[i])

        forAction=paste0("showImg('",g,".prox')")
        summary.dt$type[i]=gsub('openTabset',forAction,summary.dt$type[i])
  }
  summary.dt$type[i]=gsub(", ,",",",summary.dt$type[i])
}
DT::datatable(summary.dt, escape=FALSE, options = list(scrollX = TRUE))

driver.genes.cnv = fread(file.path(params$outdir, "driver.genes.cnv.txt"))
driver.genes.cnv$min_normalized_cn=unlist(lapply(driver.genes.cnv$min_normalized_cn,FUN=signif,digits=4))
driver.genes.cnv$max_normalized_cn=unlist(lapply(driver.genes.cnv$max_normalized_cn,FUN=signif,digits=4))
driver.genes.cnv$expr.quantile=unlist(lapply(driver.genes.cnv$expr.quantile,FUN=signif,digits=4))

cat('<div class="divScroll">')
cat('<table class="display dataTable no-footer table table-condensed" aria-describedby="CNV_Table">')
headerline='<tr id="cnvheader" style="display:none">'
for(i in colnames(driver.genes.cnv)){
  thisH=paste0('<th>',i,'</th>')
  headerline=paste0(headerline,thisH)
}
cat(paste0(headerline,'</tr>'))


for(i in 1:nrow(driver.genes.cnv)){
  rLine=paste0('<tr class="odd" id="',driver.genes.cnv$gene[i],'.cnvtt" style="display:none">')
  for(j in 1:ncol(driver.genes.cnv)){
    thisL=paste0('<td>',as.vector(as.matrix(driver.genes.cnv)[i,j]),'</td>')
    rLine=paste0(rLine,thisL)
  }
  cat(paste0(rLine,'</tr>'))
}

cat('</table>')
cat('</div>')
cn.gallery.dt = fread(file.path(params$outdir, "cn.gallery.txt"))
if (nrow(cn.gallery.dt) > 0) {
    for (g in cn.gallery.dt[, gene_name]) {
        cat(
            paste0('<p>',
                    '<img',' id="', g,'.cnv"',' src="',
                    cn.gallery.dt[gene_name == g, plot.fname],
                    '" style="display:none;" width="100%" />',
                    '</p>'
            )
        )   
    }
}
driver.genes.expr = fread(file.path(params$outdir, "driver.genes.expr.txt"))
driver.genes.expr$min_normalized_cn=unlist(lapply(driver.genes.expr$min_normalized_cn,FUN=signif,digits=4))
driver.genes.expr$max_normalized_cn=unlist(lapply(driver.genes.expr$max_normalized_cn,FUN=signif,digits=4))
driver.genes.expr$expr.quantile=unlist(lapply(driver.genes.expr$expr.quantile,FUN=signif,digits=4))
if (driver.genes.expr[,.N] > 0){
    driver.genes.expr$zscore=unlist(lapply(driver.genes.expr$zscore,FUN=signif,digits=4))
    driver.genes.expr = driver.genes.expr[order(-abs(zscore))] #  sort by Z-score
}

cat('<div class="divScroll">')
cat('<table class="display dataTable no-footer table table-condensed" aria-describedby="EXP_Table">')
headerline='<tr id="expheader" style="display:none">'
for(i in colnames(driver.genes.expr)){
  thisH=paste0('<th>',i,'</th>')
  headerline=paste0(headerline,thisH)
}
cat(paste0(headerline,'</tr>'))


for(i in 1:nrow(driver.genes.expr)){
  rLine=paste0('<tr class="odd" id="',driver.genes.expr$gene[i],'.expt" style="display:none">')
  for(j in 1:ncol(driver.genes.expr)){
    thisL=paste0('<td>',as.vector(as.matrix(driver.genes.expr)[i,j]),'</td>')
    rLine=paste0(rLine,thisL)
  }
  cat(paste0(rLine,'</tr>'))
}

cat('</table>')
cat('</div>')
expr.hist.dt = fread(file.path(params$outdir, "expr.histograms.txt"))
cool.exp = fread(paste0(params$outdir, "/", "rna.change.txt"))
expr.slickr.dt = fread(file.path(params$outdir, "expr.gallery.txt"))
cat("\n")
valid.genes = intersect(expr.hist.dt[, gene], expr.slickr.dt[, gene_name])
for (g in valid.genes) {
    expr.png.fn = expr.hist.dt[gene == g, expr.hist.fname][1]
    gg.png.fn = expr.slickr.dt[gene_name == g, plot.fname][1]
    if (file.exists(expr.png.fn) & file.exists(gg.png.fn)) {
         cat(
            paste0(
                '<p float="left">',
                '<img ', 'id="', g,'.expr"',
                ' src="',
            expr.png.fn,
                '" style="display:none;" width="45%" />',
                '<img', ' id="', g,'.gg"', ' src="',
                gg.png.fn,
                '" style="display:none;" width="45%" />',
                '</p>'
            )
        )
        }   
    }
driver.fusions.fname = file.path(params$outdir, "fusions.driver.txt")
if (file.exists(driver.fusions.fname)) {
   driver.fusions.dt = fread(driver.fusions.fname)
   if (nrow(driver.fusions.dt)) {
      driver.fusions.cols = intersect(c("genes", "walk.id", "driver.name", "chroms", "maxcn", "total.aa", "gene.pc", "ev.id", "ev.type"), colnames(driver.fusions.dt))
      dat = driver.fusions.dt[, ..driver.fusions.cols]
   }
}

fusions.gallery.dt = fread(file.path(params$outdir, "fusions.driver.txt"))
summary.dt = fread(file.path(params$outdir, "summaryTable.txt"))
driverGenes=summary.dt$gene
driverGenes=sapply(driverGenes,function(x) gsub(".*/gene/","",x))
driverGenes=sapply(driverGenes,function(x) sub(" target.*$","",x))

if(any(fusions.gallery.dt$genes %in% driverGenes)){
  cat('<div class="divScroll">')
  cat('<table class="display dataTable no-footer table table-condensed" aria-describedby="FUS_Table">')
  headerline='<tr id="fusheader" style="display:none">'
  for(i in colnames(driver.genes.expr)){
   thisH=paste0('<th>',i,'</th>')
   headerline=paste0(headerline,thisH)
  }
  cat(paste0(headerline,'</tr>'))


  for(i in 1:nrow(driver.genes.expr)){
   rLine=paste0('<tr class="odd" id="',driver.genes.expr$gene[i],'.fust" style="display:none">')
    for(j in 1:ncol(driver.genes.expr)){
     thisL=paste0('<td>',as.vector(as.matrix(driver.genes.expr)[i,j]),'</td>')
     rLine=paste0(rLine,thisL)
   }
   cat(paste0(rLine,'</tr>'))
  }

  cat('</table>')
  cat('</div>')
}
if (nrow(fusions.gallery.dt) > 0) {
      for (g in fusions.gallery.dt[, genes]) {
        if(g %in% driverGenes){
            cat(
                paste0('<p>',
                       '<img', ' id="',paste0(fusions.gallery.dt[genes == g, driver.name],'.fus'),'" src="',
                       fusions.gallery.dt[genes == g, plot.fname],
                       '" style="display:none;" width="75%" />',
                       '</a>',
                       '</p>'
                       )
            )
        }
        }
    }
proximity.gallery.dt = fread(paste0(params$outdir, "/", "proximity.gallery.txt"))
expr.histograms.dt = fread(paste0(params$outdir, "/", "expr.histograms.txt"))
    if (nrow(proximity.gallery.dt) > 0) {
      gns = intersect(proximity.gallery.dt$gene, expr.histograms.dt$gene)
        for (g in gns) {
            cat(
                paste0('<p>',
                       '<img', ' id="',paste0(g,'.prox'),'" src="',
                       proximity.gallery.dt[gene == g, plot.fname],
                       '" style="display:none;" width="75%" />',
                       '</a>',
                       '</p>'
                       )
            )
        }
    }
driver.mutations.dt = fread(file.path(params$outdir, "driver.mutations.txt"))
driver.mutations.dt$Tier=as.character(driver.mutations.dt$Tier)
driver.mutations.dt[is.na(driver.mutations.dt$Tier),]$Tier="Undefined"
cat('<table class="display dataTable no-footer table table-condensed" aria-describedby="SNV_Table">')
headerline='<tr id="snvheader" style="display:none">'
for(i in colnames(driver.mutations.dt)){
  thisH=paste0('<th>',i,'</th>')
  headerline=paste0(headerline,thisH)
}
cat(paste0(headerline,'</tr>'))


for(i in 1:nrow(driver.mutations.dt)){
  rLine=paste0('<tr class="odd" id="',driver.mutations.dt$gene[i],'.snvt" style="display:none">')
  for(j in 1:ncol(driver.mutations.dt)){
    thisL=paste0('<td>',as.vector(as.matrix(driver.mutations.dt)[i,j]),'</td>')
    rLine=paste0(rLine,thisL)
  }
  cat(paste0(rLine,'</tr>'))
}

cat('</table>')

Summary Surface Table

summary.dt = fread(file.path(params$outdir, "summarySurfaceTable.txt"))
expr.hist.dt = fread(file.path(params$outdir, "surface.expr.histograms.txt"))
expr.slickr.dt = fread(file.path(params$outdir, "surface.expr.gallery.txt"))
cn.gallery.dt = fread(file.path(params$outdir, "surface.cn.gallery.txt"))

basebutton=paste('<input type="button" onclick="openTabset"',';" value="thisValue" />',sep="'")
ExpSequences=c("overexpression","underexpression")
CnvSequences=c("amp","hetdel")
SnvSequences=c("missense")

for(i in 1:nrow(summary.dt)){
  g=gsub(".*/gene/","",summary.dt$gene[i])
  g=gsub(" target.*$","",g)
  if(grepl("expression",summary.dt$type[i])){
    for(val in ExpSequences){
      if(grepl(val,summary.dt$type[i])){
        summary.dt$type[i]=gsub(val,basebutton,summary.dt$type[i])
        summary.dt$type[i]=gsub("thisValue",val,summary.dt$type[i])
        forAction=paste0("showImg('",g,".expr');showImg('",g,".gg')",";showImg('",g,".sexpt')",";showHeaderSurface('sexpheader')")
        summary.dt$type[i]=gsub('openTabset',forAction,summary.dt$type[i])
      }
    }
  }
  if(grepl("amp|hetdel",summary.dt$type[i])){
    for(val in CnvSequences){
      if(grepl(val,summary.dt$type[i])){
        summary.dt$type[i]=gsub(val,basebutton,summary.dt$type[i])
        summary.dt$type[i]=gsub("thisValue",val,summary.dt$type[i])
        forAction=paste0("showImg('",g,".cnv')",";showImg('",g,".scnvtt')",";showHeaderSurface('scnvheader')")
        summary.dt$type[i]=gsub('openTabset',forAction,summary.dt$type[i])
      }
    }
  }
    if(grepl("fusion",summary.dt$type[i])){
        summary.dt$type[i]=gsub("fusion",basebutton,summary.dt$type[i])
        summary.dt$type[i]=gsub("thisValue","fusion",summary.dt$type[i])

        forAction=paste0("showImg('",fusions.gallery.dt[driver.name == g, driver.name],".fus')",";showImg('",g,".fust')",";showHeaderSurface('sfusheader')")
        summary.dt$type[i]=gsub('openTabset',forAction,summary.dt$type[i])
  }
  summary.dt$type[i]=gsub(", ,",",",summary.dt$type[i])
  if(grepl("missense",summary.dt$type[i])){
        summary.dt$type[i]=gsub("missense",basebutton,summary.dt$type[i])
        summary.dt$type[i]=gsub("thisValue","missense",summary.dt$type[i])
        forAction=paste0("showImg('",driver.mutations.dt[gene == g, gene],".snvt')",";showHeaderSurface('snvheader')")
        summary.dt$type[i]=gsub("openTabset",forAction,summary.dt$type[i])
  }
  summary.dt$type[i]=gsub(", ,",",",summary.dt$type[i])
}
DT::datatable(summary.dt, escape=FALSE, options = list(scrollX = TRUE))

surface.genes.cnv = fread(file.path(params$outdir, "surface.genes.cnv.txt"))
surface.genes.cnv$min_normalized_cn=unlist(lapply(surface.genes.cnv$min_normalized_cn,FUN=signif,digits=4))
surface.genes.cnv$max_normalized_cn=unlist(lapply(surface.genes.cnv$max_normalized_cn,FUN=signif,digits=4))
surface.genes.cnv$expr.quantile=unlist(lapply(surface.genes.cnv$expr.quantile,FUN=signif,digits=4))

cat('<div class="divScroll">')
cat('<table class="display dataTable no-footer table table-condensed" aria-describedby="SCNV_Table">')
headerline='<tr id="scnvheader" style="display:none">'
for(i in colnames(surface.genes.cnv)){
  thisH=paste0('<th>',i,'</th>')
  headerline=paste0(headerline,thisH)
}
cat(paste0(headerline,'</tr>'))


for(i in 1:nrow(surface.genes.cnv)){
  rLine=paste0('<tr class="odd" id="',surface.genes.cnv$gene[i],'.scnvtt" style="display:none">')
  for(j in 1:ncol(driver.genes.cnv)){
    thisL=paste0('<td>',as.vector(as.matrix(surface.genes.cnv)[i,j]),'</td>')
    rLine=paste0(rLine,thisL)
  }
  cat(paste0(rLine,'</tr>'))
}

cat('</table>')
cat('</div>')
cn.gallery.dt = fread(file.path(params$outdir, "surface.cn.gallery.txt"))
if (nrow(cn.gallery.dt) > 0) {
    for (g in cn.gallery.dt[, gene_name]) {
        cat(
            paste0('<p>',
                    '<img',' id="', g,'.cnv"',' src="',
                    cn.gallery.dt[gene_name == g, plot.fname],
                    '" style="display:none;" width="100%" />',
                    '</p>'
            )
        )   
    }
}
surface.genes.expr = fread(file.path(params$outdir, "surface.genes.expr.txt"))
if (surface.genes.expr[,.N] > 0){
    surface.genes.expr$min_normalized_cn=unlist(lapply(surface.genes.expr$min_normalized_cn,FUN=signif,digits=4))
    surface.genes.expr$max_normalized_cn=unlist(lapply(surface.genes.expr$max_normalized_cn,FUN=signif,digits=4))
    surface.genes.expr$expr.quantile=unlist(lapply(surface.genes.expr$expr.quantile,FUN=signif,digits=4))
    surface.genes.expr$expr = factor(surface.genes.expr$expr, c('over', 'under', ''))
    surface.genes.expr$zscore=unlist(lapply(surface.genes.expr$zscore,FUN=signif,digits=4))
    surface.genes.expr = surface.genes.expr[order(-abs(zscore))] #  sort by Z-score
    surface.genes.expr = surface.genes.expr[order(expr, -min_cn, -abs(zscore))] # sort to show over expressed, and then underexpressed. Whithin over-expressed we show highest CN first and for each CN we sort by Z-score
}

cat('<div class="divScroll">')
cat('<table class="display dataTable no-footer table table-condensed" aria-describedby="SEXP_Table">')
headerline='<tr id="sexpheader" style="display:none">'
for(i in colnames(surface.genes.expr)){
  thisH=paste0('<th>',i,'</th>')
  headerline=paste0(headerline,thisH)
}
cat(paste0(headerline,'</tr>'))


for(i in 1:nrow(surface.genes.expr)){
  rLine=paste0('<tr class="odd" id="',surface.genes.expr$gene[i],'.sexpt" style="display:none">')
  for(j in 1:ncol(driver.genes.expr)){
    thisL=paste0('<td>',as.vector(as.matrix(surface.genes.expr)[i,j]),'</td>')
    rLine=paste0(rLine,thisL)
  }
  cat(paste0(rLine,'</tr>'))
}

cat('</table>')
cat('</div>')
expr.hist.dt = fread(file.path(params$outdir, "surface.expr.histograms.txt"))
cool.exp = fread(paste0(params$outdir, "/", "surface.rna.change.txt"))
expr.slickr.dt = fread(file.path(params$outdir, "surface.expr.gallery.txt"))
cat("\n")
valid.genes = intersect(expr.hist.dt[, gene], expr.slickr.dt[, gene_name])
for (g in valid.genes) {
    expr.png.fn = expr.hist.dt[gene == g, expr.hist.fname][1]
    gg.png.fn = expr.slickr.dt[gene_name == g, plot.fname][1]
    if (file.exists(expr.png.fn) & file.exists(gg.png.fn)) {
         cat(
            paste0(
                '<p float="left">',
                '<img ', 'id="', g,'.expr"',
                ' src="',
            expr.png.fn,
                '" style="display:none;" width="45%" />',
                '<img', ' id="', g,'.gg"', ' src="',
                gg.png.fn,
                '" style="display:none;" width="45%" />',
                '</p>'
            )
        )
        }   
    }
driver.fusions.fname = file.path(params$outdir, "fusions.driver.txt")
if (file.exists(driver.fusions.fname)) {
   driver.fusions.dt = fread(driver.fusions.fname)
   if (nrow(driver.fusions.dt)) {
      driver.fusions.cols = intersect(c("genes", "walk.id", "driver.name", "chroms", "maxcn", "total.aa", "gene.pc", "ev.id", "ev.type"), colnames(driver.fusions.dt))
      dat = driver.fusions.dt[, ..driver.fusions.cols]
   }
}

summary.dt = fread(file.path(params$outdir, "summaryTable.txt"))
driverGenes=summary.dt$gene
driverGenes=sapply(driverGenes,function(x) gsub(".*/gene/","",x))
driverGenes=sapply(driverGenes,function(x) sub(" target.*$","",x))

if(any(fusions.gallery.dt$driver.name %in% driverGenes)){
  cat('<div class="divScroll">')
  cat('<table class="display dataTable no-footer table table-condensed" aria-describedby="SFUS_Table">')
  headerline='<tr id="sfusheader" style="display:none">'
  for(i in colnames(dat)){
   thisH=paste0('<th>',i,'</th>')
   headerline=paste0(headerline,thisH)
  }
  cat(paste0(headerline,'</tr>'))


  for(i in 1:nrow(driver.genes.expr)){
   rLine=paste0('<tr class="odd" id="',driver.fusions.dt$driver.name[i],'.fust" style="display:none">')
    for(j in 1:ncol(driver.genes.expr)){
     thisL=paste0('<td>',as.vector(as.matrix(dat)[i,j]),'</td>')
     rLine=paste0(rLine,thisL)
   }
   cat(paste0(rLine,'</tr>'))
  }

  cat('</table>')
  cat('</div>')
}
if (nrow(fusions.gallery.dt) > 0) {
        for (g in fusions.gallery.dt[, genes]) {
          if(!(g %in% driverGenes)){
            cat(
                paste0('<p>',
                       '<img', ' id="',paste0(fusions.gallery.dt[genes == g, driver.name],'.fus'),'" src="',
                       fusions.gallery.dt[genes == g, plot.fname],
                       '" style="display:none;" width="75%" />',
                       '</a>',
                       '</p>'
                       )
            )
          }
        }
    }

Whole genome view {.tabset .tabset-fade .tabset-pills}

cat('<div id="gtrack" class="section level2">')

gTrack

wzxhzdk:21

r paste('<div id="lead-circos" class="section level2">')

circos

knitr::include_graphics(file.path(params$outdir, "wgs.circos.png"))



Copy number variants

Copy number variations (CNVs) in oncogenes and tumor suppressor genes.

driver.genes.cnv = fread(file.path(params$outdir, "driver.genes.cnv.txt"))
driver.genes.cnv$min_normalized_cn=unlist(lapply(driver.genes.cnv$min_normalized_cn,FUN=signif,digits=4))
driver.genes.cnv$max_normalized_cn=unlist(lapply(driver.genes.cnv$max_normalized_cn,FUN=signif,digits=4))
driver.genes.cnv$expr.quantile=unlist(lapply(driver.genes.cnv$expr.quantile,FUN=signif,digits=4))

## driver.genes.cnv[cnv != ''] %>% kbl() %>% kable_styling() %>% scroll_box(width = "100%", height = "300px")
DT::datatable(driver.genes.cnv, options = list(scrollX = TRUE))

r paste('<div id="driver-cnv-gallery" class="section level2 tabset tabset-fade tabset-pills">')

Driver CNV gallery {.tabset .tabset-fade .tabset-pills}

cn.gallery.dt = fread(file.path(params$outdir, "cn.gallery.txt"))
if (nrow(cn.gallery.dt) > 0) {
    cat("\n")
    for (g in cn.gallery.dt[, gene_name]) {
        cat("\n")
        cat('<div id="',paste0(g,"-dcnv"),'" class="section level3">')
        cat("\n")
        cat("###", paste0(g, "<br>","\n"))
        cat(
            paste0('<p>',
                    '<a href="',
                    cn.gallery.dt[gene_name == g, plot.link],
                    '">',
                    '<img src="',
                    cn.gallery.dt[gene_name == g, plot.fname],
                    '" width="100%" />',
                    '</a>',
                    '</p>'
            )
        )   
        cat("</div>")
    }
    cat('\n', '<br>', '\n\n')
}

Surface Copy number variants

Copy number variations (CNVs) in oncogenes and tumor suppressor genes.

surface.genes.cnv = fread(file.path(params$outdir, "surface.genes.cnv.txt"))
surface.genes.cnv$min_normalized_cn=unlist(lapply(surface.genes.cnv$min_normalized_cn,FUN=signif,digits=4))
surface.genes.cnv$max_normalized_cn=unlist(lapply(surface.genes.cnv$max_normalized_cn,FUN=signif,digits=4))
surface.genes.cnv$expr.quantile=unlist(lapply(surface.genes.cnv$expr.quantile,FUN=signif,digits=4))

## surface.genes.cnv[cnv != ''] %>% kbl() %>% kable_styling() %>% scroll_box(width = "100%", height = "300px")
DT::datatable(surface.genes.cnv, options = list(scrollX = TRUE))

r paste('<div id="surface-cnv-gallery" class="section level2 tabset tabset-fade tabset-pills">')

Surface CNV gallery {.tabset .tabset-fade .tabset-pills}

cn.gallery.dt = fread(file.path(params$outdir, "surface.cn.gallery.txt"))
if (nrow(cn.gallery.dt) > 0) {
    cat("\n")
    for (g in cn.gallery.dt[, gene_name]) {
        cat("\n")
        cat('<div id="',paste0(g,"-dcnv"),'" class="section level3">')
        cat("\n")
        cat("###", paste0(g, "<br>","\n"))
        cat(
            paste0('<p>',
                    '<a href="',
                    cn.gallery.dt[gene_name == g, plot.link],
                    '">',
                    '<img src="',
                    cn.gallery.dt[gene_name == g, plot.fname],
                    '" width="100%" />',
                    '</a>',
                    '</p>'
            )
        )   
        cat("</div>")
    }
    cat('\n', '<br>', '\n\n')
}

Fusions


Known fusions

driver.fusions.fname = file.path(params$outdir, "fusions.driver.txt")
if (file.exists(driver.fusions.fname)) {
   driver.fusions.dt = fread(driver.fusions.fname)
   if (nrow(driver.fusions.dt)) {
      driver.fusions.cols = intersect(c("genes", "walk.id", "driver.name", "chroms", "maxcn", "total.aa", "gene.pc", "ev.id", "ev.type"), colnames(driver.fusions.dt))
      dat = driver.fusions.dt[, ..driver.fusions.cols]
      DT::datatable(dat, options = list(scrollX = TRUE), caption = "Fusions in which at least one involved gene is an oncogene or tumor suppressor.")
   } else {
     cat("No known driver fusions")
   }     
}

r paste('<div id="known-fusions-gallery" class="section level2 tabset tabset-fade tabset-pills">')

Known fusions gallery {.tabset .tabset-fade .tabset-pills}

if (file.good(file.path(params$outdir, "fusions.driver.txt"))){
    fusions.gallery.dt = fread(file.path(params$outdir, "fusions.driver.txt"))
    if (nrow(fusions.gallery.dt) > 0) {
        cat("\n")
        for (g in fusions.gallery.dt[, genes]) {
             cat("\n")
            cat('<div id="',paste0(g,"-fus"),'" class="section level3">')
            cat("\n")
            cat("###", paste0(g, "<br>","\n"))
            cat(
                paste0('<p>',
                       '<a href="',
                       fusions.gallery.dt[genes == g, plot.link],
                       '">',
                       '<img src="',
                       fusions.gallery.dt[genes == g, plot.fname],
                       '" width="75%" />',
                       '</a>',
                       '</p>'
                       )
            )
            cat("</div>")
            cat('\n', '<br>', '\n\n')
        }
    } else {
        cat("\n", "No fusions to show", "\n")
    }
} else {
    cat("\n", "Fusion results not available.", "<br>\n\n")
}

Other fusions

other.fusions.fname = file.path(params$outdir, "fusions.other.txt")
if (file.exists(other.fusions.fname)) {
   other.fusions.dt = fread(other.fusions.fname)
   if (nrow(other.fusions.dt)) {
   other.fusions.cols = intersect(c("genes", "walk.id", "driver.name", "chroms", "maxcn", "total.aa", "gene.pc", "ev.id", "ev.type"), colnames(driver.fusions.dt))
   dat = other.fusions.dt[, ..other.fusions.cols]
   DT::datatable(dat, options = list(scrollX = TRUE), caption = "Other in-frame non-silent gene fusions")
} else {
cat("\n", "No other fusions to show.")
}
} else {
cat("\n", "No other fusions available", "\n")
}

Other fusions gallery

if (file.exists(other.fusions.fname)) {
   other.fusions.dt = fread(other.fusions.fname)
   if (nrow(other.fusions.dt) > 0) {
      slick_up = slickR(obj = other.fusions.dt$plot.fname, height = 800, width = "95%", objLinks = other.fusions.dt$plot.link) + settings(slidesToShow = 1, slidesToScroll = 1) + settings(dots = TRUE)
slick_up
    }
}

Altered transcripts

  cat("Under construction")
  cat("\n")

Over/under-expression of oncogenes/TSGs

driver.genes.expr = fread(file.path(params$outdir, "driver.genes.expr.txt"))
driver.genes.expr$min_normalized_cn=unlist(lapply(driver.genes.expr$min_normalized_cn,FUN=signif,digits=4))
driver.genes.expr$max_normalized_cn=unlist(lapply(driver.genes.expr$max_normalized_cn,FUN=signif,digits=4))
driver.genes.expr$expr.quantile=unlist(lapply(driver.genes.expr$expr.quantile,FUN=signif,digits=4))
if (driver.genes.expr[,.N] > 0){
    driver.genes.expr$zscore=unlist(lapply(driver.genes.expr$zscore,FUN=signif,digits=4))
    driver.genes.expr = driver.genes.expr[order(-abs(zscore))] #  sort by Z-score
}

if (nrow(driver.genes.expr)) {
    DT::datatable(driver.genes.expr, options = list(scrollX = TRUE))
} else {
    cat("\n", "No overexpressed/underexpressed drivers", "\n")
}

Waterfall plot

waterfall.fn = file.path(params$outdir, "waterfall.png")
## cat(waterfall.fn)
if (file.exists(waterfall.fn)) {
   cat(paste0("![](", waterfall.fn, ")"), "\n")
   ##knitr::include_graphics(waterfall.fn)
   cat(paste0("\n", "Waterfall plot showing relative gene expression of drivers.", "\n"))
} else {
   cat("Waterfall plot with relative gene expression of drivers is not available")
}

r paste('<div id="expression-gallery" class="section level2 tabset tabset-fade tabset-pills">')

Expression gallery {.tabset .tabset-fade .tabset-pills}

 if (file.good(paste0(params$outdir, "/", "rna.change.txt"))) {
     expr.hist.dt = fread(file.path(params$outdir, "expr.histograms.txt"))
     cool.exp = fread(paste0(params$outdir, "/", "rna.change.txt"))
     expr.slickr.dt = fread(file.path(params$outdir, "expr.gallery.txt"))
     cat("\n")
     valid.genes = intersect(expr.hist.dt[, gene], expr.slickr.dt[, gene_name])
     for (g in valid.genes) {
        expr.png.fn = expr.hist.dt[gene == g, expr.hist.fname][1]
    gg.png.fn = expr.slickr.dt[gene_name == g, plot.fname][1]
        cat("\n")

    if (file.exists(expr.png.fn) & file.exists(gg.png.fn)) {
        cat("\n")
        cat('<div id="',paste0(g,"-eg"),'" class="section level3">')
        cat("\n")
        cat("###", cool.exp[gene == g, paste0(gene, " (", direction, ")", "<br>", "\n")])
        cat("Z-Score:",signif(cool.exp[cool.exp$gene==g,]$zscore,digits=4))

        cat(
            paste0(
                '<p float="left">',
                '<img src="',
            expr.png.fn,
                '" width="45%" />',
                '<img src="',
                gg.png.fn,
                '" width="45%" />',
                '</p>'
            )
        )
    }
        cat("</div>")
    }
        cat('\n', '<br>', '\n\n')
    } else {
    cat("\n", "Gene expression not available", "\n")
    }

Over/under-expression of surface genes

surface.genes.expr = fread(file.path(params$outdir, "surface.genes.expr.txt"))
if (surface.genes.expr[,.N] > 0){
    surface.genes.expr$min_normalized_cn=unlist(lapply(surface.genes.expr$min_normalized_cn,FUN=signif,digits=4))
    surface.genes.expr$max_normalized_cn=unlist(lapply(surface.genes.expr$max_normalized_cn,FUN=signif,digits=4))
    surface.genes.expr$expr.quantile=unlist(lapply(surface.genes.expr$expr.quantile,FUN=signif,digits=4))
    surface.genes.expr$expr = factor(surface.genes.expr$expr, c('over', 'under', ''))
    surface.genes.expr$zscore=unlist(lapply(surface.genes.expr$zscore,FUN=signif,digits=4))
    surface.genes.expr = surface.genes.expr[order(-abs(zscore))] #  sort by Z-score
    surface.genes.expr = surface.genes.expr[order(expr, -min_cn, -abs(zscore))] # sort to show over expressed, and then underexpressed. Whithin over-expressed we show highest CN first and for each CN we sort by Z-score
}

if (nrow(surface.genes.expr)) {
    DT::datatable(surface.genes.expr, options = list(scrollX = TRUE))
} else {
    cat("\n", "No overexpressed/underexpressed surface genes", "\n")
}

Waterfall plot - surface genes

waterfall.fn = file.path(params$outdir, "surface.waterfall.png")
## cat(waterfall.fn)
if (file.exists(waterfall.fn)) {
   cat(paste0("![](", waterfall.fn, ")"), "\n")
   ##knitr::include_graphics(waterfall.fn)
   cat(paste0("\n", "Waterfall plot showing relative gene expression of surface genes", "\n"))
} else {
   cat("Waterfall plot with relative gene expression of surface genes is not available")
}

r paste('<div id="surface-expression-gallery" class="section level2 tabset tabset-fade tabset-pills">')

Expression gallery - surface genes{.tabset .tabset-fade .tabset-pills}

 if (file.good(paste0(params$outdir, "/", "surface.rna.change.txt"))) {
     expr.hist.dt = fread(file.path(params$outdir, "surface.expr.histograms.txt"))
     cool.exp = fread(paste0(params$outdir, "/", "surface.rna.change.txt"))
     expr.slickr.dt = fread(file.path(params$outdir, "surface.expr.gallery.txt"))
     cat("\n")
     valid.genes = intersect(expr.hist.dt[, gene], expr.slickr.dt[, gene_name])
     for (g in valid.genes) {
        expr.png.fn = expr.hist.dt[gene == g, expr.hist.fname][1]
    gg.png.fn = expr.slickr.dt[gene_name == g, plot.fname][1]
        cat("\n")

    if (file.exists(expr.png.fn) & file.exists(gg.png.fn)) {
          cat("\n")
        cat('<div id="',paste0(g,"-eg"),'" class="section level3">')
        cat("\n")
         cat("###", cool.exp[gene == g, paste0(gene, " (", direction, ")", "<br>", "\n")])
         cat("Z-Score:",signif(cool.exp[cool.exp$gene==g,]$zscore,digits=4))

         cat(
            paste0(
                '<p float="left">',
                '<img src="',
            expr.png.fn,
                '" width="45%" />',
                '<img src="',
                gg.png.fn,
                '" width="45%" />',
                '</p>'
            )
        )
    }
        cat("</div>")
    } 
        cat('\n', '<br>', '\n\n')
    } else {
    cat("\n", "Gene expression for surface genes not available", "\n")
    }

SV event classifications


Burdens of event types

Count of complex events against background distribution from Cell cohort.

knitr::include_graphics(file.path(params$outdir, "ridgeplot.png"))

r paste('<div id="complex-sv-gallery" class="section level2 tabset tabset-fade tabset-pills">')

Complex SV gallery {.tabset .tabset-fade .tabset-pills}

## read data table with plot png/URL
if (file.good(file.path(params$outdir, "sv.gallery.txt"))){
    sv.slickr.dt = fread(file.path(params$outdir, "sv.gallery.txt"))[!is.na(plot.link),]
}
events=unique(sv.slickr.dt$type)
if (file.good(file.path(params$outdir, "sv.gallery.txt"))){
    sv.slickr.dt = fread(file.path(params$outdir, "sv.gallery.txt"))[!is.na(plot.link),]
    if (nrow(sv.slickr.dt)) {
      if("qrp" %in% sv.slickr.dt$type){
      cat('<div id="qrp-sec" class="section level3">')
      cat("\n")
      cat("### qrp")
      cat("\n")

    slick_up = slickR(obj = sv.slickr.dt[type=="qrp",]$plot.fname, height = 800, width = "95%", objLinks = sv.slickr.dt[type=="qrp",]$plot.link) + settings(slidesToShow = 1, slidesToScroll = 1) + settings(dots = TRUE)
    slick_up
    } 
}  else {
   cat("\n", "No complex SVs", "\n")
}} else {
   cat("\n", "Complex SVs not available", "\n")
}

if(file.good(file.path(params$outdir, "sv.gallery.txt")) && nrow(sv.slickr.dt) && "qrp" %in% sv.slickr.dt$type){ cat("\n","</div>","\n")}
## read data table with plot png/URL
events=unique(sv.slickr.dt$type)
if (file.good(file.path(params$outdir, "sv.gallery.txt"))){
    sv.slickr.dt = fread(file.path(params$outdir, "sv.gallery.txt"))[!is.na(plot.link),]
    if (nrow(sv.slickr.dt) && "tic" %in% sv.slickr.dt$type) {
      cat('<div id="tic-sec" class="section level3">')
      cat("\n")
      cat("### tic")
      cat("\n")
    slick_up = slickR(obj = sv.slickr.dt[type=="tic",]$plot.fname, height = 800, width = "95%", objLinks = sv.slickr.dt[type=="tic",]$plot.link) + settings(slidesToShow = 1, slidesToScroll = 1) + settings(dots = TRUE)
    slick_up
    }}

if(file.good(file.path(params$outdir, "sv.gallery.txt")) && nrow(sv.slickr.dt) && "tic" %in% sv.slickr.dt$type){ cat("\n","</div>","\n")}
## read data table with plot png/URL
events=unique(sv.slickr.dt$type)
if (file.good(file.path(params$outdir, "sv.gallery.txt"))){
    sv.slickr.dt = fread(file.path(params$outdir, "sv.gallery.txt"))[!is.na(plot.link),]
    if (nrow(sv.slickr.dt) && "qpdup" %in% sv.slickr.dt$type) {
      cat('<div id="qpdup-sec" class="section level3">')
      cat("\n")
      cat("### qpdup")
      cat("\n")
    slick_up = slickR(obj = sv.slickr.dt[type=="qpdup",]$plot.fname, height = 800, width = "95%", objLinks = sv.slickr.dt[type=="qpdup",]$plot.link) + settings(slidesToShow = 1, slidesToScroll = 1) + settings(dots = TRUE)
    slick_up
    }}

if(file.good(file.path(params$outdir, "sv.gallery.txt")) && nrow(sv.slickr.dt) && "qpdup" %in% sv.slickr.dt$type){ cat("\n","</div>","\n")}
## read data table with plot png/URL
events=unique(sv.slickr.dt$type)
if (file.good(file.path(params$outdir, "sv.gallery.txt"))){
    sv.slickr.dt = fread(file.path(params$outdir, "sv.gallery.txt"))[!is.na(plot.link),]
    if (nrow(sv.slickr.dt) && "qrdel" %in% sv.slickr.dt$type) {
      cat('<div id="qrdel-sec" class="section level3">')
      cat("\n")
      cat("### qrdel")
      cat("\n")
    slick_up = slickR(obj = sv.slickr.dt[type=="qrdel",]$plot.fname, height = 800, width = "95%", objLinks = sv.slickr.dt[type=="qrdel",]$plot.link) + settings(slidesToShow = 1, slidesToScroll = 1) + settings(dots = TRUE)
    slick_up
    }}

if(file.good(file.path(params$outdir, "sv.gallery.txt")) && nrow(sv.slickr.dt) && "qrdel" %in% sv.slickr.dt$type){ cat("\n","</div>","\n")}
## read data table with plot png/URL
events=unique(sv.slickr.dt$type)
if (file.good(file.path(params$outdir, "sv.gallery.txt"))){
    sv.slickr.dt = fread(file.path(params$outdir, "sv.gallery.txt"))[!is.na(plot.link),]
    if (nrow(sv.slickr.dt) && "bfb" %in% sv.slickr.dt$type) {
      cat('<div id="bfb-sec" class="section level3">')
      cat("\n")
      cat("### bfb")
      cat("\n")
    slick_up = slickR(obj = sv.slickr.dt[type=="bfb",]$plot.fname, height = 800, width = "95%", objLinks = sv.slickr.dt[type=="bfb",]$plot.link) + settings(slidesToShow = 1, slidesToScroll = 1) + settings(dots = TRUE)
    slick_up
    }}
if(file.good(file.path(params$outdir, "sv.gallery.txt")) && nrow(sv.slickr.dt) && "bfb" %in% sv.slickr.dt$type){ cat("\n","</div>","\n")}
## read data table with plot png/URL
events=unique(sv.slickr.dt$type)
if (file.good(file.path(params$outdir, "sv.gallery.txt"))){
    sv.slickr.dt = fread(file.path(params$outdir, "sv.gallery.txt"))[!is.na(plot.link),]
    if (nrow(sv.slickr.dt) && "dm" %in% sv.slickr.dt$type) {
      cat('<div id="dm-sec" class="section level3">')
      cat("\n")
      cat("### dm")
      cat("\n")
    slick_up = slickR(obj = sv.slickr.dt[type=="dm",]$plot.fname, height = 800, width = "95%", objLinks = sv.slickr.dt[type=="dm",]$plot.link) + settings(slidesToShow = 1, slidesToScroll = 1) + settings(dots = TRUE)
    slick_up
    }}
if(file.good(file.path(params$outdir, "sv.gallery.txt")) && nrow(sv.slickr.dt) && "dm" %in% sv.slickr.dt$type){ cat("\n","</div>","\n")}
## read data table with plot png/URL
events=unique(sv.slickr.dt$type)
if (file.good(file.path(params$outdir, "sv.gallery.txt"))){
    sv.slickr.dt = fread(file.path(params$outdir, "sv.gallery.txt"))[!is.na(plot.link),]
    if (nrow(sv.slickr.dt) && "chromoplexy" %in% sv.slickr.dt$type) {
      cat('<div id="chromoplexy-sec" class="section level3">')
      cat("\n")
      cat("### chromoplexy")
      cat("\n")
    slick_up = slickR(obj = sv.slickr.dt[type=="chromoplexy",]$plot.fname, height = 800, width = "95%", objLinks = sv.slickr.dt[type=="chromoplexy",]$plot.link) + settings(slidesToShow = 1, slidesToScroll = 1) + settings(dots = TRUE)
    slick_up
    }}

if(file.good(file.path(params$outdir, "sv.gallery.txt")) && nrow(sv.slickr.dt) && "chromoplexy" %in% sv.slickr.dt$type){ cat("\n","</div>","\n")}
## read data table with plot png/URL
events=unique(sv.slickr.dt$type)
if (file.good(file.path(params$outdir, "sv.gallery.txt"))){
    sv.slickr.dt = fread(file.path(params$outdir, "sv.gallery.txt"))[!is.na(plot.link),]
    if (nrow(sv.slickr.dt) && "chromothripsis" %in% sv.slickr.dt$type) {
      cat('<div id="chromothripsis-sec" class="section level3">')
      cat("\n")
      cat("### chromothripsis")
      cat("\n")
    slick_up = slickR(obj = sv.slickr.dt[type=="chromothripsis",]$plot.fname, height = 800, width = "95%", objLinks = sv.slickr.dt[type=="chromothripsis",]$plot.link) + settings(slidesToShow = 1, slidesToScroll = 1) + settings(dots = TRUE)
    slick_up
    }}
if(file.good(file.path(params$outdir, "sv.gallery.txt")) && nrow(sv.slickr.dt) && "chromothripsis" %in% sv.slickr.dt$type){ cat("\n","</div>","\n")}
## read data table with plot png/URL
events=unique(sv.slickr.dt$type)
if (file.good(file.path(params$outdir, "sv.gallery.txt"))){
    sv.slickr.dt = fread(file.path(params$outdir, "sv.gallery.txt"))[!is.na(plot.link),]
    if (nrow(sv.slickr.dt) && "tyfonas" %in% sv.slickr.dt$type) {
      cat('<div id="typhonas-sec" class="section level3">')
      cat("\n")
      cat("### tyfonas")
      cat("\n")
    slick_up = slickR(obj = sv.slickr.dt[type=="tyfonas",]$plot.fname, height = 800, width = "95%", objLinks = sv.slickr.dt[type=="tyfonas",]$plot.link) + settings(slidesToShow = 1, slidesToScroll = 1) + settings(dots = TRUE)
    slick_up
    }}
if(file.good(file.path(params$outdir, "sv.gallery.txt")) && nrow(sv.slickr.dt) && "typhonas" %in% sv.slickr.dt$type){ cat("\n","</div>","\n")}
## read data table with plot png/URL
events=unique(sv.slickr.dt$type)
if (file.good(file.path(params$outdir, "sv.gallery.txt"))){
    sv.slickr.dt = fread(file.path(params$outdir, "sv.gallery.txt"))[!is.na(plot.link),]
    if (nrow(sv.slickr.dt) && "rigma" %in% sv.slickr.dt$type) {
      cat('<div id="rigms-sec" class="section level3">')
      cat("\n")
      cat("### rigma")
      cat("\n")
    slick_up = slickR(obj = sv.slickr.dt[type=="rigma",]$plot.fname, height = 800, width = "95%", objLinks = sv.slickr.dt[type=="rigma",]$plot.link) + settings(slidesToShow = 1, slidesToScroll = 1) + settings(dots = TRUE)
    slick_up
    }}
if(file.good(file.path(params$outdir, "sv.gallery.txt")) && nrow(sv.slickr.dt) && "rigma" %in% sv.slickr.dt$type){ cat("\n","</div>","\n")}
## read data table with plot png/URL
events=unique(sv.slickr.dt$type)
if (file.good(file.path(params$outdir, "sv.gallery.txt"))){
    sv.slickr.dt = fread(file.path(params$outdir, "sv.gallery.txt"))[!is.na(plot.link),]
    if (nrow(sv.slickr.dt) && "pyrgo" %in% sv.slickr.dt$type) {
      cat('<div id="pyrgo-sec" class="section level3">')
      cat("\n")
      cat("### pyrgo")
      cat("\n")
    slick_up = slickR(obj = sv.slickr.dt[type=="pyrgo",]$plot.fname, height = 800, width = "95%", objLinks = sv.slickr.dt[type=="pyrgo",]$plot.link) + settings(slidesToShow = 1, slidesToScroll = 1) + settings(dots = TRUE)
    slick_up
    }}
if(file.good(file.path(params$outdir, "sv.gallery.txt")) && nrow(sv.slickr.dt) && "pyrgo" %in% sv.slickr.dt$type){ cat("\n","</div>","\n")}
## read data table with plot png/URL
events=unique(sv.slickr.dt$type)
if (file.good(file.path(params$outdir, "sv.gallery.txt"))){
    sv.slickr.dt = fread(file.path(params$outdir, "sv.gallery.txt"))[!is.na(plot.link),]
    if (nrow(sv.slickr.dt) && "cpxdm" %in% sv.slickr.dt$type) {
      cat('<div id="cpxdm-sec" class="section level3">')
      cat("\n")
      cat("### cpxdm")
      cat("\n")
    slick_up = slickR(obj = sv.slickr.dt[type=="cpxdm",]$plot.fname, height = 800, width = "95%", objLinks = sv.slickr.dt[type=="cpxdm",]$plot.link) + settings(slidesToShow = 1, slidesToScroll = 1) + settings(dots = TRUE)
    slick_up
    }}
if(file.good(file.path(params$outdir, "sv.gallery.txt")) && nrow(sv.slickr.dt) && "cpxdm" %in% sv.slickr.dt$type){ cat("\n","</div>","\n")}

Driver SNVs/indels

driver.mutations.dt = fread(file.path(params$outdir, "driver.mutations.txt"))
driver.mutations.dt$Tier=as.character(driver.mutations.dt$Tier)
driver.mutations.dt[is.na(driver.mutations.dt$Tier),]$Tier="Undefined"
DT::datatable(driver.mutations.dt, options = list(scrollX = TRUE))

Driver Germline SNVs/indels

driver.germline.mutations.dt = fread(file.path(params$outdir, "driver.germline.mutations.txt"))
DT::datatable(driver.germline.mutations.dt, options = list(scrollX = TRUE))

SNV signatures {.tabset .tabset-fade .tabset-pills}

Fitting COSMIC signatures to the whole genome mutation profiles of this sample we obtain the following active SNV mutation signatures:

if (file.exists(file.path(params$outdir,"signatureMetadata.csv")) && file.good(paste0(params$outdir, "/deconstruct_sigs.png"))){
    cat('<div id="SNV-Meta" class="section level2">',"\n")
    cat("## SNV signature information")
    cat("\n")
    sig.metadata=fread(file.path(params$outdir,"signatureMetadata.csv"))
    sig.metadata=sig.metadata[order(sig.metadata$sig_count,decreasing = TRUE),]
     print(kable(sig.metadata,digits=2, "simple"))
    cat("\n")
    cat("\n")
    cat('Click <a href="https://cancer.sanger.ac.uk/signatures/sbs/">here</a> for a catalog of COSMIC single base substitution signatures.')
     cat("\n")
     cat ("</div>","\n")
}else{
  cat("No active mutation signatures.")
  cat ("\n<br>\n")
}
if (file.good(paste0(params$outdir, "/deconstruct_sigs.png"))){
    cat("\n")
    cat('<div id="deconstructsigs-first" class="section level2">')
    cat("\n")
    cat("## deconstructSigs: input profile, fitted, error")
    cat("\n")
    ## knitr::include_graphics(paste0(params$outdir, "/deconstruct_sigs.png"))

    cat(
        paste0("![](", paste0(params$outdir, "/deconstruct_sigs.png"),")"), "\n"
    )
    cat ("</div>","\n")
    cat ("\n<br>\n")

    cat('<div id="sigcomp" class="section level2">')
    cat("\n")
    cat("## SNV signature composition")
    cat("\n")

    if (file.exists(paste0(params$outdir, "/sig.composition.png"))) {
        cat(
            paste0("![](", paste0(params$outdir, "/sig.composition.png"),")"), "\n")
    }    

    cat ("</div>","\n")
    cat ("\n<br>\n")

}

Oneness/Twoness

ot.plot = paste0(params$outdir, "/onenesstwoness.log.dat.png")
ot.plot.2 = paste0(params$outdir, "/onenesstwoness.prop.dat.png")
oneness.plot = paste0(params$outdir, "/Oneness.png")
twoness.plot = paste0(params$outdir, "/Twoness.png")

all.good = file.good(ot.plot) & file.good(ot.plot.2) & file.good(oneness.plot) & file.good(twoness.plot)

if (all.good) {
   #cat("# Oneness/Twoness\n")
   cat("## Score distributions\n")
   cat(paste0("![](", ot.plot,")"), "\n\n")
   cat(paste0("![](", ot.plot.2,")"), "\n\n")
   cat("## BRCA1\n")
   cat(paste0("![](", oneness.plot,")"), "\n\n")
   cat("## BRCA2\n")
   cat(paste0("![](", twoness.plot,")"), "\n\n")
}

HRDetect prediction (homologous recombination deficiency)

if (file.exists(paste0(params$outdir, "/hrdetect.rds"))){
    cat("Applying the [HRDetect](https://doi.org/10.1038/nm.4292) model, we
predict homologous recombination deficiency status of this sample
based on its SNV/INDEL/SV signatures.\n\n")

    hrd = readRDS(file.path(params$outdir, "hrdetect.rds"))
    hrd.yes = hrd[variable=="Probability", value>0.7]
    cat("This sample is classified as", ifelse(hrd.yes, "**HR deficient**", "**NOT** HR deficient"), ".\n")

    hrdetect.dims = setNames(        
        c('intercept',
          'Proportion of DELs\nwith microhomology',
          'SBS3',
          'SV signature 3',
          'SV signature 5',
          'HRD index (LOH)',
          'SBS8',
          'Probability of HR Deficiency'),
        c('Intercept', 'del.mh.prop', 'SNV3', 'SV3', 'SV5', 'hrd', 'SNV8', 'Probability')
    )

    cat(kbl(hrd[, .(Variable = hrdetect.dims[variable], value = sprintf("%f", value))]) %>%
        kable_classic(full_width = FALSE) %>%
        row_spec(8, bold = T, color = "white", background = ifelse(hrd.yes, "#D7261E", "#1f78b4")))

    cat("\n<br>\n")
    ## insert the plots of input data
    cat(
        paste0("![](", file.path(params$outdir, "hrdetect.log.dat.png"),")"), "\n\n"
    )
    cat(
        paste0("![](", file.path(params$outdir, "hrdetect.prop.dat.png"),")"), "\n\n"
    )
}

Enhancer hijacking candidates {.tabset .tabset-fade .tabset-pills}

proximity.gallery.dt = fread(paste0(params$outdir, "/", "proximity.gallery.txt"))
expr.histograms.dt = fread(paste0(params$outdir, "/", "expr.histograms.txt"))

if (nrow(proximity.gallery.dt) & nrow(expr.histograms.dt)) {
   gns = intersect(proximity.gallery.dt$gene, expr.histograms.dt$gene)
   for (g in gns) {
        cat("\n")
        cat('<div id="',paste0(g,"-ehc"),'" class="section level2">')
        cat("\n")
        cat("## ", g, "\n<br>\n")
        cat('<div class="superbigimage">',"\n",
        paste0(
            '<p float="center">',
        '<img src="',
        proximity.gallery.dt[gene == g, plot.fname],
        '" width="125%" />','</p>'),
        "\n",'</div>',"<br>","<br>","<br>","<br>","<br>","<br>",
        paste0('<p class="aligncenter">','<img src="',
        expr.histograms.dt[gene == g, expr.hist.fname],
        '" width="60%" alt="centered image"/>',
        '</p>')
            )
        cat ("</div>","\n")
    }
} else {
  cat("No enhancer hijacking candidates are available")
}
cat('\n', '<br>', '\n\n')

Loose ends

There are xx high quality loose ends in this sample.


Purity and ploidy estimation

Here is the fitting of purity and ploidy values to the distribution of a random sample of primary segment coverage intensities with replacement. A good fit should have the red vertical lines (integer CN grid) align well with the peaks in the raw intensity distribution (black histogram).


Total CN

knitr::include_graphics(file.path(params$outdir, "cn.pp.png"))

Allelic CN

if (file.good(file.path(params$outdir, "allele.scatter.png"))){
    knitr::include_graphics(file.path(params$outdir, "allele.scatter.png"))
}

Deconvolution

if (file.good(file.path(params$outdir, "deconv_results.txt"))){
    cat(paste0("This is a deconvolution of this sample's TPM Transcriptome using the ",readRDS(file.path(params$outdir, "cmd.args.rds"))$deconv," algorithm."))
    deconv_results.dt = fread(file.path(params$outdir, "deconv_results.txt"))
    colnames(deconv_results.dt)=c("Cell_Type","Deconv_Value")
    deconv_results.dt$Deconv_Value=unlist(lapply(deconv_results.dt$Deconv_Value,FUN=signif,digits=4))
    DT::datatable(deconv_results.dt, options = list(scrollX = TRUE))
}


mskilab/casereport documentation built on Oct. 19, 2022, 3 a.m.