Skip to content

Commit

Permalink
update MetadataTable & SampleNames
Browse files Browse the repository at this point in the history
  • Loading branch information
ammichalowski committed Dec 8, 2022
1 parent 3a39fcf commit b3f19d8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 25 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Imports:
leiden (>= 0.4.2),
markdown (>= 1.1),
methods (>= 4.1.3),
plotly (>= 4.10.0),
progressr (>= 0.10.1),
pryr (>= 0.1.5),
reshape2 (>= 1.4.4),
Expand Down
10 changes: 2 additions & 8 deletions R/Metadata_Table.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# This code comes from NIDAP 'Metadata Table [scRNA-seq][CCBR]' code template
# Template Manager https://nidap.nih.gov/workspace/vector/templates/ri.vector.main.template.6a8139b7-45b4-4c6a-8648-c8ec34e6fc60
# Documentation https://nidap.nih.gov/workspace/notepad/view/ri.notepad.main.notepad.70a5a28a-fa78-4f77-bee2-30f2d4854304
# Example https://nidap.nih.gov/workspace/vector/view/ri.vector.main.workbook.d9fbfd7b-fb08-4814-ae16-7327cb7f4f37?branch=master


#' @title Extracting meta.data and reductions slots from Seurat-class object
#' @description Returns the per cell metadata and dimension embeddings (optional) of the Seurat object as a data table.
#' @details Exposes the metadata of any combined Seurat object, though it is recommended to input a SingleR annotated Seurat Object.
Expand Down Expand Up @@ -40,7 +34,8 @@


MetadataTable <- function(SO, return.cell.embeddings = FALSE) {
# get cell embeddings? ====

# got cell embeddings? ====

if (return.cell.embeddings) {
reds = names(SO@reductions)
Expand Down Expand Up @@ -72,6 +67,5 @@ MetadataTable <- function(SO, return.cell.embeddings = FALSE) {

# return output ====

#print(summary(met.df))
return(met.df)
}
9 changes: 2 additions & 7 deletions R/Sample_Names.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
# This code comes from NIDAP 'Metadata Table [scRNA-seq][CCBR]' code template https://nidap.nih.gov/workspace/vector/templates/ri.vector.main.template.51ea15ce-2be0-415f-902b-3c86175eb6cd
# Documentation https://nidap.nih.gov/workspace/notepad/view/ri.notepad.main.notepad.53192624-dba0-4e63-9cbb-9bec776ede47
# Example https://nidap.nih.gov/workspace/vector/view/ri.vector.main.workbook.00e7a393-4cd7-4f20-bdd2-1c1c0cfd1ea2?branch=master


#' Extracting cell identities from the meta.data slot of Seurat-class object
#'
#' Returns tabulation of cell identities present in the orig_ident column
#'
#' It is recommended to run this function after doing SingleR annotations and before doing any visualizations/downstream analysis that requires inputting sample names.
#'
#' @param SO Seurat-class object
#'
#' @importFrom methods slotNames
#'#'
#'
#' @export
#' @return A table (data.frame) with the number of cells per each sample name (column names)
Expand Down
5 changes: 1 addition & 4 deletions man/SampleNames.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions tests/testthat/test-Metadata_Table.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
# load data
seurat.object <-readRDS(test_path("fixtures", "SO_moduleScore.rds"))


# run tests
test_that("reductions are returned", {

# load data
seurat.object <-
readRDS(test_path("fixtures", "SO_moduleScore.rds"))

# run function
metadata <-
MetadataTable(SO = seurat.object,
return.cell.embeddings = TRUE)

# test
expect_true(sum(grepl("PC_1$|PC_2$", colnames(metadata))) == 2)
expect_true(sum(grepl("UMAP_1|UMAP_2", colnames(metadata))) == 2)
expect_true(sum(grepl("tSNE_1|tSNE_2", colnames(metadata))) == 2)

})

test_that("function returns correct class", {

metadata <-
MetadataTable(SO = seurat.object,
return.cell.embeddings = TRUE)
expect_s3_class(metadata, "data.frame")

})

0 comments on commit b3f19d8

Please sign in to comment.