stefpeschel / NetCoMi

Network construction, analysis, and comparison for microbial compositional data
GNU General Public License v3.0
146 stars 26 forks source link

Netcompare Error after permutation #38

Closed lixiaopi1985 closed 2 years ago

lixiaopi1985 commented 2 years ago

Hi Stefanie,

Thank you for this amazing library.

No issue with the network construction, analysis, and plotting. However, I encountered two errors after setting permutation for the netCompare function running separately for the 16S and ITS data (See below). Hope you can provide some insights.

Best, Xiao

Error 1 (16S networks):

Calculate network properties ... Done.
Files './Field_analysis_ver2/network/bac_assoPerm_nperm1000.bmat and ./Field_analysis_ver2/network/bac_assoPerm_nperm1000.desc.txt created. 
Execute permutation tests ... 
  |======================================================================================| 100%
Stopping socket cluster ... Done.
Calculating p-values ... Error in netCompare(netAna16S, permTest = T, storeAssoPerm = T, fileStoreAssoPerm = "./Field_analysis_ver2/network/bac_assoPerm_nperm1000",  : 
  'list' object cannot be coerced to type 'double'

Error2 (ITS networks)

Calculate network properties ... Done.
Files './Field_analysis_ver2/network/FUN_assoPerm_nperm1000.bmat and ./Field_analysis_ver2/network/FUN_assoPerm_nperm1000.desc.txt created. 
Execute permutation tests ... 
  |================================================| 100%
Stopping socket cluster ... Done.
Calculating p-values ... Error in absDiffsPermDeg[b, ] <- propsPerm[[b]]$absDiffsCentr$absDiffDeg : 
  replacement has length zero

My codes:

fdataITS.gen = readRDS("./RDSdata/fdataITS_phylo_genus.rds")
fITS.metam = subset_samples(fdataITS.gen, metamStatus=="Fumigated")
taxtab.metam = fITS.metam@tax_table@.Data
rownames(fITS.metam@otu_table@.Data) = taxtab.metam[, "Genus"]
fITS.no = subset_samples(fdataITS.gen, metamStatus=="No-fumigated")
taxtab.no = fITS.no@tax_table@.Data
rownames(fITS.no@otu_table@.Data) = taxtab.no[, "Genus"]

netITS.spie = netConstruct(data = fITS.metam,
                       data2 = fITS.no,
                       measure = "spieceasi",
                       measurePar = list(lambda.min.ratio=1e-2, nlambda=20, pulsar.params=list(rep.num=50)),
                       filtTax = "highestFreq",
                       filtTaxPar = list(highestFreq=80),
                       zeroMethod = "multRepl",
                       normMethod = "clr",
                       sparsMethod = "threshold",
                       cores = parallel::detectCores()/2,
                       thresh = 0.6,
                       verbose = 3,
                       seed = 123456)

netAnaITS = netAnalyze(netITS.spie,
                       centrLCC = TRUE,
                       hubPar = c("degree", "between", "closeness", "eigenvector"),
                       clustMethod = "cluster_fast_greedy",
                       lnormFit = T,
                       normDeg = T,
                       normBetw = T,
                       normClose = T,
                       normEigen = T)

netCompareITS = netCompare(netAnaITS, 
                        permTest = T,
                        storeAssoPerm = T,
                        fileStoreAssoPerm = "./Field_analysis_ver2/network/FUN_assoPerm_nperm1000",
                        nPerm = 1000,
                        cores = 2, 
                        seed = 123)
stefpeschel commented 2 years ago

Hey Xiao,

Can't see what causes these errors at the moment and can't reproduce them with my data. Could you please send me a reproducible example with either your data (can be anonymized, or only a subset) or any public data via email? Then I will have a closer look into the issue.

Thanks a lot, Stefanie

lixiaopi1985 commented 2 years ago

@stefpeschel I just sent you an email with the data. Let me know if you need more files. Thank you!

dsiegieda commented 2 years ago

@stefpeschel, I have the same problem with my data. I'm calculating my permutations for all samples (ITS data) - it is ok, but when I subset the samples by sample type (bulk soil, rhizosphere, shoots and roots), I have this error only for bulk soil and rhizosphere (but only when I set the permuation number for 1000, when I was only running sample code with 3 permutations, everyting was fine). Here is the code: `ps.rhizo<-subset_samples(ps, Type == "rhizosphere") permutations <- 1000

flist <- filterfun(kOverA(5, 2e-05)) ent.logi <- filter_taxa(ps.rhizo, flist) ent.trim <- filter_taxa(ps.rhizo, flist, TRUE) identical(ent.trim, prune_taxa(ent.logi, ps.rhizo)) identical(sum(ent.logi), ntaxa(ent.trim)) ps.rhizo <- filter_taxa(ps.rhizo, flist, TRUE)

agglomerated <- tax_glom(ps.rhizo,"Species") agglomerated_healthy = subset_samples(agglomerated, health == "healthy") agglomerated_unhealthy = subset_samples(agglomerated, health == "unhealthy")

net <- netConstruct(data = agglomerated_healthy, data2 = agglomerated_unhealthy,
filtTax = "highestVar", filtTaxPar = list(highestVar = 50), measure = "spring", measurePar = list(nlambda=100,rep.num=10), normMethod = "none", zeroMethod = "none", sparsMethod = "none", dissFunc = "signed", verbose = 3, seed = 420)

analyzed <- netAnalyze(net, centrLCC = TRUE, avDissIgnoreInf = TRUE, sPathNorm = FALSE, clustMethod = "cluster_fast_greedy", hubPar = c("degree", "between", "closeness"), hubQuant = 0.9, lnormFit = TRUE, normDeg = FALSE, normBetw = FALSE, normClose = FALSE, normEigen = FALSE, weightDeg = FALSE)

compared <- netCompare(analyzed, permTest = TRUE, nPerm = permutations, storeAssoPerm = TRUE, fileStoreAssoPerm ="Asso_perm_comp", storeCountsPerm = FALSE, seed = 420) `

All the best, Dominika

stefpeschel commented 2 years ago

Thanks @lixiaopi1985 for sending me your data. I just uploaded a new version (only at 'develop' branch for now) that should fix this error. Could you please install the latest version from develop branch (version 1.0.2.9000) and let me know whether still any errors occur?

The 'develop' branch version can be installed via:

devtools::install_github("stefpeschel/NetCoMi", ref = "develop")
lixiaopi1985 commented 2 years ago

@stefpeschel Thank you so much for fixing this error! I did not have any problems this time on the 16S data after updating the package. I am running it on the ITS data as it showed different error messages last time, I will share the result soon.

stefpeschel commented 2 years ago

Great! Please let me know if you're still running into errors for the ITS data.

Last time, the ITS error occured when computing the group differences for the centralities. I also adapted this approach, so I hope it runs without any problems now.

lixiaopi1985 commented 2 years ago

@stefpeschel No issue running the ITS data this time, hooray!!!

Thank you so much!