stephenslab / fastTopics

Fast algorithms for fitting topic models and non-negative matrix factorizations to count data.
https://stephenslab.github.io/fastTopics
Other
75 stars 7 forks source link

Error in verify.fit.and.count.matrix(X, fit) : Dimensions of input matrices "X" , "fit$F" and "fit$L" do not agree #44

Open ZhengYingqi-doctor opened 7 months ago

ZhengYingqi-doctor commented 7 months ago

When I run de_analysis(), there was an error:

> de <- de_analysis(fit,counts,pseudocount = 0.1, control = list(ns = 1e4,nc = 4))
Error in verify.fit.and.count.matrix(X, fit) : 
  Dimensions of input matrices "X" , "fit$F" and "fit$L" do not agree

The "counts" is a dgCMatrix

> str(counts)
Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  ..@ i       : int [1:35272029] 11 19 32 69 111 118 120 158 164 165 ...
  ..@ p       : int [1:15727] 0 1580 1967 3050 4257 6138 7258 8988 10550 11551 ...
  ..@ Dim     : int [1:2] 27197 15726
  ..@ Dimnames:List of 2
  .. ..$ : chr [1:27197] "AL627309.1" "AL669831.5" "FAM87B" "LINC00115" ...
  .. ..$ : chr [1:15726] "CRLM_P2_Colon_P_AGAGCAGGTACAGTAA" "CRLM_P17_Colon_T_GAGTTACCAAGTTTGC-1" "ICC_I02T_CGAGTGCCAGAGGCTA" "ICC_I03P_CTCTGGTAGAGCATAT" ...
  ..@ x       : num [1:35272029] 1 1 1 1 4 1 1 1 1 1 ...
  ..@ factors : list()

And I found that the "fit" only has 24141 genes after run > fit <- fit_topic_model(t(counts),k = n.topics). So how to solve this issue

pcarbo commented 7 months ago

Hi @ZhengYingqi-doctor thanks for your question. The "X" input argument for fit_topic_model() and de_analysis should be the same, otherwise you will get errors such as the one you got here.

ZhengYingqi-doctor commented 7 months ago

The "X" for fit_topic_model() is "counts":

> dim(counts)
[1] 15726 27197

But after running fit <- fit_topic_model(counts,k = 16), the number of genes was changed:

ZhengYingqi-doctor commented 7 months ago
> dim(fit$F);dim(fit$L)
[1] 24141     16
[1] 15726     16
pcarbo commented 7 months ago

@ZhengYingqi-doctor Did you get a warning that looked something like this? "One or more columns of X are all zero; after removing all-zero columns, n columns will be used for model fitting."