Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters