-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
msnset se coercions #284
msnset se coercions #284
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#' SummarizedExperiment to MSnSet object conversion | ||
#' | ||
#' \code{se2msnset} generates an MSnSet object from an SummarizedExperiment object. | ||
#' | ||
#' @param se SummarizedExperiment, | ||
#' Object which will be turned into an MSnSet object. | ||
#' @return MSnSet object. | ||
#' @export | ||
se2msnset <- function(se) { | ||
# Check input | ||
assertthat::assert_that(inherits(se, "SummarizedExperiment")) | ||
|
||
# Extract expression, feature and pheno data | ||
raw <- SummarizedExperiment::assay(se) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently we also have no dependency on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
feat_data <- data.frame(SummarizedExperiment::rowData(se)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't use snake_case. We try to follow the bioc coding style and use camelCase |
||
rownames(feat_data) <- se@NAMES | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should not access slots directly. Why not use |
||
pheno_data <- data.frame(SummarizedExperiment::colData(se)) | ||
|
||
# Generate MSnSet | ||
msnset <- MSnbase::MSnSet(exprs = as.matrix(raw), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no need to use |
||
pData = Biobase::AnnotatedDataFrame(pheno_data), | ||
fData = Biobase::AnnotatedDataFrame(feat_data)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need |
||
return(msnset) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
#' MSnSet to SummarizedExperiment object conversion | ||
#' | ||
#' \code{msnset2se} generates an SummarizedExperiment object from an MSnSet object. | ||
#' | ||
#' @param msnset MSnSet object, | ||
#' Object which will be turned into an SummarizedExperiment object. | ||
#' @return SummarizedExperiment object. | ||
#' @export | ||
msnset2se <- function(msnset) { | ||
# Check input | ||
assertthat::assert_that(inherits(msnset, "MSnSet")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my comment above regarding |
||
|
||
# Extract assay, rowData and colData | ||
raw <- Biobase::exprs(msnset) | ||
row_data <- Biobase::fData(msnset) | ||
col_data <- Biobase::pData(msnset) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need |
||
|
||
# Generate SE | ||
se <- SummarizedExperiment::SummarizedExperiment(assays = as.matrix(raw), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added requireNamespace, however I still need the :: operator. |
||
rowData = row_data, | ||
colData = col_data) | ||
return(se) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
context("msnset - se conversion methods") | ||
|
||
test_that("msnset2se conversion", { | ||
data(msnset, package = "MSnbase") | ||
se <- msnset2se(msnset) | ||
|
||
expect_is(se, "SummarizedExperiment") | ||
expect_equal(colnames(msnset), colnames(se)) | ||
expect_equal(rownames(msnset), rownames(se)) | ||
expect_equal(Biobase::exprs(msnset), SummarizedExperiment::assay(se)) | ||
expect_equal(Biobase::fData(msnset), data.frame(SummarizedExperiment::rowData(se), row.names = se@NAMES)) | ||
expect_equal(Biobase::pData(msnset), data.frame(SummarizedExperiment::colData(se))) | ||
}) | ||
|
||
test_that("se2msnset conversion", { | ||
data(msnset, package = "MSnbase") | ||
se <- msnset2se(msnset) | ||
msnset_back <- se2msnset(se) | ||
|
||
expect_is(msnset_back, "MSnSet") | ||
expect_equal(colnames(msnset_back), colnames(se)) | ||
expect_equal(rownames(msnset_back), rownames(se)) | ||
expect_equal(Biobase::exprs(msnset_back), SummarizedExperiment::assay(se)) | ||
expect_equal(Biobase::fData(msnset_back), data.frame(SummarizedExperiment::rowData(se), row.names = se@NAMES)) | ||
expect_equal(Biobase::pData(msnset_back), data.frame(SummarizedExperiment::colData(se))) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently we don't use
assertthat
for evaluation of input variables. While it is very convenient it don't think we are accepting a new dependency for just an easyif (inherits(se, "SummarizedExperiment"))
check. BTW:assertthat
is not listed in theDESCRIPTION
file.