Skip to content

Commit

Permalink
Merge pull request satijalab#164 from satijalab/fix/NoPipesInFeatures
Browse files Browse the repository at this point in the history
Ensure feature names don't have pipe characters '|'
  • Loading branch information
andrewwbutler authored Aug 5, 2019
2 parents 3044270 + 68302c6 commit b95db44
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: Seurat
Version: 3.0.3.9025
Date: 2019-08-01
Version: 3.0.3.9026
Date: 2019-08-05
Title: Tools for Single Cell Genomics
Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) <doi:10.1038/nbt.3192>, Macosko E, Basu A, Satija R, et al (2015) <doi:10.1016/j.cell.2015.05.002>, and Butler A and Satija R (2017) <doi:10.1101/164889> for more details.
Authors@R: c(
Expand Down
45 changes: 44 additions & 1 deletion R/objects.R
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,25 @@ CreateAssayObject <- function(
x = rownames(x = data)
)
}
if (any(grepl(pattern = '|', x = rownames(x = counts), fixed = TRUE)) || any(grepl(pattern = '|', x = rownames(x = data), fixed = TRUE))) {
warning(
"Feature names cannot have pipe characters ('|'), replacing with dashes ('-')",
call. = FALSE,
immediate. = TRUE
)
rownames(x = counts) <- gsub(
pattern = '|',
replacement = '-',
x = rownames(x = counts),
fixed = TRUE
)
rownames(x = data) <- gsub(
pattern = '|',
replacement = '-',
x = rownames(x = data),
fixed = TRUE
)
}
# Initialize meta.features
init.meta.features <- data.frame(row.names = rownames(x = data))
assay <- new(
Expand Down Expand Up @@ -1266,7 +1285,7 @@ UpdateSeuratObject <- function(object) {
Key(object = object[[ko]]) <- UpdateKey(key = Key(object = object[[ko]]))
}
# Check feature names
message("Ensuring feature names don't have underscores")
message("Ensuring feature names don't have underscores or pipes")
for (assay.name in FilterObjects(object = object, classes.keep = 'Assay')) {
assay <- object[[assay.name]]
for (slot in c('counts', 'data', 'scale.data')) {
Expand All @@ -1276,18 +1295,36 @@ UpdateSeuratObject <- function(object) {
replacement = '-',
x = rownames(x = slot(object = assay, name = slot))
)
rownames(x = slot(object = assay, name = slot)) <- gsub(
pattern = '|',
replacement = '-',
x = rownames(x = slot(object = assay, name = slot)),
fixed = TRUE
)
}
}
VariableFeatures(object = assay) <- gsub(
pattern = '_',
replacement = '-',
x = VariableFeatures(object = assay)
)
VariableFeatures(object = assay) <- gsub(
pattern = '|',
replacement = '-',
x = VariableFeatures(object = assay),
fixed = TRUE
)
rownames(x = slot(object = assay, name = "meta.features")) <- gsub(
pattern = '_',
replacement = '-',
x = rownames(x = assay[[]])
)
rownames(x = slot(object = assay, name = "meta.features")) <- gsub(
pattern = '|',
replacement = '-',
x = rownames(x = assay[[]]),
fixed = TRUE
)
object[[assay.name]] <- assay
}
for (reduc.name in FilterObjects(object = object, classes.keep = 'DimReduc')) {
Expand All @@ -1299,6 +1336,12 @@ UpdateSeuratObject <- function(object) {
replacement = '-',
x = rownames(x = slot(object = reduc, name = slot))
)
rownames(x = slot(object = reduc, name = slot)) <- gsub(
pattern = '_',
replacement = '-',
x = rownames(x = slot(object = reduc, name = slot)),
fixed = TRUE
)
}
}
object[[reduc.name]] <- reduc
Expand Down

0 comments on commit b95db44

Please sign in to comment.