miga-base 1.2.17.0 → 1.2.17.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/miga/version.rb +2 -2
- data/utils/FastAAI/00.Libraries/01.SCG_HMMs/Archaea_SCG.hmm +41964 -0
- data/utils/FastAAI/00.Libraries/01.SCG_HMMs/Bacteria_SCG.hmm +32439 -0
- data/utils/FastAAI/00.Libraries/01.SCG_HMMs/Complete_SCG_DB.hmm +62056 -0
- data/utils/FastAAI/FastAAI +3659 -0
- data/utils/FastAAI/FastAAI-legacy/FastAAI +1336 -0
- data/utils/FastAAI/FastAAI-legacy/kAAI_v1.0_virus.py +1296 -0
- data/utils/FastAAI/README.md +84 -0
- data/utils/enveomics/Docs/recplot2.md +244 -0
- data/utils/enveomics/Examples/aai-matrix.bash +66 -0
- data/utils/enveomics/Examples/ani-matrix.bash +66 -0
- data/utils/enveomics/Examples/essential-phylogeny.bash +105 -0
- data/utils/enveomics/Examples/unus-genome-phylogeny.bash +100 -0
- data/utils/enveomics/LICENSE.txt +73 -0
- data/utils/enveomics/Makefile +52 -0
- data/utils/enveomics/Manifest/Tasks/aasubs.json +103 -0
- data/utils/enveomics/Manifest/Tasks/blasttab.json +790 -0
- data/utils/enveomics/Manifest/Tasks/distances.json +161 -0
- data/utils/enveomics/Manifest/Tasks/fasta.json +802 -0
- data/utils/enveomics/Manifest/Tasks/fastq.json +291 -0
- data/utils/enveomics/Manifest/Tasks/graphics.json +126 -0
- data/utils/enveomics/Manifest/Tasks/mapping.json +165 -0
- data/utils/enveomics/Manifest/Tasks/ogs.json +382 -0
- data/utils/enveomics/Manifest/Tasks/other.json +906 -0
- data/utils/enveomics/Manifest/Tasks/remote.json +356 -0
- data/utils/enveomics/Manifest/Tasks/sequence-identity.json +650 -0
- data/utils/enveomics/Manifest/Tasks/tables.json +308 -0
- data/utils/enveomics/Manifest/Tasks/trees.json +68 -0
- data/utils/enveomics/Manifest/Tasks/variants.json +111 -0
- data/utils/enveomics/Manifest/categories.json +165 -0
- data/utils/enveomics/Manifest/examples.json +162 -0
- data/utils/enveomics/Manifest/tasks.json +4 -0
- data/utils/enveomics/README.md +42 -0
- data/utils/enveomics/Scripts/AAsubs.log2ratio.rb +171 -0
- data/utils/enveomics/Scripts/Aln.cat.rb +221 -0
- data/utils/enveomics/Scripts/Aln.convert.pl +35 -0
- data/utils/enveomics/Scripts/AlphaDiversity.pl +152 -0
- data/utils/enveomics/Scripts/BedGraph.tad.rb +138 -0
- data/utils/enveomics/Scripts/BedGraph.window.rb +71 -0
- data/utils/enveomics/Scripts/BlastPairwise.AAsubs.pl +102 -0
- data/utils/enveomics/Scripts/BlastTab.addlen.rb +63 -0
- data/utils/enveomics/Scripts/BlastTab.advance.bash +48 -0
- data/utils/enveomics/Scripts/BlastTab.best_hit_sorted.pl +55 -0
- data/utils/enveomics/Scripts/BlastTab.catsbj.pl +104 -0
- data/utils/enveomics/Scripts/BlastTab.cogCat.rb +76 -0
- data/utils/enveomics/Scripts/BlastTab.filter.pl +47 -0
- data/utils/enveomics/Scripts/BlastTab.kegg_pep2path_rest.pl +194 -0
- data/utils/enveomics/Scripts/BlastTab.metaxaPrep.pl +104 -0
- data/utils/enveomics/Scripts/BlastTab.pairedHits.rb +157 -0
- data/utils/enveomics/Scripts/BlastTab.recplot2.R +48 -0
- data/utils/enveomics/Scripts/BlastTab.seqdepth.pl +86 -0
- data/utils/enveomics/Scripts/BlastTab.seqdepth_ZIP.pl +119 -0
- data/utils/enveomics/Scripts/BlastTab.seqdepth_nomedian.pl +86 -0
- data/utils/enveomics/Scripts/BlastTab.subsample.pl +47 -0
- data/utils/enveomics/Scripts/BlastTab.sumPerHit.pl +114 -0
- data/utils/enveomics/Scripts/BlastTab.taxid2taxrank.pl +90 -0
- data/utils/enveomics/Scripts/BlastTab.topHits_sorted.rb +123 -0
- data/utils/enveomics/Scripts/Chao1.pl +97 -0
- data/utils/enveomics/Scripts/CharTable.classify.rb +234 -0
- data/utils/enveomics/Scripts/EBIseq2tax.rb +83 -0
- data/utils/enveomics/Scripts/FastA.N50.pl +60 -0
- data/utils/enveomics/Scripts/FastA.extract.rb +152 -0
- data/utils/enveomics/Scripts/FastA.filter.pl +52 -0
- data/utils/enveomics/Scripts/FastA.filterLen.pl +28 -0
- data/utils/enveomics/Scripts/FastA.filterN.pl +60 -0
- data/utils/enveomics/Scripts/FastA.fragment.rb +100 -0
- data/utils/enveomics/Scripts/FastA.gc.pl +42 -0
- data/utils/enveomics/Scripts/FastA.interpose.pl +93 -0
- data/utils/enveomics/Scripts/FastA.length.pl +38 -0
- data/utils/enveomics/Scripts/FastA.mask.rb +89 -0
- data/utils/enveomics/Scripts/FastA.per_file.pl +36 -0
- data/utils/enveomics/Scripts/FastA.qlen.pl +57 -0
- data/utils/enveomics/Scripts/FastA.rename.pl +65 -0
- data/utils/enveomics/Scripts/FastA.revcom.pl +23 -0
- data/utils/enveomics/Scripts/FastA.sample.rb +98 -0
- data/utils/enveomics/Scripts/FastA.slider.pl +85 -0
- data/utils/enveomics/Scripts/FastA.split.pl +55 -0
- data/utils/enveomics/Scripts/FastA.split.rb +79 -0
- data/utils/enveomics/Scripts/FastA.subsample.pl +131 -0
- data/utils/enveomics/Scripts/FastA.tag.rb +65 -0
- data/utils/enveomics/Scripts/FastA.toFastQ.rb +69 -0
- data/utils/enveomics/Scripts/FastA.wrap.rb +48 -0
- data/utils/enveomics/Scripts/FastQ.filter.pl +54 -0
- data/utils/enveomics/Scripts/FastQ.interpose.pl +90 -0
- data/utils/enveomics/Scripts/FastQ.maskQual.rb +89 -0
- data/utils/enveomics/Scripts/FastQ.offset.pl +90 -0
- data/utils/enveomics/Scripts/FastQ.split.pl +53 -0
- data/utils/enveomics/Scripts/FastQ.tag.rb +70 -0
- data/utils/enveomics/Scripts/FastQ.test-error.rb +81 -0
- data/utils/enveomics/Scripts/FastQ.toFastA.awk +24 -0
- data/utils/enveomics/Scripts/GFF.catsbj.pl +127 -0
- data/utils/enveomics/Scripts/GenBank.add_fields.rb +84 -0
- data/utils/enveomics/Scripts/HMM.essential.rb +351 -0
- data/utils/enveomics/Scripts/HMM.haai.rb +168 -0
- data/utils/enveomics/Scripts/HMMsearch.extractIds.rb +83 -0
- data/utils/enveomics/Scripts/JPlace.distances.rb +88 -0
- data/utils/enveomics/Scripts/JPlace.to_iToL.rb +320 -0
- data/utils/enveomics/Scripts/M5nr.getSequences.rb +81 -0
- data/utils/enveomics/Scripts/MeTaxa.distribution.pl +198 -0
- data/utils/enveomics/Scripts/MyTaxa.fragsByTax.pl +35 -0
- data/utils/enveomics/Scripts/MyTaxa.seq-taxrank.rb +49 -0
- data/utils/enveomics/Scripts/NCBIacc2tax.rb +92 -0
- data/utils/enveomics/Scripts/Newick.autoprune.R +27 -0
- data/utils/enveomics/Scripts/RAxML-EPA.to_iToL.pl +228 -0
- data/utils/enveomics/Scripts/RecPlot2.compareIdentities.R +32 -0
- data/utils/enveomics/Scripts/RefSeq.download.bash +48 -0
- data/utils/enveomics/Scripts/SRA.download.bash +67 -0
- data/utils/enveomics/Scripts/TRIBS.plot-test.R +36 -0
- data/utils/enveomics/Scripts/TRIBS.test.R +39 -0
- data/utils/enveomics/Scripts/Table.barplot.R +31 -0
- data/utils/enveomics/Scripts/Table.df2dist.R +30 -0
- data/utils/enveomics/Scripts/Table.filter.pl +61 -0
- data/utils/enveomics/Scripts/Table.merge.pl +77 -0
- data/utils/enveomics/Scripts/Table.prefScore.R +60 -0
- data/utils/enveomics/Scripts/Table.replace.rb +69 -0
- data/utils/enveomics/Scripts/Table.round.rb +63 -0
- data/utils/enveomics/Scripts/Table.split.pl +57 -0
- data/utils/enveomics/Scripts/Taxonomy.silva2ncbi.rb +227 -0
- data/utils/enveomics/Scripts/VCF.KaKs.rb +147 -0
- data/utils/enveomics/Scripts/VCF.SNPs.rb +88 -0
- data/utils/enveomics/Scripts/aai.rb +421 -0
- data/utils/enveomics/Scripts/ani.rb +362 -0
- data/utils/enveomics/Scripts/anir.rb +137 -0
- data/utils/enveomics/Scripts/clust.rand.rb +102 -0
- data/utils/enveomics/Scripts/gi2tax.rb +103 -0
- data/utils/enveomics/Scripts/in_silico_GA_GI.pl +96 -0
- data/utils/enveomics/Scripts/lib/data/dupont_2012_essential.hmm.gz +0 -0
- data/utils/enveomics/Scripts/lib/data/lee_2019_essential.hmm.gz +0 -0
- data/utils/enveomics/Scripts/lib/enveomics.R +1 -0
- data/utils/enveomics/Scripts/lib/enveomics_rb/anir.rb +293 -0
- data/utils/enveomics/Scripts/lib/enveomics_rb/bm_set.rb +175 -0
- data/utils/enveomics/Scripts/lib/enveomics_rb/enveomics.rb +24 -0
- data/utils/enveomics/Scripts/lib/enveomics_rb/errors.rb +17 -0
- data/utils/enveomics/Scripts/lib/enveomics_rb/gmm_em.rb +30 -0
- data/utils/enveomics/Scripts/lib/enveomics_rb/jplace.rb +253 -0
- data/utils/enveomics/Scripts/lib/enveomics_rb/match.rb +88 -0
- data/utils/enveomics/Scripts/lib/enveomics_rb/og.rb +182 -0
- data/utils/enveomics/Scripts/lib/enveomics_rb/rbm.rb +49 -0
- data/utils/enveomics/Scripts/lib/enveomics_rb/remote_data.rb +74 -0
- data/utils/enveomics/Scripts/lib/enveomics_rb/seq_range.rb +237 -0
- data/utils/enveomics/Scripts/lib/enveomics_rb/stats/rand.rb +31 -0
- data/utils/enveomics/Scripts/lib/enveomics_rb/stats/sample.rb +152 -0
- data/utils/enveomics/Scripts/lib/enveomics_rb/stats.rb +3 -0
- data/utils/enveomics/Scripts/lib/enveomics_rb/utils.rb +74 -0
- data/utils/enveomics/Scripts/lib/enveomics_rb/vcf.rb +135 -0
- data/utils/enveomics/Scripts/ogs.annotate.rb +88 -0
- data/utils/enveomics/Scripts/ogs.core-pan.rb +160 -0
- data/utils/enveomics/Scripts/ogs.extract.rb +125 -0
- data/utils/enveomics/Scripts/ogs.mcl.rb +186 -0
- data/utils/enveomics/Scripts/ogs.rb +104 -0
- data/utils/enveomics/Scripts/ogs.stats.rb +131 -0
- data/utils/enveomics/Scripts/rbm-legacy.rb +172 -0
- data/utils/enveomics/Scripts/rbm.rb +108 -0
- data/utils/enveomics/Scripts/sam.filter.rb +148 -0
- data/utils/enveomics/Tests/Makefile +10 -0
- data/utils/enveomics/Tests/Mgen_M2288.faa +3189 -0
- data/utils/enveomics/Tests/Mgen_M2288.fna +8282 -0
- data/utils/enveomics/Tests/Mgen_M2321.fna +8288 -0
- data/utils/enveomics/Tests/Nequ_Kin4M.faa +2970 -0
- data/utils/enveomics/Tests/Xanthomonas_oryzae-PilA.tribs.Rdata +0 -0
- data/utils/enveomics/Tests/Xanthomonas_oryzae-PilA.txt +7 -0
- data/utils/enveomics/Tests/Xanthomonas_oryzae.aai-mat.tsv +17 -0
- data/utils/enveomics/Tests/Xanthomonas_oryzae.aai.tsv +137 -0
- data/utils/enveomics/Tests/a_mg.cds-go.blast.tsv +123 -0
- data/utils/enveomics/Tests/a_mg.reads-cds.blast.tsv +200 -0
- data/utils/enveomics/Tests/a_mg.reads-cds.counts.tsv +55 -0
- data/utils/enveomics/Tests/alkB.nwk +1 -0
- data/utils/enveomics/Tests/anthrax-cansnp-data.tsv +13 -0
- data/utils/enveomics/Tests/anthrax-cansnp-key.tsv +17 -0
- data/utils/enveomics/Tests/hiv1.faa +59 -0
- data/utils/enveomics/Tests/hiv1.fna +134 -0
- data/utils/enveomics/Tests/hiv2.faa +70 -0
- data/utils/enveomics/Tests/hiv_mix-hiv1.blast.tsv +233 -0
- data/utils/enveomics/Tests/hiv_mix-hiv1.blast.tsv.lim +1 -0
- data/utils/enveomics/Tests/hiv_mix-hiv1.blast.tsv.rec +233 -0
- data/utils/enveomics/Tests/low-cov.bg.gz +0 -0
- data/utils/enveomics/Tests/phyla_counts.tsv +10 -0
- data/utils/enveomics/Tests/primate_lentivirus.ogs +11 -0
- data/utils/enveomics/Tests/primate_lentivirus.rbm/hiv1-hiv1.rbm +9 -0
- data/utils/enveomics/Tests/primate_lentivirus.rbm/hiv1-hiv2.rbm +8 -0
- data/utils/enveomics/Tests/primate_lentivirus.rbm/hiv1-siv.rbm +6 -0
- data/utils/enveomics/Tests/primate_lentivirus.rbm/hiv2-hiv2.rbm +9 -0
- data/utils/enveomics/Tests/primate_lentivirus.rbm/hiv2-siv.rbm +6 -0
- data/utils/enveomics/Tests/primate_lentivirus.rbm/siv-siv.rbm +6 -0
- data/utils/enveomics/build_enveomics_r.bash +45 -0
- data/utils/enveomics/enveomics.R/DESCRIPTION +31 -0
- data/utils/enveomics/enveomics.R/NAMESPACE +39 -0
- data/utils/enveomics/enveomics.R/R/autoprune.R +167 -0
- data/utils/enveomics/enveomics.R/R/barplot.R +203 -0
- data/utils/enveomics/enveomics.R/R/cliopts.R +141 -0
- data/utils/enveomics/enveomics.R/R/df2dist.R +192 -0
- data/utils/enveomics/enveomics.R/R/growthcurve.R +349 -0
- data/utils/enveomics/enveomics.R/R/prefscore.R +79 -0
- data/utils/enveomics/enveomics.R/R/recplot.R +419 -0
- data/utils/enveomics/enveomics.R/R/recplot2.R +1698 -0
- data/utils/enveomics/enveomics.R/R/tribs.R +638 -0
- data/utils/enveomics/enveomics.R/R/utils.R +90 -0
- data/utils/enveomics/enveomics.R/README.md +81 -0
- data/utils/enveomics/enveomics.R/data/growth.curves.rda +0 -0
- data/utils/enveomics/enveomics.R/data/phyla.counts.rda +0 -0
- data/utils/enveomics/enveomics.R/man/cash-enve.GrowthCurve-method.Rd +16 -0
- data/utils/enveomics/enveomics.R/man/cash-enve.RecPlot2-method.Rd +16 -0
- data/utils/enveomics/enveomics.R/man/cash-enve.RecPlot2.Peak-method.Rd +16 -0
- data/utils/enveomics/enveomics.R/man/enve.GrowthCurve-class.Rd +25 -0
- data/utils/enveomics/enveomics.R/man/enve.TRIBS-class.Rd +47 -0
- data/utils/enveomics/enveomics.R/man/enve.TRIBS.merge.Rd +23 -0
- data/utils/enveomics/enveomics.R/man/enve.TRIBStest-class.Rd +47 -0
- data/utils/enveomics/enveomics.R/man/enve.__prune.iter.Rd +26 -0
- data/utils/enveomics/enveomics.R/man/enve.__prune.reduce.Rd +26 -0
- data/utils/enveomics/enveomics.R/man/enve.__tribs.Rd +44 -0
- data/utils/enveomics/enveomics.R/man/enve.barplot.Rd +111 -0
- data/utils/enveomics/enveomics.R/man/enve.cliopts.Rd +67 -0
- data/utils/enveomics/enveomics.R/man/enve.col.alpha.Rd +34 -0
- data/utils/enveomics/enveomics.R/man/enve.col2alpha.Rd +25 -0
- data/utils/enveomics/enveomics.R/man/enve.df2dist.Rd +59 -0
- data/utils/enveomics/enveomics.R/man/enve.df2dist.group.Rd +63 -0
- data/utils/enveomics/enveomics.R/man/enve.df2dist.list.Rd +46 -0
- data/utils/enveomics/enveomics.R/man/enve.growthcurve.Rd +78 -0
- data/utils/enveomics/enveomics.R/man/enve.prefscore.Rd +50 -0
- data/utils/enveomics/enveomics.R/man/enve.prune.dist.Rd +44 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot.Rd +147 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2-class.Rd +45 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.ANIr.Rd +27 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.Rd +77 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.__counts.Rd +28 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.__peakHist.Rd +24 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.__whichClosestPeak.Rd +22 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.changeCutoff.Rd +22 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.compareIdentities.Rd +52 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.coordinates.Rd +29 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.corePeak.Rd +21 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.extractWindows.Rd +45 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.Rd +34 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.__em_e.Rd +23 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.__em_m.Rd +24 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.__emauto_one.Rd +31 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.__mow_one.Rd +56 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.__mower.Rd +20 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.em.Rd +51 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.emauto.Rd +43 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.mower.Rd +82 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.peak-class.Rd +59 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.seqdepth.Rd +27 -0
- data/utils/enveomics/enveomics.R/man/enve.recplot2.windowDepthThreshold.Rd +36 -0
- data/utils/enveomics/enveomics.R/man/enve.selvector.Rd +23 -0
- data/utils/enveomics/enveomics.R/man/enve.tribs.Rd +68 -0
- data/utils/enveomics/enveomics.R/man/enve.tribs.test.Rd +28 -0
- data/utils/enveomics/enveomics.R/man/enve.truncate.Rd +27 -0
- data/utils/enveomics/enveomics.R/man/growth.curves.Rd +14 -0
- data/utils/enveomics/enveomics.R/man/phyla.counts.Rd +13 -0
- data/utils/enveomics/enveomics.R/man/plot.enve.GrowthCurve.Rd +81 -0
- data/utils/enveomics/enveomics.R/man/plot.enve.TRIBS.Rd +49 -0
- data/utils/enveomics/enveomics.R/man/plot.enve.TRIBStest.Rd +48 -0
- data/utils/enveomics/enveomics.R/man/plot.enve.recplot2.Rd +125 -0
- data/utils/enveomics/enveomics.R/man/summary.enve.GrowthCurve.Rd +22 -0
- data/utils/enveomics/enveomics.R/man/summary.enve.TRIBS.Rd +22 -0
- data/utils/enveomics/enveomics.R/man/summary.enve.TRIBStest.Rd +22 -0
- data/utils/enveomics/globals.mk +8 -0
- data/utils/enveomics/manifest.json +9 -0
- data/utils/multitrim/Multitrim How-To.pdf +0 -0
- data/utils/multitrim/README.md +67 -0
- data/utils/multitrim/multitrim.py +1555 -0
- data/utils/multitrim/multitrim.yml +13 -0
- metadata +268 -6
@@ -0,0 +1,638 @@
|
|
1
|
+
|
2
|
+
# Use as:
|
3
|
+
# > # Estimate reference (null) model:
|
4
|
+
# > tab <- read.table('Ecoli-ML-dmatrix.txt', sep='\t', h=T, row.names=1)
|
5
|
+
# > dist <- as.dist(tab);
|
6
|
+
# > all.dist <- enve.tribs(dist);
|
7
|
+
# >
|
8
|
+
# > # Estimate subset (test) model:
|
9
|
+
# > lee <- read.table('LEE-strains.txt', as.is=T)$V1
|
10
|
+
# > lee.dist <- enve.tribs(dist, lee, subsamples=seq(0,1,by=0.05), threads=12,
|
11
|
+
# + verbosity=2, pre.tribs=all.dist.merge);
|
12
|
+
# ...
|
13
|
+
# >
|
14
|
+
# > # Plot reference and selection at different subsampling levels:
|
15
|
+
# > plot(all.dist, t='boxplot');
|
16
|
+
# > plot(lee, new=FALSE, col='darkred');
|
17
|
+
# ...
|
18
|
+
# >
|
19
|
+
# > # Test significance of overclustering (or overdispersion):
|
20
|
+
# > lee.test <- enve.tribs.test(dist, lee, pre.tribs=all.dist.merge,
|
21
|
+
# + verbosity=2, threads=12);
|
22
|
+
# > summary(lee.test);
|
23
|
+
# > plot(lee.test);
|
24
|
+
# ...
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
#==============> Define S4 classes
|
29
|
+
|
30
|
+
#' Enveomics: TRIBS S4 Class
|
31
|
+
#'
|
32
|
+
#' Enve-omics representation of "Transformed-space Resampling In Biased Sets
|
33
|
+
#' (TRIBS)". This object represents sets of distances between objects,
|
34
|
+
#' sampled nearly-uniformly at random in "distance space". Subsampling
|
35
|
+
#' without selection is trivial, since both the distances space and the
|
36
|
+
#' selection occur in the same transformed space. However, it's useful to
|
37
|
+
#' compare randomly subsampled sets against a selected set of objects. This
|
38
|
+
#' is intended to identify overdispersion or overclustering (see
|
39
|
+
#' \code{\link{enve.TRIBStest}}) of a subset against the entire collection of
|
40
|
+
#' objects with minimum impact of sampling biases. This object can be produced
|
41
|
+
#' by \code{\link{enve.tribs}} and supports S4 methods \code{plot} and
|
42
|
+
#' \code{summary}.
|
43
|
+
#'
|
44
|
+
#' @slot distance \code{(numeric)} Centrality measurement of the distances
|
45
|
+
#' between the selected objects (without subsampling).
|
46
|
+
#' @slot points \code{(matrix)} Position of the different objects in distance
|
47
|
+
#' space.
|
48
|
+
#' @slot distances \code{(matrix)} Subsampled distances, where the rows are
|
49
|
+
#' replicates and the columns are subsampling levels.
|
50
|
+
#' @slot spaceSize \code{(numeric)} Number of objects.
|
51
|
+
#' @slot selSize \code{(numeric)} Number of selected objects.
|
52
|
+
#' @slot dimensions \code{(numeric)} Number of dimensions in the distance space.
|
53
|
+
#' @slot subsamples \code{(numeric)} Subsampling levels (as fractions, from
|
54
|
+
#' 0 to 1).
|
55
|
+
#' @slot call \code{(call)} Call producing this object.
|
56
|
+
#'
|
57
|
+
#' @author Luis M. Rodriguez-R [aut, cre]
|
58
|
+
#'
|
59
|
+
#' @exportClass
|
60
|
+
|
61
|
+
enve.TRIBS <- setClass("enve.TRIBS",
|
62
|
+
representation(
|
63
|
+
distance='numeric',
|
64
|
+
points='matrix',
|
65
|
+
distances='matrix',
|
66
|
+
spaceSize='numeric',
|
67
|
+
selSize='numeric',
|
68
|
+
dimensions='numeric',
|
69
|
+
subsamples='numeric',
|
70
|
+
call='call')
|
71
|
+
,package='enveomics.R'
|
72
|
+
);
|
73
|
+
|
74
|
+
#' Enveomics: TRIBS Test S4 Class
|
75
|
+
#'
|
76
|
+
#' Test of significance of overclustering or overdispersion in a selected
|
77
|
+
#' set of objects with respect to the entire set (see \code{\link{enve.TRIBS}}).
|
78
|
+
#' This object can be produced by \code{\link{enve.tribs.test}} and supports S4
|
79
|
+
#' methods \code{plot} and \code{summary}.
|
80
|
+
#'
|
81
|
+
#' @slot pval.gt \code{(numeric)}
|
82
|
+
#' P-value for the overdispersion test.
|
83
|
+
#' @slot pval.lt \code{(numeric)}
|
84
|
+
#' P-value for the overclustering test.
|
85
|
+
#' @slot all.dist \code{(numeric)}
|
86
|
+
#' Empiric PDF of distances for the entire dataset (subsampled at selection
|
87
|
+
#' size).
|
88
|
+
#' @slot sel.dist \code{(numeric)}
|
89
|
+
#' Empiric PDF of distances for the selected objects (without subsampling).
|
90
|
+
#' @slot diff.dist \code{(numeric)}
|
91
|
+
#' Empiric PDF of the difference between \code{all.dist} and \code{sel.dist}.
|
92
|
+
#' The p-values are estimating by comparing areas in this PDF greater than and
|
93
|
+
#' lesser than zero.
|
94
|
+
#' @slot dist.mids \code{(numeric)}
|
95
|
+
#' Midpoints of the empiric PDFs of distances.
|
96
|
+
#' @slot diff.mids \code{(numeric)}
|
97
|
+
#' Midpoints of the empiric PDF of difference of distances.
|
98
|
+
#' @slot call \code{(call)}
|
99
|
+
#' Call producing this object.
|
100
|
+
#'
|
101
|
+
#' @author Luis M. Rodriguez-R [aut, cre]
|
102
|
+
#'
|
103
|
+
#' @exportClass
|
104
|
+
|
105
|
+
enve.TRIBStest <- setClass(
|
106
|
+
"enve.TRIBStest",
|
107
|
+
representation(
|
108
|
+
pval.gt = "numeric",
|
109
|
+
pval.lt = "numeric",
|
110
|
+
all.dist = "numeric",
|
111
|
+
sel.dist = "numeric",
|
112
|
+
diff.dist = "numeric",
|
113
|
+
dist.mids = "numeric",
|
114
|
+
diff.mids = "numeric",
|
115
|
+
call = "call"
|
116
|
+
), package = "enveomics.R"
|
117
|
+
)
|
118
|
+
|
119
|
+
#==============> Define S4 methods
|
120
|
+
|
121
|
+
#' Enveomics: TRIBS Summary
|
122
|
+
#'
|
123
|
+
#' Summary of an \code{\link{enve.TRIBS}} object.
|
124
|
+
#'
|
125
|
+
#' @param object
|
126
|
+
#' \code{\link{enve.TRIBS}} object.
|
127
|
+
#' @param ...
|
128
|
+
#' No additional parameters are currently supported.
|
129
|
+
#'
|
130
|
+
#' @return No return value.
|
131
|
+
#'
|
132
|
+
#' @author Luis M. Rodriguez-R [aut, cre]
|
133
|
+
#'
|
134
|
+
#' @method summary enve.TRIBS
|
135
|
+
#' @export
|
136
|
+
summary.enve.TRIBS <- function(object, ...) {
|
137
|
+
cat("===[ enve.TRIBS ]-------------------------\n")
|
138
|
+
cat("Selected", attr(object, "selSize"), "of",
|
139
|
+
attr(object, "spaceSize"), "objects in",
|
140
|
+
attr(object, "dimensions"), "dimensions.\n")
|
141
|
+
cat("Collected", length(attr(object, "subsamples")), "subsamples with",
|
142
|
+
nrow(attr(object, "distances")), "replicates each.\n")
|
143
|
+
cat("------------------------------------------\n")
|
144
|
+
cat("call:", as.character(attr(object, "call")), "\n")
|
145
|
+
cat("------------------------------------------\n")
|
146
|
+
}
|
147
|
+
|
148
|
+
#' Enveomics: TRIBS Plot
|
149
|
+
#'
|
150
|
+
#' Plot an \code{\link{enve.TRIBS}} object.
|
151
|
+
#'
|
152
|
+
#' @param x
|
153
|
+
#' \code{\link{enve.TRIBS}} object to plot.
|
154
|
+
#' @param new
|
155
|
+
#' Should a new canvas be drawn?
|
156
|
+
#' @param type
|
157
|
+
#' Type of plot. The \strong{points} plot shows all the replicates, the
|
158
|
+
#' \strong{boxplot} plot represents the values found by
|
159
|
+
#' \code{\link[grDevices]{boxplot.stats}}.
|
160
|
+
#' as areas, and plots the outliers as points.
|
161
|
+
#' @param col
|
162
|
+
#' Color of the areas and/or the points.
|
163
|
+
#' @param pt.cex
|
164
|
+
#' Size of the points.
|
165
|
+
#' @param pt.pch
|
166
|
+
#' Points character.
|
167
|
+
#' @param pt.col
|
168
|
+
#' Color of the points.
|
169
|
+
#' @param ln.col
|
170
|
+
#' Color of the lines.
|
171
|
+
#' @param ...
|
172
|
+
#' Any additional parameters supported by \code{plot}.
|
173
|
+
#'
|
174
|
+
#' @return No return value.
|
175
|
+
#'
|
176
|
+
#' @author Luis M. Rodriguez-R [aut, cre]
|
177
|
+
#'
|
178
|
+
#' @method plot enve.TRIBS
|
179
|
+
#' @export
|
180
|
+
|
181
|
+
plot.enve.TRIBS <- function(
|
182
|
+
x,
|
183
|
+
new = TRUE,
|
184
|
+
type = c("boxplot", "points"),
|
185
|
+
col = "#00000044",
|
186
|
+
pt.cex = 1/2,
|
187
|
+
pt.pch = 19,
|
188
|
+
pt.col = col,
|
189
|
+
ln.col = col,
|
190
|
+
...
|
191
|
+
) {
|
192
|
+
type <- match.arg(type)
|
193
|
+
plot.opts <- list(
|
194
|
+
xlim = range(attr(x, "subsamples")) * attr(x, "selSize"),
|
195
|
+
ylim = range(attr(x, "distances")), ..., t = "n", x = 1
|
196
|
+
)
|
197
|
+
if (new) do.call(plot, plot.opts)
|
198
|
+
abline(h = attr(x, "distance"), lty = 3, col = ln.col)
|
199
|
+
replicates <- nrow(attr(x, "distances"))
|
200
|
+
if (type == "points") {
|
201
|
+
for (i in 1:ncol(attr(x, "distances")))
|
202
|
+
points(
|
203
|
+
rep(round(attr(x, "subsamples")[i] * attr(x, "selSize")), replicates),
|
204
|
+
attr(x, "distances")[, i],
|
205
|
+
cex = pt.cex, pch = pt.pch, col = pt.col
|
206
|
+
)
|
207
|
+
} else {
|
208
|
+
stats <- matrix(NA, nrow = 7, ncol = ncol(attr(x, "distances")))
|
209
|
+
for (i in 1:ncol(attr(x, "distances"))) {
|
210
|
+
b <- boxplot.stats(attr(x, "distances")[, i])
|
211
|
+
points(
|
212
|
+
rep(
|
213
|
+
round(attr(x, "subsamples")[i] * attr(x, "selSize")), length(b$out)
|
214
|
+
),
|
215
|
+
b$out, cex = pt.cex, pch = pt.pch, col = pt.col
|
216
|
+
)
|
217
|
+
stats[, i] <- c(b$conf, b$stats[c(1, 5, 2, 4, 3)])
|
218
|
+
}
|
219
|
+
x <- round(attr(x, "subsamples") * attr(x, "selSize"))
|
220
|
+
for (i in c(1, 3, 5))
|
221
|
+
polygon(
|
222
|
+
c(x, rev(x)), c(stats[i, ], rev(stats[i + 1, ])), border = NA, col = col
|
223
|
+
)
|
224
|
+
lines(x, stats[7, ], col = ln.col, lwd = 2)
|
225
|
+
}
|
226
|
+
}
|
227
|
+
|
228
|
+
#' Enveomics: TRIBS Summary Test
|
229
|
+
#'
|
230
|
+
#' Summary of an \code{\link{enve.TRIBStest}} object.
|
231
|
+
#'
|
232
|
+
#' @param object
|
233
|
+
#' \code{\link{enve.TRIBStest}} object.
|
234
|
+
#' @param ...
|
235
|
+
#' No additional parameters are currently supported.
|
236
|
+
#'
|
237
|
+
#' @return No return value.
|
238
|
+
#'
|
239
|
+
#' @author Luis M. Rodriguez-R [aut, cre]
|
240
|
+
#'
|
241
|
+
#' @method summary enve.TRIBStest
|
242
|
+
#' @export
|
243
|
+
|
244
|
+
summary.enve.TRIBStest <- function(object, ...) {
|
245
|
+
cat("===[ enve.TRIBStest ]---------------------\n")
|
246
|
+
cat("Alternative hypothesis:\n")
|
247
|
+
cat(" The distances in the selection are\n")
|
248
|
+
if (attr(object, "pval.gt") > attr(object, "pval.lt")) {
|
249
|
+
cat(" smaller than in the entire dataset\n (overclustering)\n")
|
250
|
+
} else {
|
251
|
+
cat(" larger than in the entire dataset\n (overdispersion)\n")
|
252
|
+
}
|
253
|
+
p.val <- min(attr(object, "pval.gt"), attr(object, "pval.lt"))
|
254
|
+
if (p.val == 0) {
|
255
|
+
diff.dist <- attr(object, "diff.dist")
|
256
|
+
p.val.lim <- min(diff.dist[diff.dist > 0])
|
257
|
+
cat("\n P-value <= ", signif(p.val.lim, 4), sep = "")
|
258
|
+
} else {
|
259
|
+
p.val.lim <- p.val
|
260
|
+
cat("\n P-value: ", signif(p.val, 4), sep = "")
|
261
|
+
}
|
262
|
+
cat(" ", ifelse(p.val.lim <= 0.01, "**",
|
263
|
+
ifelse(p.val.lim<=0.05, "*", "")), "\n", sep = "")
|
264
|
+
cat("------------------------------------------\n")
|
265
|
+
cat("call:", as.character(attr(object, "call")), "\n")
|
266
|
+
cat("------------------------------------------\n")
|
267
|
+
}
|
268
|
+
|
269
|
+
#' Enveomics: TRIBS Plot Test
|
270
|
+
#'
|
271
|
+
#' Plots an \code{\link{enve.TRIBStest}} object.
|
272
|
+
#'
|
273
|
+
#' @param x
|
274
|
+
#' \code{\link{enve.TRIBStest}} object to plot.
|
275
|
+
#' @param type
|
276
|
+
#' What to plot. \code{overlap} generates a plot of the two contrasting
|
277
|
+
#' empirical PDFs (to compare against each other), \code{difference} produces a
|
278
|
+
#' plot of the differences between the empirical PDFs (to compare against zero).
|
279
|
+
#' @param col
|
280
|
+
#' Main color of the plot if type=\code{difference}.
|
281
|
+
#' @param col1
|
282
|
+
#' First color of the plot if type=\code{overlap}.
|
283
|
+
#' @param col2
|
284
|
+
#' Second color of the plot if type=\code{overlap}.
|
285
|
+
#' @param ylab
|
286
|
+
#' Y-axis label.
|
287
|
+
#' @param xlim
|
288
|
+
#' X-axis limits.
|
289
|
+
#' @param ylim
|
290
|
+
#' Y-axis limits.
|
291
|
+
#' @param ...
|
292
|
+
#' Any other graphical arguments.
|
293
|
+
#'
|
294
|
+
#' @return No return value.
|
295
|
+
#'
|
296
|
+
#' @author Luis M. Rodriguez-R [aut, cre]
|
297
|
+
#'
|
298
|
+
#' @method plot enve.TRIBStest
|
299
|
+
#' @export
|
300
|
+
|
301
|
+
plot.enve.TRIBStest <- function(
|
302
|
+
x,
|
303
|
+
type =c("overlap", "difference"),
|
304
|
+
col = "#00000044",
|
305
|
+
col1 = col,
|
306
|
+
col2 = "#44001144",
|
307
|
+
ylab = "Probability",
|
308
|
+
xlim = range(attr(x, "dist.mids")),
|
309
|
+
ylim = c(0, max(c(attr(x, "all.dist"), attr(x, "sel.dist")))),
|
310
|
+
...
|
311
|
+
) {
|
312
|
+
type <- match.arg(type)
|
313
|
+
if (type == "overlap") {
|
314
|
+
plot.opts <- list(
|
315
|
+
xlim = xlim, ylim = ylim, ylab = ylab, ..., t = "n", x = 1
|
316
|
+
)
|
317
|
+
do.call(plot, plot.opts)
|
318
|
+
bins <- length(attr(x, "dist.mids"))
|
319
|
+
polygon(
|
320
|
+
attr(x, "dist.mids")[c(1, 1:bins, bins)],
|
321
|
+
c(0, attr(x, "all.dist"), 0), col = col1,
|
322
|
+
border = do.call(rgb, as.list(c(col2rgb(col1) / 256, 0.5)))
|
323
|
+
)
|
324
|
+
polygon(
|
325
|
+
attr(x, "dist.mids")[c(1, 1:bins, bins)],
|
326
|
+
c(0, attr(x, "sel.dist"), 0), col = col2,
|
327
|
+
border = do.call(rgb, as.list(c(col2rgb(col2) / 256, 0.5)))
|
328
|
+
)
|
329
|
+
} else {
|
330
|
+
plot.opts <- list(
|
331
|
+
xlim = range(attr(x, "diff.mids")),
|
332
|
+
ylim = c(0,max(attr(x, 'diff.dist'))),
|
333
|
+
ylab = ylab, ..., t = "n", x = 1
|
334
|
+
)
|
335
|
+
do.call(plot, plot.opts)
|
336
|
+
bins <- length(attr(x, "diff.mids"))
|
337
|
+
polygon(
|
338
|
+
attr(x, "diff.mids")[c(1, 1:bins, bins)],
|
339
|
+
c(0, attr(x, "diff.dist"), 0), col = col,
|
340
|
+
border = do.call(rgb, as.list(c(col2rgb(col) / 256, 0.5)))
|
341
|
+
)
|
342
|
+
}
|
343
|
+
}
|
344
|
+
|
345
|
+
#' Enveomics: TRIBS Merge
|
346
|
+
#'
|
347
|
+
#' Merges two \code{\link{enve.TRIBS}} objects generated from the same objects
|
348
|
+
#' at different subsampling levels.
|
349
|
+
#'
|
350
|
+
#' @param x
|
351
|
+
#' First \code{\link{enve.TRIBS}} object.
|
352
|
+
#' @param y
|
353
|
+
#' Second \code{\link{enve.TRIBS}} object.
|
354
|
+
#'
|
355
|
+
#' @return Returns an \code{\link{enve.TRIBS}} object.
|
356
|
+
#'
|
357
|
+
#' @author Luis M. Rodriguez-R [aut, cre]
|
358
|
+
#'
|
359
|
+
#' @export
|
360
|
+
|
361
|
+
enve.TRIBS.merge <- function(x, y) {
|
362
|
+
# Check consistency
|
363
|
+
if (attr(x, "distance") != attr(y, "distance"))
|
364
|
+
stop("Total distances in objects are different.")
|
365
|
+
if (any(attr(x, "points") != attr(y, "points")))
|
366
|
+
stop("Points in objects are different.")
|
367
|
+
if (attr(x, "spaceSize") != attr(y, "spaceSize"))
|
368
|
+
stop("Space size in objects are different.")
|
369
|
+
if (attr(x, "selSize") != attr(y, "selSize"))
|
370
|
+
stop("Selection size in objects are different.")
|
371
|
+
if (attr(x, "dimensions") != attr(y, "dimensions"))
|
372
|
+
stop("Dimensions in objects are different.")
|
373
|
+
if (nrow(attr(x, "distances")) != nrow(attr(y, "distances")))
|
374
|
+
stop("Replicates in objects are different.")
|
375
|
+
|
376
|
+
# Merge
|
377
|
+
a <- attr(x, "subsamples")
|
378
|
+
b <- attr(y, "subsamples")
|
379
|
+
o <- order(c(a, b))
|
380
|
+
o <- o[!duplicated(c(a, b)[o])]
|
381
|
+
d <- cbind(attr(x, "distances"), attr(y, "distances"))[, o]
|
382
|
+
z <- new(
|
383
|
+
"enve.TRIBS",
|
384
|
+
distance = attr(x, "distance"), points = attr(x, "points"),
|
385
|
+
distances = d, spaceSize = attr(x, "spaceSize"),
|
386
|
+
selSize = attr(x, "selSize"), dimensions = attr(x, "dimensions"),
|
387
|
+
subsamples = c(a, b)[o], call = match.call()
|
388
|
+
)
|
389
|
+
return(z)
|
390
|
+
}
|
391
|
+
|
392
|
+
#==============> Define core functions
|
393
|
+
|
394
|
+
#' Enveomics: TRIBS Test
|
395
|
+
#'
|
396
|
+
#' Estimates the empirical difference between all the distances in a set of
|
397
|
+
#' objects and a subset, together with its statistical significance.
|
398
|
+
#'
|
399
|
+
#' @param dist
|
400
|
+
#' Distances as \code{dist} object.
|
401
|
+
#' @param selection
|
402
|
+
#' Selection defining the subset.
|
403
|
+
#' @param bins
|
404
|
+
#' Number of bins to evaluate in the range of distances.
|
405
|
+
#' @param ...
|
406
|
+
#' Any other parameters supported by \code{\link{enve.tribs}},
|
407
|
+
#' except \code{subsamples}.
|
408
|
+
#'
|
409
|
+
#' @return Returns an \code{\link{enve.TRIBStest}} object.
|
410
|
+
#'
|
411
|
+
#' @author Luis M. Rodriguez-R [aut, cre]
|
412
|
+
#'
|
413
|
+
#' @export
|
414
|
+
|
415
|
+
enve.tribs.test <- function(dist, selection, bins = 50, ...) {
|
416
|
+
s.tribs <- enve.tribs(dist, selection, subsamples = c(0,1), ...)
|
417
|
+
a.tribs <- enve.tribs(
|
418
|
+
dist,
|
419
|
+
subsamples = c(0, attr(s.tribs, "selSize") / attr(s.tribs, "spaceSize")),
|
420
|
+
...
|
421
|
+
)
|
422
|
+
s.dist <- attr(s.tribs, "distances")[, 2]
|
423
|
+
a.dist <- attr(a.tribs, "distances")[, 2]
|
424
|
+
range <- range(c(s.dist, a.dist))
|
425
|
+
a.f <- hist(
|
426
|
+
a.dist, breaks = seq(range[1], range[2], length.out = bins), plot = FALSE
|
427
|
+
)
|
428
|
+
s.f <- hist(
|
429
|
+
s.dist, breaks = seq(range[1], range[2], length.out = bins), plot = FALSE
|
430
|
+
)
|
431
|
+
zp.f <- c()
|
432
|
+
zz.f <- 0
|
433
|
+
zn.f <- c()
|
434
|
+
p.x <- a.f$counts / sum(a.f$counts)
|
435
|
+
p.y <- s.f$counts / sum(s.f$counts)
|
436
|
+
for (z in 1:length(a.f$mids)) {
|
437
|
+
zn.f[z] <- 0
|
438
|
+
zz.f <- 0
|
439
|
+
zp.f[z] <- 0
|
440
|
+
for (k in 1:length(a.f$mids)) {
|
441
|
+
if (z < k) {
|
442
|
+
zp.f[z] <- zp.f[z] + p.x[k] * p.y[k-z]
|
443
|
+
zn.f[z] <- zn.f[z] + p.x[k-z] * p.y[k]
|
444
|
+
}
|
445
|
+
zz.f <- zz.f + p.x[k] * p.y[k]
|
446
|
+
}
|
447
|
+
}
|
448
|
+
return(
|
449
|
+
new(
|
450
|
+
"enve.TRIBStest",
|
451
|
+
pval.gt = sum(c(zz.f, zp.f)), pval.lt = sum(c(zz.f, zn.f)),
|
452
|
+
all.dist = p.x, sel.dist = p.y, diff.dist = c(rev(zn.f), zz.f, zp.f),
|
453
|
+
dist.mids = a.f$mids,
|
454
|
+
diff.mids = seq(
|
455
|
+
diff(range(a.f$mids)),
|
456
|
+
-diff(range(a.f$mids)),
|
457
|
+
length.out = 1 + 2 * length(a.f$mids)
|
458
|
+
),
|
459
|
+
call=match.call()
|
460
|
+
)
|
461
|
+
)
|
462
|
+
}
|
463
|
+
|
464
|
+
#' Enveomics: TRIBS
|
465
|
+
#'
|
466
|
+
#' Subsample any objects in "distance space" to reduce the effect of
|
467
|
+
#' sample-clustering. This function was originally designed to subsample
|
468
|
+
#' genomes in "phylogenetic distance space", a clear case of strong
|
469
|
+
#' clustering bias in sampling, by Luis M. Rodriguez-R and Michael R
|
470
|
+
#' Weigand.
|
471
|
+
#'
|
472
|
+
#' @param dist
|
473
|
+
#' Distances as a \code{dist} object.
|
474
|
+
#' @param selection
|
475
|
+
#' Objects to include in the subsample. By default, all objects are
|
476
|
+
#' selected.
|
477
|
+
#' @param replicates
|
478
|
+
#' Number of replications per point.
|
479
|
+
#' @param summary.fx
|
480
|
+
#' Function to summarize the distance distributions in a given replicate. By
|
481
|
+
#' default, the median distance is estimated.
|
482
|
+
#' @param dist.method
|
483
|
+
#' Distance method between random points and samples in the transformed
|
484
|
+
#' space. See \code{dist}.
|
485
|
+
#' @param subsamples
|
486
|
+
#' Subsampling fractions.
|
487
|
+
#' @param dimensions
|
488
|
+
#' Dimensions to use in the NMDS. By default, 5\% of the selection length.
|
489
|
+
#' @param metaMDS.opts
|
490
|
+
#' Any additional options to pass to metaMDS, as \code{list}.
|
491
|
+
#' @param threads
|
492
|
+
#' Number of threads to use.
|
493
|
+
#' @param verbosity
|
494
|
+
#' Verbosity. Use 0 to run quietly, increase for additional information.
|
495
|
+
#' @param points
|
496
|
+
#' Optional. If passed, the MDS step is skipped and this object is used
|
497
|
+
#' instead. It can be the \code{$points} slot of class \code{metaMDS}
|
498
|
+
#' (from \code{vegan}).
|
499
|
+
#' It must be a matrix or matrix-coercible object, with samples as rows and
|
500
|
+
#' dimensions as columns.
|
501
|
+
#' @param pre.tribs
|
502
|
+
#' Optional. If passed, the points are recovered from this object (except if
|
503
|
+
#' \code{points} is also passed. This should be an \code{\link{enve.TRIBS}}
|
504
|
+
#' object estimated on the same objects (the selection is unimportant).
|
505
|
+
#'
|
506
|
+
#' @return Returns an \code{\link{enve.TRIBS}} object.
|
507
|
+
#'
|
508
|
+
#' @author Luis M. Rodriguez-R [aut, cre]
|
509
|
+
#'
|
510
|
+
#' @export
|
511
|
+
|
512
|
+
enve.tribs <- function(
|
513
|
+
dist,
|
514
|
+
selection = labels(dist),
|
515
|
+
replicates = 1000,
|
516
|
+
summary.fx = median,
|
517
|
+
dist.method = "euclidean",
|
518
|
+
subsamples = seq(0, 1, by = 0.01),
|
519
|
+
dimensions = ceiling(length(selection) * 0.05),
|
520
|
+
metaMDS.opts = list(),
|
521
|
+
threads = 2,
|
522
|
+
verbosity = 1,
|
523
|
+
points,
|
524
|
+
pre.tribs
|
525
|
+
) {
|
526
|
+
# Sanity checks
|
527
|
+
if (!is(dist, "dist"))
|
528
|
+
stop("`dist` parameter must be a `dist` object.")
|
529
|
+
|
530
|
+
# 1. NMDS
|
531
|
+
if (missing(points)) {
|
532
|
+
if (missing(pre.tribs)) {
|
533
|
+
if (verbosity > 0) cat("===[ Estimating NMDS ]\n")
|
534
|
+
if (!suppressPackageStartupMessages(
|
535
|
+
requireNamespace("vegan", quietly=TRUE))
|
536
|
+
) stop("Unavailable required package: `vegan`.")
|
537
|
+
mds.args <- c(
|
538
|
+
metaMDS.opts,
|
539
|
+
list(comm = dist, k = dimensions, trace = verbosity)
|
540
|
+
)
|
541
|
+
points <- do.call(vegan::metaMDS, mds.args)$points
|
542
|
+
} else {
|
543
|
+
points <- attr(pre.tribs, "points")
|
544
|
+
dimensions <- ncol(points)
|
545
|
+
}
|
546
|
+
} else {
|
547
|
+
points <- as.matrix(points)
|
548
|
+
dimensions <- ncol(points)
|
549
|
+
}
|
550
|
+
|
551
|
+
# 2. Pad ranges
|
552
|
+
if (verbosity > 0) cat("===[ Padding ranges ]\n")
|
553
|
+
dots <- matrix(
|
554
|
+
NA, nrow = nrow(points), ncol = dimensions,
|
555
|
+
dimnames = list(rownames(points), 1:dimensions)
|
556
|
+
)
|
557
|
+
selection <- selection[!is.na(match(selection, rownames(dots)))]
|
558
|
+
for (dim in 1:dimensions) {
|
559
|
+
dimRange <- range(points[, dim]) + c(-1, 1) *
|
560
|
+
diff(range(points[, 1])) / length(selection)
|
561
|
+
dots[, dim] <- (points[, dim] - dimRange[1]) / diff(dimRange)
|
562
|
+
}
|
563
|
+
|
564
|
+
# 3. Select points and summarize distances
|
565
|
+
if (verbosity > 0) cat("===[ Sub-sampling ]\n")
|
566
|
+
distances <- matrix(
|
567
|
+
NA, nrow = replicates, ncol = length(subsamples),
|
568
|
+
dimnames = list(1:replicates, as.character(subsamples))
|
569
|
+
)
|
570
|
+
cl <- makeCluster(threads)
|
571
|
+
for (frx in subsamples) {
|
572
|
+
if (verbosity > 1) cat("Sub-sampling at ", (frx * 100), "%\n", sep = "")
|
573
|
+
distances[, as.character(frx)] <- parSapply(
|
574
|
+
cl, 1:replicates, enve.__tribs, frx,
|
575
|
+
match(selection, rownames(dots)), dimensions, dots, dist.method,
|
576
|
+
summary.fx, dist
|
577
|
+
)
|
578
|
+
}
|
579
|
+
stopCluster(cl)
|
580
|
+
|
581
|
+
# 4. Build object and return
|
582
|
+
return(
|
583
|
+
new(
|
584
|
+
"enve.TRIBS",
|
585
|
+
distance = do.call(
|
586
|
+
summary.fx, list(as.matrix(dist)[selection, selection])
|
587
|
+
),
|
588
|
+
points = points, distances = distances, spaceSize = nrow(points),
|
589
|
+
selSize = length(selection), dimensions = dimensions,
|
590
|
+
subsamples = subsamples, call = match.call()
|
591
|
+
)
|
592
|
+
)
|
593
|
+
}
|
594
|
+
|
595
|
+
#' Enveomics: TRIBS - Internal Ancillary Function
|
596
|
+
#'
|
597
|
+
#' Internal ancillary function (see \code{\link{enve.tribs}}).
|
598
|
+
#'
|
599
|
+
#' @param rep Replicates
|
600
|
+
#' @param frx Fraction
|
601
|
+
#' @param selection Selection
|
602
|
+
#' @param dimensions Dimensions
|
603
|
+
#' @param dots Sampling points
|
604
|
+
#' @param dist.method Distance method
|
605
|
+
#' @param summary.fx Summary function
|
606
|
+
#' @param dist Distance
|
607
|
+
#'
|
608
|
+
#' @return A numeric indicating the \code{summary.fx} value applied to the
|
609
|
+
#' distance matrix subset
|
610
|
+
#'
|
611
|
+
#' @author Luis M. Rodriguez-R [aut, cre]
|
612
|
+
#'
|
613
|
+
#' @export
|
614
|
+
|
615
|
+
enve.__tribs <- function(
|
616
|
+
rep, frx, selection, dimensions, dots, dist.method, summary.fx, dist
|
617
|
+
) {
|
618
|
+
sample <- c()
|
619
|
+
if (frx == 0) return(0)
|
620
|
+
for (point in 1:round(frx * length(selection))) {
|
621
|
+
rand.point <- runif(dimensions)
|
622
|
+
closest.dot <- ""
|
623
|
+
closest.dist <- Inf
|
624
|
+
for (dot in selection) {
|
625
|
+
dot.dist <- as.numeric(
|
626
|
+
dist(matrix(c(rand.point, dots[dot,]), nrow = 2, byrow = TRUE),
|
627
|
+
method = dist.method)
|
628
|
+
)
|
629
|
+
if (dot.dist < closest.dist) {
|
630
|
+
closest.dot <- dot
|
631
|
+
closest.dist <- dot.dist
|
632
|
+
}
|
633
|
+
}
|
634
|
+
sample <- c(sample, closest.dot)
|
635
|
+
}
|
636
|
+
return(do.call(summary.fx, list(as.matrix(dist)[sample, sample])))
|
637
|
+
}
|
638
|
+
|