-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Bioconductor 3.9 - New function: add_cellAnnotation for looms
- Loading branch information
s-aibar
committed
May 31, 2019
1 parent
3d6f53a
commit 0a4c96e
Showing
17 changed files
with
414 additions
and
701 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
#' @import SingleCellExperiment | ||
#' @import SingleCellExperiment | ||
load_as_sce <- function(loomPath) | ||
{ | ||
loom <- open_loom(loomPath, mode="r") | ||
dgem <- get_dgem(loom) | ||
cellAnnot <- get_cellAnnotation(loom) | ||
embeddings <- get_embeddings(loom) | ||
close_loom(loom) | ||
|
||
sce <- SingleCellExperiment::SingleCellExperiment(assays=list(counts=dgem), | ||
colData=data.frame(cellAnnot[colnames(dgem),, drop=FALSE]), | ||
reducedDims=S4Vectors::SimpleList(embeddings)) | ||
|
||
return(sce) | ||
} | ||
|
||
|
||
add_cellAnnotation <- function(loom, cellAnnotation) | ||
{ | ||
cellAnnotation <- data.frame(cellAnnotation) | ||
if(any(c("nGene", "nUMI") %in% colnames(cellAnnotation))) | ||
{ | ||
warning("Columns 'nGene' and 'nUMI' will not be added as annotations to the loom file.") | ||
cellAnnotation <- cellAnnotation[,colnames(cellAnnotation) != "nGene", drop=FALSE] | ||
cellAnnotation <- cellAnnotation[,colnames(cellAnnotation) != "nUMI", drop=FALSE] | ||
} | ||
|
||
if(ncol(cellAnnotation)<=0) stop("The cell annotation contains no columns") | ||
if(!all(get_cell_ids(loom) %in% rownames(cellAnnotation))) stop("Cell IDs are missing in the annotation") | ||
|
||
cellAnnotation <- cellAnnotation[get_cell_ids(loom),,drop=FALSE] | ||
# Add annotation | ||
for(cn in colnames(cellAnnotation)) | ||
{ | ||
add_col_attr(loom=loom, key=cn, value=cellAnnotation[,cn]) | ||
} | ||
|
||
invisible(loom) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.