[ensembl-dev] problems on fetching GO terms for all genes of a bacteria using API

mr6 at ebi.ac.uk mr6 at ebi.ac.uk
Tue Jan 7 10:30:11 GMT 2014


Hi Pengfei,

The get_GeneAdaptor method is equivalent using get_Adaptor('Gene').
More documentation can be found here:
http://www.ensembl.org/info/docs/Doxygen/core-api/classBio_1_1EnsEMBL_1_1DBSQL_1_1DBAdaptor.html#a2a1ee81ecb9507fc5ea7bdf39be97bf9

As for the undefined value message you are getting.
By calling get_adaptor on $dba, you are attempting to get an object
adaptor defined in the context of your bacteria database.
Ontologies are stored separately in their own database, ensembl_ontology.

The easiest way to access the ontology database would be as follow:
my $ontology_dba = Bio::EnsEMBL::DBSQL::OntologyDBAdaptor->new(
-HOST => 'mysql.ebi.ac.uk',
-USER => 'anonymous',
-PORT => '4157',
-group   => 'ontology',
-dbname => 'ensemblgenomes_ontology_21_74',
-species => 'multi' );

my $goada = $registry->get_adaptor( 'Multi', 'Ontology', 'OntologyTerm' );

You should then be able to call fetch_by_accession on $goada for a given
GO accession.


Hope that helps,
Magali

> Hi all
>   I am new to API. Now I am trying to use it to get all GO terms for each
> genes of a archaea(Methanocella conradii HZ254), and want to get a table
> with two columns, on for gene name and the other for GO term correponding
> to it
>
> Following the instruction of API and the modifications to use API for
> bacteria, I use the following code to do the job:
> # load the lookup from the main Ensembl Bacteria public server
> my $lookup = Bio::EnsEMBL::LookUp->new(
>   -URL => "http://bacteria.ensembl.org/registry.json",
>   -NO_CACHE => 1
> );
> # find the correct database adaptor using a unique name
> my ($dba) = @{$lookup->get_by_name_exact(
>   'methanocella_conradii_hz254'
> )};
> # get adaptor for ontology
> my $goada=$dba->get_adaptor('Multi','Ontology','OntologyTerm');
> my $genes = $dba->get_GeneAdaptor()->fetch_all(); # where is the
> get_GeneAdaptor() documentation
> # ###test####
> print "Found ".scalar @$genes." genes for ".$dba->species()."\n";
>
> # get go infomation (modified from kokocinsky.net ensembl coding)
> foreach my $gene (@$genes){
> my $links = $gene->get_all_DBLinks();
> foreach my $link (@$links){
> if ($link->database eq "GO"){
> my $term_id=$link->display_id;
> my $term_name='-';
> my $term=$goada->fetch_by_accession($term_id);
> if($term and $term->name){
> $term_name=$term->name;}
> print $gene->stable_id.":$term_id ($term_name)\n";
> # fetch complete GO hierachy
> foreach my $ancestor_term (@{$term->ancestors()}){
> print "\t". $ancestor_term->accession." (".$ancestor_term->name.")\n";
> }
>   }
>  }
> }
>
> it works well before "get go information"
> the output was as following:
> Can't call method "fetch_by_accession" on an undefined value at
> /home/liupf/
> hz254.pl line 27.
> 1, I do not understand the use of 'get_GeneAdaptor', I could not find
> documentation on this synthax.
> 2, please give me some suggestiones on how to fullfill my task.
>
> Thank you all!
>
> $ perl ~/ApiVersion.pl
> The API version used is 74
>
> --
> Pengfei Liu, PhD Candidate
>
> Lab of Microbial Ecology
> College of Resources and Environmental Sciences
> China Agricultural University
> No.2 Yuanmingyuanxilu, Beijing, 100193
> P.R. China
>
> Tel: +86-10-62731358
> Fax: +86-10-62731016
>
> E-mail: liupfskygre at gmail.com
> _______________________________________________
> Dev mailing list    Dev at ensembl.org
> Posting guidelines and subscribe/unsubscribe info:
> http://lists.ensembl.org/mailman/listinfo/dev
> Ensembl Blog: http://www.ensembl.info/
>





More information about the Dev mailing list