secret
Created

  • Download Gist
eutils fix
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
use Bio::DB::EUtilities;
my (%taxa, @taxa);
my (%names, %idmap);
# these are protein ids; nuc ids will work by changing -dbfrom => 'nucleotide',
# (probably)
my @ids = qw(1621261 89318838 68536103 20807972 730439);
my $factory = Bio::DB::EUtilities->new(-eutil => 'elink',
-db => 'taxonomy',
-email => 'cjfields@bioperl.org',
-dbfrom => 'protein',
-correspondence => 1,
-id => \@ids);
# iterate through the LinkSet objects
while (my $ds = $factory->next_LinkSet) {
$taxa{($ds->get_submitted_ids)[0]} = ($ds->get_ids)[0]
}
# don't use a slice when you need all values; if one of the
# ids in the original list is missing, you'll get an undef
# mixed in the array
 
@taxa = values %taxa;
 
$factory->reset_parameters(
-email => 'cjfields@bioperl.org',
-eutil => 'esummary',
-db => 'taxonomy',
-id => \@taxa );
 
while (my $ds = $factory->next_DocSum) {
$names{($ds->get_contents_by_name('TaxId'))[0]} =
($ds->get_contents_by_name('ScientificName'))[0];
}
foreach my $id (@ids) {
# again, this assumes all IDs are found, use exists to check
$idmap{$id} = $names{$taxa{$id}} if exists $taxa{$id};
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.