Navigation Menu

Skip to content

Commit

Permalink
grab status (a single value for the GI now), now retrievable using ge…
Browse files Browse the repository at this point in the history
…t_status()
  • Loading branch information
Chris Fields committed Dec 15, 2011
1 parent 48bf5f6 commit 9fc9df5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
40 changes: 35 additions & 5 deletions Bio/DB/SeqVersion/gi.pm
Expand Up @@ -168,6 +168,25 @@ sub get_recent {
$ref->[0]->[0];
}

=head2 get_status
Title : get_status
Usage : my $newest_gi = $q->get_status(2)
Function: Get most recent GI given a single GI
Returns : String
Args : A single GI number (string)
=cut

sub get_status {
my ( $self, $id ) = @_;
$self->throw("Must pass an ID") if !defined $id;
if ($id ne $self->{_last_id} ) {
$self->get_history($id);
}
$self->{_last_status};
}

=head2 get_history
Title : get_history
Expand All @@ -180,7 +199,6 @@ sub get_recent {
0 GI number
1 Version
2 Update Date
3 Status
For example, to get the GI number of the first version:
Expand All @@ -191,6 +209,10 @@ sub get_recent {
$ref->[0]->[2]
Args : One identifier (string)
Note : Status of the GI was returned here previously as the last element in
the row of elemnts above; however the status is currently only
returned for the GI requested (e.g. a single value). One can get
the status for this using the get_status() method above
=cut

Expand All @@ -203,6 +225,7 @@ sub get_history {
# are called using the same identifier
$self->{_last_result} = $ref;
$self->{_last_id} = $id;
$self->{_last_status} = $status;
$ref;
}

Expand All @@ -219,7 +242,7 @@ sub get_history {
sub _get_request {
my ( $self, $id ) = @_;

$self->throw("Must specify a single id to query") if ( !$id || ref($id) );
$self->throw("Must specify a single id to query") if ( !defined($id) || ref($id) );

my $url = sprintf( $URL, $id );
my $response = $self->get($url);
Expand All @@ -244,16 +267,23 @@ sub _get_request {
sub _process_data {
my ( $self, $html ) = @_;

# TODO: this is a quick patch, the status is not currently captured as
# it lies outside the table
# Only one status is returned (not one per revision). Setting once
my $status;
if ($html =~ /<div class="status">Current status:\s+(\S+)<\/div>/) {
$status = $1;
} else {
$self->warn("No current status found, setting to 'unknown'");
$status = 'unknown';
}

my $te = HTML::TableExtract->new(
headers => ['Gi', 'Version', 'Update Date'] ,
depth => 0);
$te->parse($html);
my $table = $te->first_table_found;
$self->throw("No table found") unless defined $table;
my $t = [$table->rows];
($t, 1); # the prior version never returned a status...
($t, $status);
}

1;
Expand Down
5 changes: 5 additions & 0 deletions t/RemoteDB/SeqVersion.t
Expand Up @@ -26,20 +26,25 @@ SKIP: {

my $latest_gi = $query->get_recent(2);
is($latest_gi, 2, 'get_recent');
is($query->get_status(2), 'live');

my @all_gis = $query->get_all(2);
cmp_ok(@all_gis, '>=', 8, 'get_all');
is($query->get_status(2), 'live');

$latest_gi = $query->get_recent('A00002');
is($latest_gi, 2, 'get_recent, string');
is($query->get_status('A00002'), 'live');

$latest_gi = $query->get_recent(27478738);
is($latest_gi, 42659163, 'get_recent, integer');
is($query->get_status(27478738), 'dead');

# check that default type is "gi"
ok $query = Bio::DB::SeqVersion->new();
ok my $ref = $query->get_history(3245);
is($ref->[0]->[0], 578167, 'get_history');
is($query->get_status('3245'), 'dead');
}

done_testing();

0 comments on commit 9fc9df5

Please sign in to comment.