guokai8 / microbial

Do microbiome analysis with dada2 and phyloseq object
GNU General Public License v3.0
12 stars 3 forks source link

Error in `$<-.data.frame` #1

Closed Hesham999666 closed 3 years ago

Hesham999666 commented 3 years ago

res <- ldamarker(ps.nonc.nocyano,group="SampleType") Normalization using relative method |========================================================================================================= |100% ~0 s remaining Error in $<-.data.frame(*tmp*, "direction", value = c("PFH", "SUH" : replacement has 2 rows, data has 1 plotLDA(res,group=c("CFH","SUH"),lda=5,pvalue=0.05) Error in subset(x, LDAscore > lda) : object 'res' not found

guokai8 commented 3 years ago

Hi @Hesham999666 , Could you provide the detail for you group information for your sample? Kai

Hesham999666 commented 3 years ago

Hi Kai print (ps.nonc.nocyano) phyloseq-class experiment-level object otu_table() OTU Table: [ 37104 taxa and 357 samples ] sample_data() Sample Data: [ 357 samples by 2 sample variables ] tax_table() Taxonomy Table: [ 37104 taxa by 6 taxonomic ranks ]

guokai8 commented 3 years ago

Please use

head(phyloseq::sample_data(ps.nonc.nocyano))

to show the information

Hesham999666 commented 3 years ago

Sample Data: [6 samples by 2 sample variables]: SampleType Sample2 1001SH CFH 1001SH 1001WH CFH 1001WH 1001WS CS 1001WS 1009SH CFH 1009SH 1009WH CFH 1009WH 1009WS CS 1009WS

guokai8 commented 3 years ago

Do you have the same sample name (1001SH ...) as the colnames for the count_table?

Hesham999666 commented 3 years ago

No it is empty , it did not show when I run head (phyloseq::sample_data(ps.nonc.nocyano)) but this from metadata file Sample,SampleType,Sample2 1001SH,CFH,1001SH 1001WH,CFH,1001WH that is why I add third column (kind of bug)

guokai8 commented 3 years ago

which one is empty? And Please check the format if it looks same as my example data:

> data(Physeq)  
> physeq
phyloseq-class experiment-level object
otu_table()   OTU Table:         [ 19216 taxa and 26 samples ]
sample_data() Sample Data:       [ 26 samples by 8 sample variables ]
tax_table()   Taxonomy Table:    [ 19216 taxa by 7 taxonomic ranks ]
phy_tree()    Phylogenetic Tree: [ 19216 tips and 19215 internal nodes ]
> head(otu_table(physeq))
OTU Table:          [6 taxa and 26 samples]
                     taxa are rows
       CL3 CC1 SV1 M31Fcsw M11Fcsw M31Plmr M11Plmr F21Plmr M31Tong M11Tong
549322   0   0   0       0       0       0       0       0       0       0
522457   0   0   0       0       0       0       0       0       0       0
951      0   0   0       0       0       0       1       0       0       0
244423   0   0   0       0       0       0       0       0       0       0
586076   0   0   0       0       0       0       0       0       0       0
246140   0   0   0       0       0       0       0       0       0       0
       LMEpi24M SLEpi20M AQC1cm AQC4cm AQC7cm NP2 NP3 NP5 TRRsed1 TRRsed2
549322        0        1     27    100    130   1   0   0       0       0
522457        0        0      0      2      6   0   0   0       0       0
951           0        0      0      0      0   0   0   0       0       0
244423        0        0      0     22     29   0   0   0       0       0
586076        0        0      0      2      1   0   0   0       0       0
246140        0        0      0      1      3   0   0   0       0       0
       TRRsed3 TS28 TS29 Even1 Even2 Even3
549322       0    0    0     0     0     0
522457       0    0    0     0     0     0
951          0    0    0     0     0     0
244423       0    0    0     0     0     0
586076       0    0    0     0     0     0
246140       0    0    0     0     0     0
> head(sample_data(physeq))
Sample Data:        [6 samples by 8 sample variables]:
        X.SampleID  Primer Final_Barcode Barcode_truncated_plus_T
CL3            CL3 ILBC_01        AACGCA                   TGCGTT
CC1            CC1 ILBC_02        AACTCG                   CGAGTT
SV1            SV1 ILBC_03        AACTGT                   ACAGTT
M31Fcsw    M31Fcsw ILBC_04        AAGAGA                   TCTCTT
M11Fcsw    M11Fcsw ILBC_05        AAGCTG                   CAGCTT
M31Plmr    M31Plmr ILBC_07        AATCGT                   ACGATT
        Barcode_full_length SampleType
CL3             CTAGCGTGCGT       Soil
CC1             CATCGACGAGT       Soil
SV1             GTACGCACAGT       Soil
M31Fcsw         TCGACATCTCT      Feces
M11Fcsw         CGACTGCAGCT      Feces
M31Plmr         CGAGTCACGAT       Skin
                                       Description group
CL3       Calhoun South Carolina Pine soil, pH 4.9     B
CC1       Cedar Creek Minnesota, grassland, pH 6.1     B
SV1     Sevilleta new Mexico, desert scrub, pH 8.3     B
M31Fcsw    M3, Day 1, fecal swab, whole body study     A
M11Fcsw   M1, Day 1, fecal swab, whole body study      A
M31Plmr    M3, Day 1, right palm, whole body study     A
Hesham999666 commented 3 years ago

Yes. It is same your format, despite I don't have Phylogenetic Tree in my data I have two 2 variables, one of them sample_x (repeated SampleID) head(sample_data(physeq)) Sample_x SampleType 1001SH 1001SH CFH ......

guokai8 commented 3 years ago

Could you share part of your data? so I can test

Hesham999666 commented 3 years ago

I have send to your email four days ago hope that you received. I try it to uploaded here but it doesn't work.

guokai8 commented 3 years ago

Hi, I got the data. But there are some errors when I load the data:

> load("heshampig_bacteria_phyloseq.rds")
Error in load("heshampig_bacteria_phyloseq.rds") : 
  bad restore file magic number (file may be corrupted) -- no data loaded
In addition: Warning messages:
1: In readChar(con, 5L, useBytes = TRUE) :
  truncating string with embedded nuls
2: file ‘heshampig_bacteria_phyloseq.rds’ has magic number 'X'
  Use of save versions prior to 2 is deprecated 

I am not sure how you save the data. You can just save your data by using

save(physeq,file="physeq.rdata",compress=T)
Hesham999666 commented 3 years ago

Hi Kai

I sent to your guokai8@gmail.com by Mar 18, 2021, 10:09 PM

I have a replied to your "Could you share part of your data? so I can test" I sent it but the file was big, So I sent it by your personal email (Gmail).

BUT Actually it is working for me now, when I am upload the microbial package before the phyloseq package.

lefese analysis for microbiome data

upload the libraries

library(microbial) library(phyloseq)

upload the phyloseq files

ps1 <- readRDS ("heshamcow_bacteria_phyloseq.rds") ps2 <- readRDS ("heshampig_bacteria_phyloseq.rds")

merge phyloseqs =

airmicrobiome <- merge_phyloseq (ps1, ps2)

add metadta to your merged phyloseq file

metadata <- read.csv("cowandpigmetadata_x.csv", sep =',', header=TRUE, row.names=1) sample_data(airmicrobiome) <- metadata

performe the lefese on phyloseq

res <- ldamarker(airmicrobiome,group="SampleType")

plotLDA(res,group=c("CFH","PFH"),lda=5,pvalue=0.05, color = c("red","green"),fontsize.x = 7,fontsize.y = 8) plotLDA(res,group=c("CFH","SUH"),lda=5,pvalue=0.05, color = c("red","green"),fontsize.x = 7,fontsize.y = 8) plotLDA(res,group=c("PFH","SUH"),lda=5,pvalue=0.05, color = c("red","green"),fontsize.x = 7,fontsize.y = 8)

Thanks Kai

guokai8 commented 3 years ago

OK. I got it. Glad it works for you. Kai