broadinstitute / infercnv

Inferring CNV from Single-Cell RNA-Seq
Other
566 stars 166 forks source link

Error in plot.new() : figure margins too large #533

Open 745757 opened 1 year ago

745757 commented 1 year ago

When I run the code in Linux infercnv_obj = infercnv::run(infercnv_obj, Cutoff = 0.1, out_dir="infercnv", cluster_by_groups=TRUE, denoise=TRUE, HMM=TRUE, num_threads=32)

In step 14, the following Error occurs: Error in plot.new() : figure margins too large

Unfortunately, I didn't find an effective solution

GeorgescuC commented 1 year ago

Hi @745757 ,

Which version of infercnv are you using?

Looking at the log or the backup of the object at step 14, what size is your matrix?

backup_obj = readRDS("14_invert_log_transformHMMi6.infercnv_obj")
dim(backup_obj@expr.data)

Regards, Christophe.

axiba053 commented 1 year ago

@GeorgescuC
Hello, I also encountered the same issue. the result of dim(backup_obj@expr.data) of my data is [1] 5531 45149 How can I resolve this issue?

GeorgescuC commented 1 year ago

Hi @axiba053 ,

Are you running the latest version of infercnv, or a somewhat recent version?

If you are on a Linux machine, can you try running options(bitmapType="Xlib") before trying to plot again?

If this doesn't solve the issue, what are the commands you are running? And would you be able to share the data privately? (the backup of the object at the step where the plotting error occurs)

Regards, Christophe.

hecunzou commented 1 year ago

Hello, When I run the code 'infercnv::run(...)' in Linux with the big data "dim() ->18965,68431", it will occurs the following Error "Error in plot.new() : figure margins too large", and it show the following calls "Calls: run ... image -> image.default -> plot -> plot.default -> plot.new". Meanwhile, in the results, it don't have the following files/figures, including:"preliminary.infercnv_obj", "infercnv.preliminary.png", "run.final.infercnv_obj", "infercnv.png" ...

While I try running options(bitmapType="Xlib") before trying to plot again, it shows the following Error "Error in .External2(C_X11, paste0("png::", filename), g$width, g$height, : unable to start device PNG" and it show the following calls "Calls: run -> plot_subclusters -> plot_cnv -> png"

I didn't find an effective solution, How can I resolve this issue?

745757 commented 1 year ago

This was resolved when I used the earlier version 12.0

GeorgescuC commented 1 year ago

Hi

@Hecunzou , Which version of infercnv are you using? When using the "Xlib" change, are you running R on your current machine, or on a server your are connected to? If you are using a server, have you also enabled X11 forwarding when connecting to it?

@745757 , Which version were you using prior to changing to 1.12.0? To have an idea of what change might have introduced the issue.

Regards, Christophe.

hecunzou commented 1 year ago

Hi, GeorgescuC

I'm using the version 1.16.0, and using infercnv on a Linux server.

When I run the code 'infercnv::run(...)' in Linux server with the big data "dim() ->18965,68431", even, the cells number (the number of column) more than 50000, it will occurs the following Error "Error in plot.new() : figure margins too large", and it show the following calls "Calls: run ... image -> image.default -> plot -> plot.default -> plot.new". Meanwhile, in the results, it don't have the following files/figures, including:"preliminary.infercnv_obj", "infercnv.preliminary.png", "run.final.infercnv_obj", "infercnv.png" ...

While I try running options(bitmapType="Xlib") before trying to plot again, it shows the following Error "Error in .External2(C_X11, paste0("png::", filename), g$width, g$height, : unable to start device PNG" and it show the following calls "Calls: run -> plot_subclusters -> plot_cnv -> png". Meanwhile, in the results, it don't have the above files/figures.

Now, I try to cut down the number of cells. This was resolved when I run the code 'infercnv::run(...)' in Linux server with the number of column less than 45000.

------------------ Original ------------------ From: @.>; Date:  Fri, Jun 16, 2023 00:24 AM To: @.>; Cc: @.>; @.>; Subject:  Re: [broadinstitute/infercnv] Error in plot.new() : figure margins too large (Issue #533)

Hi

@Hecunzou , Which version of infercnv are you using? When using the "Xlib" change, are you running R on your current machine, or on a server your are connected to? If you are using a server, have you also enabled X11 forwarding when connecting to it?

@745757 , Which version were you using prior to changing to 1.12.0? To have an idea of what change might have introduced the issue.

Regards, Christophe.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

andynkili commented 1 year ago

@GeorgescuC,

I am runnning inferCNV 1.16.0 and have the same error after setting options(bitmapType="Xlib") and enabling X11 forwarding while connecting to compute canada:

Error in .External2(C_X11, paste0("png::", filename), g$width, g$height,  :
  unable to start device PNG
Calls: lapply ... FUN -> <Anonymous> -> plot_subclusters -> plot_cnv -> png

Here is the code I use:

library(Seurat)
library(infercnv)

options(scipen = 100)
options(bitmapType="Xlib")
mydata<-readRDS("list.sample_annotated_ALLpreviousbyCLUSTERS.rds")

mydata<-lapply(names(mydata), function(x){
    DefaultAssay(mydata[[x]])<-'RNA'
    df<-mydata[[x]]@meta.data
    df<-subset(df,select = c('annotation'))

    write.table(df, file=paste(x,'cluster_annotation.tsv',sep='_'), quote=FALSE, sep='\t', col.names = F)

    #remove MHC genes from seurat object
    MHC_genes<-read.table('group-588.csv', quote = '"', header = T, sep = ',')
    counts <- GetAssayData(mydata[[x]], assay = "RNA")
    subcounts <- counts[-(which(rownames(counts) %in% MHC_genes$Approved.symbol)),]
    mydata[[x]]<-subset(mydata[[x]], features = rownames(subcounts))

    # create the infercnv object from the Seurat object
    infercnv_obj = CreateInfercnvObject(raw_counts_matrix=as.matrix(mydata[[x]]@assays$RNA@counts),
                                        annotations_file=paste(x,'cluster_annotation.tsv',sep='_'),
                                        delim="\t",
                                        gene_order_file='genes.tsv',
                                        ref_group_names=c("previous.Macrophage and Microglia.1","previous.Oligodendrocyte.6","previous.Macrophage and Microglia.8","previous.Oligodendrocyte.0","previous.Macrophage and Microglia.3","previous.Endothelial.13","previous.Macrophage and Microglia.4","previous.Macrophage and Microglia.2","previous.T-cells.9","previous.Ependymal.17","previous.Mural.14","previous.Oligodendrocyte.7","previous.Macrophage and Microglia.10","previous.RBC.15","previous.Macrophage and Microglia.11","previous.UN1.12","previous.NK-cells.16"))

    infercnv_obj = infercnv::run(infercnv_obj,
                                 cutoff=0.1,  # use 1 for smart-seq, 0.1 for 10x-genomics
                                 out_dir=paste(x,"refAllPreviousbyCLUSTER_win101_modeSubcluster",sep='_'),
                                 num_threads = 22,window_length = 101, #increase the windows to call large CNV events (reducing the noise)
                                 HMM_type = 'i6',BayesMaxPNormal = 0.5,
                                 plot_steps = F, plot_probabilities = F, save_rds = F, save_final_rds = T,no_prelim_plot = T,
                                 cluster_by_groups=T,   # cluster
                                 denoise=T,
                                 analysis_mode = "subcluster")

Note that there are a lot of clusters (17) as reference and I had initially the error: Error in plot.new() : figure margins too large before adding options(bitmapType="Xlib")

How can we fix that issue?