-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #995 from drieslab/db
feat: dbverse integration --- filterGiotto() normalizeGiotto()
- Loading branch information
Showing
7 changed files
with
399 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# silence deprecated internal functions | ||
rlang::local_options(lifecycle_verbosity = "quiet") | ||
|
||
# ---------------------------------------------------------------------------- # | ||
# Setup data | ||
visium = GiottoData::loadGiottoMini(dataset = "visium") | ||
dgc = getExpression(visium, output = "matrix") | ||
|
||
con = DBI::dbConnect(duckdb::duckdb(), ":memory:") | ||
|
||
dbsm = dbMatrix::dbMatrix(value = dgc, | ||
con = con, | ||
name = 'dgc', | ||
class = "dbSparseMatrix", | ||
overwrite = TRUE) | ||
|
||
# Create exprObj with dbsm | ||
expObj_db = createExprObj(expression_data = dbsm, | ||
expression_matrix_class = 'dbSparseMatrix', | ||
name = 'raw') | ||
|
||
# Create giotto object | ||
gobject_db = suppressWarnings(createGiottoObject(expression = expObj_db)) | ||
|
||
# ---------------------------------------------------------------------------- # | ||
# Perform filtering | ||
visium_filtered = filterGiotto(visium, spat_unit = "cell", | ||
feat_type = "rna", | ||
expression_values = "raw") | ||
|
||
gobject_db_filtered = filterGiotto(gobject_db, spat_unit = "cell", | ||
feat_type = "rna", | ||
expression_values = "raw") | ||
|
||
# Get filtered matrix | ||
dgc_visium = getExpression(visium_filtered, output = "matrix") | ||
mat_db = getExpression(gobject_db_filtered, output = "matrix") | ||
dgc_db = dbMatrix:::as_matrix(mat_db) | ||
|
||
# ---------------------------------------------------------------------------- # | ||
# Test filterGiotto() equivalence between dbMatrix and dgCMatrix | ||
|
||
test_that("dbMatrix equivalent to dgCMatrix after filterGiotto()", { | ||
expect_equal(dgc_visium, dgc_db) | ||
}) |
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,64 @@ | ||
# silence deprecated internal functions | ||
rlang::local_options(lifecycle_verbosity = "quiet") | ||
|
||
# ---------------------------------------------------------------------------- # | ||
# Setup data | ||
visium = GiottoData::loadGiottoMini(dataset = "visium") | ||
dgc = getExpression(visium, output = "matrix") | ||
|
||
con = DBI::dbConnect(duckdb::duckdb(), ":memory:") | ||
|
||
dbsm = dbMatrix::dbMatrix(value = dgc, | ||
con = con, | ||
name = 'dgc', | ||
class = "dbSparseMatrix", | ||
overwrite = TRUE) | ||
|
||
# Create exprObj with dbsm | ||
expObj_db = createExprObj(expression_data = dbsm, | ||
expression_matrix_class = 'dbSparseMatrix', | ||
name = 'raw') | ||
|
||
# Create giotto object | ||
gobject_db = suppressWarnings(createGiottoObject(expression = expObj_db)) | ||
|
||
# ---------------------------------------------------------------------------- # | ||
# Perform filtering | ||
visium_filtered = filterGiotto(visium, spat_unit = "cell", | ||
feat_type = "rna", | ||
expression_values = "raw") | ||
|
||
gobject_db_filtered = filterGiotto(gobject_db, spat_unit = "cell", | ||
feat_type = "rna", | ||
expression_values = "raw") | ||
|
||
# ---------------------------------------------------------------------------- # | ||
# Perform library normalization and scaling | ||
visium_filtered = normalizeGiotto(gobject = visium_filtered, | ||
spat_unit = 'cell', | ||
feat_type = 'rna', | ||
expression_values = 'raw', | ||
library_size_norm = TRUE, | ||
log_norm = FALSE, | ||
scale_feats = FALSE, | ||
scale_cells = FALSE) | ||
|
||
|
||
gobject_db_filtered = normalizeGiotto(gobject = gobject_db_filtered, | ||
spat_unit = 'cell', | ||
feat_type = 'rna', | ||
expression_values = 'raw', | ||
library_size_norm = TRUE, | ||
log_norm = FALSE, | ||
scale_feats = FALSE, | ||
scale_cells = FALSE) | ||
# Get normalized matrix | ||
dgc_visium = getExpression(visium_filtered, output = "matrix", values = "normalized") | ||
mat_db = getExpression(gobject_db_filtered, output = "matrix", values = "normalized") | ||
dgc_db = dbMatrix:::as_matrix(mat_db) | ||
|
||
# ---------------------------------------------------------------------------- # | ||
# Test normalizeGiotto() equivalence between dbMatrix and dgCMatrix | ||
test_that("dbMatrix equivalent to dgCMatrix after normalizeGiotto(library_size_norm = TRUE)", { | ||
expect_equal(dgc_visium, dgc_db) | ||
}) |
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,64 @@ | ||
# silence deprecated internal functions | ||
rlang::local_options(lifecycle_verbosity = "quiet") | ||
|
||
# ---------------------------------------------------------------------------- # | ||
# Setup data | ||
visium = GiottoData::loadGiottoMini(dataset = "visium") | ||
dgc = getExpression(visium, output = "matrix") | ||
|
||
con = DBI::dbConnect(duckdb::duckdb(), ":memory:") | ||
|
||
dbsm = dbMatrix::dbMatrix(value = dgc, | ||
con = con, | ||
name = 'dgc', | ||
class = "dbSparseMatrix", | ||
overwrite = TRUE) | ||
|
||
# Create exprObj with dbsm | ||
expObj_db = createExprObj(expression_data = dbsm, | ||
expression_matrix_class = 'dbSparseMatrix', | ||
name = 'raw') | ||
|
||
# Create giotto object | ||
gobject_db = suppressWarnings(createGiottoObject(expression = expObj_db)) | ||
|
||
# ---------------------------------------------------------------------------- # | ||
# Perform filtering | ||
visium_filtered = filterGiotto(visium, spat_unit = "cell", | ||
feat_type = "rna", | ||
expression_values = "raw") | ||
|
||
gobject_db_filtered = filterGiotto(gobject_db, spat_unit = "cell", | ||
feat_type = "rna", | ||
expression_values = "raw") | ||
|
||
# ---------------------------------------------------------------------------- # | ||
# Perform library normalization and scaling | ||
visium_filtered = normalizeGiotto(gobject = visium_filtered, | ||
spat_unit = 'cell', | ||
feat_type = 'rna', | ||
expression_values = 'raw', | ||
library_size_norm = FALSE, | ||
log_norm = TRUE, | ||
scale_feats = FALSE, | ||
scale_cells = FALSE) | ||
|
||
|
||
gobject_db_filtered = normalizeGiotto(gobject = gobject_db_filtered, | ||
spat_unit = 'cell', | ||
feat_type = 'rna', | ||
expression_values = 'raw', | ||
library_size_norm = FALSE, | ||
log_norm = TRUE, | ||
scale_feats = FALSE, | ||
scale_cells = FALSE) | ||
# Get normalized matrix | ||
dgc_visium = getExpression(visium_filtered, output = "matrix", values = "normalized") | ||
mat_db = getExpression(gobject_db_filtered, output = "matrix", values = "normalized") | ||
dgc_db = dbMatrix:::as_matrix(mat_db) | ||
|
||
# ---------------------------------------------------------------------------- # | ||
# Test normalizeGiotto() equivalence between dbMatrix and dgCMatrix | ||
test_that("dbMatrix equivalent to dgCMatrix after normalizeGiotto(log_norm=TRUE)", { | ||
expect_equal(dgc_visium, dgc_db) | ||
}) |
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,64 @@ | ||
# silence deprecated internal functions | ||
rlang::local_options(lifecycle_verbosity = "quiet") | ||
|
||
# ---------------------------------------------------------------------------- # | ||
# Setup data | ||
visium = GiottoData::loadGiottoMini(dataset = "visium") | ||
dgc = getExpression(visium, output = "matrix") | ||
|
||
con = DBI::dbConnect(duckdb::duckdb(), ":memory:") | ||
|
||
dbsm = dbMatrix::dbMatrix(value = dgc, | ||
con = con, | ||
name = 'dgc', | ||
class = "dbSparseMatrix", | ||
overwrite = TRUE) | ||
|
||
# Create exprObj with dbsm | ||
expObj_db = createExprObj(expression_data = dbsm, | ||
expression_matrix_class = 'dbSparseMatrix', | ||
name = 'raw') | ||
|
||
# Create giotto object | ||
gobject_db = suppressWarnings(createGiottoObject(expression = expObj_db)) | ||
|
||
# ---------------------------------------------------------------------------- # | ||
# Perform filtering | ||
visium_filtered = filterGiotto(visium, spat_unit = "cell", | ||
feat_type = "rna", | ||
expression_values = "raw") | ||
|
||
gobject_db_filtered = filterGiotto(gobject_db, spat_unit = "cell", | ||
feat_type = "rna", | ||
expression_values = "raw") | ||
|
||
# ---------------------------------------------------------------------------- # | ||
# Perform library normalization and scaling | ||
visium_filtered = normalizeGiotto(gobject = visium_filtered, | ||
spat_unit = 'cell', | ||
feat_type = 'rna', | ||
expression_values = 'raw', | ||
library_size_norm = FALSE, | ||
log_norm = FALSE, | ||
scale_feats = TRUE, | ||
scale_cells = TRUE) | ||
|
||
|
||
gobject_db_filtered = normalizeGiotto(gobject = gobject_db_filtered, | ||
spat_unit = 'cell', | ||
feat_type = 'rna', | ||
expression_values = 'raw', | ||
library_size_norm = FALSE, | ||
log_norm = FALSE, | ||
scale_feats = TRUE, | ||
scale_cells = TRUE) | ||
# Get normalized matrix | ||
dgc_visium = getExpression(visium_filtered, output = "matrix", values = "scaled") |> as.matrix() | ||
mat_db = getExpression(gobject_db_filtered, output = "matrix", values = "scaled") | ||
dgc_db = dbMatrix:::as_matrix(mat_db) | ||
|
||
# ---------------------------------------------------------------------------- # | ||
# Test normalizeGiotto() equivalence between dbMatrix and dgCMatrix | ||
test_that("dbMatrix equivalent to dgCMatrix after normalizeGiotto(scale_feats=T,scale=cells=T)", { | ||
expect_equal(dgc_visium, dgc_db) | ||
}) |
Oops, something went wrong.