cole-trapnell-lab / monocle3

Other
347 stars 102 forks source link

find_gene_modules() error #521

Open legeinei123 opened 3 years ago

legeinei123 commented 3 years ago

Hi,

I'm trying to run the find_gene_modules() function following the tutorial https://cole-trapnell-lab.github.io/monocle3/docs/differential/#branches from "Finding genes that change as a function of pseudotime". I didn't do the previous steps of the tutorial, as a had previously already created my cds class.

This is the line that produces the error

gene_module_df <- find_gene_modules(cds_subset[pr_deg_ids,], resolution=0.001)

The error I am getting is as follows:

Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels

The subset of cells I chose is a branch point with the initial cluster and the two subsequent clusters as in the tutorial. The subset cds looks like this:

class: cell_data_set 
dim: 29736 212 
metadata(2): cds_version citations
assays(1): counts
rownames(29736): Gnai3 Cdc45 ... ERCC-00170 ERCC-00171
rowData names(7): GeneID Chr ... Length gene_short_name
colnames(212): WT_PLATE8_A01 WT_PLATE8_A02 ... WT_PLATE28_H08 WT_PLATE28_H09
colData names(51): Genotype plate ... phases Size_Factor
reducedDimNames(2): PCA UMAP
mainExpName: NULL
altExpNames(0):

The two previous lines of code run fine as well.

subset_pr_test_res <- graph_test(cds_subset, neighbor_graph="principal_graph", cores=4)
pr_deg_ids <- row.names(subset(subset_pr_test_res, q_value < 0.05))

If I run the function with verbose = T i.e.

find_gene_modules(cds_subset[pr_deg_ids,], resolution=0.001, verbose = T)

I get this output prior to the error:

19:46:33 UMAP embedding parameters a = 1.577 b = 0.8951
19:46:33 Read 255 rows and found 30 numeric columns
19:46:33 Building Annoy index with metric = cosine, n_trees = 50
0%   10   20   30   40   50   60   70   80   90   100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
19:46:33 Writing NN index file to temp file C:\Users\lesli\AppData\Local\Temp\RtmpobCggH\file70c49004229
19:46:33 Searching Annoy index using 1 thread, search_k = 1500
19:46:33 Annoy recall = 100%
19:46:34 Commencing smooth kNN distance calibration using 1 thread
19:46:36 Initializing from normalized Laplacian + noise
19:46:36 Commencing optimization for 500 epochs, with 4146 positive edges
0%   10   20   30   40   50   60   70   80   90   100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
19:46:37 Optimization finished
Running leiden clustering algorithm ...
Run kNN based graph clustering starts:
  -Input data of 255 rows and 2 columns
  -k is set to 20
  Finding nearest neighbors...
    DONE. Run time: 0s
  Compute jaccard coefficient between nearest-neighbor sets ...
    DONE. Run time: 0s
  Build undirected graph from the weighted links ...
    DONE. Run time: 0s
  Run leiden clustering ...
leiden_find_partition: partition_type       CPMVertexPartition
leiden_find_partition: seed                  NULL
leiden_find_partition: resolution_parameter 0.001
leiden_find_partition: num_iter             1
leiden_find_partition: initial_membership   0
leiden_find_partition: edge_weights         0
leiden_find_partition: node_sizes           0
leiden_find_partition: number vertices      255
leiden_find_partition: number edges         5100
    Current resolution is 0.001; Modularity is 0; Quality is 10135.23; Significance is 0; Number of clusters is 1
    Done. Run time: 0.00199294090270996s

  Clustering statistics
   resolution_parameter  quality modularity significance cluster_count selected
                  0.001 10135.23          0            0             1        *

  Cell counts by cluster
   cluster cell_count cell_fraction
         1        255         1.000

  Maximal modularity is 0 for resolution parameter 0.001

  Run kNN based graph clustering DONE.
  -Number of clusters: 1
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : 
  contrasts can be applied only to factors with 2 or more levels

Does this mean that there is nothing significant to report/no separate clusters to compare? The branching on my plot seems robust, I'm not sure why it would not give an output.

Thanks!

legeinei123 commented 3 years ago

I'll also note that the function partitionCells() can't be found even though monocle 3 is installed and loaded into the library.

erlun1 commented 2 years ago

emmmm i had the same error as yours. Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels Then I tryed use more genes in the cds , everything worked well. First time I use 200 genes and 20000 cells ,it got wrong.