forked from BaderLab/netDx
-
Notifications
You must be signed in to change notification settings - Fork 2
Adding MAE wrapper functions #11
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9b435f2
added function to convert list to MAE
051aa3e
uploading auto-generated Roxygen2 file documenting convertToMAE funct…
90c984a
uploading tests for convertToMAE() function
013fc96
uploading auto-generated Roxygen2 documentation for buildPredictor_sp…
b8fad3e
Update .gitignore, NAMESPACE, and added an if statement to check assa…
c603e43
Updated convertToMAE.R to implement changes, implemented more compreh…
5bdad74
Upload vignette outlining how to run netDx on input data that comes i…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ | |
| .Ruserdata | ||
| doc | ||
| Meta | ||
| inst/doc | ||
This file contains hidden or 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 hidden or 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 hidden or 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,84 @@ | ||
| #' Wrapper that converts an input list into a MultiAssayExperiment object | ||
| #' | ||
| #' @details This function takes in a list of key-value pairs (keys: data types, | ||
| #' values: matrices/dataframes) and calls the necessary functions from the | ||
| #' MultiAssayExperiment package to incorporate the values from the input list | ||
| #' into a MultiAssayExperiment object, transforming the values according to the | ||
| #' keys. If duplicate sample names are found in the assay data, only the first | ||
| #' instance is kept. | ||
| #' @param dataList (list) input key-value pairs (keys: data types, values: | ||
| #' data in the form of matrices/dataframes); must have a key-value pair that | ||
| #' corresponds to patient IDs/metadata labelled pheno. | ||
| #' @return MAE (MultiAssayExperiment) data from input list incorporated into a | ||
| #' MultiAssayExperiment object, compatible with further analysis using the | ||
| #' netDx algorithm. | ||
| #' @examples | ||
| #' data(xpr, pheno) | ||
| #' | ||
| #' # Generate random proteomic data | ||
| #' prot <- matrix(rnorm(100*20), ncol=20) | ||
| #' colnames(prot) <- sample(pheno$ID, 20) | ||
| #' rownames(prot) <- sprintf("protein%i",1:100) | ||
| #' | ||
| #' myList <- list(rna = xpr, proteomic = prot, pheno = pheno) | ||
| #' | ||
| #' MAE <- convertToMAE(myList) | ||
| #' @export | ||
|
|
||
|
|
||
| convertToMAE <- function(dataList) { | ||
shraddhapai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Check input data: | ||
| if (class(dataList) != "list") { | ||
| stop("dataList must be a list. \n") | ||
| } | ||
| if (is.null(dataList$pheno)) { | ||
| stop("dataList must have key-value pair labelled pheno.\n") | ||
| } | ||
| if (length(dataList) == 1) { | ||
| stop("dataList must have assay data to incorporate into a | ||
| MultiAssayExperiment object") | ||
| } | ||
|
|
||
| # Note that a MultiAssayExperiment object requires an ExperimentList and | ||
| # colData (sampleMap optional if each assay uses the same colnames) | ||
|
|
||
| # Possible elements for ExperimentList: | ||
| # - base::matrix (gene expression, microRNA, metabolomics, microbiome data) | ||
| # - SummarizedExperiment::SummarizedExperiment (same as matrix, but capable | ||
| # of storing additional assay-level metadata) | ||
| # - Biobase::ExpressionSet (legacy representation, use SummarizedExperiment) | ||
| # - SummarizedExperiment::RangedSummarizedExperiment (range-based datasets; | ||
| # gene expression, methylation, data types that refer to genomic positions) | ||
| # - RaggedExperiment::RaggedExperiment (range-based datasets; copy number and | ||
| # mutation data, measurements by genomic positions) | ||
|
|
||
| # Assumes that pheno is a DataFrame (or coerceable to be a DataFrame) | ||
| patientPheno <- dataList$pheno | ||
|
|
||
| # Generate ExperimentList from input dataList | ||
| tmp <- NULL | ||
| track <- c() | ||
| datType <- names(dataList) | ||
| for (k in 1:length(dataList)) { | ||
| # For key-value pairs that aren't labelled pheno, transform into | ||
| # objects compatible with input into MultiAssayExperiment object | ||
| if (names(dataList[k]) != "pheno") { | ||
|
|
||
| # Remove duplicated columns (we keep the first column) in the assay data | ||
| if (sum(duplicated(colnames(dataList[[k]]))) != 0) { | ||
| dataList[[k]] <- dataList[[k]][,!duplicated(colnames(dataList[[k]]))] | ||
| } | ||
|
|
||
| # Assumes that data is of matrix class | ||
| # *(maybe implement matrix conversion into SummarizedExperiment in future) | ||
| track <- c(track, k) | ||
| tmp <- c(tmp, list(dataList[[k]])) | ||
| } | ||
| } | ||
| names(tmp) <- datType[track] | ||
|
|
||
| MAE <- MultiAssayExperiment(experiments = tmp, colData = patientPheno) | ||
|
|
||
| return(MAE) | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,75 @@ | ||
| # test convertToMAE.R | ||
|
|
||
| test_that("convertToMAE works", { | ||
| # 20 patients, 10 case, 10 control | ||
| pheno <- data.frame(ID=sprintf("PAT%i",1:20), | ||
| STATUS=rep(c("case","control"),each=10)) | ||
| # 100 dummy genes | ||
| rna <- matrix(rnorm(100*20),nrow=100); | ||
| colnames(rna) <- pheno$ID | ||
| rownames(rna) <- sprintf("gene%i",1:100) | ||
| # 2 dummy clin variables | ||
| clin <- t(data.frame(AGE=runif(20,10,50))) | ||
| colnames(clin) <- pheno$ID | ||
| clin <- t(clin) | ||
|
|
||
| # netDx files | ||
| dataList <- list(rna=rna,pheno=clin) | ||
|
|
||
| x <- convertToMAE(dataList) | ||
| expect_is(x, "MultiAssayExperiment") | ||
| }) | ||
|
|
||
| test_that("convertToMAE works with more than one assay", { | ||
| # 20 patients, 10 case, 10 control | ||
| pheno <- data.frame(ID=sprintf("PAT%i",1:20), | ||
| STATUS=rep(c("case","control"),each=10)) | ||
| # 100 dummy genes | ||
| rna <- matrix(rnorm(100*20),nrow=100); | ||
| colnames(rna) <- pheno$ID | ||
| rownames(rna) <- sprintf("gene%i",1:100) | ||
| # 200 dummy proteins | ||
| prot <- matrix(rnorm(200*20), nrow = 200); | ||
| colnames(prot) <- pheno$ID | ||
| rownames(prot) <- sprintf("protein%i",1:200) | ||
| # 2 dummy clin variables | ||
| clin <- t(data.frame(AGE=runif(20,10,50))) | ||
| colnames(clin) <- pheno$ID | ||
| clin <- t(clin) | ||
|
|
||
| # netDx files | ||
| dataList <- list(rna = rna, proteomics = prot, pheno = clin) | ||
|
|
||
| x <- convertToMAE(dataList) | ||
| expect_is(x, "MultiAssayExperiment") | ||
| }) | ||
|
|
||
| test_that ("convertToMAE removes duplicated sample", { | ||
| # 20 patients, 10 case, 10 control | ||
| pheno <- data.frame(ID=sprintf("PAT%i",1:20), | ||
| STATUS=rep(c("case","control"),each=10)) | ||
| # 100 dummy genes, with first sample duplicated | ||
| rna <- matrix(rnorm(100*20),nrow=100); | ||
| colnames(rna) <- pheno$ID | ||
| rownames(rna) <- sprintf("gene%i",1:100) | ||
| rna <- cbind(rna, rna[,1]) | ||
| colnames(rna)[21] <- colnames(rna)[1] | ||
| # 200 dummy proteins | ||
| prot <- matrix(rnorm(200*20), nrow = 200); | ||
| colnames(prot) <- pheno$ID | ||
| rownames(prot) <- sprintf("protein%i",1:200) | ||
| # 2 dummy clin variables | ||
| clin <- t(data.frame(AGE=runif(20,10,50))) | ||
| colnames(clin) <- pheno$ID | ||
| clin <- t(clin) | ||
|
|
||
| # netDx files | ||
| dataList <- list(rna = rna, proteomics = prot, pheno = clin) | ||
|
|
||
| x <- convertToMAE(dataList) | ||
| expect_is(x, "MultiAssayExperiment") | ||
| # number of samples in rna assay vs colData should differ by 1 | ||
| expect_equal((dim(rna)[2] - dim(colData(x))[1]), 1) | ||
| # number of samples in metadata should agree with colData | ||
| expect_equal((dim(clin)[1] - dim(colData(x))[1]), 0) | ||
| }) | ||
shraddhapai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.