miga-base 0.3.0.0 → 0.3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (260) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +21 -4
  3. data/actions/init.rb +258 -0
  4. data/actions/run_local.rb +1 -2
  5. data/actions/test_taxonomy.rb +4 -1
  6. data/bin/miga +8 -1
  7. data/lib/miga/dataset.rb +4 -4
  8. data/lib/miga/dataset_result.rb +7 -4
  9. data/lib/miga/version.rb +2 -2
  10. data/scripts/_distances_noref_nomulti.bash +3 -1
  11. data/scripts/clade_finding.bash +1 -1
  12. data/scripts/init.bash +1 -1
  13. data/scripts/miga.bash +1 -1
  14. data/scripts/mytaxa.bash +78 -72
  15. data/scripts/mytaxa_scan.bash +67 -62
  16. data/scripts/ogs.bash +1 -1
  17. data/scripts/trimmed_fasta.bash +4 -3
  18. data/utils/enveomics/Examples/aai-matrix.bash +66 -0
  19. data/utils/enveomics/Examples/ani-matrix.bash +66 -0
  20. data/utils/enveomics/Examples/essential-phylogeny.bash +105 -0
  21. data/utils/enveomics/Examples/unus-genome-phylogeny.bash +100 -0
  22. data/utils/enveomics/LICENSE.txt +73 -0
  23. data/utils/enveomics/Makefile +52 -0
  24. data/utils/enveomics/Manifest/Tasks/aasubs.json +103 -0
  25. data/utils/enveomics/Manifest/Tasks/blasttab.json +703 -0
  26. data/utils/enveomics/Manifest/Tasks/distances.json +161 -0
  27. data/utils/enveomics/Manifest/Tasks/fasta.json +571 -0
  28. data/utils/enveomics/Manifest/Tasks/fastq.json +208 -0
  29. data/utils/enveomics/Manifest/Tasks/graphics.json +126 -0
  30. data/utils/enveomics/Manifest/Tasks/ogs.json +339 -0
  31. data/utils/enveomics/Manifest/Tasks/other.json +746 -0
  32. data/utils/enveomics/Manifest/Tasks/remote.json +355 -0
  33. data/utils/enveomics/Manifest/Tasks/sequence-identity.json +454 -0
  34. data/utils/enveomics/Manifest/Tasks/tables.json +308 -0
  35. data/utils/enveomics/Manifest/Tasks/trees.json +68 -0
  36. data/utils/enveomics/Manifest/Tasks/variants.json +111 -0
  37. data/utils/enveomics/Manifest/categories.json +132 -0
  38. data/utils/enveomics/Manifest/examples.json +154 -0
  39. data/utils/enveomics/Manifest/tasks.json +4 -0
  40. data/utils/enveomics/Pipelines/assembly.pbs/CONFIG.mock.bash +69 -0
  41. data/utils/enveomics/Pipelines/assembly.pbs/FastA.N50.pl +56 -0
  42. data/utils/enveomics/Pipelines/assembly.pbs/FastA.filterN.pl +60 -0
  43. data/utils/enveomics/Pipelines/assembly.pbs/FastA.length.pl +38 -0
  44. data/utils/enveomics/Pipelines/assembly.pbs/README.md +189 -0
  45. data/utils/enveomics/Pipelines/assembly.pbs/RUNME-2.bash +112 -0
  46. data/utils/enveomics/Pipelines/assembly.pbs/RUNME-3.bash +23 -0
  47. data/utils/enveomics/Pipelines/assembly.pbs/RUNME-4.bash +44 -0
  48. data/utils/enveomics/Pipelines/assembly.pbs/RUNME.bash +50 -0
  49. data/utils/enveomics/Pipelines/assembly.pbs/kSelector.R +37 -0
  50. data/utils/enveomics/Pipelines/assembly.pbs/newbler.pbs +68 -0
  51. data/utils/enveomics/Pipelines/assembly.pbs/newbler_preparator.pl +49 -0
  52. data/utils/enveomics/Pipelines/assembly.pbs/soap.pbs +80 -0
  53. data/utils/enveomics/Pipelines/assembly.pbs/stats.pbs +57 -0
  54. data/utils/enveomics/Pipelines/assembly.pbs/velvet.pbs +63 -0
  55. data/utils/enveomics/Pipelines/blast.pbs/01.pbs.bash +38 -0
  56. data/utils/enveomics/Pipelines/blast.pbs/02.pbs.bash +73 -0
  57. data/utils/enveomics/Pipelines/blast.pbs/03.pbs.bash +21 -0
  58. data/utils/enveomics/Pipelines/blast.pbs/BlastTab.recover_job.pl +72 -0
  59. data/utils/enveomics/Pipelines/blast.pbs/CONFIG.mock.bash +98 -0
  60. data/utils/enveomics/Pipelines/blast.pbs/FastA.split.pl +55 -0
  61. data/utils/enveomics/Pipelines/blast.pbs/README.md +127 -0
  62. data/utils/enveomics/Pipelines/blast.pbs/RUNME.bash +109 -0
  63. data/utils/enveomics/Pipelines/blast.pbs/TASK.check.bash +128 -0
  64. data/utils/enveomics/Pipelines/blast.pbs/TASK.dry.bash +16 -0
  65. data/utils/enveomics/Pipelines/blast.pbs/TASK.eo.bash +22 -0
  66. data/utils/enveomics/Pipelines/blast.pbs/TASK.pause.bash +26 -0
  67. data/utils/enveomics/Pipelines/blast.pbs/TASK.run.bash +89 -0
  68. data/utils/enveomics/Pipelines/blast.pbs/sentinel.pbs.bash +29 -0
  69. data/utils/enveomics/Pipelines/idba.pbs/README.md +49 -0
  70. data/utils/enveomics/Pipelines/idba.pbs/RUNME.bash +95 -0
  71. data/utils/enveomics/Pipelines/idba.pbs/run.pbs +56 -0
  72. data/utils/enveomics/Pipelines/trim.pbs/README.md +54 -0
  73. data/utils/enveomics/Pipelines/trim.pbs/RUNME.bash +70 -0
  74. data/utils/enveomics/Pipelines/trim.pbs/run.pbs +130 -0
  75. data/utils/enveomics/README.md +40 -0
  76. data/utils/enveomics/Scripts/AAsubs.log2ratio.rb +171 -0
  77. data/utils/enveomics/Scripts/Aln.cat.rb +162 -0
  78. data/utils/enveomics/Scripts/Aln.convert.pl +35 -0
  79. data/utils/enveomics/Scripts/AlphaDiversity.pl +152 -0
  80. data/utils/enveomics/Scripts/BlastPairwise.AAsubs.pl +102 -0
  81. data/utils/enveomics/Scripts/BlastTab.addlen.rb +61 -0
  82. data/utils/enveomics/Scripts/BlastTab.advance.bash +48 -0
  83. data/utils/enveomics/Scripts/BlastTab.best_hit_sorted.pl +55 -0
  84. data/utils/enveomics/Scripts/BlastTab.catsbj.pl +106 -0
  85. data/utils/enveomics/Scripts/BlastTab.cogCat.rb +76 -0
  86. data/utils/enveomics/Scripts/BlastTab.filter.pl +47 -0
  87. data/utils/enveomics/Scripts/BlastTab.kegg_pep2path_rest.pl +194 -0
  88. data/utils/enveomics/Scripts/BlastTab.metaxaPrep.pl +104 -0
  89. data/utils/enveomics/Scripts/BlastTab.pairedHits.rb +157 -0
  90. data/utils/enveomics/Scripts/BlastTab.recplot2.R +40 -0
  91. data/utils/enveomics/Scripts/BlastTab.seqdepth.pl +86 -0
  92. data/utils/enveomics/Scripts/BlastTab.seqdepth_ZIP.pl +119 -0
  93. data/utils/enveomics/Scripts/BlastTab.seqdepth_nomedian.pl +86 -0
  94. data/utils/enveomics/Scripts/BlastTab.subsample.pl +47 -0
  95. data/utils/enveomics/Scripts/BlastTab.sumPerHit.pl +114 -0
  96. data/utils/enveomics/Scripts/BlastTab.taxid2taxrank.pl +90 -0
  97. data/utils/enveomics/Scripts/BlastTab.topHits_sorted.rb +101 -0
  98. data/utils/enveomics/Scripts/Chao1.pl +97 -0
  99. data/utils/enveomics/Scripts/CharTable.classify.rb +234 -0
  100. data/utils/enveomics/Scripts/EBIseq2tax.rb +83 -0
  101. data/utils/enveomics/Scripts/FastA.N50.pl +56 -0
  102. data/utils/enveomics/Scripts/FastA.filter.pl +52 -0
  103. data/utils/enveomics/Scripts/FastA.filterLen.pl +28 -0
  104. data/utils/enveomics/Scripts/FastA.filterN.pl +60 -0
  105. data/utils/enveomics/Scripts/FastA.fragment.rb +92 -0
  106. data/utils/enveomics/Scripts/FastA.gc.pl +42 -0
  107. data/utils/enveomics/Scripts/FastA.interpose.pl +87 -0
  108. data/utils/enveomics/Scripts/FastA.length.pl +38 -0
  109. data/utils/enveomics/Scripts/FastA.per_file.pl +36 -0
  110. data/utils/enveomics/Scripts/FastA.qlen.pl +57 -0
  111. data/utils/enveomics/Scripts/FastA.rename.pl +65 -0
  112. data/utils/enveomics/Scripts/FastA.revcom.pl +23 -0
  113. data/utils/enveomics/Scripts/FastA.slider.pl +85 -0
  114. data/utils/enveomics/Scripts/FastA.split.pl +55 -0
  115. data/utils/enveomics/Scripts/FastA.subsample.pl +131 -0
  116. data/utils/enveomics/Scripts/FastA.tag.rb +64 -0
  117. data/utils/enveomics/Scripts/FastA.wrap.rb +48 -0
  118. data/utils/enveomics/Scripts/FastQ.filter.pl +54 -0
  119. data/utils/enveomics/Scripts/FastQ.interpose.pl +90 -0
  120. data/utils/enveomics/Scripts/FastQ.offset.pl +90 -0
  121. data/utils/enveomics/Scripts/FastQ.split.pl +53 -0
  122. data/utils/enveomics/Scripts/FastQ.tag.rb +63 -0
  123. data/utils/enveomics/Scripts/FastQ.toFastA.awk +24 -0
  124. data/utils/enveomics/Scripts/GenBank.add_fields.rb +84 -0
  125. data/utils/enveomics/Scripts/HMM.essential.rb +254 -0
  126. data/utils/enveomics/Scripts/HMMsearch.extractIds.rb +83 -0
  127. data/utils/enveomics/Scripts/JPlace.distances.rb +88 -0
  128. data/utils/enveomics/Scripts/JPlace.to_iToL.rb +306 -0
  129. data/utils/enveomics/Scripts/M5nr.getSequences.rb +81 -0
  130. data/utils/enveomics/Scripts/MeTaxa.distribution.pl +198 -0
  131. data/utils/enveomics/Scripts/MyTaxa.fragsByTax.pl +35 -0
  132. data/utils/enveomics/Scripts/MyTaxa.seq-taxrank.rb +49 -0
  133. data/utils/enveomics/Scripts/NCBIacc2tax.rb +92 -0
  134. data/utils/enveomics/Scripts/Newick.autoprune.R +27 -0
  135. data/utils/enveomics/Scripts/RAxML-EPA.to_iToL.pl +228 -0
  136. data/utils/enveomics/Scripts/RefSeq.download.bash +48 -0
  137. data/utils/enveomics/Scripts/SRA.download.bash +50 -0
  138. data/utils/enveomics/Scripts/TRIBS.plot-test.R +36 -0
  139. data/utils/enveomics/Scripts/TRIBS.test.R +39 -0
  140. data/utils/enveomics/Scripts/Table.barplot.R +30 -0
  141. data/utils/enveomics/Scripts/Table.df2dist.R +30 -0
  142. data/utils/enveomics/Scripts/Table.filter.pl +61 -0
  143. data/utils/enveomics/Scripts/Table.merge.pl +77 -0
  144. data/utils/enveomics/Scripts/Table.replace.rb +69 -0
  145. data/utils/enveomics/Scripts/Table.round.rb +63 -0
  146. data/utils/enveomics/Scripts/Table.split.pl +57 -0
  147. data/utils/enveomics/Scripts/Taxonomy.silva2ncbi.rb +227 -0
  148. data/utils/enveomics/Scripts/VCF.KaKs.rb +147 -0
  149. data/utils/enveomics/Scripts/VCF.SNPs.rb +88 -0
  150. data/utils/enveomics/Scripts/aai.rb +373 -0
  151. data/utils/enveomics/Scripts/ani.rb +362 -0
  152. data/utils/enveomics/Scripts/gi2tax.rb +103 -0
  153. data/utils/enveomics/Scripts/in_silico_GA_GI.pl +96 -0
  154. data/utils/enveomics/Scripts/lib/data/essential.hmm.gz +0 -0
  155. data/utils/enveomics/Scripts/lib/enveomics_rb/enveomics.rb +26 -0
  156. data/utils/enveomics/Scripts/lib/enveomics_rb/jplace.rb +253 -0
  157. data/utils/enveomics/Scripts/lib/enveomics_rb/og.rb +182 -0
  158. data/utils/enveomics/Scripts/lib/enveomics_rb/remote_data.rb +74 -0
  159. data/utils/enveomics/Scripts/lib/enveomics_rb/seq_range.rb +237 -0
  160. data/utils/enveomics/Scripts/lib/enveomics_rb/stat.rb +30 -0
  161. data/utils/enveomics/Scripts/lib/enveomics_rb/vcf.rb +135 -0
  162. data/utils/enveomics/Scripts/ogs.annotate.rb +88 -0
  163. data/utils/enveomics/Scripts/ogs.core-pan.rb +160 -0
  164. data/utils/enveomics/Scripts/ogs.extract.rb +125 -0
  165. data/utils/enveomics/Scripts/ogs.mcl.rb +186 -0
  166. data/utils/enveomics/Scripts/ogs.rb +104 -0
  167. data/utils/enveomics/Scripts/ogs.stats.rb +131 -0
  168. data/utils/enveomics/Scripts/rbm.rb +137 -0
  169. data/utils/enveomics/Tests/Makefile +10 -0
  170. data/utils/enveomics/Tests/Mgen_M2288.faa +3189 -0
  171. data/utils/enveomics/Tests/Mgen_M2288.fna +8282 -0
  172. data/utils/enveomics/Tests/Mgen_M2321.fna +8288 -0
  173. data/utils/enveomics/Tests/Nequ_Kin4M.faa +2970 -0
  174. data/utils/enveomics/Tests/Xanthomonas_oryzae-PilA.tribs.Rdata +0 -0
  175. data/utils/enveomics/Tests/Xanthomonas_oryzae-PilA.txt +7 -0
  176. data/utils/enveomics/Tests/Xanthomonas_oryzae.aai-mat.tsv +17 -0
  177. data/utils/enveomics/Tests/Xanthomonas_oryzae.aai.tsv +137 -0
  178. data/utils/enveomics/Tests/a_mg.cds-go.blast.tsv +123 -0
  179. data/utils/enveomics/Tests/a_mg.reads-cds.blast.tsv +200 -0
  180. data/utils/enveomics/Tests/a_mg.reads-cds.counts.tsv +55 -0
  181. data/utils/enveomics/Tests/alkB.nwk +1 -0
  182. data/utils/enveomics/Tests/anthrax-cansnp-data.tsv +13 -0
  183. data/utils/enveomics/Tests/anthrax-cansnp-key.tsv +17 -0
  184. data/utils/enveomics/Tests/hiv1.faa +59 -0
  185. data/utils/enveomics/Tests/hiv1.fna +134 -0
  186. data/utils/enveomics/Tests/hiv2.faa +70 -0
  187. data/utils/enveomics/Tests/hiv_mix-hiv1.blast.tsv +233 -0
  188. data/utils/enveomics/Tests/hiv_mix-hiv1.blast.tsv.lim +1 -0
  189. data/utils/enveomics/Tests/hiv_mix-hiv1.blast.tsv.rec +233 -0
  190. data/utils/enveomics/Tests/phyla_counts.tsv +10 -0
  191. data/utils/enveomics/Tests/primate_lentivirus.ogs +11 -0
  192. data/utils/enveomics/Tests/primate_lentivirus.rbm/hiv1-hiv1.rbm +9 -0
  193. data/utils/enveomics/Tests/primate_lentivirus.rbm/hiv1-hiv2.rbm +8 -0
  194. data/utils/enveomics/Tests/primate_lentivirus.rbm/hiv1-siv.rbm +6 -0
  195. data/utils/enveomics/Tests/primate_lentivirus.rbm/hiv2-hiv2.rbm +9 -0
  196. data/utils/enveomics/Tests/primate_lentivirus.rbm/hiv2-siv.rbm +6 -0
  197. data/utils/enveomics/Tests/primate_lentivirus.rbm/siv-siv.rbm +6 -0
  198. data/utils/enveomics/build_enveomics_r.bash +44 -0
  199. data/utils/enveomics/enveomics.R/DESCRIPTION +31 -0
  200. data/utils/enveomics/enveomics.R/NAMESPACE +35 -0
  201. data/utils/enveomics/enveomics.R/R/autoprune.R +121 -0
  202. data/utils/enveomics/enveomics.R/R/barplot.R +165 -0
  203. data/utils/enveomics/enveomics.R/R/cliopts.R +119 -0
  204. data/utils/enveomics/enveomics.R/R/df2dist.R +117 -0
  205. data/utils/enveomics/enveomics.R/R/growthcurve.R +263 -0
  206. data/utils/enveomics/enveomics.R/R/recplot.R +320 -0
  207. data/utils/enveomics/enveomics.R/R/recplot2.R +745 -0
  208. data/utils/enveomics/enveomics.R/R/tribs.R +423 -0
  209. data/utils/enveomics/enveomics.R/R/utils.R +16 -0
  210. data/utils/enveomics/enveomics.R/README.md +52 -0
  211. data/utils/enveomics/enveomics.R/data/growth.curves.rda +0 -0
  212. data/utils/enveomics/enveomics.R/data/phyla.counts.rda +0 -0
  213. data/utils/enveomics/enveomics.R/man/enve.GrowthCurve-class.Rd +30 -0
  214. data/utils/enveomics/enveomics.R/man/enve.TRIBS-class.Rd +43 -0
  215. data/utils/enveomics/enveomics.R/man/enve.TRIBS.merge.Rd +19 -0
  216. data/utils/enveomics/enveomics.R/man/enve.TRIBStest-class.Rd +37 -0
  217. data/utils/enveomics/enveomics.R/man/enve.__prune.iter.Rd +24 -0
  218. data/utils/enveomics/enveomics.R/man/enve.__prune.reduce.Rd +24 -0
  219. data/utils/enveomics/enveomics.R/man/enve.__tribs.Rd +33 -0
  220. data/utils/enveomics/enveomics.R/man/enve.barplot.Rd +64 -0
  221. data/utils/enveomics/enveomics.R/man/enve.cliopts.Rd +37 -0
  222. data/utils/enveomics/enveomics.R/man/enve.col.alpha.Rd +19 -0
  223. data/utils/enveomics/enveomics.R/man/enve.col2alpha.Rd +18 -0
  224. data/utils/enveomics/enveomics.R/man/enve.df2dist.Rd +26 -0
  225. data/utils/enveomics/enveomics.R/man/enve.df2dist.group.Rd +25 -0
  226. data/utils/enveomics/enveomics.R/man/enve.df2dist.list.Rd +26 -0
  227. data/utils/enveomics/enveomics.R/man/enve.growthcurve.Rd +49 -0
  228. data/utils/enveomics/enveomics.R/man/enve.prune.dist.Rd +28 -0
  229. data/utils/enveomics/enveomics.R/man/enve.recplot.Rd +97 -0
  230. data/utils/enveomics/enveomics.R/man/enve.recplot2-class.Rd +40 -0
  231. data/utils/enveomics/enveomics.R/man/enve.recplot2.Rd +40 -0
  232. data/utils/enveomics/enveomics.R/man/enve.recplot2.__counts.Rd +24 -0
  233. data/utils/enveomics/enveomics.R/man/enve.recplot2.__findPeak.Rd +40 -0
  234. data/utils/enveomics/enveomics.R/man/enve.recplot2.__findPeaks.Rd +18 -0
  235. data/utils/enveomics/enveomics.R/man/enve.recplot2.__peakHist.Rd +22 -0
  236. data/utils/enveomics/enveomics.R/man/enve.recplot2.__whichClosestPeak.Rd +20 -0
  237. data/utils/enveomics/enveomics.R/man/enve.recplot2.changeCutoff.Rd +18 -0
  238. data/utils/enveomics/enveomics.R/man/enve.recplot2.corePeak.Rd +18 -0
  239. data/utils/enveomics/enveomics.R/man/enve.recplot2.extractWindows.Rd +27 -0
  240. data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.Rd +53 -0
  241. data/utils/enveomics/enveomics.R/man/enve.recplot2.peak-class.Rd +44 -0
  242. data/utils/enveomics/enveomics.R/man/enve.tribs.Rd +44 -0
  243. data/utils/enveomics/enveomics.R/man/enve.tribs.test.Rd +21 -0
  244. data/utils/enveomics/enveomics.R/man/enveomics.R-package.Rd +15 -0
  245. data/utils/enveomics/enveomics.R/man/growth.curves.Rd +14 -0
  246. data/utils/enveomics/enveomics.R/man/phyla.counts.Rd +13 -0
  247. data/utils/enveomics/enveomics.R/man/plot.enve.GrowthCurve.Rd +43 -0
  248. data/utils/enveomics/enveomics.R/man/plot.enve.TRIBS.Rd +29 -0
  249. data/utils/enveomics/enveomics.R/man/plot.enve.TRIBStest.Rd +30 -0
  250. data/utils/enveomics/enveomics.R/man/plot.enve.recplot2.Rd +71 -0
  251. data/utils/enveomics/enveomics.R/man/summary.enve.GrowthCurve.Rd +18 -0
  252. data/utils/enveomics/enveomics.R/man/summary.enve.TRIBS.Rd +18 -0
  253. data/utils/enveomics/enveomics.R/man/summary.enve.TRIBStest.Rd +18 -0
  254. data/utils/enveomics/enveomics.R/man/z$-methods.Rd +27 -0
  255. data/utils/enveomics/globals.mk +8 -0
  256. data/utils/enveomics/manifest.json +9 -0
  257. data/utils/index_metadata.rb +0 -0
  258. data/utils/plot-taxdist.R +0 -0
  259. data/utils/requirements.txt +19 -19
  260. metadata +242 -2
@@ -0,0 +1,423 @@
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
+ #==============> Define S4 classes
28
+ setClass("enve.TRIBS",
29
+ ### Enve-omics representation of "Transformed-space Resampling In Biased Sets
30
+ ### (TRIBS)". This object represents sets of distances between objects,
31
+ ### sampled nearly-uniformly at random in "distance space". Subsampling
32
+ ### without selection is trivial, since both the distances space and the
33
+ ### selection occur in the same transformed space. However, it's useful to
34
+ ### compare randomly subsampled sets against a selected set of objects. This
35
+ ### is intended to identify overdispersion or overclustering (see
36
+ ### `enve.TRIBStest`) of a subset against the entire collection of objects
37
+ ### with minimum impact of sampling biases. This object can be produced by
38
+ ### `enve.tribs` and supports S4 methods `plot` and `summary`.
39
+ representation(
40
+ distance='numeric', ##<< Centrality measurement of the distances between the
41
+ ##<< selected objects (without subsampling).
42
+ points='matrix', ##<< Position of the different objects in distance
43
+ ##<< space.
44
+ distances='matrix', ##<< Subsampled distances, where the rows are replicates
45
+ ##<< and the columns are subsampling levels.
46
+ spaceSize='numeric', ##<< Number of objects.
47
+ selSize='numeric', ##<< Number of selected objects.
48
+ dimensions='numeric',##<< Number of dimensions in the distance space.
49
+ subsamples='numeric',##<< Subsampling levels (as fractions, from 0 to 1).
50
+ call='call') ##<< Call producing this object.
51
+ ,package='enveomics.R'
52
+ );
53
+ setClass("enve.TRIBStest",
54
+ ### Test of significance of overclustering or overdispersion in a selected
55
+ ### set of objects with respect to the entire set (see `enve.TRIBS`). This
56
+ ### object can be produced by `enve.tribs.test` and supports S4 methods
57
+ ### `plot` and `summary`.
58
+ representation(
59
+ pval.gt='numeric',
60
+ ### P-value for the overdispersion test.
61
+ pval.lt='numeric',
62
+ ### P-value for the overclustering test.
63
+ all.dist='numeric',
64
+ ### Empiric PDF of distances for the entire dataset (subsampled at selection
65
+ ### size).
66
+ sel.dist='numeric',
67
+ ### Empiric PDF of distances for the selected objects (without subsampling).
68
+ diff.dist='numeric',
69
+ ### Empiric PDF of the difference between `all.dist` and `sel.dist`. The
70
+ ### p-values are estimating by comparing areas in this PDF greater than and
71
+ ### lesser than zero.
72
+ dist.mids='numeric',
73
+ ### Midpoints of the empiric PDFs of distances.
74
+ diff.mids='numeric',
75
+ ### Midpoints of the empiric PDF of difference of distances.
76
+ call='call')
77
+ ### Call producing this object.
78
+ ,package='enveomics.R'
79
+ );
80
+
81
+ #==============> Define S4 methods
82
+ summary.enve.TRIBS <- function
83
+ ### Summary of an `enve.TRIBS` object.
84
+ (object,
85
+ ### `enve.TRIBS` object.
86
+ ...
87
+ ### No additional parameters are currently supported.
88
+ ){
89
+ cat('===[ enve.TRIBS ]-------------------------\n');
90
+ cat('Selected',attr(object,'selSize'),'of',
91
+ attr(object,'spaceSize'),'objects in',
92
+ attr(object,'dimensions'),'dimensions.\n');
93
+ cat('Collected',length(attr(object,'subsamples')),'subsamples with',
94
+ nrow(attr(object,'distances')),'replicates each.\n');
95
+ cat('------------------------------------------\n');
96
+ cat('call:',as.character(attr(object,'call')),'\n');
97
+ cat('------------------------------------------\n');
98
+ }
99
+
100
+ plot.enve.TRIBS <- function
101
+ ### Plot an `enve.TRIBS` object.
102
+ (x,
103
+ ### `enve.TRIBS` object to plot.
104
+ new=TRUE,
105
+ ### Should a new canvas be drawn?
106
+ type=c('boxplot', 'points'),
107
+ ### Type of plot. The 'points' plot shows all the replicates, the 'boxplot'
108
+ ### plot represents the values found by `boxplot.stats` as areas, and plots
109
+ ### the outliers as points.
110
+ col='#00000044',
111
+ ### Color of the areas and/or the points.
112
+ pt.cex=1/2,
113
+ ### Size of the points.
114
+ pt.pch=19,
115
+ ### Points character.
116
+ pt.col=col,
117
+ ### Color of the points.
118
+ ln.col=col,
119
+ ### Color of the lines.
120
+ ...
121
+ ### Any additional parameters supported by `plot`.
122
+ ){
123
+ type <- match.arg(type);
124
+ plot.opts <- list(xlim=range(attr(x,'subsamples'))*attr(x,'selSize'),
125
+ ylim=range(attr(x,'distances')), ..., t='n', x=1);
126
+ if(new) do.call(plot, plot.opts);
127
+ abline(h=attr(x,'distance'), lty=3, col=ln.col);
128
+ replicates <- nrow(attr(x,'distances'));
129
+ if(type=='points'){
130
+ for(i in 1:ncol(attr(x,'distances')))
131
+ points(rep(round(attr(x,'subsamples')[i]*attr(x,'selSize')),
132
+ replicates), attr(x,'distances')[,i], cex=pt.cex, pch=pt.pch,
133
+ col=pt.col);
134
+ }else{
135
+ stats <- matrix(NA, nrow=7, ncol=ncol(attr(x,'distances')));
136
+ for(i in 1:ncol(attr(x,'distances'))){
137
+ b <- boxplot.stats(attr(x,'distances')[,i]);
138
+ points(rep(round(attr(x,'subsamples')[i]*attr(x,'selSize')),
139
+ length(b$out)), b$out, cex=pt.cex, pch=pt.pch, col=pt.col);
140
+ stats[, i] <- c(b$conf, b$stats[c(1,5,2,4,3)]);
141
+ }
142
+ x <- round(attr(x,'subsamples')*attr(x,'selSize'))
143
+ for(i in c(1,3,5))
144
+ polygon(c(x, rev(x)), c(stats[i,], rev(stats[i+1,])), border=NA,
145
+ col=col);
146
+ lines(x, stats[7,], col=ln.col, lwd=2);
147
+ }
148
+ }
149
+
150
+ summary.enve.TRIBStest <- function
151
+ ### Summary of an `enve.TRIBStest` object.
152
+ (object,
153
+ ### `enve.TRIBStest` object.
154
+ ...
155
+ ### No additional parameters are currently supported.
156
+ ){
157
+ cat('===[ enve.TRIBStest ]---------------------\n');
158
+ cat('Alternative hypothesis:\n');
159
+ cat(' The distances in the selection are\n');
160
+ if(attr(object, 'pval.gt') > attr(object, 'pval.lt')){
161
+ cat(' smaller than in the entire dataset\n (overclustering)\n');
162
+ }else{
163
+ cat(' larger than in the entire dataset\n (overdispersion)\n');
164
+ }
165
+ p.val <- min(attr(object, 'pval.gt'), attr(object, 'pval.lt'));
166
+ if(p.val==0){
167
+ diff.dist <- attr(object, 'diff.dist');
168
+ p.val.lim <- min(diff.dist[diff.dist>0]);
169
+ cat('\n P-value <= ', signif(p.val.lim, 4), sep='');
170
+ }else{
171
+ p.val.lim <- p.val;
172
+ cat('\n P-value: ', signif(p.val, 4), sep='');
173
+ }
174
+ cat(' ', ifelse(p.val.lim<=0.01, "**", ifelse(p.val.lim<=0.05, "*", "")),
175
+ '\n', sep='');
176
+ cat('------------------------------------------\n');
177
+ cat('call:',as.character(attr(object,'call')),'\n');
178
+ cat('------------------------------------------\n');
179
+ }
180
+
181
+ plot.enve.TRIBStest <- function
182
+ ### Plots an `enve.TRIBStest` object.
183
+ (x,
184
+ ### `enve.TRIBStest` object to plot.
185
+ type=c('overlap', 'difference'),
186
+ ### What to plot. 'overlap' generates a plot of the two contrasting empirical
187
+ ### PDFs (to compare against each other), 'difference' produces a plot of the
188
+ ### differences between the empirical PDFs (to compare against zero).
189
+ col='#00000044',
190
+ ### Main color of the plot if type='difference'.
191
+ col1=col,
192
+ ### First color of the plot if type='overlap'.
193
+ col2='#44001144',
194
+ ### Second color of the plot if type='overlap'.
195
+ ylab='Probability',
196
+ ### Y-axis label.
197
+ xlim=range(attr(x, 'dist.mids')),
198
+ ### X-axis limits.
199
+ ylim=c(0,max(c(attr(x, 'all.dist'), attr(x, 'sel.dist')))),
200
+ ### Y-axis limits.
201
+ ...
202
+ ### Any other graphical arguments.
203
+ ){
204
+ type <- match.arg(type);
205
+ if(type=='overlap'){
206
+ plot.opts <- list(xlim=xlim, ylim=ylim, ylab=ylab, ..., t='n', x=1);
207
+ do.call(plot, plot.opts);
208
+ bins <- length(attr(x, 'dist.mids'))
209
+ polygon(attr(x, 'dist.mids')[c(1, 1:bins, bins)],
210
+ c(0,attr(x, 'all.dist'),0), col=col1,
211
+ border=do.call(rgb, as.list(c(col2rgb(col1)/256, 0.5))));
212
+ polygon(attr(x, 'dist.mids')[c(1, 1:bins, bins)],
213
+ c(0,attr(x, 'sel.dist'),0), col=col2,
214
+ border=do.call(rgb, as.list(c(col2rgb(col2)/256, 0.5))));
215
+ }else{
216
+ plot.opts <- list(xlim=range(attr(x, 'diff.mids')),
217
+ ylim=c(0,max(attr(x, 'diff.dist'))), ylab=ylab, ..., t='n', x=1);
218
+ do.call(plot, plot.opts);
219
+ bins <- length(attr(x, 'diff.mids'));
220
+ polygon(attr(x, 'diff.mids')[c(1, 1:bins, bins)],
221
+ c(0,attr(x, 'diff.dist'),0), col=col,
222
+ border=do.call(rgb, as.list(c(col2rgb(col)/256, 0.5))));
223
+ }
224
+ }
225
+
226
+ enve.TRIBS.merge <- function
227
+ ### Merges two `enve.TRIBS` objects generated from the same objects at
228
+ ### different subsampling levels.
229
+ (x,
230
+ ### First `enve.TRIBS` object.
231
+ y
232
+ ### Second `enve.TRIBS` object.
233
+ ){
234
+ # Check consistency
235
+ if(attr(x,'distance') != attr(y,'distance'))
236
+ stop('Total distances in objects are different.');
237
+ if(any(attr(x,'points') != attr(y,'points')))
238
+ stop('Points in objects are different.');
239
+ if(attr(x,'spaceSize') != attr(y,'spaceSize'))
240
+ stop('Space size in objects are different.');
241
+ if(attr(x,'selSize') != attr(y,'selSize'))
242
+ stop('Selection size in objects are different.');
243
+ if(attr(x,'dimensions') != attr(y,'dimensions'))
244
+ stop('Dimensions in objects are different.');
245
+ if(nrow(attr(x,'distances')) != nrow(attr(y,'distances')))
246
+ stop('Replicates in objects are different.');
247
+ # Merge
248
+ a <- attr(x,'subsamples');
249
+ b <- attr(y,'subsamples');
250
+ o <- order(c(a,b));
251
+ o <- o[!duplicated(c(a,b)[o])] ;
252
+ d <- cbind(attr(x,'distances'), attr(y,'distances'))[, o] ;
253
+ z <- new('enve.TRIBS',
254
+ distance=attr(x,'distance'), points=attr(x,'points'),
255
+ distances=d, spaceSize=attr(x,'spaceSize'),
256
+ selSize=attr(x,'selSize'), dimensions=attr(x,'dimensions'),
257
+ subsamples=c(a,b)[o], call=match.call());
258
+ return(z) ;
259
+ ### Returns an `enve.TRIBS` object.
260
+ }
261
+
262
+ #==============> Define core functions
263
+ enve.tribs.test <- function
264
+ ### Estimates the empirical difference between all the distances in a set of
265
+ ### objects and a subset, together with its statistical significance.
266
+ (dist,
267
+ ### Distances as `dist` object.
268
+ selection,
269
+ ### Selection defining the subset.
270
+ bins=50,
271
+ ### Number of bins to evaluate in the range of distances.
272
+ ...
273
+ ### Any other parameters supported by `enve.tribs`, except `subsamples`.
274
+ ){
275
+ s.tribs <- enve.tribs(dist, selection, subsamples=c(0,1), ...);
276
+ a.tribs <- enve.tribs(dist,
277
+ subsamples=c(0,attr(s.tribs, 'selSize')/attr(s.tribs, 'spaceSize')), ...);
278
+ s.dist <- attr(s.tribs, 'distances')[, 2];
279
+ a.dist <- attr(a.tribs, 'distances')[, 2];
280
+ range <- range(c(s.dist, a.dist));
281
+ a.f <- hist(a.dist, breaks=seq(range[1], range[2], length.out=bins),
282
+ plot=FALSE);
283
+ s.f <- hist(s.dist, breaks=seq(range[1], range[2], length.out=bins),
284
+ plot=FALSE);
285
+ zp.f <- c(); zz.f <- 0; zn.f <- c();
286
+ p.x <- a.f$counts/sum(a.f$counts);
287
+ p.y <- s.f$counts/sum(s.f$counts);
288
+ for(z in 1:length(a.f$mids)){
289
+ zn.f[z] <- 0;
290
+ zz.f <- 0;
291
+ zp.f[z] <- 0;
292
+ for(k in 1:length(a.f$mids)){
293
+ if(z < k){
294
+ zp.f[z] <- zp.f[z] + p.x[k]*p.y[k-z];
295
+ zn.f[z] <- zn.f[z] + p.x[k-z]*p.y[k];
296
+ }
297
+ zz.f <- zz.f + p.x[k]*p.y[k];
298
+ }
299
+ }
300
+ return(new('enve.TRIBStest',
301
+ pval.gt=sum(c(zz.f, zp.f)), pval.lt=sum(c(zz.f, zn.f)),
302
+ all.dist=p.x, sel.dist=p.y, diff.dist=c(rev(zn.f), zz.f, zp.f),
303
+ dist.mids=a.f$mids,
304
+ diff.mids=seq(diff(range(a.f$mids)), -diff(range(a.f$mids)),
305
+ length.out=1+2*length(a.f$mids)),
306
+ call=match.call()));
307
+ ### Returns an `enve.TRIBStest` object.
308
+ }
309
+
310
+ enve.tribs <- function
311
+ ### Subsample any objects in "distance space" to reduce the effect of
312
+ ### sample-clustering. This function was originally designed to subsample
313
+ ### genomes in "phylogenetic distance space", a clear case of strong
314
+ ### clustering bias in sampling, by Luis M. Rodriguez-R and Michael R
315
+ ### Weigand.
316
+ (dist,
317
+ ### Distances as a `dist` object.
318
+ selection=labels(dist),
319
+ ### Objects to include in the subsample. By default, all objects are
320
+ ### selected.
321
+ replicates=1000,
322
+ ### Number of replications per point
323
+ summary.fx=median,
324
+ ### Function to summarize the distance distributions in a given replicate. By
325
+ ### default, the median distance is estimated.
326
+ dist.method='euclidean',
327
+ ### Distance method between random points and samples in the transformed
328
+ ### space. See `dist`.
329
+ subsamples=seq(0,1,by=0.01),
330
+ ### Subsampling fractions
331
+ dimensions=ceiling(length(selection)*0.05),
332
+ ### Dimensions to use in the NMDS. By default, 5% of the selection length.
333
+ metaMDS.opts=list(),
334
+ ### Any additional options to pass to metaMDS, as `list`.
335
+ threads=2,
336
+ ### Number of threads to use.
337
+ verbosity=1,
338
+ ### Verbosity. Use 0 to run quietly, increase for additional information.
339
+ points,
340
+ ### Optional. If passed, the MDS step is skipped and this object is used
341
+ ### instead. It can be the `$points` slot of class `metaMDS` (from `vegan`).
342
+ ### It must be a matrix or matrix-coercible object, with samples as rows and
343
+ ### dimensions as columns.
344
+ pre.tribs
345
+ ### Optional. If passed, the points are recovered from this object (except if
346
+ ### `points` is also passed. This should be an `enve.TRIBS` object estimated
347
+ ### on the same objects (the selection is unimportant).
348
+ ){
349
+ if(!is(dist, 'dist'))
350
+ stop('`dist` parameter must be a `dist` object.');
351
+ # 1. NMDS
352
+ if(missing(points)){
353
+ if(missing(pre.tribs)){
354
+ if(verbosity > 0)
355
+ cat('===[ Estimating NMDS ]\n');
356
+ if(!suppressPackageStartupMessages(
357
+ requireNamespace("vegan", quietly=TRUE)))
358
+ stop('Unavailable required package: `vegan`.');
359
+ mds.args <- c(metaMDS.opts, list(comm=dist, k=dimensions,
360
+ trace=verbosity));
361
+ points <- do.call(vegan::metaMDS, mds.args)$points;
362
+ }else{
363
+ points <- attr(pre.tribs, 'points');
364
+ dimensions <- ncol(points);
365
+ }
366
+ }else{
367
+ points <- as.matrix(points);
368
+ dimensions <- ncol(points);
369
+ }
370
+ # 2. Pad ranges
371
+ if(verbosity > 0) cat('===[ Padding ranges ]\n');
372
+ dots <- matrix(NA, nrow=nrow(points), ncol=dimensions,
373
+ dimnames=list(rownames(points), 1:dimensions));
374
+ selection <- selection[!is.na(match(selection, rownames(dots)))];
375
+ for(dim in 1:dimensions){
376
+ dimRange <- range(points[,dim]) +
377
+ c(-1,1)*diff(range(points[,1]))/length(selection);
378
+ dots[, dim] <- (points[,dim]-dimRange[1])/diff(dimRange);
379
+ }
380
+ # 3. Select points and summarize distances
381
+ if(verbosity > 0) cat('===[ Sub-sampling ]\n');
382
+ distances <- matrix(NA, nrow=replicates, ncol=length(subsamples),
383
+ dimnames=list(1:replicates, as.character(subsamples)));
384
+ cl <- makeCluster(threads);
385
+ for(frx in subsamples){
386
+ if(verbosity > 1) cat('Sub-sampling at ',(frx*100),'%\n',sep='');
387
+ distances[, as.character(frx)] = parSapply(cl, 1:replicates, enve.__tribs,
388
+ frx, match(selection, rownames(dots)), dimensions, dots, dist.method,
389
+ summary.fx, dist);
390
+ }
391
+ stopCluster(cl);
392
+ # 4. Build object and return
393
+ return(new('enve.TRIBS',
394
+ distance=do.call(summary.fx, list(as.matrix(dist)[selection, selection])),
395
+ points=points, distances=distances, spaceSize=nrow(points),
396
+ selSize=length(selection), dimensions=dimensions, subsamples=subsamples,
397
+ call=match.call()));
398
+ ### Returns an `enve.TRIBS` object.
399
+ }
400
+
401
+ enve.__tribs <- function
402
+ ### Internal ancilliary function (see `enve.tribs`).
403
+ (rep, frx, selection, dimensions, dots, dist.method, summary.fx, dist){
404
+ sample <- c();
405
+ if(frx==0) return(0);
406
+ for(point in 1:round(frx*length(selection))){
407
+ rand.point <- runif(dimensions);
408
+ closest.dot <- '';
409
+ closest.dist <- Inf;
410
+ for(dot in selection){
411
+ dot.dist <- as.numeric(dist(matrix(c(rand.point, dots[dot,]), nrow=2,
412
+ byrow=TRUE), method=dist.method));
413
+ if(dot.dist < closest.dist){
414
+ closest.dot <- dot;
415
+ closest.dist <- dot.dist;
416
+ }
417
+ }
418
+ sample <- c(sample, closest.dot);
419
+ }
420
+ return( do.call(summary.fx, list(as.matrix(dist)[sample, sample])) );
421
+ }
422
+
423
+
@@ -0,0 +1,16 @@
1
+
2
+
3
+ enve.col.alpha <- function
4
+ ### Modify alpha in a color (or vector of colors).
5
+ (col,
6
+ ### Color or vector of colors. It can be any value supported by `col2rgb`,
7
+ ### such as 'darkred' or '#009988'.
8
+ alpha=1/2
9
+ ### Alpha value to add to the color, from 0 to 1.
10
+ ){
11
+ return(
12
+ apply(col2rgb(col), 2,
13
+ function(x) do.call(rgb, as.list(c(x[1:3]/256, alpha))) ) )
14
+ ### Returns a color or a vector of colors in hex notation including alpha.
15
+ }
16
+
@@ -0,0 +1,52 @@
1
+ # enveomics.R
2
+
3
+ ## Installing `enveomics.R`
4
+ To install the latest version of `enveomics.R` uploaded to CRAN, execute in R:
5
+
6
+ ```R
7
+ install.packages('enveomics.R')
8
+ ```
9
+
10
+ To install the current developer version of `enveomics.R`, execute in R:
11
+
12
+ ```R
13
+ install.packages('devtools')
14
+ library('devtools')
15
+ install_github('lmrodriguezr/enveomics', subdir='enveomics.R')
16
+ ```
17
+
18
+ ## Using `enveomics.R`
19
+ To load enveomics.R, simply execute:
20
+
21
+ ```R
22
+ library(enveomics.R);
23
+ ```
24
+
25
+ And open help messages using any of the following commands:
26
+
27
+ ```R
28
+ ?enveomics.R
29
+ ?enve.barplot
30
+ ?enve.recplot2
31
+ ?enve.recplot2.changeCutoff
32
+ ?enve.recplot2.findPeaks
33
+ ?enve.recplot2.corePeak
34
+ ?enve.recplot2.extractWindows
35
+ ?enve.prune.dist
36
+ ?enve.tribs
37
+ ?enve.tribs.test
38
+ ?enve.growthcurve
39
+ ?enve.col.alpha
40
+ ```
41
+
42
+ You can run some examples using these libraries in the
43
+ [enveomics-GUI](https://github.com/lmrodriguezr/enveomics-gui).
44
+
45
+ ## Changelog
46
+ * 1.1.0: New function enve.growthcurve and related class enve.GrowthCurve
47
+ with S3 methods plot and summary.
48
+ * 1.0.2: Fine-tuned default parameters in enve.recplot2.findPeaks and
49
+ solved a minor bug in enve.recplot2 that caused failures in low-coverage
50
+ datasets when using too many threads.
51
+ * 1.0.1: enve.recplot2 now supports pos.breaks=0 to define a
52
+ bin per subject sequence.