Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
745757 opened this issue Apr 28, 2023 · 8 comments
Open

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

745757 opened this issue Apr 28, 2023 · 8 comments

Comments

@745757
Copy link

745757 commented Apr 28, 2023

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
Copy link
Collaborator

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([email protected])

Regards,
Christophe.

@axiba053
Copy link

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

@GeorgescuC
Copy link
Collaborator

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
Copy link

hecunzou commented Jun 7, 2023

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
Copy link
Author

745757 commented Jun 8, 2023

This was resolved when I used the earlier version 12.0

@GeorgescuC
Copy link
Collaborator

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
Copy link

hecunzou commented Jun 16, 2023 via email

@andynkili
Copy link

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants