-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setting up webapollo_1.0 branch for release
webapollo_1.0 is branched off of jbrowse_1.7 branch but want Perl data generation code (in ./bin and ./lib) from master so, pulling in ./bin and ./lib directories from master via: git checkout master -- bin lib and now committing
- Loading branch information
1 parent
d330a57
commit 05ef386
Showing
42 changed files
with
7,312 additions
and
127 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,167 @@ | ||
#!/usr/bin/env perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Getopt::Long qw(:config no_ignore_case bundling); | ||
use IO::File; | ||
use File::Basename; | ||
use JSON; | ||
|
||
my $STORE_CLASS = "JBrowse/Store/SeqFeature/BAM"; | ||
my $ALIGNMENT_TYPE = "WebApollo/View/Track/DraggableAlignments"; | ||
my $COVERAGE_TYPE = "JBrowse/View/Track/FeatureCoverage"; | ||
|
||
my $in_file = "data/trackList.json"; | ||
my $out_file = "data/trackList.json"; | ||
my $label; | ||
my $bam_url; | ||
my $key; | ||
my $classname = "bam"; | ||
my $mismatches = 0; | ||
my $coverage = 0; | ||
my $min_score = undef; | ||
my $max_score = undef; | ||
|
||
parse_options(); | ||
add_bam_track(); | ||
|
||
sub parse_options { | ||
my $help; | ||
GetOptions("in|i=s" => \$in_file, | ||
"out|o=s" => \$out_file, | ||
"label|l=s" => \$label, | ||
"bam_url|u=s" => \$bam_url, | ||
"key|k=s" => \$key, | ||
"classname|c=s" => \$classname, | ||
"mismatches|m" => \$mismatches, | ||
"coverage|C" => \$coverage, | ||
"min_score|s=i" => \$min_score, | ||
"max_score|S=i" => \$max_score, | ||
"help|h" => \$help); | ||
print_usage() if $help; | ||
die "Missing label option\n" if !$label; | ||
die "Missing bam_url option\n" if !$bam_url; | ||
die "Missing min_score option\n" if ($coverage && !defined $min_score); | ||
die "Missing max_score option\n" if ($coverage && !defined $max_score); | ||
$key = $label if !$key; | ||
} | ||
|
||
sub print_usage { | ||
my $progname = basename($0); | ||
die << "END"; | ||
usage: $progname | ||
[-i|--in <input_trackList.json>] | ||
[-o|--out <output_trackList.json>] | ||
-l|--label <track_label> | ||
-u|--bam_url <url_to_bam_file> | ||
[-k|--key <track_key>] | ||
[-c|--classname <css_class>] | ||
[-m|--mismatches] | ||
[-C|--coverage] | ||
[-s|--min_score <min_score>] | ||
[-S|--max_score <max_score>] | ||
[-h|--help] | ||
i: input trackList.json file [default: data/trackList.json] | ||
o: output trackList.json file [default: data/trackList.json] | ||
u: URL to BAM file (can be a relative path) | ||
k: key (display name) for track [default: label value] | ||
c: CSS class for display [default: bam] | ||
m: display mismatches in alignment (generates no subfeatures) | ||
C: display coverage data instead of alignments | ||
s: minimum score to use for generating coverage plot (only applicable | ||
to when the -C option is chosen) | ||
S: maximum score to use for generating coverage plot (only applicable | ||
to when the -C option is chosen) | ||
END | ||
} | ||
|
||
sub add_bam_track { | ||
my $json = new JSON; | ||
local $/; | ||
my $in; | ||
$in = new IO::File($in_file) or | ||
die "Error reading input $in_file: $!"; | ||
my $track_list_contents = <$in>; | ||
$in->close(); | ||
my $track_list = $json->decode($track_list_contents); | ||
my $bam_entry; | ||
my $index; | ||
my $tracks = $track_list->{tracks}; | ||
for ($index = 0; $index < scalar(@{$tracks}); ++$index) { | ||
my $track = $tracks->[$index]; | ||
if ($track->{label} eq $label) { | ||
$bam_entry = $track; | ||
last; | ||
} | ||
} | ||
if (!$bam_entry) { | ||
$bam_entry = !$coverage ? generate_new_bam_alignment_entry() : | ||
generate_new_bam_coverage_entry(); | ||
push @{$track_list->{tracks}}, $bam_entry; | ||
} | ||
else { | ||
if ($coverage) { | ||
if ($bam_entry->{type} eq $ALIGNMENT_TYPE) { | ||
$bam_entry = generate_new_bam_coverage_entry(); | ||
$tracks->[$index] = $bam_entry; | ||
} | ||
} | ||
else { | ||
if ($bam_entry->{type} eq $COVERAGE_TYPE) { | ||
$bam_entry = generate_new_bam_alignment_entry(); | ||
$tracks->[$index] = $bam_entry; | ||
} | ||
} | ||
} | ||
$bam_entry->{label} = $label; | ||
$bam_entry->{urlTemplate} = $bam_url; | ||
$bam_entry->{key} = $key; | ||
if (!$coverage) { | ||
$bam_entry->{subfeatures} = $mismatches ? | ||
JSON::false : JSON::true; | ||
$bam_entry->{style}->{className} = $classname; | ||
$bam_entry->{style}->{showSubfeatures} = $mismatches ? | ||
JSON::false : JSON::true; | ||
$bam_entry->{style}->{showMismatches} = $mismatches ? | ||
JSON::true : JSON::false; | ||
} | ||
else { | ||
$bam_entry->{min_score} = $min_score; | ||
$bam_entry->{max_score} = $max_score; | ||
} | ||
my $out; | ||
$out = new IO::File($out_file, "w") or | ||
die "Error writing output $out_file: $!"; | ||
print $out $json->pretty->encode($track_list); | ||
$out->close(); | ||
} | ||
|
||
sub generate_new_bam_alignment_entry { | ||
return { | ||
storeClass => $STORE_CLASS, | ||
type => $ALIGNMENT_TYPE, | ||
style => { | ||
arrowheadClass => JSON::null, | ||
featureScale => 0.5, | ||
labelScale => 100, | ||
subfeatureClasses => { | ||
"M" => "cigarM", | ||
"D" => "cigarD", | ||
"N" => "cigarN", | ||
"=" => "cigarEQ", | ||
"E" => "cigarEQ", | ||
"X" => "cigarX", | ||
"I" => "cigarI" | ||
} | ||
} | ||
}; | ||
} | ||
|
||
sub generate_new_bam_coverage_entry { | ||
return { | ||
storeClass => $STORE_CLASS, | ||
type => $COVERAGE_TYPE | ||
}; | ||
} |
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,134 @@ | ||
#!/usr/bin/env perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Getopt::Long qw(:config no_ignore_case bundling); | ||
use IO::File; | ||
use File::Basename; | ||
use JSON; | ||
|
||
my $in_file = "data/trackList.json"; | ||
my $out_file = "data/trackList.json"; | ||
my $label; | ||
my $bw_url; | ||
my $key; | ||
my $bicolor_pivot = "mean"; | ||
my $pos_color = undef; | ||
my $neg_color = undef; | ||
my $min_score = undef; | ||
my $max_score = undef; | ||
|
||
parse_options(); | ||
add_bw_track(); | ||
|
||
sub parse_options { | ||
my $help; | ||
GetOptions("in|i=s" => \$in_file, | ||
"out|o=s" => \$out_file, | ||
"label|l=s" => \$label, | ||
"bw_url|u=s" => \$bw_url, | ||
"key|k=s" => \$key, | ||
"bicolor_pivot|b=s" => \$bicolor_pivot, | ||
"pos_color|c=s" => \$pos_color, | ||
"neg_color|C=s" => \$neg_color, | ||
"min_score|s=i" => \$min_score, | ||
"max_score|S=i" => \$max_score, | ||
"help|h" => \$help); | ||
print_usage() if $help; | ||
die "Missing label option\n" if !$label; | ||
die "Missing bw_url option\n" if !$bw_url; | ||
$key = $label if !$key; | ||
} | ||
|
||
sub print_usage { | ||
my $progname = basename($0); | ||
die << "END"; | ||
usage: $progname | ||
[-i|--in <input_trackList.json>] | ||
[-o|--out <output_trackList.json>] | ||
-l|--label <track_label> | ||
-u|--bw_url <url_to_big_wig_file> | ||
[-k|--key <track_key>] | ||
[-b|bicolor_pivot <pivot_for_changing_colors>] | ||
[-c|pos_color <color_for_positive_side_of_pivot>] | ||
[-C|neg_color <color_for_negative_side_of_pivot>] | ||
[-s|min_score <min_score>] | ||
[-S|max_score <max_score>] | ||
[-h|--help] | ||
i: input trackList.json file [default: data/trackList.json] | ||
o: output trackList.json file [default: data/trackList.json] | ||
u: URL to BigWig file (can be a relative path) | ||
k: key (display name) for track [default: label value] | ||
b: point where to set pivot for color changes - can be "mean", "zero", | ||
or a numeric value [default: mean] | ||
c: CSS color for positive side of pivot [default: blue] | ||
C: CSS color for negative side of pivot [default: red] | ||
s: mininum score to be graphed [default: autocalculated] | ||
S: maximum score to be graphed [default: autocalculated] | ||
END | ||
} | ||
|
||
sub add_bw_track { | ||
my $json = new JSON; | ||
local $/; | ||
my $in; | ||
$in = new IO::File($in_file) or | ||
die "Error reading input $in_file: $!"; | ||
my $track_list_contents = <$in>; | ||
$in->close(); | ||
my $track_list = $json->decode($track_list_contents); | ||
my $bw_entry; | ||
foreach my $track (@{$track_list->{tracks}}) { | ||
if ($track->{label} eq $label) { | ||
$bw_entry = $track; | ||
last; | ||
} | ||
} | ||
if (!$bw_entry) { | ||
$bw_entry = generate_new_bw_entry(); | ||
push @{$track_list->{tracks}}, $bw_entry; | ||
}; | ||
$bw_entry->{label} = $label; | ||
$bw_entry->{urlTemplate} = $bw_url; | ||
$bw_entry->{key} = $key; | ||
$bw_entry->{bicolor_pivot} = $bicolor_pivot; | ||
if (defined $min_score) { | ||
$bw_entry->{min_score} = $min_score; | ||
} | ||
else { | ||
delete $bw_entry->{min_score}; | ||
} | ||
if (defined $max_score) { | ||
$bw_entry->{max_score} = $max_score; | ||
} | ||
else { | ||
delete $bw_entry->{max_score}; | ||
} | ||
if ($pos_color) { | ||
$bw_entry->{style}->{pos_color} = $pos_color; | ||
} | ||
else { | ||
delete $bw_entry->{style}->{pos_color}; | ||
} | ||
if ($neg_color) { | ||
$bw_entry->{style}->{neg_color} = $neg_color; | ||
} | ||
else { | ||
delete $bw_entry->{style}->{neg_color}; | ||
} | ||
delete $bw_entry->{style} if !scalar(keys %{$bw_entry->{style}}); | ||
my $out; | ||
$out = new IO::File($out_file, "w") or | ||
die "Error writing output $out_file: $!"; | ||
print $out $json->pretty->encode($track_list); | ||
$out->close(); | ||
} | ||
|
||
sub generate_new_bw_entry { | ||
return { | ||
storeClass => "JBrowse/Store/BigWig", | ||
type => "JBrowse/View/Track/Wiggle/Density", | ||
}; | ||
} |
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
Oops, something went wrong.