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/
582 stars 187 forks source link

Sample merging the phyloseq object with merge_samples() hits an error but works for other objects. #546

Closed wolass closed 6 years ago

wolass commented 8 years ago

I am having a problem merging samples using merge_samples() function: the phyl1 is a phyloseq object, if I run:

m_phyl1 <- merge_samples(phyl1,"Patient.number") 

I get this error:

 Error in validObject(.Object) : invalid class “phyloseq” object: 
 Component sample names do not match.
 Try sample_names()

But if I only take sample data from thys phyloseq object by using sample_data() function on it, everything works fine...

merge_samples(sample_data(phyl1),"Patient.number")

So my sample data merges but my phyloseq refuses to... What is the problem here? My session info:

R version 3.2.2 (2015-08-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.3 LTS

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=pl_PL.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=pl_PL.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=pl_PL.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=pl_PL.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] parallel  grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] anareg_0.1.0        dunn.test_1.3.1     MASS_7.3-44         scales_0.3.0        knitr_1.11          mgcv_1.8-7         
 [7] nlme_3.1-122        microbiome_0.99.62  RPA_1.26.0          affy_1.48.0         Biobase_2.30.0      BiocGenerics_0.16.0
[13] plyr_1.8.3          dplyr_0.4.3         ggplot2_1.0.1       tidyr_0.3.1         phyloseq_1.14.0 
rehgar12 commented 7 years ago

having the same problem, same error:

merge_samples(Trfclean, "timepoint") Error in validObject(.Object) : invalid class “phyloseq” object: Component sample names do not match. Try sample_names()

sample_variables(Trfclean) [1] "X.SampleID" "InputFileName"
...
[15] "studyday" "timepoint"
... [61] "Description"

sample_names(sample_data(Trfclean)) [1] "6894" "6893" "6824" "6874" "6842" "6868" "6885" "6869" "6881" "6839" [11] "6841" "6821" "6810" "6823" "6861" "6843" "6844" "6849" "6887" "6833" [21] "6827" "6856" "6819" "6858" "6888" "6826" "6812" "6879" "6854" "6882" [31] "6889" "6871" "6835" "6846" "6883" "6851" "6816" "6878" "6828" "6814" [41] "6834" "6863" "6818" "6864" "6845" "6832" "6848" "6850" "6857" "6891" [51] "6825" "6836" "6880" "6886" "6890" "6865" "6877" "6862" "6813" "6838" [61] "6811" "6852" "6817" "6867" "6847" "6875" "6870" "6808" "6829" "6822" [71] "6884" "6876" "6853" "6855" "6873" "6892" "6860" "6866" "6806" "6837" [81] "6807" "6872" "6831" "6820" "6840"

sample_names(otu_table(Trfclean)) [1] "6894" "6893" "6824" "6874" "6842" "6868" "6885" "6869" "6881" "6839" [11] "6841" "6821" "6810" "6823" "6861" "6843" "6844" "6849" "6887" "6833" [21] "6827" "6856" "6819" "6858" "6888" "6826" "6812" "6879" "6854" "6882" [31] "6889" "6871" "6835" "6846" "6883" "6851" "6816" "6878" "6828" "6814" [41] "6834" "6863" "6818" "6864" "6845" "6832" "6848" "6850" "6857" "6891" [51] "6825" "6836" "6880" "6886" "6890" "6865" "6877" "6862" "6813" "6838" [61] "6811" "6852" "6817" "6867" "6847" "6875" "6870" "6808" "6829" "6822" [71] "6884" "6876" "6853" "6855" "6873" "6892" "6860" "6866" "6806" "6837" [81] "6807" "6872" "6831" "6820" "6840"

nrow(sample_data(Trfclean)) [1] 85 ncol(otu_table(Trfclean)) [1] 85

You can see the sample IDs in the sample_data and otu_table are identical.

drcarrot commented 7 years ago

After using this function many times without a glitch, I am having the same problem. I am working with a small phyloseq object, constructed through dada2.

rrarefied phyloseq-class experiment-level object otu_table() OTU Table: [ 5541 taxa and 12 samples ] sample_data() Sample Data: [ 12 samples by 2 sample variables ] tax_table() Taxonomy Table: [ 5541 taxa by 6 taxonomic ranks ]

sample_names(rrarefied@otu_table)==sample_names(rrarefied@sam_data) [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE

sample_names(rrarefied)==row.names(rrarefied@sam_data) [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE

rarefiedm = merge_samples(rrarefied, "meta") Error in validObject(.Object) : invalid class “phyloseq” object: Component sample names do not match. Try sample_names()

But this works

rarefiedm = merge_samples(sample_data(rrarefied), var1) rarefiedm Sample Data: [2 samples by 2 sample variables]: meta names sa1 1 16332.71 sa2 2 28081.40

NeonatalResearcher commented 6 years ago

It seems I am not the only one who has had this problem. I also can merge sample data, but this does not create a phyloseq object, just a data table without the associated OTU and taxonomy data.

Did anyone find out what was going wrong and how to fix it?

drcarrot commented 6 years ago

Nope!

On Tue, Nov 7, 2017 at 5:55 PM, NeonatalResearcher <notifications@github.com

wrote:

It seems I am not the only one who has had this problem. I also can merge sample data, but this does not create a phyloseq object, just a data table without the associated OTU and taxonomy data.

Did anyone find out what was going wrong and how to fix it?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/joey711/phyloseq/issues/546#issuecomment-342548014, or mute the thread https://github.com/notifications/unsubscribe-auth/AZracSX99dkEe9Fue2F66opnn8_vJrK3ks5s0ItwgaJpZM4GY28s .

joey711 commented 6 years ago

Have you tried merge_phyloseq?

joey711 commented 6 years ago

Also, I don't see a single reproducible example in this thread. It is often very difficult, or even impossible, to reproduce a problem when it is copy-pasted from unprovided dataset in the middle of a session.

See MRE on SO for details and discussion.

drcarrot commented 6 years ago

Hi, I apologize for the lack of a reproducible data. Attached is one dataset I am having the same trouble with. Again, I only have this problem when the sequences have been processed with dada2.

Thanks for your help!

On Tue, Nov 7, 2017 at 6:24 PM, Paul J. McMurdie notifications@github.com wrote:

Also, I don't see a single reproducible example in this thread. It is often very difficult, or even impossible, to reproduce a problem when it is copy-pasted from unprovided dataset in the middle of a session.

See MRE on SO https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example for details and discussion.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/joey711/phyloseq/issues/546#issuecomment-342557421, or mute the thread https://github.com/notifications/unsubscribe-auth/AZraca8hiTxfQxDsM1viX38DvFC7f1qHks5s0JI0gaJpZM4GY28s .

joey711 commented 6 years ago

The appropriate command for merging two phyloseq objects is merge_phyloseq, not merge_samples.

drcarrot commented 6 years ago

Hi, I am sorry to push this further, but I still haven't been able to solve this issue. I am new to github and thought a file had been attached last time! I have tried changing the OTU names on each of the separate Phyloseq components and remerging with merge-phyloseq; I have checked and re-checked whether the sample names match, and I cannot find what the problem is: merge_samples() does not work for datasets I process in dada2 and I don't know why. I have attached a small phyloseq object that is giving me this error. Any help is greatly appreciated!

merged=readRDS("merged.RDS")

q=merge_samples(merged, "meta") Error in validObject(.Object) : invalid class “phyloseq” object: Component sample names do not match. Try sample_names() sample_names(merged) [1] "1266" "1267" "2860" "3780" "58556" "6084" "61830" "7242" "81517" "8157" [11] "9002" "9506" "9753" sample_names(merged@sam_data) [1] "1266" "1267" "2860" "3780" "58556" "6084" "61830" "7242" "81517" "8157" [11] "9002" "9506" "9753" sample_names(merged@otu_table) [1] "1266" "1267" "2860" "3780" "58556" "6084" "61830" "7242" "81517" "8157" [11] "9002" "9506" "9753"

sessionInfo() R version 3.4.0 (2017-04-21) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] psych_1.7.8 Carrotworks_0.0.0.9000 phyloseq_1.20.0

loaded via a namespace (and not attached): [1] Rcpp_0.12.13 compiler_3.4.0 plyr_1.8.4 XVector_0.16.0
[5] iterators_1.0.8 tools_3.4.0 zlibbioc_1.22.0 jsonlite_1.5
[9] tibble_1.3.4 nlme_3.1-131 rhdf5_2.20.0 gtable_0.2.0
[13] lattice_0.20-35 mgcv_1.8-22 pkgconfig_2.0.1 rlang_0.1.2.9000
[17] Matrix_1.2-11 foreach_1.4.3 igraph_1.1.2 parallel_3.4.0
[21] stringr_1.2.0 cluster_2.0.6 Biostrings_2.44.2 S4Vectors_0.14.7
[25] IRanges_2.10.5 multtest_2.32.0 stats4_3.4.0 ade4_1.7-8
[29] grid_3.4.0 Biobase_2.36.2 data.table_1.10.4-2 survival_2.41-3
[33] foreign_0.8-69 reshape2_1.4.2 ggplot2_2.2.1 magrittr_1.5
[37] MASS_7.3-47 splines_3.4.0 scales_0.5.0 codetools_0.2-15
[41] BiocGenerics_0.22.1 mnormt_1.5-5 biomformat_1.4.0 permute_0.9-4
[45] ape_4.1 colorspace_1.3-2 stringi_1.1.5 lazyeval_0.2.0
[49] munsell_0.4.3 vegan_2.4-4
merged.zip

abhijeetsingh1704 commented 6 years ago

It seems the it is the problem of the mapped data file. The mapped data file should be created by defining the separation type. map <-read.csv("file.csv", sep=";", header=TRUE) This command changed my problem. Hope will work for all too.

marsfro commented 4 years ago

Hello! I have the same problem/ Can't to merge phyloseq object from kraken-biom-file and sample date

sample_names(com2@sam_data) NULL What to do?

gabridinosauro commented 3 years ago

Yes it is a problem. I do not get what to do. The samples names are the same but it still does not work.

mr2raccoon commented 3 years ago

Did anyone find a solution? I am stuck with the same problem.

marsfro commented 3 years ago

Dear all! I remember, that too long deside this problem, but now I don’t working with this package. But I send you Rscript with decision, migth it will help you, It seems, that problem is in colnames, They should be the same. Good luck, Maria.

Четверг, 8 апреля 2021, 9:48 +03:00 от mr2raccoon @.***>:     Did anyone find a solution? I am stuck with the same problem. — You are receiving this because you commented. Reply to this email directly, view it on GitHub , or unsubscribe .    


С уважением, Мария Фролова.

ИБК РАН

142290 г. Пущино, МО, ул. Институтская 3

тел.: (4967) 739162

факс: (4967) 330509  

mr2raccoon commented 3 years ago

I figured something out that worked for me: column_to_rownames(df, var = "sample_ID") This did the job. My sample data is now inside the phyloseqobj.

fuljanic commented 3 years ago

Hey everyone, I had a similar problem with phyloseq error "component names do not match" when creating a phyloseq object from otu table and metadata table even though sample names were identical in both. Turns out the problem was caused by one object being a tibble and the other dataframe. Make sure metadata table and OTU table are both either tibble or dataframe.

armetcal commented 2 years ago

Hey all, another possible cause of this error is if your variable that you're trying to merge by is coercible to numeric (even if it's currently in factor format). Try changing it to something non-coercible! (i.e. c('1','2','3') -> c('A','B','C'))

LucreziaMor commented 2 years ago

Hey all, another possible cause of this error is if your variable that you're trying to merge by is coercible to numeric (even if it's currently in factor format). Try changing it to something non-coercible! (i.e. c('1','2','3') -> c('A','B','C'))

This worked for me! thank you very much!!