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,165 @@
1
+
2
+ enve.barplot <- structure(function(
3
+ ### Creates nice barplots from tab-delimited tables
4
+ x,
5
+ ### Can be either the input data or the path to the file containing the
6
+ ### table. If it contains the data, it must be a data frame or an object
7
+ ### coercible to data frame. If it is a path, it must point to a
8
+ ### tab-delimited file containing header (first row) and row names (first
9
+ ### column).
10
+ sizes,
11
+ ### A numeric vector containing the real size of the samples (columns) in
12
+ ### the same order of the input table. If set, the values are assumed to be
13
+ ### 100%, otherwise the sum of the columns is used.
14
+ top=25,
15
+ ### Maximum number of categories to display. Any additional categories will
16
+ ### be listed as "Others".
17
+ colors.per.group=9,
18
+ ### Number of categories in the first two saturation groups of colors. The
19
+ ### third group contains the remaining categories if needed.
20
+ bars.width=4,
21
+ ### Width of the barplot with respect to the legend.
22
+ legend.ncol=1,
23
+ ### Number of columns in the legend.
24
+ other.col='#000000',
25
+ ### Color of the "Others" category.
26
+ add.trend=FALSE,
27
+ ### Controls if semi-transparent areas are to be plotted between the bars to
28
+ ### connect the regions (trend regions).
29
+ organic.trend=FALSE,
30
+ ### Controls if the trend regions are to be smoothed (curves). By default,
31
+ ### trend regions have straight edges. If TRUE, forces add.trend=TRUE.
32
+ sort.by=median,
33
+ ### Any function that takes a numeric vector and returns a numeric scalar.
34
+ ### This function is applied to each row, and the resulting values are used
35
+ ### to sort the rows (decreasingly). Good options include: sd, min, max,
36
+ ### mean, median.
37
+ min.report=101,
38
+ ### Minimum percentage to report the value in the plot. Any value above 100
39
+ ### indicates that no values are to be reported.
40
+ order=NULL,
41
+ ### Controls how the rows should be ordered. If NULL (default), sort.by is
42
+ ### applied per row and the results are sorted decreasingly. If NA, no
43
+ ### sorting is performed, i.e., the original order is respected. If a vector
44
+ ### is provided, it is assumed to be the custom order to be used (either by
45
+ ### numeric index or by row names).
46
+ col,
47
+ ### Colors to use. If provided, overrides the variables `top` and
48
+ ### `colors.per.group`, but `other.col` is still used if the vector is
49
+ ### insufficient for all the rows. An additional palette is available with
50
+ ### col='coto' (contributed by Luis (Coto) Orellana).
51
+ ...
52
+ ### Any additional parameters to be passed to `barplot`.
53
+ ){
54
+
55
+ # Read input
56
+ if(is.character(x)){
57
+ c <- read.table(x, sep='\t', header=TRUE, row.names=1, quote='',
58
+ comment.char='')
59
+ }else{
60
+ c <- as.data.frame(x)
61
+ }
62
+ if(missing(sizes)) sizes = colSums(c)
63
+ p <- c
64
+ for (i in 1:ncol(c)) p[, i] <- c[, i]*100/sizes[i]
65
+ if(top > nrow(p)) top = nrow(p)
66
+
67
+ # Sort
68
+ if(is.null(order[1])){
69
+ p <- p[order(apply(p, 1, sort.by)), ]
70
+ }else if(is.na(order[1])){
71
+
72
+ }else{
73
+ p <- p[order, ]
74
+ }
75
+ if(organic.trend) add.trend=TRUE
76
+
77
+ # Colors
78
+ if(is.null(top)) top <- nrow(p)
79
+ if(missing(col)){
80
+ color.col <- rainbow(min(colors.per.group, top), s=1, v=4/5)
81
+ if(top > colors.per.group) color.col <- c(color.col,
82
+ rainbow(min(colors.per.group*2, top)-colors.per.group, s=3/4, v=3/5))
83
+ if(top > colors.per.group*2) color.col <- c(color.col,
84
+ rainbow(top-colors.per.group*2, s=1, v=1.25/4))
85
+ }else if(length(col)==1 & col=='coto'){
86
+ color.col <- c("#5BC0EB","#FDE74C","#9BC53D","#E55934","#FA7921","#EF476F",
87
+ "#FFD166","#06D6A0","#118AB2","#073B4C","#264653","#2A9D8F",
88
+ "#E9C46A","#F4A261","#E76F51")
89
+ color.col <- head(color.col, n=nrow(p))
90
+ top <- length(color.col)
91
+ }else{
92
+ color.col <- col
93
+ color.col <- tail(color.col, n=nrow(p))
94
+ top <- length(color.col)
95
+ }
96
+
97
+ # Plot
98
+ layout(matrix(1:2, nrow=1), widths=c(bars.width,1))
99
+ mar <- par('mar')
100
+ par(mar=c(5,4,4,0)+0.1)
101
+ mp <- barplot(as.matrix(p),
102
+ col=rev(c(color.col, rep(other.col, nrow(p)-length(color.col)))),
103
+ border=NA,space=ifelse(add.trend,ifelse(organic.trend,0.75,0.5),0.2), ...)
104
+ if(add.trend || min.report < max(p)){
105
+ color.alpha <- paste(c(substr(color.col, 1, 7), other.col), '40', sep='')
106
+ if(top < nrow(p)){
107
+ cf <- colSums(p[1:(nrow(p)-top), ])
108
+ }else{
109
+ cf <- rep(0, ncol(p))
110
+ }
111
+ for(i in (nrow(p)-top+1):nrow(p)){
112
+ f <- as.numeric(p[i, ])
113
+ cf <- as.numeric(cf + f)
114
+ if(nrow(p)-i < top){
115
+ if(organic.trend){
116
+ spc <- 0.5
117
+ x <- c(mp[1]-spc)
118
+ y1 <- c(cf[1]-f[1])
119
+ y2 <- c(cf[1])
120
+ for(j in 2:ncol(p)){
121
+ x <- c(x, seq(mp[j-1]+spc, mp[j]-spc, length.out=22))
122
+ y1 <- c(y1, cf[j-1]-f[j-1],
123
+ (tanh(seq(-2.5,2.5,length.out=20))/2+.5)*
124
+ ((cf[j]-f[j])-(cf[j-1]-f[j-1]))+(cf[j-1]-f[j-1]), cf[j]-f[j])
125
+ y2 <- c(y2, cf[j-1],
126
+ (tanh(seq(-2.5,2.5,length.out=20))/2+.5)*
127
+ (cf[j]-cf[j-1])+(cf[j-1]), cf[j])
128
+ }
129
+ x <- c(x, mp[length(mp)]+spc)
130
+ y1 <- c(y1, cf[length(cf)]-f[length(f)])
131
+ y2 <- c(y2, cf[length(cf)])
132
+ polygon(c(x, rev(x)), c(y1, rev(y2)), col=color.alpha[nrow(p)-i+1],
133
+ border=NA)
134
+ }else if(add.trend){
135
+ x <- rep(mp, each=2)+c(-0.5,0.5)
136
+ if(add.trend) polygon(c(x, rev(x)),
137
+ c(rep(cf-f, each=2), rev(rep(cf, each=2))),
138
+ col=color.alpha[nrow(p)-i+1], border=NA)
139
+ }
140
+ text(mp, cf-f/2, ifelse(f>min.report, signif(f, 3), ''), col='white')
141
+ }
142
+ }
143
+ }
144
+
145
+ # Legend
146
+ par(mar=rep(0,4)+0.1)
147
+ plot(1, t='n', bty='n', xlab='', ylab='', xaxt='n', yaxt='n')
148
+ nam <- rownames(p[nrow(p):(nrow(p)-top+1), ])
149
+ if(top < nrow(p)) nam <- c(nam,
150
+ paste('Other (',nrow(p)-length(color.col),')', sep=''))
151
+ legend('center', col=c(color.col, other.col), legend=nam, pch=15, bty='n',
152
+ pt.cex=2, ncol=legend.ncol)
153
+ par(mar=mar)
154
+ }, ex=function(){
155
+ # Load data
156
+ data("phyla.counts", package="enveomics.R", envir=environment())
157
+ # Create a barplot sorted by variance with organic trends
158
+ enve.barplot(phyla.counts, # Counts of phyla in four sites
159
+ sizes=c(250,100,75,200), # Total sizes of the datasets of each site
160
+ bars.width=2, # Decrease from default, so the names are fully displayed
161
+ organic.trend=TRUE, # Nice curvy background
162
+ sort.by=var # Sort by variance across sites
163
+ )
164
+ })
165
+
@@ -0,0 +1,119 @@
1
+ enve.cliopts <- function(
2
+ ### Generates nicely formatted command-line interfaces for
3
+ ### functions (_closures_ only).
4
+ fx,
5
+ ### Function for which the interface should be generated.
6
+ rd_file,
7
+ ### (Optional) .Rd file with the standard documentation of the function.
8
+ positional_arguments,
9
+ ### (Optional) Number of _positional_ arguments passed to parse_args
10
+ ### (package:optparse).
11
+ usage,
12
+ ### (Optional) Usage passed to OptionParser (package:optparse).
13
+ mandatory=c(),
14
+ ### Mandatory arguments.
15
+ vectorize=c(),
16
+ ### Arguments of the function to vectorize (comma-delimited). If numeric,
17
+ ### use also `number`.
18
+ ignore=c(),
19
+ ### Arguments of the function to ignore.
20
+ number=c(),
21
+ ### Force these arguments as numerics. Useful for numeric
22
+ ### vectors (see `vectorize`) or arguments with no defaults.
23
+ defaults=list(),
24
+ ### Defaults to use instead of the ones provided by the formals.
25
+ o_desc=list(),
26
+ ### Descriptions of the options. Help from `rd` is ignored for arguments
27
+ ### present in this list.
28
+ p_desc=""
29
+ ### Description of the function. Help from `rd` is ignored for the
30
+ ### function description unless this value is an empty string.
31
+ ){
32
+
33
+ #= Load stuff
34
+ if(!suppressPackageStartupMessages(
35
+ requireNamespace("optparse", quietly=TRUE)))
36
+ stop("Package 'optparse' is required.")
37
+ requireNamespace("tools", quietly=TRUE)
38
+ if(missing(positional_arguments)) positional_arguments <- FALSE
39
+ if(missing(usage)) usage <- "usage: %prog [options]"
40
+
41
+ #= Get help (if any)
42
+ if(!missing(rd_file)){
43
+ rd <- tools::parse_Rd(rd_file)
44
+ for(i in 1:length(rd)){
45
+ tag <- attr(rd[[i]],'Rd_tag')
46
+ if(tag=="\\description" && p_desc==""){
47
+ p_desc <- paste("\n\t",as.character(rd[[i]]),sep='')
48
+ }else if(tag=="\\arguments"){
49
+ for(j in 1:length(rd[[i]])){
50
+ if(length(rd[[i]][[j]])==2){
51
+ name <- as.character(rd[[i]][[j]][[1]])
52
+ if(length(o_desc[[name]])==1) next
53
+ desc <- as.character(rd[[i]][[j]][[2]])
54
+ o_desc[[name]] <- paste(gsub("\n","\n\t\t",desc), collapse='')
55
+ }
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ #= Set options
62
+ o_i <- 0
63
+ opts <- list()
64
+ f <- formals(fx)
65
+ if(length(defaults)>0){
66
+ for(i in 1:length(defaults)) f[[names(defaults)[i]]] <- defaults[[i]]
67
+ }
68
+ for(i in names(f)){
69
+ if(i=="..." || i %in% ignore) next
70
+ o_i <- o_i + 1
71
+ flag <- gsub("\\.","-",i)
72
+
73
+ optopt <- list(help="")
74
+ if(length(o_desc[[i]])==1) optopt$help <- o_desc[[i]]
75
+ if(!is.null(f[[i]]) && !suppressWarnings(is.na(f[[i]])) && is.logical(f[[i]])){
76
+ optopt$opt_str <- paste(ifelse(f[[i]], "--no-", "--"), flag, sep='')
77
+ optopt$action <- ifelse(f[[i]], "store_false", "store_true")
78
+ }else{
79
+ optopt$opt_str <- paste("--", flag, sep='')
80
+ optopt$action <- "store"
81
+ optopt$help <- paste(optopt$help, "\n\t\t[",
82
+ ifelse(i %in% mandatory, "** MANDATORY", "default %default"),
83
+ ifelse(i %in% vectorize, ", separate values by commas", ""),
84
+ "].", sep="")
85
+ }
86
+ if(!is.name(f[[i]])){
87
+ optopt$default <- f[[i]]
88
+ optopt$metavar <- class(f[[i]])
89
+ }
90
+ if(i %in% number) optopt$metavar <- "NUMERIC"
91
+ optopt$dest <- i
92
+
93
+ opts[[o_i]] <- do.call(optparse::make_option, optopt)
94
+ }
95
+ opt <- optparse::parse_args(
96
+ optparse::OptionParser(option_list=opts, description=p_desc, usage=usage),
97
+ positional_arguments=positional_arguments)
98
+
99
+ #= Post-hoc checks
100
+ if(length(opt[['options']])==0) opt <- list(options=opt, args=c())
101
+ for(i in mandatory){
102
+ if(length(opt$options[[i]])==0) stop('Missing mandatory argument: ',i)
103
+ }
104
+ for(i in vectorize){
105
+ if(length(opt$options[[i]])==1)
106
+ opt$options[[i]] <- strsplit(opt$options[[i]],",")[[1]]
107
+ }
108
+ for(i in number){
109
+ if(length(opt$options[[i]])>0)
110
+ opt$options[[i]] <- as.numeric(opt$options[[i]])
111
+ }
112
+ opt$options$help <- NULL
113
+
114
+ return(opt)
115
+ ### Returns a `list` with keys: `options`, a named list with the values for
116
+ ### the function's arguments; and `args`, a vector with zero or more strings
117
+ ### containing the positional arguments.
118
+ }
119
+
@@ -0,0 +1,117 @@
1
+
2
+ enve.df2dist <- function(
3
+ ### Transform a dataframe (or coercible object, like a table) into a `dist` object.
4
+ x,
5
+ ### A table (or coercible object) with at least three columns: (1) ID of the object 1,
6
+ ### (2) ID of the object 2, and (3) distance between the two objects.
7
+ obj1.index=1,
8
+ ### Index of the column containing the ID of the object 1.
9
+ obj2.index=2,
10
+ ### Index of the column containing the ID of the object 2.
11
+ dist.index=3,
12
+ ### Index of the column containing the distance.
13
+ default.d=NA,
14
+ ### Default value (for missing values)
15
+ max.sim=0
16
+ ### If not-zero, assumes that the values are similarity (not distance)
17
+ ### and this is the maximum similarity (corresponding to distance 0).
18
+ ### Applies transformation: distance = (max.sim - values)/max.sim.
19
+ ){
20
+ x <- as.data.frame(x);
21
+ a <- as.character(x[, obj1.index]);
22
+ b <- as.character(x[, obj2.index]);
23
+ d <- as.double(x[, dist.index]);
24
+ if(max.sim!=0) d <- (max.sim - d)/max.sim
25
+ ids <- unique(c(a,b));
26
+ m <- matrix(default.d, nrow=length(ids), ncol=length(ids), dimnames=list(ids, ids));
27
+ diag(m) <- 0.0
28
+ for(i in 1:nrow(x)){
29
+ m[a[i], b[i]] <- d[i];
30
+ }
31
+ m <- pmin(m, t(m), na.rm=TRUE)
32
+ return(as.dist(m));
33
+ ### Returns a `dist` object.
34
+ }
35
+
36
+
37
+
38
+ enve.df2dist.group <- function(
39
+ ### Transform a dataframe (or coercible object, like a table) into a `dist` object, where
40
+ ### there are 1 or more distances between each pair of objects.
41
+ x,
42
+ ### A dataframe (or coercible object) with at least three columns: (1) ID of the object 1,
43
+ ### (2) ID of the object 2, and (3) distance between the two objects.
44
+ obj1.index=1,
45
+ ### Index of the column containing the ID of the object 1.
46
+ obj2.index=2,
47
+ ### Index of the column containing the ID of the object 2.
48
+ dist.index=3,
49
+ ### Index of the column containing the distance.
50
+ summary=median,
51
+ ### Function summarizing the different distances between the two objects.
52
+ empty.rm=TRUE
53
+ ### Remove rows with empty or NA groups
54
+ ){
55
+ x <- as.data.frame(x);
56
+ if(empty.rm) x <- x[ !(is.na(x[,obj1.index]) | is.na(x[,obj2.index]) | x[,obj1.index]=='' | x[,obj2.index]==''), ]
57
+ a <- as.character(x[, obj1.index]);
58
+ b <- as.character(x[, obj2.index]);
59
+ d <- as.double(x[, dist.index]);
60
+ ids <- unique(c(a,b));
61
+ if(length(ids)<2) return(NA);
62
+ m <- matrix(NA, nrow=length(ids), ncol=length(ids), dimnames=list(ids, ids));
63
+ diag(m) <- 0
64
+ for(i in 2:length(ids)){
65
+ id.i <- ids[i];
66
+ for(j in 1:(i-1)){
67
+ id.j <- ids[j];
68
+ d.ij <- summary(c( d[ a==id.i & b==id.j], d[ b==id.i & a==id.j] ));
69
+ m[id.i, id.j] <- d.ij;
70
+ m[id.j, id.i] <- d.ij;
71
+ }
72
+ }
73
+ return(as.dist(m));
74
+ ### Returns a `dist` object.
75
+ }
76
+
77
+ enve.df2dist.list <- function(
78
+ ### Transform a dataframe (or coercible object, like a table) into a `dist` object.
79
+ x,
80
+ ### A dataframe (or coercible object) with at least three columns: (1) ID of the object 1,
81
+ ### (2) ID of the object 2, and (3) distance between the two objects.
82
+ groups,
83
+ ### Named array where the IDs correspond to the object IDs, and the values correspond to
84
+ ### the group.
85
+ obj1.index=1,
86
+ ### Index of the column containing the ID of the object 1.
87
+ obj2.index=2,
88
+ ### Index of the column containing the ID of the object 2.
89
+ dist.index=3,
90
+ ### Index of the column containing the distance.
91
+ empty.rm=TRUE,
92
+ ### Remove incomplete matrices
93
+ ...
94
+ ### Any other parameters supported by `enve.df2dist.group`.
95
+ ){
96
+ x <- as.data.frame(x);
97
+ a <- as.character(x[, obj1.index]);
98
+ b <- as.character(x[, obj2.index]);
99
+ d <- as.numeric(x[, dist.index]);
100
+ ids.all <- unique(c(a,b));
101
+ l <- list();
102
+ same_group <- groups[a]==groups[b];
103
+ same_group <- ifelse(is.na(same_group), FALSE, TRUE);
104
+ for(group in unique(groups)){
105
+ ids <- ids.all[ groups[ids.all]==group ];
106
+ if(length(ids)>1 & group!=""){
107
+ x.sub <- x[ same_group & (groups[a]==group) & (groups[b]==group), ]
108
+ if(nrow(x.sub)>0){
109
+ d.g <- enve.df2dist(x.sub, obj1.index, obj2.index, dist.index, ...);
110
+ if(!empty.rm | !any(is.na(d.g))) l[[ group ]] <- d.g;
111
+ }
112
+ }
113
+ }
114
+ return(l);
115
+ ### Returns a `list` of `dist` object.
116
+ }
117
+
@@ -0,0 +1,263 @@
1
+ #==============> Define S4 classes
2
+ setClass("enve.GrowthCurve",
3
+ ### Enve-omics representation of fitted growth curves.
4
+ representation(
5
+ design = "array", ##<< Experimental design of the experiment.
6
+ models = "list", ##<< Fitted growth curve models.
7
+ predict = "list", ##<< Fitted growth curve values.
8
+ call='call') ##<< Call producing this object.
9
+ ,package='enveomics.R');
10
+ setMethod("$", "enve.GrowthCurve", function(x, name) attr(x, name))
11
+
12
+ #==============> Define S4 methods
13
+ plot.enve.GrowthCurve <- function
14
+ ### Plots an `enve.GrowthCurve` object.
15
+ (x,
16
+ ### `enve.GrowthCurve` object to plot.
17
+ col,
18
+ ### Base colors to use for the different samples. Can be recycled. By
19
+ ### default, grey for one sample or rainbow colors for more than one.
20
+ pt.alpha=0.9,
21
+ ### Color alpha for the observed data points, using `col` as a base.
22
+ ln.alpha=1.0,
23
+ ### Color alpha for the fitted growth curve, using `col` as a base.
24
+ ln.lwd=1,
25
+ ### Line width for the fitted curve.
26
+ ln.lty=1,
27
+ ### Line type for the fitted curve.
28
+ band.alpha=0.4,
29
+ ### Color alpha for the confidence interval band of the fitted growth curve,
30
+ ### using `col` as a base.
31
+ band.density=NULL,
32
+ ### Density of the filling pattern in the interval band. If NULL, a solid
33
+ ### color is used.
34
+ band.angle=45,
35
+ ### Angle of the density filling pattern in the interval band. Ignored if
36
+ ### `band.density` is NULL.
37
+ xp.alpha=0.5,
38
+ ### Color alpha for the line connecting individual experiments, using `col`
39
+ ### as a base.
40
+ xp.lwd=1,
41
+ ### Width of line for the experiments.
42
+ xp.lty=1,
43
+ ### Type of line for the experiments.
44
+ pch=19,
45
+ ### Point character for observed data points.
46
+ new=TRUE,
47
+ ### Should a new plot be generated? If FALSE, the existing canvas is used.
48
+ legend=new,
49
+ ### Should the plot include a legend? If FALSE, no legend is added. If TRUE,
50
+ ### a legend is added in the bottom-right corner. Otherwise, a legend is
51
+ ### added in the position specified as `xy.coords`.
52
+ add.params=FALSE,
53
+ ### Should the legend include the parameters of the fitted model?
54
+ ...
55
+ ### Any other graphic parameters.
56
+ ){
57
+
58
+ # Arguments
59
+ if(missing(col)){
60
+ col <-
61
+ if(length(x$design)==0) grey(0.2)
62
+ else rainbow(length(x$design), v=3/5, s=3/5)
63
+ }
64
+
65
+ if(new){
66
+ # Initiate canvas
67
+ od.fit.max <- max(sapply(x$predict, function(x) max(x[,"upr"])))
68
+ od.obs.max <- max(sapply(x$models, function(x) max(x$data[,"od"])))
69
+ opts <- list(...)
70
+ plot.defaults <- list(xlab="Time", ylab="Density",
71
+ xlim=range(x$predict[[1]][,"t"]), ylim=c(0, max(od.fit.max, od.obs.max)))
72
+ for(i in names(plot.defaults)){
73
+ if(is.null(opts[[i]])) opts[[i]] <- plot.defaults[[i]]
74
+ }
75
+ opts[["x"]] <- 1
76
+ opts[["type"]] <- "n"
77
+ do.call(plot, opts)
78
+ }
79
+
80
+ # Graphic default
81
+ pch <- rep(pch, length.out=length(x$design))
82
+ col <- rep(col, length.out=length(x$design))
83
+ pt.col <- enve.col2alpha(col, pt.alpha)
84
+ ln.col <- enve.col2alpha(col, ln.alpha)
85
+ band.col <- enve.col2alpha(col, band.alpha)
86
+ xp.col <- enve.col2alpha(col, xp.alpha)
87
+ band.angle <- rep(band.angle, length.out=length(x$design))
88
+ if(!all(is.null(band.density))){
89
+ band.density <- rep(band.density, length.out=length(x$design))
90
+ }
91
+
92
+ for(i in 1:length(x$design)){
93
+ # Observed data
94
+ d <- x$models[[i]]$data
95
+ points(d[,"t"], d[,"od"], pch=pch[i], col=pt.col[i])
96
+ for(j in unique(d[,"replicate"])){
97
+ sel <- d[,"replicate"]==j
98
+ lines(d[sel,"t"], d[sel,"od"], col=xp.col[i], lwd=xp.lwd, lty=xp.lty)
99
+ }
100
+ # Fitted growth curves
101
+ if(x$models[[i]]$convInfo$isConv){
102
+ d <- x$predict[[i]]
103
+ lines(d[,"t"], d[,"fit"], col=ln.col[i], lwd=ln.lwd, lty=ln.lty)
104
+ polygon(c(d[,"t"], rev(d[,"t"])), c(d[,"lwr"], rev(d[,"upr"])),
105
+ border=NA, col=band.col[i], density=band.density[i],
106
+ angle=band.angle[i])
107
+ }
108
+ }
109
+
110
+ if(!all(is.logical(legend)) || legend){
111
+ if(all(is.logical(legend))) legend <- "bottomright"
112
+ legend.txt <- names(x$design)
113
+ if(add.params){
114
+ for(p in names(coef(x$models[[1]]))){
115
+ legend.txt <- paste(legend.txt, ", ", p, "=",
116
+ sapply(x$models, function(x) signif(coef(x)[p],2)) , sep="")
117
+ }
118
+ }
119
+ legend(legend, legend=legend.txt, pch=pch, col=ln.col)
120
+ }
121
+ }
122
+
123
+ summary.enve.GrowthCurve <- function(
124
+ ### Summary of an `enve.GrowthCurve` object.
125
+ object,
126
+ ### `enve.GrowthCurve` object.
127
+ ...
128
+ ### No additional parameters are currently supported.
129
+ ){
130
+
131
+ x <- object
132
+ cat('===[ enve.GrowthCurves ]------------------\n')
133
+ for(i in names(x$design)){
134
+ cat(i, ':\n', sep='')
135
+ if(x$models[[i]]$convInfo$isConv){
136
+ for(j in names(coef(x$models[[i]]))){
137
+ cat(' - ', j, ' = ', coef(x$models[[i]])[j], '\n', sep='')
138
+ }
139
+ }else{
140
+ cat(' Model didn\'t converge:\n ',
141
+ x$models[[i]]$convInfo$stopMessage, '\n', sep='')
142
+ }
143
+ cat(' ', nrow(x$models[[i]]$data), ' observations, ',
144
+ length(unique(x$models[[i]]$data[,"replicate"])), ' replicates.\n',
145
+ sep='')
146
+ }
147
+ cat('------------------------------------------\n')
148
+ cat('call:',as.character(attr(x,'call')),'\n')
149
+ cat('------------------------------------------\n')
150
+ }
151
+
152
+ #==============> Core functions
153
+ enve.growthcurve <- structure(function(
154
+ ### Calculates growth curves using the logistic growth function.
155
+ x,
156
+ ### Data frame (or coercible) containing the observed growth data (e.g.,
157
+ ### O.D. values). Each column is an independent growth curve and each
158
+ ### row is a time point. NA's are allowed.
159
+ times=1:nrow(x),
160
+ ### Vector with the times at which each row was taken. By default, all
161
+ ### rows are assumed to be part of constantly periodic measurements.
162
+ triplicates=FALSE,
163
+ ### If TRUE, the columns are assumed to be sorted by sample with three
164
+ ### replicates by sample. It requires a number of columns multiple of 3.
165
+ design,
166
+ ### Experimental design of the data. An `array` of mode list with sample
167
+ ### names as index and the list of column names in each sample as the
168
+ ### values. By default, each column is assumed to be an independent sample
169
+ ### if `triplicates` is FALSE, or every three columns are assumed to be a
170
+ ### sample if `triplicates` is TRUE. In the latter case, samples are
171
+ ### simply numbered.
172
+ new.times=seq(min(times), max(times), length.out=length(times)*10),
173
+ ### Values of time for the fitted curve.
174
+ level=0.95,
175
+ ### Confidence (or prediction) interval in the fitted curve.
176
+ interval=c("confidence","prediction"),
177
+ ### Type of interval to be calculated for the fitted curve.
178
+ plot=TRUE,
179
+ ### Should the growth curve be plotted?
180
+ FUN=function(t,K,r,P0) K*P0*exp(r*t)/(K+P0*(exp(r*t)-1)),
181
+ ### Function to fit. By default: logistic growth with paramenters `K`:
182
+ ### carrying capacity, `r`: intrinsic growth rate, and `P0`: Initial
183
+ ### population.
184
+ nls.opt=list(),
185
+ ### Any additional options passed to `nls`.
186
+ ...
187
+ ### Any additional parameters to be passed to `plot.enve.GrowthCurve`.
188
+ ){
189
+
190
+ # Arguments
191
+ if(missing(design)){
192
+ design <-
193
+ if(triplicates)
194
+ tapply(colnames(x), colnames(x)[rep(1:(ncol(x)/3)*3-2, each=3)], c,
195
+ simplify=FALSE)
196
+ else tapply(colnames(x), colnames(x), c, simplify=FALSE)
197
+ }
198
+ mod <- list()
199
+ fit <- list()
200
+ interval <- match.arg(interval)
201
+ enve._growth.fx <- NULL
202
+ enve._growth.fx <<- FUN
203
+
204
+ for(sample in names(design)){
205
+ od <- c()
206
+ for(col in design[[sample]]){
207
+ od <- c(od, x[,col])
208
+ }
209
+ data <- data.frame(t=rep(times, length(design[[sample]])), od=od,
210
+ replicate=rep(1:length(design[[sample]]), each=length(times)))
211
+ data <- data[!is.na(data$od),]
212
+ opts <- nls.opt
213
+ opts[["data"]] <- data
214
+ opt.defaults <- list(formula = od ~ enve._growth.fx(t, K, r, P0),
215
+ algorithm="port", lower=list(P0=1e-16),
216
+ control=nls.control(warnOnly=TRUE),
217
+ start=list(
218
+ K = 2*max(data$od),
219
+ r = length(times)/max(data$t),
220
+ P0 = min(data$od[data$od>0])
221
+ ))
222
+ for(i in names(opt.defaults)){
223
+ if(is.null(opts[[i]])){
224
+ opts[[i]] <- opt.defaults[[i]]
225
+ }
226
+ }
227
+ mod[[sample]] <- do.call(nls, opts)
228
+ fit[[sample]] <- cbind(t=new.times,
229
+ predFit(mod[[sample]], level=level, interval=interval,
230
+ newdata=data.frame(t=new.times)))
231
+ }
232
+ enve._growth.fx <<- NULL
233
+ gc <- new("enve.GrowthCurve",
234
+ design=design, models=mod, predict=fit,
235
+ call=match.call());
236
+ if(plot) plot(gc, ...);
237
+ return(gc)
238
+ ### Returns an `enve.GrowthCurve` object.
239
+ }, ex=function(){
240
+ # Load data
241
+ data("growth.curves", package="enveomics.R", envir=environment())
242
+ # Generate growth curves with different colors
243
+ g <- enve.growthcurve(growth.curves[,-1], growth.curves[,1], triplicates=TRUE)
244
+ # Generate black-and-white growth curves with different symbols
245
+ plot(g, pch=15:17, col="black", band.density=45, band.angle=c(-45,45,0))
246
+ });
247
+
248
+ enve.col2alpha <- function(
249
+ ### Takes a vector of colors and sets the alpha.
250
+ x,
251
+ ### A vector of any value base colors.
252
+ alpha
253
+ ### Alpha level to set (in the 0-1 range).
254
+ ){
255
+ out <- c()
256
+ for(i in x){
257
+ opt <- as.list(col2rgb(i)[,1]/256)
258
+ opt[["alpha"]] = alpha
259
+ out <- c(out, do.call(rgb, opt))
260
+ }
261
+ names(out) <- names(x)
262
+ return(out)
263
+ }