line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bio::GMOD::StandardURLs; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
34633
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
48
|
|
4
|
1
|
|
|
1
|
|
7
|
use vars qw/@ISA/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
48
|
|
5
|
1
|
|
|
1
|
|
808
|
use Bio::GMOD::Util::CheckVersions; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Bio::GMOD::Util::Rearrange; |
7
|
|
|
|
|
|
|
use LWP::UserAgent; |
8
|
|
|
|
|
|
|
use XML::Simple; |
9
|
|
|
|
|
|
|
use Data::Dumper; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
@ISA = qw/Bio::GMOD Bio::GMOD::Util::CheckVersions/; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub available_species { |
14
|
|
|
|
|
|
|
my ($self,@p) = @_; |
15
|
|
|
|
|
|
|
my ($expanded) = rearrange([qw/EXPANDED/],@p); |
16
|
|
|
|
|
|
|
my $config = ($self->standard_urls) ? $self->standard_urls : $self->_parse_xml(); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my %species; |
19
|
|
|
|
|
|
|
my @species = @{$config->{species}}; |
20
|
|
|
|
|
|
|
foreach (@species) { |
21
|
|
|
|
|
|
|
$species{$_->{binomial_name}} = $_->{short_name}; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
return \%species if $expanded; |
24
|
|
|
|
|
|
|
return (wantarray) ? ( sort values %species ) : (scalar keys %species); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub releases { |
29
|
|
|
|
|
|
|
my ($self,@p) = @_; |
30
|
|
|
|
|
|
|
my ($requested_species,$expanded,$status) = rearrange([qw/SPECIES EXPANDED STATUS/],@p); |
31
|
|
|
|
|
|
|
my $config = ($self->standard_urls) ? $self->standard_urls : $self->_parse_xml(); |
32
|
|
|
|
|
|
|
$status ||= 'available'; |
33
|
|
|
|
|
|
|
my @available_releases; |
34
|
|
|
|
|
|
|
my @species = @{$config->{species}}; |
35
|
|
|
|
|
|
|
foreach my $species (@species) { |
36
|
|
|
|
|
|
|
if ($requested_species) { |
37
|
|
|
|
|
|
|
next unless ($species->{short_name} eq $requested_species || $species->{binomial_name} eq $requested_species); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
my @releases = _fetch_releases($species); |
40
|
|
|
|
|
|
|
foreach (@releases) { |
41
|
|
|
|
|
|
|
my $available = $_->{available}; |
42
|
|
|
|
|
|
|
next if ($available eq 'yes' && $status eq 'unavailable'); |
43
|
|
|
|
|
|
|
next if ($available ne 'yes' && $status eq 'available'); |
44
|
|
|
|
|
|
|
if ($expanded) { |
45
|
|
|
|
|
|
|
push (@available_releases,[$_->{version},$_->{release_date},$_->{available}]); |
46
|
|
|
|
|
|
|
} else { |
47
|
|
|
|
|
|
|
push (@available_releases,$_->{version}); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
return @available_releases; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub datasets { |
55
|
|
|
|
|
|
|
my ($self,@p) = @_; |
56
|
|
|
|
|
|
|
my ($requested_species,$release) = rearrange([qw/SPECIES RELEASE/],@p); |
57
|
|
|
|
|
|
|
my $config = ($self->standard_urls) ? $self->standard_urls : $self->_parse_xml(); |
58
|
|
|
|
|
|
|
$release ||= $self->get_current($requested_species); |
59
|
|
|
|
|
|
|
$release = $self->get_current($requested_species) if $release eq 'current'; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my @species = @{$config->{species}}; |
62
|
|
|
|
|
|
|
my @supported_datasets = $self->supported_datasets; |
63
|
|
|
|
|
|
|
my $short_name; |
64
|
|
|
|
|
|
|
my $root = $config->{mod}->{mod_url}; |
65
|
|
|
|
|
|
|
foreach (@species) { |
66
|
|
|
|
|
|
|
next unless ($_->{short_name} eq $requested_species || $_->{binomial_name} eq $requested_species); |
67
|
|
|
|
|
|
|
$short_name = $_->{short_name}; |
68
|
|
|
|
|
|
|
my @releases = _fetch_releases($_); |
69
|
|
|
|
|
|
|
foreach (@releases) { |
70
|
|
|
|
|
|
|
next unless $_->{version} eq $release; |
71
|
|
|
|
|
|
|
my %urls = map { $_ => "$root/genome/$short_name/$release/$_" } @supported_datasets; |
72
|
|
|
|
|
|
|
return \%urls; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub supported_datasets { |
79
|
|
|
|
|
|
|
my $self = shift; |
80
|
|
|
|
|
|
|
my $config = ($self->standard_urls) ? $self->standard_urls : $self->_parse_xml(); |
81
|
|
|
|
|
|
|
my @datasets = keys %{$config->{mod}->{supported_datasets}}; |
82
|
|
|
|
|
|
|
return @datasets; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub get_current { |
87
|
|
|
|
|
|
|
my ($self,$requested_species) = @_; |
88
|
|
|
|
|
|
|
my $config = ($self->standard_urls) ? $self->standard_urls : $self->_parse_xml(); |
89
|
|
|
|
|
|
|
my @species = @{$config->{species}}; |
90
|
|
|
|
|
|
|
foreach (@species) { |
91
|
|
|
|
|
|
|
next unless ($_->{short_name} eq $requested_species || $_->{binomial_name} eq $requested_species); |
92
|
|
|
|
|
|
|
my @releases = _fetch_releases($_); |
93
|
|
|
|
|
|
|
my $most_recent = $releases[-1]->{version}; |
94
|
|
|
|
|
|
|
return $most_recent; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub fetch { |
99
|
|
|
|
|
|
|
my ($self,@p) = @_; |
100
|
|
|
|
|
|
|
my ($species,$dataset,$release,$url) = rearrange([qw/SPECIES DATASET RELEASE URL/],@p); |
101
|
|
|
|
|
|
|
my $config = ($self->standard_urls) ? $self->standard_urls : $self->_parse_xml(); |
102
|
|
|
|
|
|
|
my $version = $self->biogmod_version; |
103
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
104
|
|
|
|
|
|
|
$ua->agent("Bio::GMOD::StandardURLs.pm/$version"); |
105
|
|
|
|
|
|
|
my $root = $config->{mod}->{mod_url}; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
$species = $self->get_shortname($species); |
108
|
|
|
|
|
|
|
unless ($url) { |
109
|
|
|
|
|
|
|
$release ||= $self->get_current($species); |
110
|
|
|
|
|
|
|
$release = $self->get_current($species) if $release eq 'current'; |
111
|
|
|
|
|
|
|
$self->logit(-msg=>"You must specify a species, dataset, and release") unless ($species && $dataset && $release); |
112
|
|
|
|
|
|
|
$url = "$root/genome/$species/$release/$dataset"; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# Does this work? |
116
|
|
|
|
|
|
|
my $request = HTTP::Request->new('GET',$url); |
117
|
|
|
|
|
|
|
my $response = $ua->request($request); |
118
|
|
|
|
|
|
|
$self->logit(-msg=>"Couldn't fetch $url: $!") unless $response->is_success; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
if ($response->is_success) { |
121
|
|
|
|
|
|
|
my $content = $response->content(); |
122
|
|
|
|
|
|
|
return $content; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
return 0; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# Accessors |
128
|
|
|
|
|
|
|
sub standard_urls { return shift->{standard_urls}; } |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub get_shortname { |
131
|
|
|
|
|
|
|
my ($self,$species) = @_; |
132
|
|
|
|
|
|
|
my $config = ($self->standard_urls) ? $self->standard_urls : $self->_parse_xml(); |
133
|
|
|
|
|
|
|
my @species = @{$config->{species}}; |
134
|
|
|
|
|
|
|
foreach (@species) { |
135
|
|
|
|
|
|
|
return $_->{short_name} if ($_->{short_name} eq $species); |
136
|
|
|
|
|
|
|
return $_->{short_name} if ($_->{binomial_name} eq $species); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# Parse the standard URLs XML |
141
|
|
|
|
|
|
|
sub _parse_xml { |
142
|
|
|
|
|
|
|
my $self = shift; |
143
|
|
|
|
|
|
|
my $adaptor = $self->adaptor; |
144
|
|
|
|
|
|
|
my $standard_urls = $adaptor->standard_urls_xml; |
145
|
|
|
|
|
|
|
my $version = $self->biogmod_version; |
146
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
147
|
|
|
|
|
|
|
$ua->agent("Bio::GMOD::StandardURLS.pm/$version"); |
148
|
|
|
|
|
|
|
my $request = HTTP::Request->new('GET',$standard_urls); |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
my $response = $ua->request($request); |
151
|
|
|
|
|
|
|
die "Couldn't fetch $standard_urls: $!\n" unless $response->is_success; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
my $content = $response->content; |
154
|
|
|
|
|
|
|
my $config = XMLin($content); |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
# Cache the content for multiple requests |
157
|
|
|
|
|
|
|
$self->{standard_urls} = $config; |
158
|
|
|
|
|
|
|
return $config; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub _fetch_releases { |
163
|
|
|
|
|
|
|
my $species = shift; |
164
|
|
|
|
|
|
|
my @releases; |
165
|
|
|
|
|
|
|
if (ref $species->{release} eq 'ARRAY') { |
166
|
|
|
|
|
|
|
@releases = @{$species->{release}}; |
167
|
|
|
|
|
|
|
} else { |
168
|
|
|
|
|
|
|
my %release = %{$species->{release}}; |
169
|
|
|
|
|
|
|
push @releases,\%release; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
return @releases; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
1; |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
__END__ |