broadinstitute / infercnv

Inferring CNV from Single-Cell RNA-Seq
Other
557 stars 164 forks source link

observations part heatmap is empty #516

Open BioLaoXu opened 1 year ago

BioLaoXu commented 1 year ago

Hear Team Thank you and your team for inventing such a user-friendly tool. I encountered some issues while using infercnv, which left me very confused. I processed the data according to seurat's standard procedure, and I labeled three subsets of CD45 expression as immune cell cluster, and the remaining clusters as tumor-like clusters.then i put the celltype annotation information and seurat count matrix&gene meta information file for infercnv,infercnv running complete the analysis smoothly, but the result is very weird, the reference group cells have a heat map of CNV, but the results of the observations cells are empty, is my parameter given wrong or an error occurred inside the model or my approach is wrong.The graph below is my result,Looking forward to your reply,thanks

image

Here is my code:

load("expMatrix.rda")
print(dim(counts_matrix))

infercnv_obj = CreateInfercnvObject(raw_counts_matrix=counts_matrix,
                                    annotations_file="cellAnno.txt",
                                    delim="\t",
                                    gene_order_file="geneMeta.txt",
                                    ref_group_names=c("ImmuneCell")) 

infercnv_obj = infercnv::run(infercnv_obj,
                             cutoff=1, 
                             out_dir="result_no_ref", 
                             cluster_by_groups=F,
                             denoise=TRUE,
                             HMM=F,
                             output_format = "pdf",
                             num_threads=16,write_expr_matrix =T)
BioLaoXu commented 1 year ago

Dear development team, I have further redrawn the solution on this page for plot_cnv,my code as below,but an error has occurred.

infercnv_obj = readRDS("./result/run.final.infercnv_obj")
Sys.setenv("DISPLAY"="localhost:11.0")
options(bitmapType="Xlib")

plot_cnv(infercnv_obj,
         out_dir="./plot",
         obs_title="Observations (Cells)",
         ref_title="References (Cells)",
         cluster_by_groups=F,
         x.center=1,
         x.range="auto",
         hclust_method='ward.D',
         color_safe_pal=FALSE,
         output_filename="infercnv",
         output_format="png",
         png_res=300,
         dynamic_resize=0
)

微信图片_20230227092900

GeorgescuC commented 1 year ago

Hi @xf78 ,

The wiki page you mention is for a different bug where the the entire figure is blank, not only the observations heatmap. In your case it seems like using the default backend is fine.

Looking at the log of your dataset I see a couple things:

1) only 1291 genes are kept in the analysis, which is a very low number. Simply looking at the number of cells you have, it is likely you are using 10X rather than SmartSeq2 sequencing, while using a cutoff of 1. You most likely need to lower the cutoff to adjust for the sequencing depth in your dataset. If you it is indeed 10X data, trying with a cutoff of 0.1 should be better.

2) you have ~200k cells (99% as observations) and the dendrogram structure looks like you have a lot of small subclusters (maybe down to mostly individual cells. It is possible that because each subcluster is so small, each has less than 1 pixel of height on the heatmap, meaning there is compression between different expression patterns, which may be averaged to 1/blank. If this persists after addressing the previous point about number of genes, I would reduce the leiden_resolution parameter to 0.01, but you may need to go lower.

3) the dynamic_resize option is set to 0 (default), which means the figure has a static size. Seeing how many cells are in your dataset, it would probably be good to have the setting be non zero so the figure is taller and there is less compression (number of cells represented per pixel in height). You can start with a small value such as 0.1 or 0.2 to avoid having too big a figure.

I would first address 1) and 2) and see if the plots still have a blank observations heatmap after. If that is the case, please let me post the log and information about your machine/environment.

Regards, Christophe.

BioLaoXu commented 1 year ago

Thanks@GeorgescuC

My data is indeed produced by the 10X platform,I modified the parameters of the run function as you suggested, and the detailed code is as follows

plot_cnv=infercnv::plot_cnv
formals(plot_cnv)$dynamic_resize=0.1

load("expMatrix.rda")
print(dim(counts_matrix))

infercnv_obj = CreateInfercnvObject(raw_counts_matrix=counts_matrix,
                                    annotations_file="cellAnno.txt",
                                    delim="\t",
                                    gene_order_file="geneMeta.txt",
                                    ref_group_names=c("ImmuneCell")
                                    # ref_group_names=NULL
                                    ) 

infercnv_obj = infercnv::run(infercnv_obj,
                             cutoff=0.1, leiden_resolution=0.01,
                             out_dir="result_c0.1", 
                             cluster_by_groups=F,
                             denoise=TRUE,
                             HMM=F,
                             output_format = "pdf",
                             num_threads=16,write_expr_matrix =T)

but an error has occurred,The error message is same with [#510] image

GeorgescuC commented 1 year ago

Hi @xf78 ,

Can you try rerunning infercnv after running options(error = function() traceback(2)) first? This will should more information about precisely where the issue happens. In the thread you mentionned, the issue appears to be with the install of a dependency, but it might be different for your case.

Regards, Christophe.