Skip to content

Commit

Permalink
Adding the header
Browse files Browse the repository at this point in the history
  • Loading branch information
pjotrp committed Nov 7, 2014
1 parent 23fa81a commit f767adb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 23 deletions.
34 changes: 26 additions & 8 deletions README.md
Expand Up @@ -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 %>": {
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions bin/blastxmlparser
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
39 changes: 24 additions & 15 deletions 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
]

0 comments on commit f767adb

Please sign in to comment.