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,61 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #
4
+ # @author: Luis M. Rodriguez-R
5
+ # @update: Feb-06-2015
6
+ # @license: artistic license 2.0
7
+ #
8
+
9
+ require 'optparse'
10
+
11
+ o = {:subject=>FALSE, :quiet=>FALSE}
12
+ ARGV << '-h' if ARGV.size==0
13
+ OptionParser.new do |opts|
14
+ opts.banner = "
15
+ Appends an extra column to a BLAST with the length of the query or the subject sequence.
16
+ You can pipe two instances to add both:
17
+ cat input.blast | #{$0} -f queries.fa | #{$0} -f subjects.fa -s > output.blast
18
+
19
+ Usage: #{$0} [options] < input.blast > output.blast"
20
+ opts.separator ""
21
+ opts.separator "Mandatory"
22
+ opts.on("-f", "--fasta FILE", "Path to the FastA file"){ |v| o[:fasta] = v }
23
+ opts.separator ""
24
+ opts.separator "Options"
25
+ opts.on("-s", "--subject",
26
+ "Use the subject column of the BLAST, by default the query column is used"){ o[:subject] = TRUE }
27
+ opts.on("-q", "--quiet", "Run quietly (no STDERR output)"){ o[:quiet] = TRUE }
28
+ opts.on("-h", "--help", "Display this screen") do
29
+ puts opts
30
+ exit
31
+ end
32
+ opts.separator ""
33
+ end.parse!
34
+ abort "-f is mandatory" if o[:fasta].nil?
35
+
36
+ len = {}
37
+ id = ""
38
+ $stderr.puts "Reading FastA file: #{o[:fasta]}" unless o[:quiet]
39
+ fh = File.open(o[:fasta], "r")
40
+ fh.each_line do |ln|
41
+ defline = /^>(\S+)/.match(ln)
42
+ if defline.nil?
43
+ ln.gsub! /[^A-Za-z]/, ''
44
+ abort "Error: Unsupported format, expecting FastA" if len[id].nil?
45
+ len[id] = len[id] + ln.size
46
+ else
47
+ id = defline[1]
48
+ len[id] = 0
49
+ end
50
+ end
51
+ fh.close
52
+
53
+ $stderr.puts "Appending #{o[:subject]?"subject":"query"} length column" unless o[:quiet]
54
+ ARGF.each_line do |ln|
55
+ ln.chomp!
56
+ row = ln.split /\t/
57
+ id = o[:subject] ? row[1] : row[0];
58
+ abort "Impossible to find sequence of #{id}" if len[id].nil?
59
+ puts "#{ln}\t#{len[id]}"
60
+ end
61
+
@@ -0,0 +1,48 @@
1
+ #!/bin/bash
2
+
3
+ #
4
+ # @author Luis M. Rodriguez-R
5
+ # @update Mar-23-2016
6
+ # @license artistic license 2.0
7
+ #
8
+
9
+ if [[ ! $2 ]] ; then
10
+ echo "
11
+ .DESCRIPTION
12
+ Calculates the percentage of a partial BLAST result. The
13
+ value produced slightly subestimates the actual advance,
14
+ due to un-flushed output and trailing queries that could
15
+ be processed but generate no results.
16
+
17
+ .USAGE
18
+ $0 blast.txt qry.fasta
19
+
20
+ blast.txt Incomplete Tabular BLAST output.
21
+ qry.fasta FastA file with query sequences.
22
+ ";
23
+ exit 1;
24
+ fi
25
+
26
+ if [[ ! -r $1 ]]; then
27
+ echo "Cannot open file: $1";
28
+ exit 1;
29
+ fi
30
+
31
+ if [[ ! -r $2 ]]; then
32
+ echo "Cannot open file: $2";
33
+ exit 1;
34
+ fi
35
+
36
+ LAST_Q=`tail -n 2 $1 | head -n 1 | awk '{print $1}'`
37
+ LAST_Q_NO=`grep -n "^>$LAST_Q\\( \\|$\\)" $2 | sed -e 's/:.*//'`
38
+ if [[ ! $LAST_Q_NO ]]; then
39
+ echo "Cannot find sequence: $LAST_Q";
40
+ echo "Make sure you are providing the right query file.";
41
+ exit 1;
42
+ fi
43
+ TOTAL_Q_NO=`cat $2 | wc -l | sed -e 's/ *//'`
44
+ let PERC=100*$LAST_Q_NO/$TOTAL_Q_NO
45
+
46
+ echo "$PERC%: $LAST_Q_NO / $TOTAL_Q_NO"
47
+ exit 0;
48
+
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env perl
2
+
3
+ #
4
+ # @author: Luis M. Rodriguez-R <lmrodriguezr at gmail dot com>
5
+ # @license: artistic license 2.0
6
+ # @last_update: Mar-23-2015
7
+ #
8
+
9
+ use strict;
10
+ use warnings;
11
+
12
+ die "
13
+ Usage:
14
+ sort blast.txt ... | $0 > blast.bh.txt
15
+ $0 blast_sorted.txt ... > blast.bh.txt
16
+ $0 -h|--help|-?
17
+
18
+ blast.txt ... One or more files in Tabular BLAST format.
19
+ blast_sorted.txt ... One or more files in Tabular BLAST format pre-sorted.
20
+ blast.bh.txt Output file in BLAST format containing best-hits only.
21
+ -h|--help|-? Any of these flags trigger this help message and exits.
22
+
23
+ NOTE: This script assumes that the BLAST is sorted. Because it can read
24
+ from the STDIN, calling this script without arguments cause it to still until
25
+ killed or until an EOF (^D) is presented.
26
+
27
+ " if exists $ARGV[0] and $ARGV[0] =~ /^\-?\-(h(elp)?|\?)/i;
28
+
29
+ my $last_qry = '';
30
+ my @best_res;
31
+
32
+ sub best_result($$){
33
+ my($r1, $r2)=@_;
34
+ return $r1 unless $r2;
35
+ return $r1->[11] > $r2->[11] ? @$r1 : @$r2;
36
+ }
37
+
38
+ my $i=0;
39
+ while(<>){
40
+ chomp;
41
+ #print STDERR " Reading entry $i... \r" unless $i%1000;
42
+ my @res = split /\t/;
43
+ die "\nCannot parse BLAST line $.: $_\n" unless exists $res[1];
44
+ if($last_qry eq $res[0]){
45
+ @best_res = &best_result(\@res, \@best_res);
46
+ }else{
47
+ print join("\t", @best_res), "\n" if $#best_res>0;
48
+ @best_res = @res;
49
+ $last_qry = $res[0];
50
+ }
51
+ }
52
+ print join("\t", @best_res), "\n" if @best_res;
53
+
54
+
55
+
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env perl
2
+ #
3
+ # @author: Luis M. Rodriguez-R <lmrodriguezr at gmail dot com>
4
+ # @updated: Mar-23-2015
5
+ # @license: artistic license 2.0
6
+ #
7
+
8
+ use warnings;
9
+ use strict;
10
+ use List::Util qw/min max/;
11
+ use Getopt::Std;
12
+
13
+ sub HELP_MESSAGE { die "
14
+
15
+ Description:
16
+ Generates a list of hits from a BLAST result concatenating the subject
17
+ sequences. This can be used, e.g., to analyze BLAST results against
18
+ draft genomes.
19
+
20
+ Usage:
21
+ $0 [options] seq.fa map.bls
22
+
23
+ seq.fa Subject sequences (ref) in FastA format.
24
+ map.bls Mapping of the reads to the reference in BLAST Tabular
25
+ format.
26
+
27
+ Options:
28
+ -i <float> Minimum identity to report a result. By default: 70.
29
+ -l <int> Minimum alignment length to report a result. By default: 60.
30
+ -s The FastA provided is to be treated as a subset of the subject.
31
+ By default, it expects all the subjects to be present in the
32
+ BLAST.
33
+ -q Run quietly.
34
+ -h Display this message and exit.
35
+
36
+ This script creates two files using <map.bls> as prefix with extensions
37
+ .rec (for the recruitment plot) and .lim (for the limits of the different
38
+ sequences in <seq.fa>).
39
+
40
+ ";}
41
+
42
+ my %o;
43
+ getopts('i:l:sqh', \%o);
44
+ my($fa, $map) = @ARGV;
45
+ ($fa and $map) or &HELP_MESSAGE;
46
+ $o{h} and &HELP_MESSAGE;
47
+ $o{i} ||= 70;
48
+ $o{l} ||= 60;
49
+
50
+ my %seq = ();
51
+ my @seq = ();
52
+ my $tot = 0;
53
+
54
+ SEQ:{
55
+ print STDERR "== Reading reference sequences\n" unless $o{q};
56
+ open FA, "<", $fa or die "Cannot read the file: $fa: $!\n";
57
+ my $cur_seq = '';
58
+ while(<FA>){
59
+ chomp;
60
+ if(m/^>(\S+)/){
61
+ my $c = $1;
62
+ $seq{$c} = exists $seq{$cur_seq} ? $seq{$cur_seq}+1 : 1;
63
+ push @seq, $c;
64
+ $cur_seq = $c;
65
+ }else{
66
+ s/[^A-Za-z]//g;
67
+ $seq{$cur_seq} += length $_;
68
+ }
69
+ }
70
+ close FA;
71
+ print STDERR " Found ".(scalar @seq)." sequences.\n" unless $o{q};
72
+ }
73
+
74
+ open LIM, ">", "$map.lim" or die "Cannot create the file: $map.lim: $!\n";
75
+ my $l = 0;
76
+ for my $s (@seq){
77
+ print LIM "$s\t".(++$l)."\t$seq{$s}\n";
78
+ ($l, $seq{$s}) = ($seq{$s}, $l);
79
+ }
80
+ close LIM;
81
+
82
+ MAP:{
83
+ print STDERR "== Reading mapping\n" unless $o{q};
84
+ open BLS, "<", $map or die "Cannot read the file: $map: $!\n";
85
+ open REC, ">", "$map.rec" or die "Cannot create the file: $map.rec: $!\n";
86
+ RESULT:while(<BLS>){
87
+ chomp;
88
+ my @ln = split /\t/;
89
+ $ln[11] or die "Cannot parse line $map:$.: $_\n";
90
+ next unless $ln[3]>=$o{l};
91
+ next unless $ln[2]>=$o{i};
92
+ unless(exists $seq{$ln[1]}){
93
+ die "Cannot find the subject sequence: $ln[1]\n" unless $o{s};
94
+ next RESULT;
95
+ }
96
+ my $start = $seq{$ln[1]}+min($ln[8], $ln[9]);
97
+ my $end = $seq{$ln[1]}+max($ln[8], $ln[9]);
98
+ print REC "$start\t$end\t$ln[2]\t$ln[11]\t$ln[0]",
99
+ (exists($ln[13])?"\t".($ln[2]*$ln[3]/min($ln[12],$ln[13]))."\t":
100
+ exists($ln[12])?"\t".($ln[2]*$ln[3]/$ln[12])."\t":""),"\n";
101
+ }
102
+ close BLS;
103
+ close REC;
104
+ print STDERR " done.\n" unless $o{q};
105
+ }
106
+
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #
4
+ # @author Luis M. Rodriguez-R <lmrodriguezr at gmail dot com>
5
+ # @update Mar-23-2016
6
+ # @license artistic license 2.0
7
+ #
8
+
9
+ require "optparse"
10
+
11
+ o = {:cog=>false, :desc=>false, :q=>false, :w=>true}
12
+ ARGV << "-h" if ARGV.size==0
13
+ OptionParser.new do |opts|
14
+ opts.banner = "Replaces the COG gene IDs in a BLAST for the COG category."
15
+ opts.separator ""
16
+ opts.separator "Mandatory"
17
+ opts.on("-w", "--whog FILE", "Path to the whog file."){ |v| o[:whog]=v }
18
+ opts.on("-i", "--blast FILE",
19
+ "Path to the Tabular BLAST file with COG IDs as subject."
20
+ ){ |v| o[:blast]=v }
21
+ opts.separator ""
22
+ opts.separator "Optional"
23
+ opts.on("-g", "--cog",
24
+ "If set, returns the COG ID, not the COG category."){ o[:cog]=true }
25
+ opts.on("-d", "--desc",
26
+ "Includes COG description (requires -g/--cog)."){ o[:desc]=true }
27
+ opts.on("-n", "--noverbose", "Run quietly, but show warnings."){ o[:q]=true }
28
+ opts.on("-q", "--quiet", "Run quietly."){ o[:q]=true; o[:w]=false }
29
+ opts.on("-h", "--help", "Display this screen") do
30
+ puts opts
31
+ exit
32
+ end
33
+ opts.separator ""
34
+ end.parse!
35
+
36
+ abort "-w/--whog is mandatory." if o[:whog].nil?
37
+ abort "-i/--blast is mandatory." if o[:blast].nil?
38
+
39
+ $stderr.puts "Parsing whog file." unless o[:q]
40
+ cat = {}
41
+ curCats = []
42
+ fh = File.open o[:whog], "r"
43
+ while ln=fh.gets
44
+ ln.chomp!
45
+ next if /^\s*$/.match ln
46
+ if m=/^\[([A-Z]+)\] (COG\d+) (.*)/.match(ln)
47
+ curCats = o[:cog] ? [ m[2]+(o[:desc]?" #{m[3]}":"") ] : m[1].split(//)
48
+ elsif /^_+$/.match ln
49
+ curCats = []
50
+ elsif m=/^\s+(?:.+?:\s+)?(.*)/.match(ln)
51
+ m[1].split(/\s+/).each do |g|
52
+ cat[g] ||= []
53
+ curCats.each { |i| cat[g] << i }
54
+ end
55
+ else
56
+ abort "Impossible to parse line #{$.}: #{ln}"
57
+ end
58
+ end
59
+ fh.close
60
+
61
+ $stderr.puts "Parsing BLAST." unless o[:q]
62
+ fh = File.open(o[:blast], "r")
63
+ while ln=fh.gets
64
+ row = ln.split(/\t/)
65
+ if cat[ row[1] ].nil?
66
+ $stderr.puts "Warning: line #{$.}: #{row[1]}: " +
67
+ "Impossible to find category.\n" if o[:w]
68
+ else
69
+ cat[ row[1] ].each do |c|
70
+ row[1] = c
71
+ puts row.join("\t")
72
+ end
73
+ end
74
+ end
75
+ fh.close
76
+
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env perl
2
+ #
3
+ # @author: Luis M. Rodriguez-R <lmrodriguezr at gmail dot com>
4
+ # @update: Mar-23-2015
5
+ # @license: artistic license 2.0
6
+ #
7
+
8
+ use warnings;
9
+ use strict;
10
+ use Getopt::Std;
11
+
12
+ my %o;
13
+ getopts('si', \%o);
14
+ my($list, $blast) = @ARGV;
15
+
16
+ ($list and $blast) or die "
17
+ .Description:
18
+ Extracts a subset of hits (queries or subjects) from a tabular BLAST.
19
+
20
+ .Usage: $0 [options] list.txt blast.txt > subset.txt
21
+
22
+ Options:
23
+ -s If set, assumes that list.txt contains subject IDs.
24
+ By default: assumes query IDs.
25
+ -i If set, reports the inverse of the list (i.e., reports
26
+ only hits absent in the list).
27
+
28
+ list.txt List of IDs to extract.
29
+ blast.txt Tabular BLAST file containing the superset of hits.
30
+ subset.txt Tabulat BLAST file to be created.
31
+
32
+ ";
33
+
34
+ open LI, "<", $list or die "Cannot read file: $list: $!\n";
35
+ my %li = map { chomp; $_ => 1 } <LI>;
36
+ close LI;
37
+
38
+ open BLAST, "<", $blast or die "Cannot read file: $blast: $!\n";
39
+ while(my $ln = <BLAST>){
40
+ chomp $ln;
41
+ my @ln = split("\t", $ln);
42
+ my $good = exists $li{$ln[ ($o{s} ? 1 : 0) ]};
43
+ $good = not $good if $o{i};
44
+ print "$ln\n" if $good;
45
+ }
46
+ close BLAST;
47
+
@@ -0,0 +1,194 @@
1
+ #!/usr/bin/env perl
2
+
3
+ use warnings;
4
+ use strict;
5
+ use LWP::Simple;
6
+ use JSON;
7
+ use File::Copy;
8
+
9
+ my($blast, $cache_file, $max_cache) = @ARGV;
10
+ ($blast) or die "
11
+ Description:
12
+ Takes a BLAST against KEGG_PEP (or KO) and retrieves the pathways in which the subject
13
+ peptides are involved.
14
+
15
+ Usage:
16
+ $0 blast.txt[ cache_file] > output.txt
17
+
18
+ blast.txt Input (filtered) BLAST file.
19
+ cache_file (optional) File containing the saved cache. If unset, the
20
+ cache won't be recoverable across instances of this script.
21
+ It is strongly recommended to set a file. Multiple
22
+ parallel instances of this script may use the same cache
23
+ file.
24
+ output.txt Tab-delimited output file, with the columns:
25
+ o Query ID
26
+ o Subject ID
27
+ o Pathway ID
28
+ o Pathway (reference) description
29
+ o Organism
30
+
31
+ ";
32
+
33
+ $max_cache ||= 0;
34
+ $cache_file ||= "";
35
+
36
+ sub read_cache($){
37
+ my ($cache_file) = @_;
38
+ my $cache = {};
39
+ my $n = 0;
40
+ if($cache_file and -s $cache_file){
41
+ local $/;
42
+ my $json = "";
43
+ while(-e "$cache_file.tmp"){
44
+ print STDERR "Locked cache (read), waiting 1 sec.\n";
45
+ sleep 1;
46
+ }
47
+ open CACHE, "<", $cache_file or die "Cannot read file: $cache_file: $!\n";
48
+ while(<CACHE>){ $json.=$_ }
49
+ close CACHE;
50
+ $cache = decode_json($json);
51
+ $n = scalar keys %$cache;
52
+ }
53
+ return ($cache, $n);
54
+ }
55
+
56
+ sub write_cache($$){
57
+ my($cache, $cache_file) = @_;
58
+ if($cache_file){
59
+ # Get previously saved entries.
60
+ my($cache2, $cache_n2) = &read_cache($cache_file);
61
+ for my $k (keys %$cache2){
62
+ $cache->{$k} ||= $cache2->{$k} unless $k eq "###:paths";
63
+ }
64
+ $cache->{'###:paths'} ||= {};
65
+ for my $p (keys %{$cache2->{'###:paths'}}){
66
+ $cache->{'###:paths'}->{$p} ||= $cache2->{'###:paths'}->{$p};
67
+ }
68
+ # Save merged cache.
69
+ if(-s $cache_file){ copy $cache_file, "$cache_file.pre" or die "Cannot create file: $cache_file.tmp: $!\n" }
70
+ my $json = encode_json($cache);
71
+ while(-e "$cache_file.tmp"){
72
+ print STDERR "Locked cache (write), waiting 1 sec.\n";
73
+ sleep 1;
74
+ }
75
+ open CACHE, ">", "$cache_file.tmp" or die "Cannot create file: $cache_file.tmp: $!\n";
76
+ print CACHE $json;
77
+ close CACHE;
78
+ copy "$cache_file.tmp", $cache_file or die "Cannot create file: $cache_file: $!\n";
79
+ unlink "$cache_file.tmp" or die "Cannot unlink file: $cache_file.tmp: $!\n";
80
+ }
81
+ }
82
+
83
+ sub download_pathways($$){
84
+ my($cache, $ids) = @_;
85
+ my @todownload = ();
86
+ for my $id (@$ids){
87
+ push @todownload, $id unless exists $cache->{'###:paths'}->{$id};
88
+ }
89
+ while($#todownload>=0){
90
+ my @downloading = splice(@todownload, 0, 100);
91
+ my $path = get "http://rest.kegg.jp/list/".join("+", @downloading);
92
+ if($path){
93
+ chomp $path;
94
+ for my $p (split /\n/, $path){
95
+ my @wl = split /\t/, $p;
96
+ $wl[1] =~ s/ - /\t/;
97
+ $cache->{'###:paths'}->{$wl[0]} = $wl[1];
98
+ }
99
+ }
100
+ }
101
+ return $cache;
102
+ }
103
+
104
+ sub download($$){
105
+ my($cache, $todownload) = @_;
106
+ $cache->{'###:paths'} ||= {};
107
+ return $cache unless $#$todownload>=0;
108
+ $cache->{$_} = [] for @$todownload;
109
+ my $list = get "http://rest.kegg.jp/link/pathway/".join("+", @$todownload);
110
+ $list ||= "";
111
+ chomp $list;
112
+ my @pathids = ();
113
+ for my $res (split /\n/, $list){
114
+ my @rel = split /\t/, $res;
115
+ $#rel==1 or die "Unexpected number of columns:\n$res\n";
116
+ my $id = $rel[1];
117
+ push @pathids, $id;
118
+ unless(exists $cache->{$rel[0]}){
119
+ #print STDERR "Request/response difference in ID: ".$rel[0].", searching match.\n";
120
+ for my $id (@$todownload){
121
+ $rel[0] = $id if lc $id eq lc $rel[0];
122
+ }
123
+ die "Cannot find corresponding request.\n" unless exists $cache->{$rel[0]};
124
+ }
125
+ push @{ $cache->{$rel[0]} }, $id;
126
+ }
127
+ return &download_pathways($cache, \@pathids);
128
+ }
129
+
130
+ sub print_out($$){
131
+ my($cache, $hits) = @_;
132
+ for my $hit (@$hits){
133
+ die "Impossible to find gene in cache: ".$hit->[1]."\n" unless exists $cache->{$hit->[1]};
134
+ for my $path (@{$cache->{$hit->[1]}}){
135
+ next if $path =~ /^path:ko\d/;
136
+ unless(exists $cache->{'###:paths'}->{$path}){
137
+ print STDERR "Cannot find pathway in cache: $path (from ".$hit->[1]."), emergency download\n";
138
+ $cache = &download_pathways($cache, [$path]);
139
+ die "Impossible to find pathway: $path.\n" unless exists $cache->{'###:paths'}->{$path};
140
+ }
141
+ print "", join("\t", $hit->[0], $hit->[1], $path, $cache->{'###:paths'}->{$path}), "\n";
142
+ }
143
+ }
144
+ }
145
+
146
+ print STDERR "Loading cache.\n";
147
+ my ($cache, $n) = &read_cache($cache_file);
148
+ print STDERR " $n entries loaded.\n";
149
+ my @nopath = ();
150
+ for my $k (keys %$cache){
151
+ next if $k eq "###:paths";
152
+ for my $p (@{ $cache->{$k} }){
153
+ push @nopath, $p unless exists $cache->{'###:paths'}->{$p};
154
+ }
155
+ }
156
+ if($#nopath>=0){
157
+ print STDERR " Sanitizing ".@nopath." pathways in cache.\n";
158
+ while($#nopath>=0){
159
+ my @paths = ();
160
+ for(1 .. 15){ push @paths, shift @nopath unless $#nopath==-1 }
161
+ $cache = &download_pathways($cache, \@paths);
162
+ }
163
+ &write_cache($cache, $cache_file);
164
+ }
165
+
166
+ my $lines=0;
167
+ my $downs=0;
168
+ my @buff = ();
169
+ my @todownload = ();
170
+ print STDERR "Mapping genes.\n";
171
+ open BLAST, "<", $blast or die "Cannot read file: $blast: $!\n";
172
+ while(<BLAST>){
173
+ chomp;
174
+ my @l = split /\t/;
175
+ print STDERR " Mapping line ".(++$lines).". \r";
176
+ unless(($#todownload+2)%100){
177
+ print STDERR "+\r";
178
+ print STDERR " *\r" unless ++$downs%10;
179
+ $cache = &download($cache, \@todownload);
180
+ @todownload = ();
181
+ &print_out($cache, \@buff);
182
+ @buff = ();
183
+ &write_cache($cache, $cache_file) unless $downs%10;
184
+ }
185
+ push @buff, \@l;
186
+ push @todownload, $l[1] unless exists $cache->{$l[1]};
187
+ }
188
+ print STDERR "\nDone.\n";
189
+ close BLAST;
190
+
191
+ $cache = &download($cache, \@todownload);
192
+ &print_out($cache, \@buff);
193
+ &write_cache($cache, $cache_file);
194
+