Skip to content
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

Make longFormat a generic #333

Open
lgatto opened this issue Nov 24, 2024 · 1 comment
Open

Make longFormat a generic #333

lgatto opened this issue Nov 24, 2024 · 1 comment

Comments

@lgatto
Copy link
Collaborator

lgatto commented Nov 24, 2024

Would you consider making longFormat() a generic function (ideally in BiocGenerics) to allow implementation if different methods?

Currently, you have

MultiAssayExperiment::longFormat
function (object, colDataCols = NULL, i = 1L) 
{
    if (is(object, "ExperimentList")) 
        return(do.call(rbind, .longFormatElist(object, i = i)))
    else if (!is(object, "MultiAssayExperiment")) 
        return(.longFormatANY(object, i = i))
    if (any(.emptyAssays(experiments(object)))) 
        object <- .dropEmpty(object, warn = FALSE)
    longDataFrame <- do.call(function(...) rbind(..., make.row.names = FALSE), 
        .longFormatElist(experiments(object), i = i))
    longDataFrame <- .mapOrderPrimary(longDataFrame, sampleMap(object))
    if (!is.null(colDataCols)) 
        longDataFrame <- .matchAddColData(longDataFrame, colData(object), 
            colDataCols)
    as(longDataFrame, "DataFrame")
}
<bytecode: 0x5c13c5da9e48>
<environment: namespace:MultiAssayExperiment>

The QFeatures class extends MultiAssayExperiment, and has

QFeatures::longFormat
function (object, colvars = NULL, rowvars = NULL, index = 1L) 
{
    if (!is.null(rowvars)) {
        rdNames <- rowDataNames(object)
        misNames <- sapply(rdNames, function(x) any(!rowvars %in% 
            x))
        if (any(misNames)) 
            stop("Some 'rowvars' not found in assay(s): ", paste0(names(misNames)[misNames], 
                collapse = ", "))
        longDataFrame <- MultiAssayExperiment::longFormat(object, 
            colvars, index)
        rds <- lapply(rowData(object), function(rd) rd[, rowvars, 
            drop = FALSE])
        rds <- do.call(rbind, rds)
        cbind(longDataFrame, rds[as.character(longDataFrame$rowname), 
            , drop = FALSE])
    }
    else {
        MultiAssayExperiment::longFormat(object, colvars, index)
    }
}
<bytecode: 0x5c13df3029a0>
<environment: namespace:QFeatures>

The main advantage is support for variables from colData and rowData to the long format output (which is very handy).

The main motivation for this request is that I would also like to be able to convert SummarizedExperiment objects to long format.

@lgatto
Copy link
Collaborator Author

lgatto commented Nov 24, 2024

  • Now that I look into it more carefully, MultiAssayExperiment::longFormat() isn't a method, but works on SEs calling MultiAssayExperiment:::.longFormatANY(). What is the reason for not using methods to handle this?
  • And my second/other request would be to support rowData variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant