Skip to content

Add renameMetaPrograms function for renaming MPs in GeneNMF results#45

Open
liuzhenyu-yyy wants to merge 1 commit into
carmonalab:masterfrom
liuzhenyu-yyy:master
Open

Add renameMetaPrograms function for renaming MPs in GeneNMF results#45
liuzhenyu-yyy wants to merge 1 commit into
carmonalab:masterfrom
liuzhenyu-yyy:master

Conversation

@liuzhenyu-yyy

Copy link
Copy Markdown

This PR introduces a new utility function renameMetaPrograms for renaming meta-programs in GeneNMF analysis results. This function allow users to assign new names to existing meta-programs, and ensures all associated data structures are updated accordingly. Comprehensive documentation has also been added.

This is especially useful under 2 conditions:

  • to rename and reorder MPs based on similar biological functions (eg. MP1/3/5 cell cycle, MP2/4/6 EMT -> MP1-3 cell cycle, MP4-6 EMT).
  • to revise discontinuous MP names after filtering by dropMetaPrograms (eg. MP1/3/4/5 after filtering out MP2 -> MP1/2/3/4)

Core scripts are adapted from getMetaPrograms and tested on my local machine.

GeneNMF/R/main.R

Lines 268 to 302 in 355c466

#Rename meta-programs after sorting them by metrics
ord <- order(metaprograms.metrics$sampleCoverage,
metaprograms.metrics$silhouette,
decreasing = T)
old.names <- names(markers.consensus)[ord]
new.names <- paste0("MP",seq_along(ord))
markers.consensus <- markers.consensus[ord]
names(markers.consensus) <- new.names
#Reorder metrics and composition tables
metaprograms.metrics <- metaprograms.metrics[ord,,drop=F]
rownames(metaprograms.metrics) <- new.names
metaprograms.composition <- metaprograms.composition[ord,,drop=F]
rownames(metaprograms.composition) <- new.names
map.index <- seq_along(old.names)
names(map.index) <- as.numeric(gsub("MetaProgram","",old.names))
cl_members.new <- map.index[as.character(cl_members)]
names(cl_members.new) <- names(cl_members)
#weights of individual genes in each MP
markers.consensus <- lapply(markers.consensus, function(m){m/sum(m)})
markers.genes <- lapply(markers.consensus, names)
output.object <- list()
output.object[["metaprograms.genes"]] <- markers.genes
output.object[["metaprograms.genes.weights"]] <- markers.consensus
output.object[["metaprograms.metrics"]] <- metaprograms.metrics
output.object[["metaprograms.composition"]] <- metaprograms.composition
output.object[["programs.similarity"]] <- J
output.object[["programs.tree"]] <- tree
output.object[["programs.clusters"]] <- cl_members.new
return(output.object)

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.

1 participant