-
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
Conversation
Merge branch 'draft_converters' of https://github.com/microbiome/mia into draft_converters # Conflicts: # R/convert.R
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.
When dada2, phyloseq and biom ackages are not loaded, the functions says that these classes cannot be found --> I think that is ok. (just to note)
…into draft_converters
Merge branch 'devel' of https://github.com/microbiome/mia into draft_converters # Conflicts: # NEWS
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## devel #506 +/- ##
========================================
Coverage ? 72.73%
========================================
Files ? 41
Lines ? 4666
Branches ? 0
========================================
Hits ? 3394
Misses ? 1272
Partials ? 0 ☔ View full report in Codecov by Sentry. |
This reverts commit 167cb37.
…into draft_converters
Merge branch 'devel' of https://github.com/microbiome/mia into draft_converters # Conflicts: # NEWS # R/deprecate.R
Should I do that even though it's a note and not a warning? I'm still trying to understand the note better and determine if it's something to be concerned about. |
This is what happens
So it it caused, because dada2:dada class is not found. But when dada2 package is loaded, it is found. We do not want to add new dependencies, that is why those packages are not loaded when mia is loaded. Previously these functions were implemented as "basic" functions, so they were not this kind of generic functions that choose method based on class. In theory, you could probably add a script to mia.R that loads these packages if available, but that is suboptimal solution. I think it is not good that there are this kind of notes when mia is loaded. Some users might think that these are warnings. |
Any thoughts @antagomir |
If we go with mia then I am OK with either solution. One generic function would be nice but if this is not possible, then specific functions. Another solution could be a separate utility package. We might have other misc utility needs too. But that will be more maintenance overhead. |
+ convert() is very neat solution --> I think we have to go with separate functions. You can just rename the functions from their original files and then just combine the documentation under convert |
Merge branch 'devel' of https://github.com/microbiome/mia into draft_converters # Conflicts: # NEWS
…into draft_converters
calculateCCA to getCCA | ||
+ add informative error message in rarefyAssay on assays with strictly-negative values |
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
# input check | ||
.require_package("phyloseq") | ||
if(!is(obj,"phyloseq")){ | ||
stop("'obj' must be a 'phyloseq' object") | ||
} | ||
# | ||
# Get the assay | ||
counts <- obj@otu_table@.Data | ||
# Check the orientation, and transpose if necessary | ||
if( !obj@otu_table@taxa_are_rows ){ | ||
counts <- t(counts) | ||
} | ||
# Create a list of assays | ||
assays <- SimpleList(counts = counts) | ||
|
||
if(!is.null(obj@tax_table@.Data)){ | ||
rowData <- DataFrame(data.frame(obj@tax_table@.Data)) | ||
} else{ | ||
rowData <- S4Vectors::make_zero_col_DFrame(nrow(assays$counts)) | ||
rownames(rowData) <- rownames(assays$counts) | ||
} | ||
if(!is.null(obj@sam_data)){ | ||
colData <- DataFrame(data.frame(obj@sam_data)) | ||
} else{ | ||
colData <- S4Vectors::make_zero_col_DFrame(ncol(assays$counts)) | ||
rownames(colData) <- colnames(assays$counts) | ||
} | ||
if(!is.null(obj@phy_tree)){ | ||
rowTree <- obj@phy_tree | ||
} else { | ||
rowTree <- NULL | ||
} | ||
if (!is.null(obj@refseq)) { | ||
referenceSeq <- obj@refseq | ||
} else { | ||
referenceSeq <- NULL | ||
} | ||
TreeSummarizedExperiment(assays = assays, | ||
rowData = rowData, |
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.
Not sure, if the link is just broken between files, but it seems now that you have copy.-pasted code to another file. Instead, it should only look like that the name has changed.
Also, as this is not anymore big change (only the name is changed and documentation is moved under common page), I am wondering if you should make new PR with new branch if that is easier.
We have parameter naming PR that will be soon merged, and it affects also these files. It was good that we explored the possibility of common convert function even though it will not be implemented.
I am wondering what is the easiest approach.
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.
Yes I think it may be easier to open a new PR because I have probably made some unnecessary changes in this PR when I tried to implement convert
generic function.
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.
Should I make new methods for the functions that do not have one (e.g. makeTreeSEFromDADA2
) ?
Also should we keep both names makeTreeSE* and makeTreeSummarizedExperiment* for every converters or not?
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.
Now this bigger PR was merged #582, so you can continue with this.
Those names will be deprecated. All the functions that were available for user must be deprecated and added to deprecate.R file.
Each functionality will have only one function that is convertTo* or convertFrom*
Merge branch 'devel' of https://github.com/microbiome/mia into draft_converters # Conflicts: # NEWS # R/convertFromBIOM.R # R/makeTreeSummarizedExperimentFromPhyloseq.R # R/makephyloseqFromTreeSummarizedExperiment.R # man/makePhyloseqFromTreeSE.Rd # man/makeTreeSEFromBiom.Rd # man/makeTreeSEFromPhyloseq.Rd # tests/testthat/test-4IO.R # tests/testthat/test-5Unifrac.R
removeTaxaPrefixes = FALSE, rank.from.prefix = rankFromPrefix, | ||
rankFromPrefix = FALSE, | ||
artifact.rm = remove.artifacts, remove.artifacts = FALSE, ...){ | ||
# input check | ||
.require_package("biomformat") | ||
if(!is(x,"biom")){ |
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.
The name of object is changed from obj to x indicating that your branch is out of sync
setGeneric("convertToPhyloseq", signature = c("x"), | ||
function(x, ...) | ||
standardGeneric("convertToPhyloseq")) | ||
|
||
#' @rdname convert | ||
#' @export | ||
setMethod("convertToPhyloseq", | ||
signature = c(x = "SummarizedExperiment"), | ||
function(x, assay.type = "counts", assay_name = NULL, ...){ | ||
# Input check | ||
.require_package("phyloseq") | ||
# Check that tse do not have zero rows | ||
if(!all(dim(x) > 0)){ | ||
stop("'x' contains zero rows. 'x' can not be converted | ||
to a phyloseq object.", | ||
call. = FALSE) | ||
} | ||
|
||
if (!is.null(assay_name)) { | ||
.Deprecated(old="assay_name", new="assay.type", "Now assay_name is deprecated. Use assay.type instead.") | ||
} | ||
|
||
# Check assay.type | ||
.check_assay_present(assay.type, x) | ||
|
||
# phyloseq object requires nonduplicated rownames. If there are | ||
# duplicated rownames, they are converted so that they are unique | ||
if( any(duplicated(rownames(x))) ){ | ||
rownames(x) <- getTaxonomyLabels(x) | ||
} | ||
# List of arguments |
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.
These look like they are new functions even though they are not. The name has only changed. This cannot be merged since this breaks the history of the functions. One option is to create new branch and continue from there
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.
OK I think I am going to create a new branch then, it will be easier
Create a new generic function
convert
to replace the following converters :