-
Notifications
You must be signed in to change notification settings - Fork 27
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
create new generic converter #506
Closed
Closed
Changes from all commits
Commits
Show all changes
66 commits
Select commit
Hold shift + click to select a range
1bc1d14
new generic function convert
thpral 8d1f351
keep the original functions in their original files
thpral efeb240
up
thpral fca1fbd
up
thpral 10d353b
convert documentation
thpral 2c27585
up
thpral 24366d7
up
thpral a5898c6
correct documentation
thpral bb48891
correct internal functions naming
thpral 7eb4616
up
thpral ef58f1b
up
thpral 813f6e6
up
thpral ecd88df
up
thpral 06b7dfa
up
thpral 6fcfcc0
up
thpral 4a937fc
correct convert man page
thpral 6afdc7e
correct BiocCheck warnings
thpral 3f31882
up
thpral 5c57a91
Merge branch 'devel' into draft_converters
TuomasBorman 580ad1b
change param tree_name to tree.name for convert
thpral 2f7db75
up
thpral 1f7cf4b
Merge branch 'draft_converters' of https://github.com/microbiome/mia …
thpral c8b6242
new parameter for choosing output type when converting SE and TSE
thpral 08277cb
up
thpral c5847e4
merge devel and resolve conflicts
thpral ee4d240
up
TuomasBorman 84d4976
changes after review
thpral 837c4a7
merge remote (resolve conflicts)
thpral d368db2
merge devel and resolve conflicts
thpral d285bf9
correct arguments loadFromBiom
thpral c4f6265
correct deprecate and NAMESPACE file
thpral 204b774
merge devel
thpral fca7a9c
correct importBIOM default arguments after merging devel
thpral 5599459
move loadFromBiom arguments (doc)
thpral 5e95935
export loadFromBiom
thpral ea0e066
export converters in deprecate file
thpral ccb0bec
update DESCRIPTION
thpral fc9d5e7
merge devel
thpral 86ea4ab
rename man page loadFromBiom to importBIOM to avoid duplicated aliases
thpral 9e193d0
resolve conflicts and merge devel
thpral 26d1a4b
add import tags for phyloseq and dada classes
thpral c9956d0
merge devel
thpral 2d415a1
merge devel and remove import tags for dada and phyloseq classes
thpral 167cb37
fix lost braces
thpral b833e14
try to fix R CMD check note
thpral 4cdfc9c
up
thpral 97f40d2
reverse last 2 commits
thpral 70016dd
Revert "fix lost braces"
thpral b977a1c
Merge branch 'draft_converters' of https://github.com/microbiome/mia …
thpral 332acfa
merge devel
thpral 7129b67
replace convert with new names in deprecate, biom and phyloseq
thpral 67db5f2
merge devel
thpral 99ec6cd
replace convert with new functions
thpral f400ab4
rename converters files
thpral 93afb81
rearrange convert man page
thpral 383adea
Merge branch 'devel' into draft_converters
thpral da81e8d
fix errors and warnings
thpral d360e0e
Merge branch 'draft_converters' of https://github.com/microbiome/mia …
thpral 49a2a26
fix convertToPhyloseq
thpral e0590b8
try to fix R CMD check note
thpral dd43f9a
merge devel
thpral 9cc92a2
merge devel
thpral d236775
small fix
thpral fdbd8af
renaming files
thpral a30c9fd
renaming files
thpral 2f906a1
resolve R CMD check warning
thpral 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 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 |
---|---|---|
@@ -1,10 +1,16 @@ | ||
#' Loading a biom file | ||
#' Converters | ||
#' | ||
#' For convenience a few functions are available to convert data from a | ||
#' \sQuote{biom} file or object into a | ||
#' For convenience a few functions are available to convert BIOM, DADA2 and | ||
#' phyloseq objects to | ||
#' \code{\link[TreeSummarizedExperiment:TreeSummarizedExperiment-class]{TreeSummarizedExperiment}} | ||
#' objects and | ||
#' \code{\link[TreeSummarizedExperiment:TreeSummarizedExperiment-class]{TreeSummarizedExperiment}} | ||
#' objects to phyloseq objects. | ||
#' | ||
#' @param file biom file location | ||
#' @param file BIOM file location | ||
#' | ||
#' @param obj BIOM object to be converted to a | ||
#' \code{\link[TreeSummarizedExperiment:TreeSummarizedExperiment-class]{TreeSummarizedExperiment}} | ||
#' | ||
#' @param prefix.rm \code{TRUE} or \code{FALSE}: Should | ||
#' taxonomic prefixes be removed? The prefixes is removed only from detected | ||
|
@@ -27,22 +33,31 @@ | |
#' | ||
#' @param ... additional arguments | ||
#' \itemize{ | ||
#' \item \code{patter}: \code{character} value specifying artifacts | ||
#' \item{\code{pattern}}{\code{character} value specifying artifacts | ||
#' to be removed. If \code{patterns = "auto"}, special characters | ||
#' are removed. (default: \code{pattern = "auto"}) | ||
#' are removed. (default: \code{pattern = "auto"}) | ||
#' } | ||
#' } | ||
#' | ||
#' @return An object of class | ||
#' @details | ||
#' \code{convertFromBIOM} coerces a BIOM object to a | ||
#' \code{\link[TreeSummarizedExperiment:TreeSummarizedExperiment-class]{TreeSummarizedExperiment}} | ||
#' object. | ||
#' | ||
#' \code{importBIOM} loads a BIOM file and creates a | ||
#' \code{\link[TreeSummarizedExperiment:TreeSummarizedExperiment-class]{TreeSummarizedExperiment}} | ||
#' object from the BIOM object contained in the loaded file | ||
#' @return | ||
#' \code{importBIOM} returns an object of class | ||
#' \code{\link[TreeSummarizedExperiment:TreeSummarizedExperiment-class]{TreeSummarizedExperiment}} | ||
#' | ||
#' \code{convertFromBIOM} returns an object of class | ||
#' \code{\link[TreeSummarizedExperiment:TreeSummarizedExperiment-class]{TreeSummarizedExperiment}} | ||
#' | ||
#' @name makeTreeSEFromBiom | ||
#' @seealso | ||
#' \code{\link[=makeTreeSEFromPhyloseq]{makeTreeSEFromPhyloseq}} | ||
#' \code{\link[=makeTreeSEFromDADA2]{makeTreeSEFromDADA2}} | ||
#' \code{\link[=importQIIME2]{importQIIME2}} | ||
#' \code{\link[=importMothur]{importMothur}} | ||
#' @name convert | ||
#' | ||
#' @examples | ||
#' ### Load and convert BIOM results to a TreeSE | ||
#' # Load biom file | ||
#' library(biomformat) | ||
#' biom_file <- system.file("extdata", "rich_dense_otu_table.biom", | ||
|
@@ -53,7 +68,7 @@ | |
#' | ||
#' # Make TreeSE from biom object | ||
#' biom_object <- biomformat::read_biom(biom_file) | ||
#' tse <- makeTreeSEFromBiom(biom_object) | ||
#' tse <- convertFromBIOM(biom_object) | ||
#' | ||
#' # Get taxonomyRanks from prefixes and remove prefixes | ||
#' tse <- importBIOM(biom_file, | ||
|
@@ -69,31 +84,30 @@ | |
#' artifact.rm = TRUE) | ||
NULL | ||
|
||
#' @rdname makeTreeSEFromBiom | ||
#' | ||
#' \code{importBIOM} loads a BIOM file and creates a TreeSE from the BIOM object | ||
#' contained in the loaded file. | ||
#' @rdname convert | ||
#' @export | ||
importBIOM <- function(file, ...) { | ||
.require_package("biomformat") | ||
biom <- biomformat::read_biom(file) | ||
makeTreeSEFromBiom(biom, ...) | ||
convertFromBIOM(biom,...) | ||
} | ||
|
||
#' @rdname makeTreeSEFromBiom | ||
#' | ||
#' @param x object of type \code{\link[biomformat:read_biom]{biom}} | ||
#' | ||
#' @export | ||
#' \code{convertFromBIOM} creates a TreeSE object from a BIOM object. | ||
#' @importFrom S4Vectors make_zero_col_DFrame DataFrame | ||
#' @importFrom dplyr %>% bind_rows | ||
makeTreeSEFromBiom <- function( | ||
x, prefix.rm = removeTaxaPrefixes, | ||
#' @rdname convert | ||
#' @export | ||
convertFromBIOM <- function( | ||
obj, prefix.rm = removeTaxaPrefixes, | ||
removeTaxaPrefixes = FALSE, rank.from.prefix = rankFromPrefix, | ||
rankFromPrefix = FALSE, | ||
artifact.rm = remove.artifacts, remove.artifacts = FALSE, ...){ | ||
# input check | ||
.require_package("biomformat") | ||
if(!is(x,"biom")){ | ||
stop("'x' must be a 'biom' object", call. = FALSE) | ||
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 name of object is changed from obj to x indicating that your branch is out of sync |
||
if(!is(obj,"biom")){ | ||
stop("'obj' must be a 'biom' object", call. = FALSE) | ||
} | ||
if( !.is_a_bool(prefix.rm) ){ | ||
stop("'prefix.rm' must be TRUE or FALSE.", call. = FALSE) | ||
|
@@ -105,9 +119,9 @@ makeTreeSEFromBiom <- function( | |
stop("'artifact.rm' must be TRUE or FALSE.", call. = FALSE) | ||
} | ||
# | ||
counts <- as(biomformat::biom_data(x), "matrix") | ||
sample_data <- biomformat::sample_metadata(x) | ||
feature_data <- biomformat::observation_metadata(x) | ||
counts <- as(biomformat::biom_data(obj), "matrix") | ||
sample_data <- biomformat::sample_metadata(obj) | ||
feature_data <- biomformat::observation_metadata(obj) | ||
|
||
# colData is initialized with empty tables with rownames if it is NULL | ||
if( is.null(sample_data) ){ | ||
|
@@ -185,8 +199,8 @@ makeTreeSEFromBiom <- function( | |
} | ||
|
||
# Adjust row and colnames | ||
rownames(counts) <- rownames(feature_data) <- biomformat::rownames(x) | ||
colnames(counts) <- rownames(sample_data) <- biomformat::colnames(x) | ||
rownames(counts) <- rownames(feature_data) <- biomformat::rownames(obj) | ||
colnames(counts) <- rownames(sample_data) <- biomformat::colnames(obj) | ||
|
||
# Convert into DataFrame | ||
sample_data <- DataFrame(sample_data) | ||
|
@@ -202,14 +216,6 @@ makeTreeSEFromBiom <- function( | |
return(tse) | ||
} | ||
|
||
####################### makeTreeSummarizedExperimentFromBiom ################### | ||
#' @param x object of type \code{\link[biomformat:read_biom]{biom}} | ||
#' @rdname makeTreeSEFromBiom | ||
#' @export | ||
makeTreeSummarizedExperimentFromBiom <- function(x, ...){ | ||
makeTreeSEFromBiom(x, ...) | ||
} | ||
|
||
################################ HELP FUNCTIONS ################################ | ||
# This function removes prefixes from taxonomy names | ||
.remove_prefixes_from_taxa <- function( | ||
|
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,77 @@ | ||
#' @param phy a \code{phyloseq} object | ||
#' | ||
#' @details | ||
#' \code{convertFromPhyloseq} converts \code{phyloseq} | ||
#' objects into | ||
#' \code{\link[TreeSummarizedExperiment:TreeSummarizedExperiment-class]{TreeSummarizedExperiment}} objects. | ||
#' All data stored in a \code{phyloseq} object is transferred. | ||
#' | ||
#' @return | ||
#' \code{convertFromPhyloseq} returns an object of class | ||
#' \code{\link[TreeSummarizedExperiment:TreeSummarizedExperiment-class]{TreeSummarizedExperiment}} | ||
#' | ||
#' @importFrom S4Vectors SimpleList DataFrame make_zero_col_DFrame | ||
#' @importFrom SummarizedExperiment colData colData<- | ||
#' | ||
#' @export | ||
#' | ||
#' @rdname convert | ||
#' @seealso | ||
#' \code{\link[=importQIIME2]{importQIIME2}} | ||
#' \code{\link[=importMothur]{importMothur}} | ||
#' | ||
#' @examples | ||
#' | ||
#' ### Coerce a phyloseq object to a TreeSE object | ||
#' if (requireNamespace("phyloseq")) { | ||
#' data(GlobalPatterns, package="phyloseq") | ||
#' convertFromPhyloseq(GlobalPatterns) | ||
#' data(enterotype, package="phyloseq") | ||
#' convertFromPhyloseq(enterotype) | ||
#' data(esophagus, package="phyloseq") | ||
#' convertFromPhyloseq(esophagus) | ||
#' } | ||
convertFromPhyloseq <- function(phy, ...) { | ||
# input check | ||
.require_package("phyloseq") | ||
if(!is(phy,"phyloseq")){ | ||
stop("'phy' must be a 'phyloseq' object") | ||
} | ||
# | ||
# Get the assay | ||
counts <- phy@otu_table@.Data | ||
# Check the orientation, and transpose if necessary | ||
if( !phy@otu_table@taxa_are_rows ){ | ||
counts <- t(counts) | ||
} | ||
# Create a list of assays | ||
assays <- SimpleList(counts = counts) | ||
|
||
if(!is.null(phy@tax_table@.Data)){ | ||
rowData <- DataFrame(data.frame(phy@tax_table@.Data)) | ||
} else{ | ||
rowData <- S4Vectors::make_zero_col_DFrame(nrow(assays$counts)) | ||
rownames(rowData) <- rownames(assays$counts) | ||
} | ||
if(!is.null(phy@sam_data)){ | ||
colData <- DataFrame(data.frame(phy@sam_data)) | ||
} else{ | ||
colData <- S4Vectors::make_zero_col_DFrame(ncol(assays$counts)) | ||
rownames(colData) <- colnames(assays$counts) | ||
} | ||
if(!is.null(phy@phy_tree)){ | ||
rowTree <- phy@phy_tree | ||
} else { | ||
rowTree <- NULL | ||
} | ||
if (!is.null(phy@refseq)) { | ||
referenceSeq <- phy@refseq | ||
} else { | ||
referenceSeq <- NULL | ||
} | ||
TreeSummarizedExperiment(assays = assays, | ||
rowData = rowData, | ||
colData = colData, | ||
rowTree = rowTree, | ||
referenceSeq = referenceSeq) | ||
} |
Oops, something went wrong.
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.
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.
Problem with news, same line is added