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

create new generic converter #506

Closed
wants to merge 66 commits into from
Closed

create new generic converter #506

wants to merge 66 commits into from

Conversation

thpralas
Copy link
Collaborator

Create a new generic function convert to replace the following converters :

  • makeTreeSEFromPhyloseq
  • makeTreeSEFromBiom
  • makeTreeSEFromDADA2
  • makePhyloseqFromTreeSE

Copy link
Contributor

@TuomasBorman TuomasBorman left a 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)

R/convert.R Outdated Show resolved Hide resolved
R/convert.R Outdated Show resolved Hide resolved
R/convert.R Outdated Show resolved Hide resolved
Copy link

codecov bot commented Apr 4, 2024

Codecov Report

Attention: Patch coverage is 53.39806% with 48 lines in your changes missing coverage. Please review.

Please upload report for BASE (devel@c17fa9f). Learn more about missing BASE report.

Current head c5847e4 differs from pull request most recent head 2f906a1

Please upload reports for the commit 2f906a1 to get more accurate results.

Files Patch % Lines
R/deprecate.R 0.00% 25 Missing ⚠️
R/makephyloseqFromTreeSummarizedExperiment.R 78.18% 12 Missing ⚠️
R/convert.R 50.00% 11 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

This reverts commit 167cb37.
Merge branch 'devel' of https://github.com/microbiome/mia into draft_converters

# Conflicts:
#	NEWS
#	R/deprecate.R
@thpralas
Copy link
Collaborator Author

thpralas commented Jun 3, 2024

If you cannot find solution for this, we can also rename the existing functions and move the documentation under shared "convert" page.

  • makeTreeSEFromPhyloseq --> convertFromPhyloseq
  • makeTreeSEFromBiom --> convertFromBIOM
  • makeTreeSEFromDADA2 --> convertFromDADA2
  • makePhyloseqFromTreeSE --> convertToPhyloseq

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.

@TuomasBorman
Copy link
Contributor

TuomasBorman commented Jun 3, 2024

This is what happens

> devtools::load_all()
ℹ Loading mia
in method for ‘convert’ with signature ‘x="dada"’: no definition for class “dada”
in method for ‘convert’ with signature ‘x="phyloseq"’: no definition for class “phyloseq”
in method for ‘convert’ with signature ‘x="biom"’: no definition for class “biom”
> library(dada2)
Loading required package: Rcpp
> devtools::load_all()
ℹ Loading mia
in method for ‘convert’ with signature ‘x="phyloseq"’: no definition for class “phyloseq”
in method for ‘convert’ with signature ‘x="biom"’: no definition for class “biom”

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.

@TuomasBorman
Copy link
Contributor

Any thoughts @antagomir

@antagomir
Copy link
Member

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.

@TuomasBorman
Copy link
Contributor

+ convert() is very neat solution
- We cannot have more dependencies, we have too many already
- We cannot have notes, when package is loaded. It does not look good.

--> 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

Comment on lines +138 to +139
calculateCCA to getCCA
+ add informative error message in rarefyAssay on assays with strictly-negative values
Copy link
Contributor

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

Comment on lines 34 to 72
# 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,
Copy link
Contributor

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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?

Copy link
Contributor

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")){
Copy link
Contributor

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

Comment on lines +58 to +88
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
Copy link
Contributor

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

Copy link
Collaborator Author

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

@TuomasBorman
Copy link
Contributor

#591

@TuomasBorman TuomasBorman deleted the draft_converters branch June 25, 2024 07:32
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

Successfully merging this pull request may close these issues.

3 participants