This is really a question for the Bioperl forum
This is really a question for the Bioperl forum
am 16.08.2011 17:00:39 von ANJAN PURKAYASTHA
--001517401ae28def6a04aaa0a467
Content-Type: text/plain; charset=ISO-8859-1
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
===================================
--001517401ae28def6a04aaa0a467--
Re: This is really a question for the Bioperl forum
am 16.08.2011 17:18:08 von Shawn Wilson
--0015176f110a1f643b04aaa0e386
Content-Type: text/plain; charset=ISO-8859-1
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).
--0015176f110a1f643b04aaa0e386--
Re: This is really a question for the Bioperl forum
am 16.08.2011 17:57:34 von Brandon McCaig
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=3DHASH(0x158dbe0)->id   Bio::Taxon=3DHASH(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=3DHASH(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 =3D $bacteria->id;
my $name =3D $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)
--=20
Brandon McCaig
V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
Castopulence Software
..org>
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/