monocle-release icon indicating copy to clipboard operation
monocle-release copied to clipboard

what is the "condition" in orderCells() function

Open lizhaozhi opened this issue 4 years ago • 51 comments

Hi,

I am trying to construct single-cell trajectories using monocle, but I got an error message when I use the orderCells() function. the condition has length > 1 and only the first element will be used

any ideas what's going on? Appreciate your ideas.


Maybe it is caused by one if() statement in project2MST() function. The class of this projection matrix in this project2MST() function is c("matrix", "array").

  projection <- rbind(projection, tmp)        -> "matrix", "array"
  if(class(projection) != 'matrix')                 -> error
    projection <- as.matrix(projection)

possible solution: projection <- as.matrix(rbind(projection, tmp))


version: R Biobase eSet ExpressionSet CellDataSet "4.0.0" "2.48.0" "1.3.0" "1.0.0" "1.2.0"

lizhaozhi avatar Oct 07 '20 21:10 lizhaozhi

I have the same problem, did you solve it? Error in if (class(projection) != "matrix") projection <- as.matrix(projection) : the condition has length > 1 此外: Warning message: In graph.dfs(dp_mst, root = root_cell, neimode = "all", unreachable = FALSE, : Argument neimode' is deprecated; use mode' instead

wwh199459 avatar May 30 '22 01:05 wwh199459

I have the same problem, too. Anyone could help? Many thanks. Bests.

wangshisheng avatar Jun 06 '22 14:06 wangshisheng

@wangshisheng @ctrapnell @lizhaozhi i had the same issue, had anyone could help us? my R version was 4.2.0

Best

honghh2018 avatar Jun 09 '22 11:06 honghh2018

Had any advice for this issue ? @wangshisheng @ctrapnell @lizhaozhi Many thanks, Best

honghh2018 avatar Jun 10 '22 01:06 honghh2018

The same issue here. @ctrapnell

yishan03 avatar Jun 12 '22 20:06 yishan03

您好!已经收到邮件,祝好!                                    洪汉辉

honghh2018 avatar Jun 12 '22 20:06 honghh2018

I have the same problem, this is my solution. I download monocle from https://www.bioconductor.org/packages/3.15/bioc/src/contrib/Archive/monocle/ And change the code in function project2MST() in order_cell.R file.

from

if(class(projection) != 'matrix')                 
    projection <- as.matrix(projection)

to

projection <- as.matrix(projection)

then install the package using install.packages("path to folder with the package", repos = NULL, type = "source")

hope this help

44REAM avatar Jun 16 '22 17:06 44REAM

I have the same problem, this is my solution. I download monocle from https://www.bioconductor.org/packages/3.15/bioc/src/contrib/Archive/monocle/ And change the code in function project2MST() in order_cell.R file.

from

if(class(projection) != 'matrix')                 
    projection <- as.matrix(projection)

to

projection <- as.matrix(projection)

then install the package using install.packages("path to folder with the package", repos = NULL, type = "source")

hope this help

Dear 44REAM, Thank you. After changing the function, did you make a new archived packaged with 'tar -czf monocle_2.24.0.tar.gz monocle 2' to replace the original one and installed? or you installed the package with the unarchived folder containing the modified 'order_cell.R' 'install.packages("R_package/monocle 2", repos = NULL, type = "source")'? I encountered the problem in installation....Could you show me more details about how you performed the installation? Many thanks! Guoliang

lyuguol avatar Jun 17 '22 08:06 lyuguol

I have the same problem, too. Anyone could help? Thanks very much. Bests.

MwGuo11 avatar Jun 18 '22 12:06 MwGuo11

您好!已经收到邮件,祝好!                                    洪汉辉

您好,您的问题解决了吗,谢谢!

MwGuo11 avatar Jun 18 '22 12:06 MwGuo11

Dear Hanhui,

Yes, the problem was perfectly solved by following 44REAM's solution, however, with a bit of modification when performing the last step of installation.

I quote the following solution again as a big thanks for 44REAM as well:

  1. download monocle from https://www.bioconductor.org/packages/3.15/bioc/src/contrib/Archive/monocle/
  2. decompress the package 'monocle_2.24.0.tar.gz', and get a 'monocle' folder.
  3. open the folder 'monocle/R', change the code in function 'project2MST()' in the 'order_cell.R' file: change from

if(class(projection) != 'matrix')
projection <- as.matrix(projection)

to

projection <- as.matrix(projection)

  1. save the 'order_cell.R' file.
  2. copy the 'monocle' folder and paste to the location where I usually install my packages.
  3. In R studio, using the command to load the 'monocle' folder:

devtools::load_all("path to the location/monocle")

7.Done. and managed to run the 'orderCells(cds)'.

Thank you and best,

Guoliang

lyuguol avatar Jun 19 '22 17:06 lyuguol

Dear Hanhui,

Yes, the problem was perfectly solved by following 44REAM's solution, however, with a bit of modification when performing the last step of installation.

I quote the following solution again as a big thanks for 44REAM as well:

  1. download monocle from https://www.bioconductor.org/packages/3.15/bioc/src/contrib/Archive/monocle/
  2. decompress the package 'monocle_2.24.0.tar.gz', and get a 'monocle' folder.
  3. open the folder 'monocle/R', change the code in function 'project2MST()' in the 'order_cell.R' file: change from

if(class(projection) != 'matrix') projection <- as.matrix(projection)

to

projection <- as.matrix(projection)

  1. save the 'order_cell.R' file.
  2. copy the 'monocle' folder and paste to the location where I usually install my packages.
  3. In R studio, using the command to load the 'monocle' folder:

devtools::load_all("path to the location/monocle")

7.Done. and managed to run the 'orderCells(cds)'.

Thank you and best,

Guoliang

Thanks very much!

MwGuo11 avatar Jun 20 '22 02:06 MwGuo11

Thank you @MwGuo11 & @44REAM for providing the edit to update the package.

I noticed that I could not rerun my monocle2 pipeline on the same data that I produced results from previously. It may be from updating my R to the latest version.

Now that I've utilized your update I can get past orderCells(). However, I cannot get retrieve BEAM() results.

`BEAM_res <- BEAM(monocle_cds, branch_point = 1, cores = 8)

Error in if (progenitor_method == "duplicate") { : the condition has length > 1`

I never returned this error before for BEAM(). Does anyone have any experience or input on this error?

patrickeboada avatar Jun 21 '22 17:06 patrickeboada

Thank you @MwGuo11 & @44REAM for providing the edit to update the package.

I noticed that I could not rerun my monocle2 pipeline on the same data that I produced results from previously. It may be from updating my R to the latest version.

Now that I've utilized your update I can get past orderCells(). However, I cannot get retrieve BEAM() results.

`BEAM_res <- BEAM(monocle_cds, branch_point = 1, cores = 8)

Error in if (progenitor_method == "duplicate") { : the condition has length > 1`

I never returned this error before for BEAM(). Does anyone have any experience or input on this error?

I also have the same problem, I modified the code of / monocle/R /BEAM.R on the basis of 44REAM's solution.

from:

if (progenitor_method == "duplicate") { } else if (progenitor_method == "sequential_split") { }

to:

if ('duplicate' %in% progenitor_method){} else if('sequential_split' %in% progenitor_method){}

weu74lin avatar Jun 23 '22 03:06 weu74lin

@weu74lin

Thank you for your advice on these edits. This change corrected the error.

patrickeboada avatar Jun 23 '22 09:06 patrickeboada

@weu74lin great idea!

patrickeboada avatar Jun 23 '22 10:06 patrickeboada

@weu74lin @44REAM Thanks very much!

yejingyu0628 avatar Jul 12 '22 09:07 yejingyu0628

Hi, I cannot get retrieve plot_genes_branched_heatmap() results.

plot_genes_branched_heatmap(mycds_sub_beam,
branch_point = 1, num_clusters = 2, show_rownames = T)

Error in if (isSparseMatrix(exprs(X))) { : the condition has length > 1 In addition: Warning message: In class(cellData) != "matrix" && isSparseMatrix(cellData) == FALSE : 'length(x) = 2 > 1' in coercion to 'logical(1)'

Does anyone have any experience or input on this error?

orange511 avatar Aug 15 '22 14:08 orange511

@orange511 it happened to me once when i set the parameter 'cores = 1' in this function. if you change to 2 or else, it will pass; if this doesn't work, you should find another solution.

cieloLab avatar Nov 10 '22 17:11 cieloLab

Hi, I cannot get retrieve plot_genes_branched_heatmap() results.

plot_genes_branched_heatmap(mycds_sub_beam, branch_point = 1, num_clusters = 2, show_rownames = T)

Error in if (isSparseMatrix(exprs(X))) { : the condition has length > 1 In addition: Warning message: In class(cellData) != "matrix" && isSparseMatrix(cellData) == FALSE : 'length(x) = 2 > 1' in coercion to 'logical(1)'

Does anyone have any experience or input on this error?

I met the same problem.

I modified the code of / monocle/R /utils.R from: class(x) %in% c("dgCMatrix", "dgTMatrix") to: any(class(x) %in% c("dgCMatrix", "dgTMatrix"))

zy-fang avatar Nov 11 '22 03:11 zy-fang

@zy-fang thank you! it works after i modified that. And it fix the same error when i use plot_genes_branched_pseudotime. however, i still got some warning:

plot_genes_branched_heatmap(cds[row.names(subset(BEAM_res, qval < 1e-4)),],  branch_point = 1,  num_clusters = 4, 
                                   cores = 4,use_gene_short_name = T,  show_rownames = T)
Warning message:
In class(cellData) != "matrix" && isSparseMatrix(cellData) == FALSE : 'length(x) = 2 > 1' in coercion to 'logical(1)'

plot_genes_branched_pseudotime(cds[genes,], branch_point = 1, color_by = "State")
Warning messages:
1: In for (i in seq_len(differences)) r <- r[i1] - r[-length(r):-(length(r) -  :
  closing unused connection 6 (<-localhost:11964)
2: In for (i in seq_len(differences)) r <- r[i1] - r[-length(r):-(length(r) -  :
  closing unused connection 5 (<-localhost:11964)
3: In for (i in seq_len(differences)) r <- r[i1] - r[-length(r):-(length(r) -  :
  closing unused connection 4 (<-localhost:11964)
4: In for (i in seq_len(differences)) r <- r[i1] - r[-length(r):-(length(r) -  :
  closing unused connection 3 (<-localhost:11964)
5: In class(cellData) != "matrix" && isSparseMatrix(cellData) == FALSE :
  'length(x) = 2 > 1' in coercion to 'logical(1)'

Did these warning happen to you and should i ignore it? thank you very much!

cieloLab avatar Nov 11 '22 15:11 cieloLab

I think these warnings can be ignored.

In class(cellData) != "matrix" && isSparseMatrix(cellData) == FALSE : 'length(x) = 2 > 1' in coercion to 'logical(1)'.

This is because when cellData is a matrix, class(cellData) is going to be c("matrix", "array"). So the class(cellData) != "matrix" will be c(FALSE,TRUE). When do the “&&”at the end, only the first one (FALSE) is taken into account.

4: In for (i in seq_len(differences)) r <- r[i1] - r[-length(r):-(length(r) - : closing unused connection 3 (<-localhost:11964)

This warning is about multiple core parallelism.

zy-fang avatar Nov 12 '22 12:11 zy-fang

@zy-fang Thank you for your advice and these details which help me a lot.

cieloLab avatar Nov 13 '22 06:11 cieloLab

sc_cds <- newCellDataSet(

  • as.matrix(ct),
  • phenoData = pd,
  • featureData =fd,
  • expressionFamily = negbinomial.size(),
  • lowerDetectionLimit=1) Warning message: In class(cellData) != "matrix" && isSparseMatrix(cellData) == FALSE : 'length(x) = 2 > 1' in coercion to 'logical(1)' I also meet this warnings when using the newCellDataSet function. Furthermore, when I run the following codes cds <- estimateSizeFactors(cds) Error in if (isSparseMatrix(counts)) { : the condition has length > 1

cds <- estimateDispersions(cds) Error in .local(object, ...) : NAs found in size factors. Have you called 'estimateSizeFactors'? These error have made the analysis discontinued in the following steps. Thank you for anyone who can solve these problems.

Georgeguoql avatar Nov 21 '22 16:11 Georgeguoql

sc_cds <- newCellDataSet(

  • as.matrix(ct),
  • phenoData = pd,
  • featureData =fd,
  • expressionFamily = negbinomial.size(),
  • lowerDetectionLimit=1) Warning message: In class(cellData) != "matrix" && isSparseMatrix(cellData) == FALSE : 'length(x) = 2 > 1' in coercion to 'logical(1)' I also meet this warnings when using the newCellDataSet function. Furthermore, when I run the following codes cds <- estimateSizeFactors(cds) Error in if (isSparseMatrix(counts)) { : the condition has length > 1

cds <- estimateDispersions(cds) Error in .local(object, ...) : NAs found in size factors. Have you called 'estimateSizeFactors'? These error have made the analysis discontinued in the following steps. Thank you for anyone who can solve these problems.

Georgeguoql avatar Nov 21 '22 16:11 Georgeguoql

sc_cds <- newCellDataSet(

  • as.matrix(ct),
  • phenoData = pd,
  • featureData =fd,
  • expressionFamily = negbinomial.size(),
  • lowerDetectionLimit=1) Warning message: In class(cellData) != "matrix" && isSparseMatrix(cellData) == FALSE : 'length(x) = 2 > 1' in coercion to 'logical(1)' I also meet this warnings when using the newCellDataSet function. Furthermore, when I run the following codes cds <- estimateSizeFactors(cds) Error in if (isSparseMatrix(counts)) { : the condition has length > 1

cds <- estimateDispersions(cds) Error in .local(object, ...) : NAs found in size factors. Have you called 'estimateSizeFactors'? These error have made the analysis discontinued in the following steps. Thank you for anyone who can solve these problems.

Georgeguoql avatar Nov 21 '22 16:11 Georgeguoql

sc_cds <- newCellDataSet(

  • as.matrix(ct),
  • phenoData = pd,
  • featureData =fd,
  • expressionFamily = negbinomial.size(),
  • lowerDetectionLimit=1) Warning message: In class(cellData) != "matrix" && isSparseMatrix(cellData) == FALSE : 'length(x) = 2 > 1' in coercion to 'logical(1)' I also meet this warnings when using the newCellDataSet function. Furthermore, when I run the following codes cds <- estimateSizeFactors(cds) Error in if (isSparseMatrix(counts)) { : the condition has length > 1

cds <- estimateDispersions(cds) Error in .local(object, ...) : NAs found in size factors. Have you called 'estimateSizeFactors'? These error have made the analysis discontinued in the following steps. Thank you for anyone who can solve these problems.

Georgeguoql avatar Nov 21 '22 16:11 Georgeguoql

sc_cds <- newCellDataSet(

  • as.matrix(ct),
  • phenoData = pd,
  • featureData =fd,
  • expressionFamily = negbinomial.size(),
  • lowerDetectionLimit=1) Warning message: In class(cellData) != "matrix" && isSparseMatrix(cellData) == FALSE : 'length(x) = 2 > 1' in coercion to 'logical(1)' I also meet this warnings when using the newCellDataSet function. Furthermore, when I run the following codes cds <- estimateSizeFactors(cds) Error in if (isSparseMatrix(counts)) { : the condition has length > 1

cds <- estimateDispersions(cds) Error in .local(object, ...) : NAs found in size factors. Have you called 'estimateSizeFactors'? These error have made the analysis discontinued in the following steps. Thank you for anyone who can solve these problems.

Georgeguoql avatar Nov 21 '22 16:11 Georgeguoql

sc_cds <- newCellDataSet(

  • as.matrix(ct),
  • phenoData = pd,
  • featureData =fd,
  • expressionFamily = negbinomial.size(),
  • lowerDetectionLimit=1) Warning message: In class(cellData) != "matrix" && isSparseMatrix(cellData) == FALSE : 'length(x) = 2 > 1' in coercion to 'logical(1)' I also meet this warnings when using the newCellDataSet function. Furthermore, when I run the following codes cds <- estimateSizeFactors(cds) Error in if (isSparseMatrix(counts)) { : the condition has length > 1

cds <- estimateDispersions(cds) Error in .local(object, ...) : NAs found in size factors. Have you called 'estimateSizeFactors'? These error have made the analysis discontinued in the following steps. Thank you for anyone who can solve these problems.

Georgeguoql avatar Nov 21 '22 16:11 Georgeguoql

sc_cds <- newCellDataSet(

  • as.matrix(ct),
  • phenoData = pd,
  • featureData =fd,
  • expressionFamily = negbinomial.size(),
  • lowerDetectionLimit=1) Warning message: In class(cellData) != "matrix" && isSparseMatrix(cellData) == FALSE : 'length(x) = 2 > 1' in coercion to 'logical(1)' I also meet this warnings when using the newCellDataSet function. Furthermore, when I run the following codes cds <- estimateSizeFactors(cds) Error in if (isSparseMatrix(counts)) { : the condition has length > 1

cds <- estimateDispersions(cds) Error in .local(object, ...) : NAs found in size factors. Have you called 'estimateSizeFactors'? These error have made the analysis discontinued in the following steps. Thank you for anyone who can solve these problems.

Georgeguoql avatar Nov 21 '22 16:11 Georgeguoql