[Bioperl-l] Re: Bio::Ontology help solicited
Siddhartha Basu
sidd.basu at gmail.com
Thu Jun 19 19:55:10 UTC 2008
Hi Govind,
There are few ways by which you could search and find the term...
On Thu, 19 Jun 2008, Govind Chandra wrote:
> Hi Hilmar,
>
> Below is an extract from perldoc Bio::Ontology::Ontology from which I
> _wrongly_ concluded that -identifier and -name do the same thing.
>
>
>
> find_terms
>
> Title : find_terms
> Usage : ($term) = $oe->find_terms(-identifier => "SO:0000263");
> Function: Find term instances matching queries for their attributes.
>
> An implementation may not support querying for arbitrary
> attributes, but can generally be expected to accept
> -identifier and -name as queries. If both are provided,
> they are implicitly intersected.
>
> Example :
> Returns : an array of zero or more Bio::Ontology::TermI objects
> Args : Named parameters. The following parameters should be recognized
> by any implementations:
>
> -identifier query by the given identifier
> -name query by the given name
>
>
>
> I had been messing with this script for a few hours before posting for
> help and had tried various combinations of -identifier and -name. But
> neither -identifier => "GO:0000072" nor -name => "M phase specific
> microtubule process" work. I know that the GOid exists because I can
> find it in the obo file. There is something more fundamentally wrong in
> my script than just the syntax. Like you suggested, below, I
> get_all_terms() but the list @allterms is empty.
>
> ### code begins ###
> use strict;
> use Bio::OntologyIO;
>
> my $file='gene_ontology.1_2.obo';
> my $parser = Bio::OntologyIO->new(
> -format => "obo",
> -file => $file
> );
> my $ontology = $parser->next_ontology();
1. You need to get the ontology object to which the term belongs. And if
you don't know if offhand then you have to search and get it.
my $id = 'GO:0000072';
my $term;
ONT:
while ( my $ontrow = $parser->next_ontology() ) {
my ($newterm) = $ontrow->find_terms( -identifier => $id );
next ONT if !$newterm;
$term = $newterm;
last ONT;
}
if ($term) {
print 'First try: ', $term->identifier, "\t", $term->name, "\t",
$term->ontology->name(),
"\n";
}
2. You know the ontology to which the term belong.
my $id = 'GO:0000072';
my $name = 'biological_process';
my $ont;
ONT:
while ( my $ontrow = $parser->next_ontology() ) {
if ($ontrow->name() eq $name) {
$ont = $ontrow;
last ONT;
}
}
my ($term) = $ont->find_terms(-identifier => $id);
if ($term) {
print 'Second try: ', $term->identifier, "\t", $term->name, "\t",
$term->ontology->name(),
"\n";
}
3. Get the engine and search through it
my $id = 'GO:0000072';
my $eng = $parser->next_ontology->engine();
my ($term) = $eng->find_terms(-identifier => $id);
if ($term) {
print 'Third try: ', $term->identifier, "\t", $term->name, "\t",
$term->ontology->name(),
"\n";
}
Hope that helps.
-siddhartha
> print(ref($ontology), "\n");
> my @allterms = $ontology->get_all_terms();
> print(scalar(@allterms), "\n");
> my $limiter;
> foreach my $term (@allterms) {
> print($term->name(),"\n");
> print($term->definition(),"\n");
> if($limiter++ > 30) {last;}
> }
> exit;
> ### code ends ###
>
> ### output begins ###
> Bio::Ontology::Ontology
> 0
> ### output ends ###
>
> Given that the script works with the "go" format files (except
> process.ontology in which case it complains and exits) I suspect the obo
> file but am surprised that Bio::OntologyIO->next_ontology() does not
> complain. Will it be asking for too much to request you to get the obo
> file I am trying to parse from
>
> ftp.geneontology.org/pub/go/ontology/obo_format_1_2/gene_ontology.1_2.obo
>
> and see if it works for you?
>
> Thanks
>
> Govind
>
>
>
>
>
> On Thu, 2008-06-19 at 10:50 -0400, Hilmar Lapp wrote:
> > On Jun 19, 2008, at 10:27 AM, Govind Chandra wrote:
> >
> > > I changed the line below
> > >
> > > my ($term)=$ontology->find_terms(-name => "GO:0000072");
> > >
> > > to
> > >
> > > my ($term)=$ontology->find_terms(-identifier => "GO:0000072");
> >
> > That's odd. Did you convince yourself that a term with this identifier
> > is indeed in the ontology? If you iterate over all terms (using e.g.
> > $ontology->get_all_terms()), is there a term with this identifier?
> >
> > E.g.: print join("\n", map { $_->identifier; }
> > (grep { $_->identifier =~ /0000072/; }
> > $ontology->get_all_terms())),"\n";
> >
> > Does this print anything?
> >
> > > but it does not make any difference. From perldoc I gathered that -
> > > name
> > > and -identifier should do the same thing anyway.
> >
> >
> > I'm not sure where you gathered that from. Could you point me to the
> > location that says that?
> >
> > -hilmar
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l
More information about the Bioperl-l
mailing list