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,147 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # @author Luis M. Rodriguez-R
4
+ # @license Artistic-2.0
5
+
6
+ $:.push File.expand_path("../lib", __FILE__)
7
+ require "enveomics_rb/enveomics"
8
+ require "enveomics_rb/vcf"
9
+
10
+ o = {}
11
+ OptionParser.new do |opt|
12
+ opt.banner = "
13
+ Estimates the Ka/Ks ratio from the SNPs in a VCF file. Ka and Ks are corrected
14
+ using pseudo-counts, but no corrections for multiple substitutions are
15
+ applied.
16
+
17
+ Usage: #{$0} [options]".gsub(/^ +/,"")
18
+ opt.separator ""
19
+ opt.separator "Mandatory"
20
+ opt.on("-i", "--input FILE",
21
+ "Input file in Variant Call Format (VCF)."){ |v| o[:file] = v}
22
+ opt.on("-s", "--seqs FILE",
23
+ "Input gene sequences (nucleotides) in FastA format."){ |v| o[:seqs] = v}
24
+ opt.separator ""
25
+ opt.separator "Parameters"
26
+ opt.on("-f", "--syn-frx FLOAT",
27
+ "Fraction of synonymous substitutions. If passed, the number of sites are",
28
+ "estimated (not counted per gene), speeding up the computation ~10X."
29
+ ){ |v| o[:syn_frx] = v.to_f }
30
+ opt.on("-b", "--syn-bacterial-code",
31
+ "Sets --syn-frx to 0.760417, approximately the proportion of synonymous",
32
+ "substitutions in the bacterial code."){ o[:syn_frx] = 0.760417 }
33
+ opt.separator ""
34
+ opt.separator "Miscellaneous"
35
+ opt.on("-c", "--codon-file FILE",
36
+ "Output file including the codons of substitution variants."
37
+ ){ |v| o[:codon_file] = v }
38
+ opt.on("-h", "--help", "Display this screen.") do
39
+ puts opt
40
+ exit
41
+ end
42
+ opt.separator ""
43
+ end.parse!
44
+
45
+ abort "--input is mandatory" if o[:file].nil?
46
+ abort "--seqs is mandatory" if o[:seqs].nil?
47
+
48
+ # Codon table (11. The Bacterial, Archaeal and Plant Plastid Code)
49
+ # https://www.ncbi.nlm.nih.gov/Taxonomy/Utils/wprintgc.cgi#SG11
50
+ t = {
51
+ AAs: "FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
52
+ Starts: "---M------**--*----M------------MMMM---------------M------------",
53
+ Base1: "TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG",
54
+ Base2: "TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG",
55
+ Base3: "TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG"
56
+ }
57
+ $codon_aa = {}
58
+ $codon_st = {}
59
+ (0 .. (t[:Base1].size-1)).each do |i|
60
+ cod = [:Base1, :Base2, :Base3].map{ |k| t[k][i] }.join
61
+ $codon_aa[cod] = t[:AAs][i]
62
+ $codon_st[cod] = t[:Starts][i]
63
+ end
64
+
65
+ ##
66
+ # Is the change +cod+ to +cod_alt+ synonymous? +start_codon+ indicates if the
67
+ # codon the first in the gene.
68
+ def syn?(cod, cod_alt, start_codon=false)
69
+ start_codon ?
70
+ ( $codon_st[cod] == $codon_st[cod_alt] ) :
71
+ ( $codon_aa[cod] == $codon_aa[cod_alt] )
72
+ end
73
+
74
+ ##
75
+ # Estimates the fraction of times that the substitutions in the sequence +seq+
76
+ # result in synonymous mutations from those in position +pos+ by any of the
77
+ # nucleotides in +alts+.
78
+ def syn_fraction(seq, pos, alts)
79
+ cod_let = (pos-1)%3
80
+ cod_pos = (pos-1) - cod_let
81
+ cod = seq[cod_pos .. (cod_pos+2)]
82
+ syn = 0
83
+ cod_alts = alts.map do |alt|
84
+ cod_alt = "#{cod}"
85
+ cod_alt[cod_let] = alt
86
+ cod_alt
87
+ end
88
+ syn = cod_alts.map{ |i| syn?(cod, i, pos<=3) ? 1 : 0 }.inject(0,:+)
89
+ $codon_fh.puts [syn, cod, cod_alts.join(",")].join("\t") unless $codon_fh.nil?
90
+ syn.to_f/alts.size
91
+ end
92
+
93
+ # Read sequences
94
+ seqs = {}
95
+ File.open(o[:seqs], "r") do |fh|
96
+ id = ""
97
+ fh.each_line do |ln|
98
+ if ln =~ /^>(\S+)/
99
+ id = $1
100
+ seqs[id] = ""
101
+ else
102
+ seqs[id] += ln.chomp.gsub(/[^A-Za-z]/, "")
103
+ end
104
+ end
105
+ end
106
+
107
+ # Process variants
108
+ $codon_fh = nil
109
+ unless o[:codon_file].nil?
110
+ $codon_fh = File.open(o[:codon_file], "w")
111
+ $codon_fh.puts "#" + %w[Syn Ref Alt].join("\t")
112
+ end
113
+ vcf = VCF.new(o[:file])
114
+ gen = {}
115
+ vcf.each_variant do |v|
116
+ next if v.indel?
117
+ raise "REF doesn't match VCF:\n#{v}" unless seqs[v.chrom][v.pos-1] == v.ref
118
+ gen[v.chrom] ||= [0.0, 0.0]
119
+ alts = v.alt.split(",")
120
+ syn = syn_fraction(seqs[v.chrom], v.pos, alts)
121
+ gen[v.chrom][0] += 1.0-syn
122
+ gen[v.chrom][1] += syn
123
+ end
124
+ $codon_fh.close unless $codon_fh.nil?
125
+ $codon_fh = nil
126
+
127
+ # Ka/Ks
128
+ puts "#" +
129
+ "SeqID KaKs Ka Ks NonSynSubs SynSubs NonSynSites SynSites".tr(" ","\t")
130
+ gen.each do |k,v|
131
+ if o[:syn_frx].nil?
132
+ v[2,3] = [0.0,0.0]
133
+ (1 .. seqs[k].size).each do |pos|
134
+ alts = %w(A C T G) - [seqs[k][pos-1]]
135
+ syn = syn_fraction(seqs[k], pos, alts)
136
+ v[2] += 1.0-syn
137
+ v[3] += syn
138
+ end
139
+ else
140
+ v[2] = seqs[k].size.to_f*o[:syn_frx]
141
+ v[3] = seqs[k].size.to_f*(1.0-o[:syn_frx])
142
+ end
143
+ ka = (v[0] + 1) / (v[2] + 2)
144
+ ks = (v[1] + 1) / (v[3] + 2)
145
+ puts ([k, ka/ks, ka, ks] + v).join("\t")
146
+ end
147
+
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # @author Luis M. Rodriguez-R
4
+ # @license Artistic-2.0
5
+
6
+ $:.push File.expand_path(File.dirname(__FILE__) + "/lib")
7
+ require "enveomics_rb/enveomics"
8
+ require "enveomics_rb/vcf"
9
+
10
+ o = {min_dp:4, max_dp:Float::INFINITY, min_ref_dp:2, min_alt_dp:2, min_qual:0.0,
11
+ indels:false, min_ic:0.0}
12
+ OptionParser.new do |opt|
13
+ opt.banner = "
14
+ Counts the number of Single-Nucleotide Polymorphisms (SNPs) in a VCF file.
15
+
16
+ Usage: #{$0} [options]".gsub(/^ +/,"")
17
+ opt.separator ""
18
+ opt.separator "Mandatory"
19
+ opt.on("-i", "--input FILE",
20
+ "Input file in Variant Call Format (VCF)."){ |v| o[:file] = v}
21
+ opt.separator ""
22
+ opt.separator "Parameters"
23
+ opt.on("-o", "--out FILE",
24
+ "Output (filtered) file in Variant Call Format (VCF)."){ |v| o[:out] = v}
25
+ opt.on("-m", "--min-dp INT",
26
+ "Minimum number of reads covering the position. By default: #{o[:min_dp]}."
27
+ ){ |v| o[:min_dp] = v.to_i }
28
+ opt.on("-M", "--max-dp INT",
29
+ "Maximum number of reads covering the position. By default: #{o[:max_dp]}."
30
+ ){ |v| o[:max_dp] = (v=="Infinity" ? Float::INFINITY : v.to_i) }
31
+ opt.on("-r", "--min-ref-dp INT",
32
+ "Minimum number of reads supporting allele REF. " +
33
+ "By default: #{o[:min_ref_dp]}."
34
+ ){ |v| o[:min_ref_dp] = v.to_i }
35
+ opt.on("-a", "--min-alt-dp INT",
36
+ "Minimum number of reads supporting allele ALT. " +
37
+ "By default: #{o[:min_alt_dp]}."
38
+ ){ |v| o[:min_alt_dp] = v.to_i }
39
+ opt.on("-q", "--min-quality FLOAT",
40
+ "Minimum quality of the position mapping. By default: #{o[:min_qual]}."
41
+ ){ |v| o[:max_dp] = v.to_f }
42
+ opt.on("-s", "--min-shannon FLOAT",
43
+ "Minimum information content (in bits, from 0 to 1). " +
44
+ "By default: #{o[:min_ic]}"){ |v| o[:min_ic] = v.to_f }
45
+ opt.on("--[no-]indels",
46
+ "Process (or ignore) indels. By default: ignore."
47
+ ){ |v| o[:indels] = v }
48
+ opt.on("-h", "--help", "Display this screen.") do
49
+ puts opt
50
+ exit
51
+ end
52
+ opt.separator ""
53
+ end.parse!
54
+
55
+ abort "--input is mandatory" if o[:file].nil?
56
+
57
+ vcf = VCF.new(o[:file])
58
+ c = 0
59
+ dp = 0
60
+ ref_dp = 0
61
+ alt_dp = 0
62
+ h = 0
63
+ unless o[:out].nil?
64
+ ofh = File.open(o[:out], "w")
65
+ vcf.each_header{ |h| ofh.print h }
66
+ end
67
+ vcf.each_variant do |v|
68
+ next if v.indel? and not o[:indels]
69
+ next if v.dp < o[:min_dp]
70
+ next if v.dp > o[:max_dp]
71
+ next if v.ref_dp < o[:min_ref_dp]
72
+ next if v.alt_dp < o[:min_alt_dp]
73
+ next if v.qual < o[:min_qual]
74
+ next if v.shannon < o[:min_ic]
75
+ c += 1
76
+ dp += v.dp
77
+ ref_dp += v.ref_dp
78
+ alt_dp += v.alt_dp
79
+ h += v.shannon
80
+ ofh.print v.to_s unless o[:out].nil?
81
+ end
82
+ ofh.close unless o[:out].nil?
83
+
84
+ puts "SNPs: #{c}", "Information content: #{h}",
85
+ "Average SNP depth: #{dp.to_f/c}",
86
+ "Average REF allele depth: #{ref_dp.to_f/c}",
87
+ "Average ALT allele depth: #{alt_dp.to_f/c}"
88
+
@@ -0,0 +1,373 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # @author Luis M. Rodriguez-R
4
+ # @license Artistic-2.0
5
+
6
+ require "optparse"
7
+ require "tmpdir"
8
+ has_rest_client = true
9
+ has_sqlite3 = true
10
+ begin
11
+ require "rubygems"
12
+ require "restclient"
13
+ rescue LoadError
14
+ has_rest_client = false
15
+ end
16
+ begin
17
+ require "sqlite3"
18
+ rescue LoadError
19
+ has_sqlite3 = false
20
+ end
21
+
22
+ o = {bits:0, id:20, len:0, hits:50, q:false, bin:"", program:"blast+", thr:1,
23
+ dec:2, auto:false, lookupfirst:false, dbrbm: true, nucl: false,
24
+ len_fraction:0.0, max_actg:0.95}
25
+ ARGV << "-h" if ARGV.size==0
26
+ OptionParser.new do |opts|
27
+ opts.banner = "
28
+ Calculates the Average Amino acid Identity between two genomes.
29
+
30
+ Usage: #{$0} [options]"
31
+ opts.separator ""
32
+ opts.separator "Mandatory"
33
+ opts.on("-1", "--seq1 FILE",
34
+ "Path to the FastA file containing the genome 1 (proteins)."
35
+ ){ |v| o[:seq1] = v }
36
+ opts.on("-2", "--seq2 FILE",
37
+ "Path to the FastA file containing the genome 2 (proteins)."
38
+ ){ |v| o[:seq2] = v }
39
+ if has_rest_client
40
+ opts.separator " Alternatively, you can supply the NCBI-acc of a " +
41
+ "genome (nucleotides) with the format ncbi:CP014272 instead of files."
42
+ else
43
+ opts.separator " Install rest-client to enable NCBI-acc support."
44
+ end
45
+ opts.separator ""
46
+ opts.separator "Search Options"
47
+ opts.on("-l", "--len INT",
48
+ "Minimum alignment length (in residues). By default: #{o[:len]}."
49
+ ){ |v| o[:len] = v.to_i }
50
+ opts.on("-L", "--len-fraction NUM",
51
+ "Minimum alignment length as a fraction of the shorter sequence",
52
+ "(range 0-1). By default: #{o[:len_fraction]}."
53
+ ){ |v| o[:len_fraction] = v.to_f }
54
+ opts.on("-i", "--id NUM",
55
+ "Minimum alignment identity (in %). By default: #{o[:id]}."
56
+ ){ |v| o[:id] = v.to_f }
57
+ opts.on("-s", "--bitscore NUM",
58
+ "Minimum bit score (in bits). By default: #{o[:bits]}."
59
+ ){ |v| o[:bits] = v.to_f }
60
+ opts.on("-n", "--hits INT",
61
+ "Minimum number of hits. By default: #{o[:hits]}."
62
+ ){ |v| o[:hits] = v.to_i }
63
+ opts.on("-N", "--nucl",
64
+ "The input sequences are nucleotides (genes), not proteins."
65
+ ){ |v| o[:nucl] = v }
66
+ opts.on("--max-actg FLOAT",
67
+ "Maximum fraction of ACTGN in the sequences before assuming nucleotides.",
68
+ "By default: #{o[:max_actg]}."
69
+ ){ |v| o[:max_actg] = v.to_f }
70
+ opts.separator ""
71
+ opts.separator "Software Options"
72
+ opts.on("-b", "--bin DIR",
73
+ "Path to the directory containing the binaries of the search program."
74
+ ){ |v| o[:bin] = v }
75
+ opts.on("-p", "--program STR",
76
+ "Search program to be used. One of: blast+ (default), blast, blat."
77
+ ){ |v| o[:program] = v }
78
+ opts.on("-t", "--threads INT",
79
+ "Number of parallel threads to be used. By default: #{o[:thr]}."
80
+ ){ |v| o[:thr] = v.to_i }
81
+ opts.separator ""
82
+ opts.separator "SQLite3 Options"
83
+ opts.on("-S", "--sqlite3 FILE",
84
+ "Path to the SQLite3 database to create (or update) with the results."
85
+ ){ |v| o[:sqlite3] = v }
86
+ opts.separator " Install sqlite3 gem to enable database support." unless
87
+ has_sqlite3
88
+ opts.on("--name1 STR",
89
+ "Name of --seq1 to use in --sqlite3. By default determined by filename."
90
+ ){ |v| o[:seq1name] = v }
91
+ opts.on("--name2 STR",
92
+ "Name of --seq2 to use in --sqlite3. By default determined by filename."
93
+ ){ |v| o[:seq2name] = v }
94
+ opts.on("--[no-]save-rbm",
95
+ "Save (or don't save) the reciprocal best matches in the --sqlite3 db.",
96
+ "By default: #{o[:dbrbm]}."){ |v| o[:dbrbm] = !!v }
97
+ opts.on("--lookup-first",
98
+ "Indicates if the AAI should be looked up first in the database.",
99
+ "Requires --sqlite3, --auto, --name1, and --name2.",
100
+ "Incompatible with --res, --tab, --out, and --rbm."
101
+ ){ |v| o[:lookupfirst] = v }
102
+ opts.separator ""
103
+ opts.separator "Other Output Options"
104
+ opts.on("-d", "--dec INT",
105
+ "Decimal positions to report. By default: #{o[:dec]}"
106
+ ){ |v| o[:dec] = v.to_i }
107
+ opts.on("-R", "--rbm FILE",
108
+ "Saves a file with the reciprocal best matches."){ |v| o[:rbm] = v }
109
+ opts.on("-o", "--out FILE",
110
+ "Saves a file describing the alignments used for two-way AAI."
111
+ ){ |v| o[:out] = v }
112
+ opts.on("-r", "--res FILE",
113
+ "Saves a file with the final results."){ |v| o[:res] = v }
114
+ opts.on("-T", "--tab FILE",
115
+ "Saves a file with the final two-way results in a tab-delimited form.",
116
+ "The columns are (in that order):",
117
+ "AAI, standard deviation, proteins used, proteins in the smallest genome."
118
+ ){ |v| o[:tab]=v }
119
+ opts.on("-a", "--auto",
120
+ "ONLY outputs the AAI value in STDOUT (or nothing, if calculation fails)."
121
+ ){ o[:auto] = true }
122
+ opts.on("-q", "--quiet", "Run quietly (no STDERR output)"){ o[:q] = true }
123
+ opts.on("-h", "--help", "Display this screen") do
124
+ puts opts
125
+ exit
126
+ end
127
+ opts.separator ""
128
+ end.parse!
129
+ abort "-1 is mandatory" if o[:seq1].nil?
130
+ abort "-2 is mandatory" if o[:seq2].nil?
131
+ abort "SQLite3 requested (-S) but sqlite3 not supported. First install gem " +
132
+ "sqlite3." unless o[:sqlite3].nil? or has_sqlite3
133
+ o[:bin] = o[:bin]+"/" if o[:bin].size > 0
134
+ if o[:lookupfirst]
135
+ abort "--lookup-first needs --sqlite3" if o[:sqlite3].nil?
136
+ abort "--lookup-first requires --auto" unless o[:auto]
137
+ abort "--lookup-first requires --name1" if o[:seq1name].nil?
138
+ abort "--lookup-first requires --name2" if o[:seq2name].nil?
139
+ abort "--lookup-first conflicts with --res" unless o[:res].nil?
140
+ abort "--lookup-first conflicts with --tab" unless o[:tab].nil?
141
+ abort "--lookup-first conflicts with --out" unless o[:out].nil?
142
+ abort "--lookup-first conflicts with --rbm" unless o[:rbm].nil?
143
+ end
144
+
145
+ # Create SQLite3 file
146
+ unless o[:sqlite3].nil?
147
+ $stderr.puts "Accessing SQLite3 file: #{o[:sqlite3]}." unless o[:q]
148
+ sqlite_db = SQLite3::Database.new o[:sqlite3]
149
+ sqlite_db.execute "create table if not exists rbm( seq1 varchar(256), " +
150
+ "seq2 varchar(256), id1 varchar(256), id2 varchar(256), id float, " +
151
+ "evalue float, bitscore float )"
152
+ sqlite_db.execute "create table if not exists aai( seq1 varchar(256), " +
153
+ "seq2 varchar(256), aai float, sd float, n int, omega int )"
154
+ end
155
+
156
+ # Look-up first
157
+ if o[:lookupfirst]
158
+ val = sqlite_db.execute "select aai from aai where seq1=? and seq2=?",
159
+ [o[:seq1name], o[:seq2name]]
160
+ val = sqlite_db.execute "select aai from aai where seq1=? and seq2=?",
161
+ [o[:seq2name], o[:seq1name]] if val.empty?
162
+ unless val.empty?
163
+ puts val.first.first
164
+ exit
165
+ end
166
+ end
167
+
168
+ Dir.mktmpdir do |dir|
169
+ $stderr.puts "Temporal directory: #{dir}." unless o[:q]
170
+
171
+ # Create databases.
172
+ $stderr.puts "Creating databases." unless o[:q]
173
+ minfrg = nil
174
+ seq_names = []
175
+ seq_len = {}
176
+ actg_cnt = {}
177
+ ori_ids = {}
178
+ [:seq1, :seq2].each do |seq|
179
+ abort "GIs are no longer supported by NCBI. Please use NCBI-acc instead." if
180
+ /^gi:/.match(o[seq])
181
+ acc = /^ncbi:(\S+)/.match(o[seq])
182
+ if not acc.nil?
183
+ abort "NCBI-acc requested, but rest-client not supported. First " +
184
+ "install gem rest-client." unless has_rest_client
185
+ abort "NCBI-acc are currently not supported with --nucl. Please use " +
186
+ "ani.rb instead." if o[:nucl]
187
+ $stderr.puts " Downloading dataset from NCBI:#{acc[1]}." unless o[:q]
188
+ responseLink = RestClient.get(
189
+ "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/elink.fcgi",
190
+ {params:{db:"protein",dbfrom:"nuccore",id:acc[1],idtype:"acc"}})
191
+ abort "Unable to reach NCBI EUtils, error code " +
192
+ responseLink.code.to_s + "." unless responseLink.code == 200
193
+ fromId = true
194
+ protIds = []
195
+ o[seq] = "#{dir}/ncbi-#{seq.to_s}.fa"
196
+ fo = File.open(o[seq], "w")
197
+ responseLink.to_str.each_line.grep(/\s<Id>/) do |ln|
198
+ idMatch = /<Id>(\S+)<\/Id>/.match(ln)
199
+ unless idMatch.nil?
200
+ protIds.push(idMatch[1]) unless fromId
201
+ fromId = false
202
+ end
203
+ end
204
+ response = RestClient.post(
205
+ "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi",
206
+ db:"nuccore",rettype:"fasta",id:protIds.join(","),idtype:"acc")
207
+ abort "Unable to reach NCBI EUtils, error code " +
208
+ response.code.to_s + "." unless response.code == 200
209
+ fo.puts response.to_str
210
+ fo.close
211
+ seq_names << ( o[ "#{seq}name".to_sym ].nil? ?
212
+ "ncbi:#{acc[1]}" :
213
+ o[ "#{seq}name".to_sym ])
214
+ else
215
+ seq_names << ( o[ "#{seq}name".to_sym ].nil? ?
216
+ File.basename(o[seq], ".faa") :
217
+ o[ "#{seq}name".to_sym ])
218
+ end
219
+ $stderr.puts " Reading FastA file: #{o[seq]}" unless o[:q]
220
+ unless o[:sqlite3].nil?
221
+ sqlite_db.execute "delete from rbm where seq1=? and seq2=?", seq_names
222
+ sqlite_db.execute "delete from aai where seq1=? and seq2=?", seq_names
223
+ end
224
+ ori_ids[seq] = [nil]
225
+ seq_len[seq] = [0]
226
+ actg_cnt[seq] = 0
227
+ seqs = 0
228
+ fi = File.open(o[seq], "r")
229
+ fo = File.open("#{dir}/#{seq.to_s}.fa", "w")
230
+ fi.each_line do |ln|
231
+ if ln =~ /^>(\S+)/
232
+ seqs += 1
233
+ ori_ids[seq] << $1 unless o[:rbm].nil? and o[:sqlite3].nil?
234
+ seq_len[seq][seqs] = 0
235
+ fo.puts ">#{seqs}"
236
+ else
237
+ fo.puts ln
238
+ seq_len[seq][seqs] += ln.chomp.gsub(/[^A-Za-z]/,"").length
239
+ actg_cnt[seq] += ln.chomp.gsub(/[^ACTGN]/,"").length
240
+ end
241
+ end
242
+ fi.close
243
+ fo.close
244
+ unless o[:nucl]
245
+ actg_frx = actg_cnt[seq].to_f/seq_len[seq].inject(:+).to_f
246
+ abort "Input sequences appear to be nucleotides " +
247
+ "(ACTGN fraction: %.2f%%)." % (actg_frx*100) if actg_frx > o[:max_actg]
248
+ end
249
+ $stderr.puts " File contains #{seqs} sequences." unless o[:q]
250
+ minfrg ||= seqs
251
+ minfrg = seqs if minfrg > seqs
252
+ case o[:program].downcase
253
+ when "blast"
254
+ `"#{o[:bin]}formatdb" -i "#{dir}/#{seq.to_s}.fa" \
255
+ -p #{o[:nucl] ? "F" : "T"}`
256
+ when "blast+"
257
+ `"#{o[:bin]}makeblastdb" -in "#{dir}/#{seq.to_s}.fa" \
258
+ -dbtype #{o[:nucl] ? "nucl" : "prot"}`
259
+ when "blat"
260
+ # Nothing to do
261
+ else
262
+ abort "Unsupported program: #{o[:program]}."
263
+ end
264
+ end
265
+
266
+ # Best-hits.
267
+ $stderr.puts "Running one-way comparisons." unless o[:q]
268
+ rbh = []
269
+ id2 = 0
270
+ sq2 = 0
271
+ n2 = 0
272
+ unless o[:out].nil?
273
+ fo = File.open(o[:out], "w")
274
+ fo.puts %w(identity aln.len mismatch gap.open evalue bitscore).join("\t")
275
+ end
276
+ res = File.open(o[:res], "w") unless o[:res].nil?
277
+ rbm = File.open(o[:rbm], "w") unless o[:rbm].nil?
278
+ [1,2].each do |i|
279
+ qry_seen = []
280
+ q = "#{dir}/seq#{i}.fa"
281
+ s = "#{dir}/seq#{i==1?2:1}.fa"
282
+ case o[:program].downcase
283
+ when "blast"
284
+ `"#{o[:bin]}blastall" -p blast#{o[:nucl] ? "n": "p"} -d "#{s}" \
285
+ -i "#{q}" -v 1 -b 1 -a #{o[:thr]} -m 8 -o "#{dir}/#{i}.tab"`
286
+ when "blast+"
287
+ `"#{o[:bin]}blast#{o[:nucl] ? "n" : "p"}" -db "#{s}" -query "#{q}" \
288
+ -max_target_seqs 1 -num_threads #{o[:thr]} -outfmt 6 \
289
+ -out "#{dir}/#{i}.tab"`
290
+ when "blat"
291
+ `#{o[:bin]}blat "#{s}" "#{q}" #{"-prot" unless o[:nucl]} -out=blast8 \
292
+ "#{dir}/#{i}.tab.uns"`
293
+ `sort -k 1 "#{dir}/#{i}.tab.uns" > "#{dir}/#{i}.tab"`
294
+ else
295
+ abort "Unsupported program: #{o[:program]}."
296
+ end
297
+ fh = File.open("#{dir}/#{i}.tab", "r")
298
+ id = 0
299
+ sq = 0
300
+ n = 0
301
+ fh.each_line do |ln|
302
+ ln.chomp!
303
+ row = ln.split(/\t/)
304
+ next unless qry_seen[ row[0].to_i ].nil?
305
+ next if row[3].to_i < o[:len] and
306
+ next if row[2].to_f < o[:id]
307
+ next if row[11].to_f < o[:bits]
308
+ next if row[3].to_f/[
309
+ seq_len[i==1 ? :seq1 : :seq2][row[0].to_i],
310
+ seq_len[i==1 ? :seq2 : :seq1][row[1].to_i]
311
+ ].min < o[:len_fraction]
312
+ qry_seen[ row[0].to_i ] = 1
313
+ id += row[2].to_f
314
+ sq += row[2].to_f ** 2
315
+ n += 1
316
+ if i==1
317
+ rbh[ row[0].to_i ] = row[1].to_i
318
+ else
319
+ if !rbh[ row[1].to_i ].nil? and rbh[ row[1].to_i ]==row[0].to_i
320
+ id2 += row[2].to_f
321
+ sq2 += row[2].to_f**2
322
+ n2 += 1
323
+ fo.puts [row[2..5],row[10..11]].join("\t") unless o[:out].nil?
324
+ rbm.puts [ori_ids[:seq1][row[1].to_i],
325
+ ori_ids[:seq2][row[0].to_i], row[2..5], row[8..9],
326
+ row[6..7], row[10..11]].join("\t") unless o[:rbm].nil?
327
+ sqlite_db.execute("insert into rbm values(?,?,?,?,?,?,?)",
328
+ seq_names + [ori_ids[:seq1][row[1].to_i],
329
+ ori_ids[:seq2][row[0].to_i], row[2], row[10], row[11]]
330
+ ) if not o[:sqlite3].nil? and o[:dbrbm]
331
+ end
332
+ end
333
+ end
334
+ fh.close
335
+ if n < o[:hits]
336
+ puts "Insuffient hits to estimate one-way AAI: #{n}." unless o[:auto]
337
+ res.puts "Insufficient hits to estimate one-way AAI: #{n}" unless
338
+ o[:res].nil?
339
+ else
340
+ printf "! One-way AAI %d: %.#{o[:dec]}f%% (SD: %.#{o[:dec]}f%%), " +
341
+ "from %i proteins.\n", i, id/n, (sq/n - (id/n)**2)**0.5, n unless
342
+ o[:auto]
343
+ res.puts sprintf "<b>One-way AAI %d:</b> %.#{o[:dec]}f%% " +
344
+ "(SD: %.#{o[:dec]}f%%), from %i proteins.<br/>", i, id/n,
345
+ (sq/n - (id/n)**2)**0.5, n unless o[:res].nil?
346
+ end
347
+ end
348
+ rbm.close unless o[:rbm].nil?
349
+ if n2 < o[:hits]
350
+ puts "Insufficient hits to estimate two-way AAI: #{n2}" unless o[:auto]
351
+ res.puts "Insufficient hits to estimate two-way AAI: #{n2}" unless
352
+ o[:res].nil?
353
+ else
354
+ printf "! Two-way AAI : %.#{o[:dec]}f%% (SD: %.#{o[:dec]}f%%), from %i" +
355
+ " proteins.\n", id2/n2, (sq2/n2 - (id2/n2)**2)**0.5, n2 unless o[:auto]
356
+ res.puts sprintf "<b>Two-way AAI:</b> %.#{o[:dec]}f%% (SD: " +
357
+ "%.#{o[:dec]}f%%), from %i proteins.<br/>", id2/n2,
358
+ (sq2/n2 - (id2/n2)**2)**0.5, n2 unless o[:res].nil?
359
+ unless o[:tab].nil?
360
+ tab = File.open(o[:tab], "w")
361
+ tab.printf "%.#{o[:dec]}f\t%.#{o[:dec]}f\t%i\t%i\n", id2/n2,
362
+ (sq2/n2 - (id2/n2)**2)**0.5, n2, minfrg
363
+ tab.close
364
+ end
365
+ sqlite_db.execute("insert into aai values(?,?,?,?,?,?)",
366
+ seq_names + [id2/n2, (sq2/n2 - (id2/n2)**2)**0.5, n2, minfrg]) unless
367
+ o[:sqlite3].nil?
368
+ puts id2/n2 if o[:auto]
369
+ end
370
+ res.close unless o[:res].nil?
371
+ fo.close unless o[:out].nil?
372
+ end
373
+