diff --git a/README.md b/README.md index e345ae3..013a626 100644 --- a/README.md +++ b/README.md @@ -236,10 +236,12 @@ can be ```Javascript =HEADER +<% require 'json' %> [ - { "Meta": { - "query" : <%= hit.query %> - } + { "HEADER": { + "options": <%= options.to_h.to_json %>, + "files": <%= ARGV %>, + "version": "<%= BLASTXML_VERSION %>" }, =BODY { "<%= hit.parent.query_def %>": { @@ -252,12 +254,28 @@ can be ] ``` -Note that the template is smart enough to remove the final comma ',' -from the last BODY element, though you can also inject in the template something like +may generate something like - -```ruby - <%= ( body.last? ? "", "," ) %>. +```Javascript +[ + { "HEADER": { + "options": {"template":"template/blast2json2.erb","filter":"hsp.evalue>0.01"}, + "files": ["test/data/nt_example_blastn.m7"], + "version": "2.0.2-pre1" + }, + { "I_1 [477 - 884] ": { + "num": 41, + "id": "lcl|X_42251", + "len": 153, + "E-value": 0.0247015, + }, + { "I_1 [477 - 884] ": { + "num": 43, + "id": "lcl|V_105720", + "len": 180, + "E-value": 0.0247015, + } +] ``` ## Additional options diff --git a/bin/blastxmlparser b/bin/blastxmlparser index 6dae0b2..8187f10 100755 --- a/bin/blastxmlparser +++ b/bin/blastxmlparser @@ -129,6 +129,7 @@ begin raise "No input file(s) defined" if ARGV.size == 0 + ARGV.each do | fn | logger.info("XML parsing #{fn}") parser_type = options.parser @@ -149,6 +150,7 @@ begin chunks = [] chunks_count = 0 NUM_CHUNKS=10_000 + print template.header(binding) if template process = lambda { |iter2,i| # Process one BLAST iter block if parser_type == :nosplit @@ -225,6 +227,7 @@ begin process.call(iter,i) } end + print template.footer(binding) if template end rescue OptionParser::InvalidOption => e $stderr.print e.message diff --git a/template/blast2json2.erb b/template/blast2json2.erb index c48a8ba..767d7a8 100644 --- a/template/blast2json2.erb +++ b/template/blast2json2.erb @@ -1,19 +1,28 @@ =HEADER -/* TEST HEADER */ +<% require 'json' %> +[ + { "HEADER": { + "options": <%= options.to_h.to_json %>, + "files": <%= ARGV %>, + "version": "<%= BLASTXML_VERSION %>" + }, + =BODY + { "<%= hit.parent.query_def %>": { + "query_id": "<%= hit.parent.query_id %>", + "num": <%= hit.hit_num %>, + "accession": "<%= hit.accession %>", + "id": "<%= hit.hit_id %>", + "len": <%= hit.len %>, + "E-value": <%= hsp.evalue %>, + "identity": <%= hsp.identity %>, + "align_len": <%= hsp.align_len %>, + "bitscore": <%= hsp.bit_score %>, + "qseq": "<%= hsp.qseq %>", + "midline": "<%= hsp.midline %>", + "hseq": "<%= hsp.hseq %>", + }, -{ "<%= hit.parent.query_def %>": { - "query_id": "<%= hit.parent.query_id %>", - "num": <%= hit.hit_num %>, - "accession": "<%= hit.accession %>", - "id": "<%= hit.hit_id %>", - "len": <%= hit.len %>, - "E-value": <%= hsp.evalue %>, - "identity": <%= hsp.identity %>, - "align_len": <%= hsp.align_len %>, - "bitscore": <%= hsp.bit_score %>, - "qseq": "<%= hsp.qseq %>", - "midline": "<%= hsp.midline %>", - "hseq": "<%= hsp.hseq %>", -}; +=FOOTER +]