Skip to content

Commit

Permalink
Added a small helper script, add-track-json.pl that developers
Browse files Browse the repository at this point in the history
   and advanced users can use to programmatically add a block of track
   configuration JSON to an existing JBrowse configuration file.
  • Loading branch information
rbuels committed Aug 1, 2012
1 parent 8ff3b2e commit 106df2f
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
78 changes: 78 additions & 0 deletions bin/add-track-json.pl
@@ -0,0 +1,78 @@
#!/usr/bin/env perl
use strict;
use warnings;

use Pod::Usage;

use JSON 2;

@ARGV or pod2usage( -verbose => 2 );

# read in the JSON
my $j = JSON->new->relaxed->pretty;
my $json_fh =
@ARGV == 1 ? \*STDIN : do {
my $file = shift @ARGV;
open( my $fh, '<', $file ) or die "$! reading $file";
$fh
};
my $track_data = $j->decode( do{ local $/; scalar <$json_fh> } );

# validate the track JSON structure
$track_data->{label} or die "invalid track JSON: missing a label element\n";

# read and parse the target file
my $target_file = shift @ARGV or pod2usage();
my $target_file_data = eval {
$j->decode( do {
open my $f, '<', $target_file or die "$! reading $target_file";
local $/;
scalar <$f>
});
}; if( $@ ) {
die "error reading target file: $@\n";
}

push @{ $target_file_data->{tracks} ||= [] }, $track_data;

{
open my $fh, '>', $target_file or die "$! writing $target_file";
print $fh $j->encode( $target_file_data );
}


__END__
=head1 NAME
add-track-json.pl - add a single JSON track configuration (from STDIN
or from a file) to the given JBrowse configuration file
=head1 DESCRIPTION
Reads a block of JSON describing a track from a file or from standard
input or from a file, and adds it to the target JBrowse configuration
file.
For example, if you wanted to add a sequence track to
data/trackList.json, you could run something like:
echo ' { "urlTemplate" : "seq/{refseq}/",
"label" : "DNA",
"type" : "SequenceTrack"
} ' | bin/add-track-json.pl data/trackList.json
=head1 USAGE
bin/add-track-json.pl [ track.json ] config.json
# OR
cat track.json | bin/add-track-json.pl config.json
=head2 OPTIONS
none yet
=cut
4 changes: 4 additions & 0 deletions release-notes.txt
Expand Up @@ -15,6 +15,10 @@
both prettier, and more comprehensive, displaying all available
data for the feature.

* Added a small helper script, `add-track-json.pl` that developers
and advanced users can use to programmatically add a block of track
configuration JSON to an existing JBrowse configuration file.

1.4.2 2012-07-12 15:38:55 America/New_York

* Restore support for histScale, subfeatureScale, and labelScale in
Expand Down

0 comments on commit 106df2f

Please sign in to comment.