forked from GMOD/jbrowse
-
Notifications
You must be signed in to change notification settings - Fork 3
/
wig-to-json.pl
executable file
·184 lines (129 loc) · 5 KB
/
wig-to-json.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env perl
=head1 NAME
wig-to-json.pl - format graph images of Wiggle (.wig) data for use by JBrowse
=head1 USAGE
wig-to-json.pl \
--wig <wiggle file> \
[ --out <JSON directory> ] \
[ --tracklabel <track identifier> ] \
[ --key <human-readable track name> ] \
[ --bgcolor <R,G,B> ] \
[ --fgcolor <R,G,B> ] \
[ --width <tile width> ] \
[ --height <tile height> ] \
[ --min <min> ] \
[ --max <max> ] \
[ --clientConfig '{ JSON-format extra configuration for this track }' ]
=head1 OPTIONS
=over 4
=item --wig <file>
Required. Wiggle file to process.
=item --out <dir>
Directory where the output will go. Defaults to "data/".
=item --trackLabel <label>
Unique label for the track. Defaults to wiggle filename.
=item --key <key>
Human-readable name for the track. Defaults to the same value as the
--trackLabel.
=item --bgcolor <red>,<green>,<blue>
RGB color of wiggle track background, in the form of three
comma-separated numbers giving red, green, and blue color values
respectively, in the range 0-255. Defaults to '255,255,255', which is
white.
Example:
--bgcolor 255,255,255
=item --fgcolor <red>,<green>,<blue>
RGB color of wiggle track foreground (i.e. data graph). Same format
as C<--bgcolor>, defaults to '105,155,111', which is sea green.
=item --width <num pixels>
Width of each image tile in pixels. Defaults to 2000.
=item --height <num pixels>
Height of each image tile in pixels. Defaults to 100.
=item --min <number>
=item --max <number>
Lowest and highest values in wig file. If either are not supplied,
they will be calculated automatically, which takes a bit of extra
time.
=item --clientConfig '{ JSON-format extra configuration for this track }'
Extra configuration for the client, in JSON syntax. Example:
--clientConfig '{"featureCss": "background-color: #668; height: 8px;", "histScale": 2}'
=back
=cut
use strict;
use warnings;
use File::Basename;
use FindBin qw($Bin);
use Getopt::Long;
use Pod::Usage;
use JSON 2;
use lib "$Bin/../lib";
use GenomeDB;
my ($path, $trackLabel, $key, $cssClass);
my $outdir = "data";
my $fgColor = "105,155,111";
my $bgColor = "255,255,255";
my $tileWidth = 2000;
my $trackHeight = 100;
my $min = "";
my $max = "";
my $clientConfig;
my $wig2png = "$Bin/wig2png";
unless( -x $wig2png ) {
die "Can't find binary executable $wig2png, did you compile it? (Hint: try typing './configure && make' in jbrowse root directory)\n";
}
my $help;
GetOptions("wig=s" => \$path,
"out=s" => \$outdir,
"tracklabel|trackLabel=s" => \$trackLabel,
"key=s" => \$key,
"bgcolor=s" => \$bgColor,
"fgcolor=s" => \$fgColor,
"width=s" => \$tileWidth,
"height=s" => \$trackHeight,
"min=f" => \$min,
"max=f" => \$max,
"help|h|?" => \$help,
"clientConfig=s" => \$clientConfig,
) or pod2usage();
pod2usage( -verbose => 2 ) if $help;
pod2usage( 'Must provide a --wig argument.' ) unless defined $path;
my @refSeqs = @{ JSON::from_json(do{ open my $f, '<', "$outdir/refSeqs.json"; local $/; <$f>}) || [] }
or die "Run prepare-refseqs.pl first to supply information about your reference sequences.\n";
$trackLabel = basename( $path ) unless defined $trackLabel;
my $urlTemplate = "tracks/$trackLabel/{refseq}/trackData.json";
my $gdb = GenomeDB->new( $outdir );
my %style = (
"class" => $cssClass,
"key" => defined($key) ? $key : $trackLabel,
"urlTemplate" => $urlTemplate,
"clientConfig" => $clientConfig,
);
$style{clientConfig} = JSON::from_json($clientConfig)
if defined($clientConfig);
my $track = $gdb->getTrack( $trackLabel )
|| $gdb->createImageTrack( $trackLabel,
\%style,
$style{key},
);
$track->startLoad;
system $wig2png, (
$path,
'--outdir' => $track->outDir,
'--tile-width' => $tileWidth,
'--track-height' => $trackHeight,
'--background-color' => $bgColor,
'--foreground-color' => $fgColor,
( defined $min ? ("--min-value" => $min ) : () ),
( defined $max ? ("--max-value" => $max ) : () ),
) and die "Failed to run wig2png: $?\n";
$track->finishLoad;
$gdb->writeTrackEntry( $track );
=head1 AUTHORS
Mitchell Skinner E<lt>mitch_skinner@berkeley.eduE<gt>
Ian Holmes E<lt>ihh@berkeley.eduE<gt>
Copyright (c) 2007-2009 The Evolutionary Software Foundation
This package and its accompanying libraries are free software; you can
redistribute it and/or modify it under the terms of the LGPL (either
version 2.1, or at your option, any later version) or the Artistic
License 2.0. Refer to LICENSE for the full license text.
=cut