kgori / sigfit

Flexible Bayesian inference of mutational signatures
GNU General Public License v3.0
33 stars 8 forks source link

Trinucleotide context names for plot_spectrum #68

Closed fanghu-hku closed 1 year ago

fanghu-hku commented 1 year ago

Hi, Thank you for developing sigfit and it is an amazing tool. When I am trying to run the example code from Vignette:

library(sigfit) data("cosmic_signatures_v2") set.seed(1) probs <- c(0.4, 0.3, 0.2, 0.1) %*% as.matrix(cosmic_signatures_v2[c(1, 3, 7, 11), ]) mutations <- matrix(rmultinom(1, 20000, probs), nrow = 1) colnames(mutations) <- colnames(cosmic_signatures_v2) plot_spectrum(mutations, name = "Simulated counts")

The output of the spectrum looks weird as the Trinucleotide context names below bars are unicode instead of letters. Do you have any ideas of what happened?

sessionInfo() R version 4.0.3 (2020-10-10) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 20.04.1 LTS

Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0 LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
[4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

kgori commented 1 year ago

Hi,

I've not seen this problem before. Could you upload a screenshot? Have you come across this problem on other plots?

Kevin

fanghu-hku commented 1 year ago

03483c4e6c02895f4619c4101e7e5b5

Hi Kevin, The screenshot is attached. I didn't come across this problem before. Actually I used sigfit about one year ago and it works well. Not sure if there is something wrong with the UTF-8 encoding or something?

Hu

kgori commented 1 year ago

Hi Hu,

These spectrum plots are made using the standard barplot function. The only unusual things we do are:

  1. Use family="mono" to render the x-axis text
  2. Use cairo_pdf instead of pdf to write the output file

Maybe you could check if the text renders correctly with a generic barplot call, e.g.

cairo_pdf("test_cairo.pdf")
set.seed(1)
data <- runif(10, 1, 5)
lab <- letters[1:10]
barplot(data, names.arg = lab, las = 2, ylim = c(0, 5), yaxt = "n", family = "mono")
axis(side = 2, at = seq(0, 5))
title(main = "Test")
dev.off()

and see if the text comes out properly.

Kevin

fanghu-hku commented 1 year ago

Hi Kevin, Thanks for your reply. This doen't work properly (see Test1).

cairo_pdf("test_cairo.pdf")
set.seed(1)
data <- runif(10, 1, 5)
lab <- letters[1:10]
barplot(data, names.arg = lab, las = 2, ylim = c(0, 5), yaxt = "n", family = "mono")
axis(side = 2, at = seq(0, 5))
title(main = "Test")
dev.off()

But when I remove " family = "mono"" (Test2) or replace "cairo_pdf" with "pdf" (Test2), it seems work well. TEST1.pdf TEST2.pdf TEST3.pdf

kgori commented 1 year ago

Hi,

This looks like it's an issue with how either Cairo or monospaced fonts are set up on your system. However, I've pushed a possible workaround for you to a new "pdf" branch. If you want to try it out, you could reinstall sigfit using

remotes::install_github("kgori/sigfit@pdf",
                        build_vignettes=TRUE,
                        build_opts = c("--no-resave-data", "--no-manual"))

Then, when plotting, use the use_cairo argument to select the graphics device:

plot_spectrum(mutations, name = "Plotted with Cairo device", pdf_path = "cairoplot.pdf", use_cairo = TRUE)
plot_spectrum(mutations, name = "Plotted with standard device", pdf_path = "standardplot.pdf", use_cairo = FALSE)

Hopefully the standard device with be able to render your text properly.