joey711 / phyloseq

phyloseq is a set of classes, wrappers, and tools (in R) to make it easier to import, store, and analyze phylogenetic sequencing data; and to reproducibly share that data and analysis with others. See the phyloseq front page:
http://joey711.github.io/phyloseq/
586 stars 186 forks source link

`merge_phyloseq` fails if sample data contains only one column #1744

Open ying14 opened 7 months ago

ying14 commented 7 months ago

Hi, long-term phyloseq user and fan. When running merge_phyloseq(), an error occurs if the merged sample data only has one column:

data(GlobalPatterns)
phy1 <- subset_samples(GlobalPatterns,SampleType=="Soil")
phy2 <- subset_samples(GlobalPatterns,SampleType=="Ocean")
sample_data(phy1) <- sample_data(phy1)[,"SampleType"]
sample_data(phy2) <- sample_data(phy2)[,"SampleType"]
merge_phyloseq(phy1,phy2)

#> Error in access(object, "sam_data", errorIfNULL) : 
#>   sam_data slot is empty.

The issue seems to be related to a specific step in the internal function merge_phyloseq_pair(), where one-column data frames are incorrectly simplified into vectors.

I believe this might be the fix: within the setMethod("merge_phyloseq_pair", signature("sample_data", "sample_data") function, change newx <- newx[,names(newx)!="X0"] to newx <- newx[,names(newx)!="X0",drop=FALSE].

spholmes commented 7 months ago

Super helpful Ying Hello ...thanks, exactly the right answer, Edge case we need to take care of. Best wishes Susan

A quinta, 18/04/2024, 20:16, Ying Taur @.***> escreveu:

Hi, long-term phyloseq user and fan. When running merge_phyloseq(), an error occurs if the merged sample data only has one column:

data(GlobalPatterns)phy1 <- subset_samples(GlobalPatterns,SampleType=="Soil")phy2 <- subset_samples(GlobalPatterns,SampleType=="Ocean") sample_data(phy1) <- sample_data(phy1)[,"SampleType"] sample_data(phy2) <- sample_data(phy2)[,"SampleType"] merge_phyloseq(phy1,phy2)

> Error in access(object, "sam_data", errorIfNULL) : #> sam_data slot is empty.

The issue seems to be related to a specific step in the internal function merge_phyloseq_pair(), where one-column data frames are incorrectly simplified into vectors.

I believe this might be the fix: within the setMethod("merge_phyloseq_pair", signature("sample_data", "sample_data") function, change newx <- newx[,names(newx)!="X0"] to newx <- newx[,names(newx)!="X0",drop=FALSE].

— Reply to this email directly, view it on GitHub https://github.com/joey711/phyloseq/issues/1744, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJFZPIRRZUYYLX2VVW2POLY6ALZRAVCNFSM6AAAAABGN4ED2CVHI2DSMVQWIX3LMV43ASLTON2WKOZSGI2TCMZYGI4DINY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

ying14 commented 7 months ago

Great.... thank you Susan!