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

Support custom dimension reduction method #143

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Puriney
Copy link

@Puriney Puriney commented May 16, 2018

  • Example to be added to reproduce this PR's effect
  • Guide/message/help/suggestion to be added to help the seasoned R users to write a legal custom dimension reduction function

Why this PR

I noticed Monocle2 did reserve room for users to choose a custom dimension reduction (DR) method. See here:

if (is.function(reduction_method)) {
reducedDim <- reduction_method(FM, ...)
colnames(reducedDim) <- colnames(FM)

However, the downstream analysis (orderCells and plot_cell_trajectory) did not fully support it. So thsi PR is to help validate and support the feature.

What happened after this PR

  1. The custom DR function will project the cells to the custom space so that the original reduceDimension internally writes the projected coordinates to reducedDimS(monocle_object).
  2. The original orderCells will order cells with the same strategy used by the ICA method.
  3. The original plot_cell_trajectory will visualize the pseudotime track with the same strategy used by the ICA method.

Demo

Here I provide a gist to demonstrate the technical side of this PR is working without problems. The pseudotime tracks generated based on ICA and randomized PCA are visualized as:

monocle_custome

How to properly define a custom function

randomized_pca_monocle2 <- function(mat){
  # @param tmat A scaled (de-mean & de-var) matrix with features by samples
  # @return A matrix with features by samples projected on PCA space
  rpca_obj <- rpca(t(mat), k=2, center=FALSE, scale=FALSE, retx=TRUE)
  t(rpca_obj$x)
}

HSMM_rpca <- reduceDimension(
  HSMM,
  norm_method = 'log',
  max_components = 2,
  reduction_method = randomized_pca_monocle2, #'ICA',
  verbose = FALSE)

Puriney added 4 commits May 15, 2018 16:24
mst_branch_nodes <- V(minSpanningTree(cds))[which(degree(minSpanningTree(cds)) > 2)]$name
💊 correct the dimension of reducedDimS if a custom DR method is used.
@Puriney Puriney changed the title Support custom reduction method Support custom dimension reduction method May 16, 2018
@Puriney
Copy link
Author

Puriney commented May 16, 2018

Related to issue #141

@Puriney
Copy link
Author

Puriney commented May 23, 2018

This PR has synced to the base that is officially latest version ea83577.

@Xiaojieqiu
Copy link
Collaborator

Thanks Yun! We really appreciate your pull request and will try to merge into monocle! In fact, the method DDRTree introduced in monocle 2 and others we will release soon are much better than ICA (and the like) based method as they learn more complex trajectory, much scalable, fast and enables a lot very exciting downstream analysis. From the standpoint to maintaining a software, we may eventually depreciate the support for ICA in newer version Monocle and your changes will be affected. Thanks!

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

Successfully merging this pull request may close these issues.

2 participants