stianlagstad / chimeraviz

chimeraviz is an R package that automates the creation of chimeric RNA visualizations.
37 stars 14 forks source link

Graphics issue in plotFusion and plotFusionReads #7

Closed komalsrathi closed 6 years ago

komalsrathi commented 6 years ago

Hi Stian,

I am facing a lot of graphics issue so for simplicity, I am just using your test code so it is easier for you to reproduce the problem:

library(chimeraviz)

# Get reference to results file from deFuse
defuse833ke <- system.file(
  "extdata",
  "defuse_833ke_results.filtered.tsv",
  package="chimeraviz")

# Load the results file into a list of fusion objects
fusions <- importDefuse(defuse833ke, "hg19", 1)

length(fusions)

fusion <- getFusionById(fusions, 5267)

fastq1 <- system.file(
  "extdata",
  "reads_supporting_defuse_fusion_5267.1.fq",
  package = "chimeraviz")

fastq2 <- system.file(
  "extdata",
  "reads_supporting_defuse_fusion_5267.2.fq",
  package = "chimeraviz")

referenceFilename <- "reference.fa"
writeFusionReference(fusion = fusion, filename = referenceFilename)
source(system.file(
  "scripts",
  "rsubread.R",
  package="chimeraviz"))

# Then create index
rsubreadIndex(referenceFasta = referenceFilename)
rsubreadAlign(
  referenceName = referenceFilename,
  fastq1 = fastq1,
  fastq2 = fastq2,
  outputBamFilename = "fusionAlignment")

if(!exists("bamfile5267")) {
  bamfile5267 <- system.file(
    "extdata",
    "5267readsAligned.bam",
    package="chimeraviz")
}

fusion <- addFusionReadsAlignment(fusion, bamfile5267)
plotFusionReads(fusion = fusion)

# another bam file
if(!exists("bamfile5267")) {
  bamfile5267 <- system.file(
    "extdata",
    "5267readsAligned.bam",
    package="chimeraviz")
}
fusion <- addFusionReadsAlignment(fusion, bamfile5267)
plotFusionReads(fusion = fusion, showAllNucleotides = TRUE)

At this point, this is the plot I am getting -

image

Why is it not showing the ATGC and showing colored bars instead?

Another plot that is not showing correctly:

if(!exists("defuse833ke"))
  defuse833ke <- system.file(
    "extdata",
    "defuse_833ke_results.filtered.tsv",
    package = "chimeraviz")

# Then load the fusion events
fusions <- importDefuse(defuse833ke, "hg19", 1)
fusion <- getFusionById(fusions, 5267)
if(!exists("edbSqliteFile"))
  edbSqliteFile <- system.file(
    "extdata",
    "Homo_sapiens.GRCh37.74.sqlite",
    package="chimeraviz")
# Then load it
edb <- ensembldb::EnsDb(edbSqliteFile)

if(!exists("fusion5267and11759reads"))
  fusion5267and11759reads <- system.file(
    "extdata",
    "fusion5267and11759reads.bam",
    package = "chimeraviz")

plotFusion(
  fusion = fusion,
  bamfile = bamfile5267,
  edb = edb,
  nonUCSC = TRUE,
  reduceTranscripts = TRUE)

image

Here the red arc is not showing properly that should connect the two exons of RCC1 and HENMT1.

Here is my sessionInfo:

> sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X El Capitan 10.11.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8

attached base packages:
 [1] grid      stats4    parallel  stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] chimeraviz_1.2.2       ensembldb_2.0.4        AnnotationFilter_1.0.0 GenomicFeatures_1.28.5 AnnotationDbi_1.38.2  
 [6] Biobase_2.36.2         Gviz_1.20.0            GenomicRanges_1.28.6   GenomeInfoDb_1.12.3    Biostrings_2.44.2     
[11] XVector_0.16.0         IRanges_2.10.5         S4Vectors_0.14.7       BiocGenerics_0.22.1    BiocInstaller_1.26.1  

loaded via a namespace (and not attached):
 [1] ProtGenerics_1.8.0            bitops_1.0-6                  matrixStats_0.52.2           
 [4] bit64_0.9-7                   RColorBrewer_1.1-2            httr_1.3.1                   
 [7] rprojroot_1.2                 tools_3.4.2                   backports_1.1.1              
[10] R6_2.2.2                      DT_0.2                        rpart_4.1-11                 
[13] Hmisc_4.0-3                   DBI_0.7                       lazyeval_0.2.0               
[16] colorspace_1.3-2              nnet_7.3-12                   gridExtra_2.3                
[19] bit_1.1-12                    curl_3.0                      compiler_3.4.2               
[22] htmlTable_1.9                 DelayedArray_0.2.7            rtracklayer_1.36.6           
[25] scales_0.5.0                  checkmate_1.8.4               readr_1.1.1                  
[28] RCircos_1.2.0                 stringr_1.2.0                 digest_0.6.12                
[31] Rsamtools_1.28.0              foreign_0.8-69                rmarkdown_1.6                
[34] Rsubread_1.26.1               base64enc_0.1-3               dichromat_2.0-0              
[37] pkgconfig_2.0.1               htmltools_0.3.6               BSgenome_1.44.2              
[40] htmlwidgets_0.9               rlang_0.1.2                   RSQLite_2.0                  
[43] shiny_1.0.5                   BiocParallel_1.10.1           acepack_1.4.1                
[46] VariantAnnotation_1.22.3      RCurl_1.95-4.8                magrittr_1.5                 
[49] GenomeInfoDbData_0.99.0       Formula_1.2-2                 Matrix_1.2-11                
[52] Rcpp_0.12.13                  munsell_0.4.3                 stringi_1.1.5                
[55] yaml_2.1.14                   SummarizedExperiment_1.6.5    zlibbioc_1.22.0              
[58] org.Hs.eg.db_3.4.1            plyr_1.8.4                    AnnotationHub_2.8.2          
[61] blob_1.1.0                    lattice_0.20-35               splines_3.4.2                
[64] hms_0.3                       knitr_1.17                    biomaRt_2.32.1               
[67] XML_3.98-1.9                  evaluate_0.10.1               biovizBase_1.24.0            
[70] latticeExtra_0.6-28           data.table_1.10.4-1           httpuv_1.3.5                 
[73] gtable_0.2.0                  ggplot2_2.2.1                 mime_0.5                     
[76] xtable_1.8-2                  ArgumentCheck_0.10.2          survival_2.41-3              
[79] tibble_1.3.4                  GenomicAlignments_1.12.2      memoise_1.1.0                
[82] cluster_2.0.6                 interactiveDisplayBase_1.14.0 BiocStyle_2.4.1      
stianlagstad commented 6 years ago

The first issue is that there's not enough rom on the screen to actually show you all the nucleotides. You can limit the amount of nucleotides with the nucleotideAmount parameter - that'll let you experiment a bit and find the limit. Try setting it to 10 to start, and also set showAllNucleotides to FALSE.

plotFusionReads(fusion = fusion, showAllNucleotides = FALSE, nucleotideAmount = 10)

rplot


I reproduced the second issue this morning on a mac at work. For some reason it draws the arc outside of the actual plot. But it seems to be a mac-specific problem. I'm not able to reproduce the error with my home laptop running Ubuntu. This code:

library(chimeraviz)
if(!exists("defuse833ke"))
  defuse833ke <- system.file(
    "extdata",
    "defuse_833ke_results.filtered.tsv",
    package = "chimeraviz")

# Then load the fusion events
fusions <- importDefuse(defuse833ke, "hg19", 1)
fusion <- getFusionById(fusions, 5267)
if(!exists("edbSqliteFile"))
  edbSqliteFile <- system.file(
    "extdata",
    "Homo_sapiens.GRCh37.74.sqlite",
    package="chimeraviz")
# Then load it
edb <- ensembldb::EnsDb(edbSqliteFile)

if(!exists("fusion5267and11759reads"))
  fusion5267and11759reads <- system.file(
    "extdata",
    "fusion5267and11759reads.bam",
    package = "chimeraviz")

if(!exists("bamfile5267")) {
  bamfile5267 <- system.file(
    "extdata",
    "5267readsAligned.bam",
    package="chimeraviz")
}

plotFusion(
  fusion = fusion,
  bamfile = bamfile5267,
  edb = edb,
  nonUCSC = TRUE,
  reduceTranscripts = TRUE)

Produces this plot for me: rplot

Edit: Back on the mac, that same code produces this plot: rplot

I'll look into this as soon as I can!

stianlagstad commented 6 years ago

Just to show a sign of life: So far I'm clueless. In the plotFusion function I use Gviz::coords() to fetch the coordinates of where the exons are plotted in the picture. I use these to decide where to draw the red arc. For some reason the y coordinates those code lines returns on a mac are off. I don't know why yet. I don't really think it's a Gviz issue.

Relevant chimeraviz code from plotFusion.R:

    # Get coordinates for the exons in the plot
    exonCoordinates1 <- Gviz::coords(res1$GeneRegionTrack)
    exonCoordinates2 <- Gviz::coords(res2$GeneRegionTrack)
stianlagstad commented 6 years ago

After getting some help on the bioc-devel list I got a bit further. The arc turns up where it's supposed to when I use another graphics device. Could you try that as well? I.e. try:

# Load data and example fusion event
defuse833ke <- system.file(
  "extdata",
  "defuse_833ke_results.filtered.tsv",
  package="chimeraviz")
fusions <- importDefuse(defuse833ke, "hg19", 1)
fusion <- getFusionById(fusions, 5267)
# Load edb
edbSqliteFile <- system.file(
  "extdata",
  "Homo_sapiens.GRCh37.74.sqlite",
  package="chimeraviz")
edb <- ensembldb::EnsDb(edbSqliteFile)
# bamfile with reads in the regions of this fusion event
bamfile5267 <- system.file(
  "extdata",
  "fusion5267and11759reads.bam",
  package="chimeraviz")
# Temporary file to store the plot
pngFilename <- "testplot.png"
# Open device
png(pngFilename, width = 1000, height = 750)
# Plot!
plotFusion(
  fusion = fusion,
  bamfile = bamfile5267,
  edb = edb,
  nonUCSC = TRUE)
# Close device
dev.off()

and then see what testplot.png looks like?

komalsrathi commented 6 years ago

Yes this works for me -- thanks! I am testing the entire code now and will update you on it.

testplot

Thanks a lot!

stianlagstad commented 6 years ago

Great! I'll look more into the default graphics driver on mac and try to figure out the issue. But I'll close this :)