FAQ
Hello all,
I posted this question in the bioperl forum- no replies after a day, so
let's see if anyone here can help.

I wrote a short test script for the Bio::DB::Taxonomy module:
================================================
#!/usr/bin/perl -w
use strict;
use Bio::DB::Taxonomy;

my ($nodesfile, $namesfile)= ('nodes.dmp', 'names.dmp');

my $db= new Bio::DB::Taxonomy(-source => 'flatfile',
-nodesfile => $nodesfile,
-namesfile => $namesfile
);

my $bacteria= $db->get_Taxonomy_Node(-taxonid => '2');
print("$bacteria->id\t$bacteria->name\n");
================================================

For those of you who don't use BioPerl, the command
"$db->get_Taxonomy_Node(-
taxonid => '2')" returns a Bio::Taxon object.

After the execution of the print statement I expect to see the ouput " 2
Bacteria".

Instead I get a warning:
UNIVERSAL->import is deprecated and will be removed in a future perl at
/usr/share/perl5/vendor_perl/Bio/Tree/TreeFunctionsI.pm line 94.

and the following ouput:
Bio::Taxon=HASH(0x158dbe0)->id Bio::Taxon=HASH(0x158dbe0)->name

The script seems to be working but there seems to be a problem with
dereferencing a Bio::Taxon object.

Can anyone suggest how I get to the attributes of the Bio::Taxon object?
TIA,
Anjan


--
===================================
Anjan Purkayastha, PhD
Senior Computational Biologist
TessArae LLC
46090 Lake Center Plaza, Suite 304
Potomac Falls, VA 20165**
Office- 703.444.7188 ext. 116
Mobile-703.740.6939
===================================

Search Discussions

  • Shawn wilson at Aug 16, 2011 at 3:18 pm
    On Aug 16, 2011 11:02 AM, "ANJAN PURKAYASTHA" wrote:
    >
    I wrote a short test script for the Bio::DB::Taxonomy module:
    ================================================
    #!/usr/bin/perl -w
    use strict;
    use Bio::DB::Taxonomy;

    my ($nodesfile, $namesfile)= ('nodes.dmp', 'names.dmp');

    my $db= new Bio::DB::Taxonomy(-source => 'flatfile',
    -nodesfile => $nodesfile,
    -namesfile => $namesfile
    );

    my $bacteria= $db->get_Taxonomy_Node(-taxonid => '2');
    print("$bacteria->id\t$bacteria->name\n");
    ================================================

    For those of you who don't use BioPerl, the command
    "$db->get_Taxonomy_Node(-
    taxonid => '2')" returns a Bio::Taxon object.

    After the execution of the print statement I expect to see the ouput " 2
    Bacteria".

    Instead I get a warning:
    UNIVERSAL->import is deprecated and will be removed in a future perl at
    /usr/share/perl5/vendor_perl/Bio/Tree/TreeFunctionsI.pm line 94.
    Your warning is because the maintainer put a 'warn' when you call that
    function. It is probably documented in the pod (or should be) that that
    method call is depreciated and you should do this another way.
    and the following ouput:
    Bio::Taxon=HASH(0x158dbe0)->id Bio::Taxon=HASH(0x158dbe0)->name

    The script seems to be working but there seems to be a problem with
    dereferencing a Bio::Taxon object.
    The later, you'll see with Data::Dumper (but you might consider moving to
    the new method first).
  • Brandon McCaig at Aug 16, 2011 at 3:58 pm

    On Tue, Aug 16, 2011 at 11:00 AM, ANJAN PURKAYASTHA wrote:
    print("$bacteria->id\t$bacteria->name\n"); ...
    and the following ouput:
    Bio::Taxon=HASH(0x158dbe0)->id    Bio::Taxon=HASH(0x158dbe0)->name
    You appear to intend to call methods on $bacteria, but since you're
    within a string what's really happening is $bacteria is being
    converted to a string, which is where the "ClassName=HASH(0xaddress)"
    output comes from, and the ->method_name part is just output literally
    since Perl doesn't understand what you want. You can't normally call a
    method embedded in a string like that. You have two (three) options:

    * Call the methods separately and store the results in variables:

    my $id = $bacteria->id;
    my $name = $bacteria->name;
    print "$id\t$name\n";

    * Pass the result of each method call as a separate parameter to print:

    print $bacteria->id, "\t", $bacteria->name, "\n";

    * Use the "turtle operator" as a hack to achieve the method call
    within the string:

    print "@{[$bacteria->id]}\t@{[$bacteria->name]}\n";

    The latter words because @{} attempts to dereference an arrayref and
    [] creates a new anonymous arrayref; the contents of which are the
    result of each method call. This way is probably least recommended
    because it's somewhat obscure (obviously it's more difficult to read)
    and it's probably less efficient too since Perl probably has to create
    the arrayref only to dereference it right away and forget about it. So
    you should probably use one of the former two options instead.

    (I reserve the right to be completely wrong :D)


    --
    Brandon McCaig <http://www.bamccaig.com/> <bamccaig@gmail.com>
    V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
    Castopulence Software <http://www.castopulence.org/> <bamccaig@castopulence.org>

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedAug 16, '11 at 3:00p
activeAug 16, '11 at 3:58p
posts3
users3
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase