Skip to content

Commit

Permalink
Major change to --json output
Browse files Browse the repository at this point in the history
  • Loading branch information
tseemann committed Feb 24, 2020
1 parent ff75805 commit c8efc37
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
42 changes: 30 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,26 +188,44 @@ If you prefer CSV because it loads more smoothly into MS Excel, use the `--csv`
```
% mlst --csv Peptobismol.fna.gz > mlst.csv
```
JSON output is available too:
JSON output is available too; it returns an array of dictionaries, one per
input file. The `id` will be the same as `filename` unless `--label` is
used, but that only works when scanning a single file.
```
% mlst -q --json out.json --label Sepi test/example.fna.gz
% mlst -q --json out.json test/example.gbk.gz test/novel.fasta.bz2
% cat out.json
{
"Sepi" : {
"sequence_type" : "184",
[
{
"scheme" : "sepidermidis",
"alleles" : {
"arcC" : "16",
"mutS" : "1",
"yqiL" : "1",
"gtr" : "2",
"pyrR" : "2",
"tpiA" : "1",
"pyrR" : "2",
"gtr" : "2",
"aroE" : "1",
"mutS" : "1"
"arcC" : "16"
},
"sequence_type" : "184",
"filename" : "test/example.gbk.gz",
"id" : "test/example.gbk.gz"
},
{
"sequence_type" : "-",
"filename" : "test/novel.fasta.bz2",
"scheme" : "spneumoniae",
"alleles" : {
"gki" : "2",
"aroE" : "7",
"ddl" : "22",
"gdh" : "15",
"xpt" : "1",
"recP" : "~10",
"spi" : "6"
},
"filename" : "test/example.fna.gz",
"scheme" : "sepidermidis"
"id" : "test/novel.fasta.bz2"
}
}
]
```
You can also save the "novel" alleles for submission to PubMLST::
```
Expand Down
9 changes: 5 additions & 4 deletions bin/mlst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use Digest::MD5 qw(md5_hex);
#..............................................................................
# Globals

my $VERSION = "2.18.1";
my $VERSION = "2.19.0";
my $EXE = basename( $FindBin::RealScript );
my $AUTHOR = 'Torsten Seemann';
my $URL = 'https://github.com/tseemann/mlst';
Expand Down Expand Up @@ -98,7 +98,7 @@ msg("Excluding $num_excluded schemes:", (keys %exclude)) if $num_excluded > 0;
#..............................................................................
# Output results

my %json;
my $json;

# output the header for the old style syntax
if ($scheme and $legacy) {
Expand Down Expand Up @@ -149,7 +149,8 @@ for my $argv (@ARGV)
}

if ($json_fn) {
$json{$LABEL} = {
push @$json, {
'id' => $LABEL,
'filename' => $argv,
'scheme' => $sch,
'sequence_type' => $ST,
Expand All @@ -166,7 +167,7 @@ for my $argv (@ARGV)
if ($json_fn) {
msg("Writing JSON: $json_fn");
path($json_fn)->spew(
to_json( \%json, {ascii=>1,pretty=>1} ),
to_json( $json, {ascii=>1,pretty=>1} ),
);
}

Expand Down

0 comments on commit c8efc37

Please sign in to comment.