diff --git a/bin/add-track-json.pl b/bin/add-track-json.pl new file mode 100755 index 0000000000..2b4e7dbc19 --- /dev/null +++ b/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 diff --git a/release-notes.txt b/release-notes.txt index 001646589d..2f565274aa 100644 --- a/release-notes.txt +++ b/release-notes.txt @@ -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