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,234 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #
4
+ # @author Luis M. Rodriguez-R
5
+ # @update Jan-13-2016
6
+ # @license artistic license 2.0
7
+ #
8
+
9
+ require "optparse"
10
+
11
+ o = {:q=>false}
12
+ ARGV << "-h" if ARGV.size==0
13
+ OptionParser.new do |opts|
14
+ opts.banner = "
15
+ Uses a dichotomous key to classify objects parsing a character table.
16
+
17
+ Usage: #{$0} [options]"
18
+ opts.separator ""
19
+ opts.separator "Input Options (mandatory)"
20
+ opts.on("-t", "--table FILE",
21
+ "Input table containing the states (columns) per object (row).",
22
+ "It must be tab-delimited and with row and column names.",
23
+ "See Tests/anthrax-cansnp-data.tsv for an example."){ |v| o[:table]=v }
24
+ opts.on("-k", "--key FILE",
25
+ "Input table containing the dychotomous key in linked style, defined in",
26
+ "four columns (can contain #-lead comment lines):",
27
+ " 1. ID of the step, typically a sequential integer.",
28
+ " 2. Name of character to evaluate. Must coincide with the -t headers.",
29
+ " 3. First character decision (see below).",
30
+ " 4. Second character decision (see below).",
31
+ "A character decision must be formated as: state (must coincide with the",
32
+ "values in -t), colon (:), step to follow. If the state is * (star) any",
33
+ "state triggers the decision (this should be the norm in column 4). The",
34
+ "step to follow should be a step ID in square brackets, or the name of",
35
+ "the classification. See Tests/anthrax-cansnp-key.tsv for an example."
36
+ ){ |v| o[:key]=v }
37
+ opts.separator ""
38
+ opts.separator "Output Options"
39
+ opts.on("-c", "--classification FILE",
40
+ "Two-column table with the classification of the input objects."
41
+ ){ |v| o[:class]=v }
42
+ opts.on("-n", "--newick FILE",
43
+ "Tree containing all the classified objects. This only makes sense for",
44
+ "synoptic keys."){ |v| o[:nwk]=v }
45
+ opts.separator ""
46
+ opts.separator "Additional Options"
47
+ opts.on("-q", "--quiet", "Run quietly (no STDERR output)."){ o[:q] = true }
48
+ opts.on("-h", "--help", "Display this screen.") do
49
+ puts opts
50
+ exit
51
+ end
52
+ opts.separator ""
53
+ end.parse!
54
+ abort "-t is mandatory" if o[:table].nil?
55
+ abort "-k is mandatory" if o[:key].nil?
56
+
57
+ ##### Extensions:
58
+ class String
59
+ def nwk_sanitize() self.gsub(/[\(\):;,"'\s]/,'_') ; end
60
+ end
61
+
62
+ ##### Classes:
63
+ module Dychotomous
64
+ class Decision
65
+ attr_reader :state, :terminal, :conclusion
66
+ def initialize(string)
67
+ r = string.split /:/
68
+ @state = r[0]
69
+ @terminal = !(r[1] =~ /^\[(.*)\]$/)
70
+ @conclusion = @terminal ? r[1] : $1
71
+ end
72
+ def ==(state)
73
+ return true if self.state == '*'
74
+ self.state == state.to_s
75
+ end
76
+ end
77
+ class Character
78
+ attr_reader :name, :a, :b
79
+ def initialize(name, a, b)
80
+ @name = name
81
+ @a = a
82
+ @b = b
83
+ end
84
+ def eval(object)
85
+ state = object.state(self.name)
86
+ return self.a if self.a == state
87
+ return self.b if self.b == state
88
+ raise "Impossible to make a decision for #{object.name} based on " +
89
+ "character #{self.name}. Offending state: #{state.to_s}."
90
+ end
91
+ end
92
+ class Key
93
+ attr_reader :first
94
+ def initialize(file)
95
+ @characters = {}
96
+ fh = File.open(file, 'r')
97
+ while ln = fh.gets
98
+ next if ln=~/^#/ or ln=~/^\s*$/
99
+ r = ln.chomp.split /\t/
100
+ @characters[ r[0] ] = Character.new(r[1],
101
+ Decision.new(r[2]), Decision.new(r[3]))
102
+ @first = @characters[ r[0] ] if @first.nil?
103
+ end
104
+ fh.close
105
+ end
106
+ def [](name)
107
+ raise "Cannot find character #{name} in key." if @characters[name].nil?
108
+ @characters[name]
109
+ end
110
+ end
111
+ end
112
+ module CharData
113
+ class Object
114
+ attr_reader :name, :states
115
+ def initialize(name)
116
+ @name = name
117
+ @states = {}
118
+ end
119
+ def <<(state) @states[state.character] = state ; end
120
+ def state(name) @states[name] ; end
121
+ end
122
+ class State
123
+ attr_reader :character, :state
124
+ def initialize(character, state)
125
+ @character = character
126
+ @state = state
127
+ end
128
+ def to_s() self.state.to_s ; end
129
+ end
130
+ class Table
131
+ attr_reader :objects
132
+ def initialize(file)
133
+ @objects = []
134
+ fh = File.open(file, 'r')
135
+ header = fh.gets.chomp.split(/\t/)
136
+ while ln = fh.gets
137
+ next if ln=~/^#/ or ln=~/^\s*$/
138
+ r = ln.chomp.split /\t/
139
+ o = Object.new(r[0])
140
+ (1 .. r.size).each{ |i| o << State.new(header[i], r[i]) }
141
+ self << o
142
+ end
143
+ fh.close
144
+ end
145
+ def <<(object) @objects << object ; end
146
+ end
147
+ end
148
+ module ClassData
149
+ class Classification
150
+ attr_reader :key, :object, :result
151
+ def initialize key, object
152
+ @key = key
153
+ @object = object
154
+ self.classify!
155
+ end
156
+ def classify!
157
+ @result = self.key.first.eval(object)
158
+ while ! self.result.terminal
159
+ @result = self.key[ self.result.conclusion ].eval(object)
160
+ end
161
+ end
162
+ end
163
+ class Collection
164
+ attr_reader :key, :table, :classifications
165
+ def initialize(key, table)
166
+ @key = key
167
+ @table = table
168
+ @classifications = []
169
+ self.classify!
170
+ end
171
+ def classify!
172
+ table.objects.each do |object|
173
+ @classifications << Classification.new(key, object)
174
+ end
175
+ end
176
+ def classified_as(conclusion)
177
+ self.classifications.select{ |c|
178
+ c.result.conclusion==conclusion }.map{ |c| c.object }
179
+ end
180
+ def to_nwk
181
+ self.to_nwk_node(self.key.first) + ";"
182
+ end
183
+ def to_nwk_node(node)
184
+ if node.is_a? Dychotomous::Character
185
+ a = self.to_nwk_node(node.a)
186
+ b = self.to_nwk_node(node.b)
187
+ return "" if (a + b)==""
188
+ return "(" + a + b + ")#{node.name.nwk_sanitize}" if a=="" or b==""
189
+ return "(" + self.to_nwk_node(node.a) + "," +
190
+ self.to_nwk_node(node.b) + ")#{node.name.nwk_sanitize}"
191
+ end
192
+ if node.is_a? Dychotomous::Decision and node.terminal
193
+ objects = self.classified_as(node.conclusion)
194
+ return '' if objects.empty?
195
+ return objects[0].name.nwk_sanitize if objects.size==1
196
+ return "(" + objects.map{|o| o.name.nwk_sanitize}.join(",") + ")"
197
+ end
198
+ return self.to_nwk_node( self.key[node.conclusion] ) if
199
+ node.is_a? Dychotomous::Decision
200
+ raise "Unsupported class: to_nwk_node: #{node}."
201
+ end
202
+ end
203
+ end
204
+
205
+ ##### MAIN:
206
+ begin
207
+ $stderr.puts "Reading dychotomous key." unless o[:q]
208
+ key = Dychotomous::Key.new(o[:key])
209
+ $stderr.puts "Reading character table." unless o[:q]
210
+ table = CharData::Table.new(o[:table])
211
+ $stderr.puts "Classifying objects." unless o[:q]
212
+ classif = ClassData::Collection.new(key, table)
213
+
214
+ unless o[:class].nil?
215
+ $stderr.puts "Generating classification table." unless o[:q]
216
+ fh = File.open(o[:class], 'w')
217
+ classif.classifications.each do |c|
218
+ fh.puts c.object.name + "\t" + c.result.conclusion
219
+ end
220
+ fh.close
221
+ end
222
+
223
+ unless o[:nwk].nil?
224
+ $stderr.puts "Generating classification tree." unless o[:q]
225
+ fh = File.open(o[:nwk], 'w')
226
+ fh.puts classif.to_nwk
227
+ fh.close
228
+ end
229
+
230
+ rescue => err
231
+ $stderr.puts "Exception: #{err}\n\n"
232
+ err.backtrace.each { |l| $stderr.puts l + "\n" }
233
+ err
234
+ end
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #
4
+ # @author Luis M. Rodriguez-R <lmrodriguezr at gmail dot com>
5
+ # @update Oct-13-2015
6
+ # @license Artistic License 2.0
7
+ #
8
+
9
+ $:.push File.expand_path(File.dirname(__FILE__) + "/lib")
10
+ require "enveomics_rb/remote_data"
11
+ use "nokogiri"
12
+
13
+ #================================[ Options parsing ]
14
+ $o = {
15
+ q: false, ids: [], dbfrom: "uniprotkb", header: true,
16
+ ret: "ScientificName",
17
+ ranks: %w(superkingdom phylum class order family genus species)}
18
+
19
+ OptionParser.new do |opt|
20
+ opt.banner = "
21
+ Maps a list of EBI-supported IDs to their corresponding NCBI taxonomy using
22
+ EBI RESTful API. Avoid using this script on millions of entries at a time,
23
+ since each entry elicits requests to EBI and NCBI servers.
24
+
25
+ Usage: #{$0} [options]".gsub(/^ +/,"")
26
+ opt.separator ""
27
+ opt.on("-i", "--ids ID1,ID2,...", Array,
28
+ "Comma-separated list of EBI IDs. Required unless -I is passed."
29
+ ){ |v| $o[:ids]=v }
30
+ opt.on("-I", "--infile FILE",
31
+ "Raw text file containing the list of EBI IDs, one per line.",
32
+ "Required unless -i is passed."){ |v| $o[:infile]=v }
33
+ opt.on("-d", "--database DB",
34
+ "EBI database defining the EBI IDs. By default: " + $o[:dbfrom].to_s + "."
35
+ ){ |v| $o[:dbfrom]=v }
36
+ opt.on("-r", "--ranks RANK1,RANK2,...", Array,
37
+ "Taxonomic ranks to report. By default:",
38
+ $o[:ranks].join(",") + "."){ |v| $o[:ranks]=v }
39
+ opt.on("-n", "--noheader",
40
+ "Do not includ a header in the output."){ $o[:header]=false }
41
+ opt.on("-t", "--taxids",
42
+ "Return Taxonomy IDs instead of scientific names."){ $o[:ret]="TaxId" }
43
+ opt.on("-q", "--quiet", "Run quietly."){ |v| $o[:q]=true }
44
+ opt.on("-h", "--help","Display this screen") do
45
+ puts opt
46
+ exit
47
+ end
48
+ opt.separator ""
49
+ end.parse!
50
+
51
+ #================================[ Main ]
52
+ begin
53
+ $o[:ids] += File.readlines($o[:infile]).map{ |l| l.chomp } unless
54
+ $o[:infile].nil?
55
+ $o[:ranks].map!{ |r| r.downcase }
56
+ puts (["ID", "TaxId"] + $o[:ranks].map{ |r| r.capitalize }).join("\t") if
57
+ $o[:header]
58
+ $o[:ids].each do |id|
59
+ id = $1 if id =~ /^[a-z]+\|\S+\|(\S+)/
60
+ taxid = RemoteData.ebiseq2taxid(id, $o[:dbfrom])
61
+ if taxid.nil?
62
+ warn "Cannot find link to taxonomy: #{id}"
63
+ next
64
+ end
65
+ taxonomy = {}
66
+ unless taxid.nil?
67
+ doc = Nokogiri::XML( RemoteData.efetch({db: "taxonomy", id: taxid}) )
68
+ taxonomy[ doc.at_xpath("/TaxaSet/Taxon/Rank").content ] =
69
+ doc.at_xpath("/TaxaSet/Taxon/#{$o[:ret]}").content
70
+ doc.xpath("/TaxaSet/Taxon/LineageEx/Taxon").each do |taxon|
71
+ taxonomy[ taxon.at_xpath("./Rank").content ] =
72
+ taxon.at_xpath("./#{$o[:ret]}").content
73
+ end
74
+ end
75
+ puts ([id, taxid] +
76
+ $o[:ranks].map{ |rank| taxonomy[ rank ] ||= "" }).join("\t")
77
+ end # $o[:ids].each
78
+ rescue => err
79
+ $stderr.puts "Exception: #{err}\n\n"
80
+ err.backtrace.each { |l| $stderr.puts l + "\n" }
81
+ err
82
+ end
83
+
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env perl
2
+ #
3
+ # @author: Luis M. Rodriguez-R <lmrodriguezr at gmail dot com>
4
+ # @update: Oct 07 2015
5
+ # @license: artistic license 2.0
6
+ #
7
+ use strict;
8
+ use warnings;
9
+ use List::Util qw/sum min max/;
10
+
11
+ my ($seqs, $minlen, $n__) = @ARGV;
12
+ $seqs or die "
13
+ Description:
14
+ Calculates the N50 value of a set of sequences. Alternatively, it
15
+ can calculate other N** values. It also calculates the total number
16
+ of sequences and the total added length.
17
+
18
+ Usage:
19
+ $0 seqs.fa[ minlen[ **]]
20
+
21
+ seqs.fa A FastA file containing the sequences.
22
+ minlen (optional) The minimum length to take into consideration.
23
+ By default: 0.
24
+ ** Value N** to calculate. By default: 50 (N50).
25
+ ";
26
+ $minlen ||= 0;
27
+ $n__ ||= 50;
28
+
29
+ my @len = ();
30
+ open SEQ, "<", $seqs or die "Cannot open file: $seqs: $!\n";
31
+ while(<SEQ>){
32
+ if(/^>/){
33
+ push @len, 0;
34
+ }else{
35
+ next if /^;/;
36
+ chomp;
37
+ s/\W//g;
38
+ $len[-1]+=length $_;
39
+ }
40
+ }
41
+ close SEQ;
42
+ @len = sort { $a <=> $b } map { $_>=$minlen?$_:() } @len;
43
+ my $tot = (sum(@len) || 0);
44
+
45
+ my $thr = $n__*$tot/100;
46
+ my $pos = 0;
47
+ for(@len){
48
+ $pos+= $_;
49
+ if($pos>=$thr){
50
+ print "N$n__: $_\n";
51
+ last;
52
+ }
53
+ }
54
+ print "Sequences: ".scalar(@len)."\n";
55
+ print "Total length: $tot\n";
56
+
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env perl
2
+ #
3
+ # @author Luis M. Rodriguez-R <lmrodriguezr at gmail dot com>
4
+ # @update Oct-07-2015
5
+ # @license artistic license 2.0
6
+ #
7
+
8
+ use warnings;
9
+ use strict;
10
+ use Getopt::Std;
11
+
12
+ sub HELP_MESSAGE { die "
13
+ .Description:
14
+ Extracts a subset of sequences from a FastA file.
15
+
16
+ .Usage: $0 [options] list.txt seqs.fa > subset.fa
17
+
18
+ [options]
19
+ -r Reverse list. Extracts sequences NOT present in the list.
20
+ -q Runs quietly.
21
+ -h Prints this message and exits.
22
+
23
+ [mandatory]
24
+ list.txt List of sequences to extract.
25
+ seqs.fa FastA file containing the superset of sequences.
26
+ subset.fa FastA file to be created.
27
+
28
+ " }
29
+
30
+ my %o=();
31
+ getopts('rhq', \%o);
32
+ my($list, $fa) = @ARGV;
33
+ ($list and $fa) or &HELP_MESSAGE;
34
+ $o{h} and &HELP_MESSAGE;
35
+
36
+ print STDERR "Reading list.\n" unless $o{q};
37
+ open LI, "<", $list or die "Cannot read file: $list: $!\n";
38
+ my %li = map { chomp; $_ => 1 } <LI>;
39
+ close LI;
40
+
41
+ print STDERR "Filtering FastA.\n" unless $o{q};
42
+ open FA, "<", $fa or die "Cannot read file: $fa: $!\n";
43
+ my $good = 0;
44
+ while(my $ln = <FA>){
45
+ next if $ln =~ /^;/;
46
+ chomp $ln;
47
+ if($ln =~ m/^>((\S+).*)/){ $good = (exists $li{$1} or exists $li{">$1"} or exists $li{$2} or exists $li{$ln}) }
48
+ elsif($ln =~ m/^>/){ $good=$o{r}; print STDERR "Warning: Non-cannonical defline, line $.: $ln\n" }
49
+ print "$ln\n" if (($good and not $o{r}) or ($o{r} and not $good));
50
+ }
51
+ close FA;
52
+
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env perl
2
+
3
+ use warnings;
4
+ use strict;
5
+ use Bio::SeqIO;
6
+
7
+ my $file = $ARGV[0];
8
+ my $min = $ARGV[1];
9
+ ($file and $min) or die <<HELP
10
+
11
+ This script will filter a multi fastA file by length
12
+
13
+ Usage "perl $0 fastafile minlenght "
14
+ HELP
15
+ ;
16
+ my $seq_in = Bio::SeqIO->new( -format => 'fasta',-file => $file);
17
+
18
+ while( my $seq1 = $seq_in->next_seq() ) {
19
+
20
+ my $id = $seq1->primary_id;
21
+ chomp $id;
22
+ my $seq = $seq1->seq;
23
+ chomp $seq;
24
+ my $lseq = length($seq);
25
+ if($lseq>=$min){
26
+ print ">$id","\n",$seq,"\n";
27
+ }
28
+ }