Skip to content

Commit

Permalink
add SampleNames .R and .Rd files
Browse files Browse the repository at this point in the history
  • Loading branch information
ammichalowski committed Dec 1, 2022
1 parent a27296a commit 446d631
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
63 changes: 63 additions & 0 deletions R/Sample_Names.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# 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
#'
#'
#' @export
#' @return A table (data.frame) with the number of cells per each sample name (column names)


SampleNames <- function(SO) {
# extract metadata table and sample names

cat("\n Extracting Sample Names from metadata table: ")
if ("meta.data" %in% slotNames(SO)) {
if ("orig.ident" %in% colnames(SO@meta.data)) {
dim.df <-
as.data.frame(t(as.matrix(table(
SO@meta.data$orig.ident
))))
} else {
dim.df <-
as.data.frame(t(as.matrix(table(
SO@meta.data$orig_ident
))))
}
colnames(dim.df) <-
lapply(colnames(dim.df), function(x)
gsub(".h5", "", x))
} else {
if ("orig.ident" %in% colnames(SO$RNA@meta.data)) {
dim.df <-
as.data.frame(t(as.matrix(
table(SO$RNA@meta.data$orig.ident)
)))
} else {
dim.df <-
as.data.frame(t(as.matrix(
table(SO$RNA@meta.data$orig_ident)
)))
}
dim.df <-
as.data.frame(t(as.matrix(table(
SO$RNA@meta.data$orig.ident
))))
colnames(dim.df) <-
lapply(colnames(dim.df), function(x)
gsub(".h5", "", x))
}

# output data.frame
cat(sprintf("%g sample names returned", ncol(dim.df)))
return(dim.df)

}
20 changes: 20 additions & 0 deletions man/SampleNames.Rd

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

0 comments on commit 446d631

Please sign in to comment.