[ensembl-dev] gene to coords code issue

Sean O'Keeffe so2346 at columbia.edu
Fri Apr 20 20:34:21 BST 2012


Hi Andy,
You are indeed spot on. I am using the ensembl 53 api. Switching to ensembl
66 solves the issue.
However, I'm trying to extract hg18 coordinates not hg19 - this was why I
used ensembl_53.
What should I do to get these coords?

Sean.

On 20 April 2012 12:40, Andy Yates <ayates at ebi.ac.uk> wrote:

> Hi Sean,
>
> Normally if you are getting responses saying "can't call method on
> undefined value" points to you using an unreleased API version. Can you
> confirm the version of Ensembl you are using please? Also can you run the
> program ensembl/misc-scripts/ping_ensembl.pl which will attempt to
> diagnose your connection/setup
>
> All the best,
>
> Andy
>
> Andrew Yates                   Ensembl Core Software Project Leader
> EMBL-EBI                       Tel: +44-(0)1223-492538
> Wellcome Trust Genome Campus   Fax: +44-(0)1223-494468
> Cambridge CB10 1SD, UK         http://www.ensembl.org/
>
> On 20 Apr 2012, at 16:16, Sean O'Keeffe wrote:
>
> > Thanks for the response Javier.
> >
> > I see the reference to an array of objects and I've implemented this.
> > However I don't get it. The script dies at the call to
> fetch_all_by_external_name() - Can't call method
> "fetch_all_by_external_name" on an undefined value.
> > It never gets to implement the loop of array objects. The $variable $id
> is valid and prints out prior to the script dying.
> >
> > ...
> > print $id,"\n";
> > my $adaptor = $registry->get_adaptor( 'Human', 'Core', 'gene' );
> >
> > my $gene = $adaptor->fetch_all_by_external_name($id);
> >
> >   foreach $g(@$gene){
> >     $chr = $g->seq_region_name();
> >     $start = $g->seq_region_start();
> >     $end = $g->seq_region_end();
> >     print OUT join("\t", $chr,$start,$end,$id),"\n";
> >   }
> >
> >
> > On 20 April 2012 00:49, Javier Herrero <jherrero at ebi.ac.uk> wrote:
> > Dear Sean
> >
> > The method fetch_all_by_external_name returns a reference to an array of
> Bio::EnsEMBL::Gene objects. All the methods named "fetch_all_by..." return
> a reference to an array. The array might be empty or contain just one
> entry, but you will always get a reference to an array. Contrarily, all the
> methods named "fetch_by..." return either undef or 1 single object.
> >
> > Typically, you would use a foreach loop to go through all possible
> returned object:
> >
> >
> > open OUT, ">$gene_file.coords";
> > for my $geneid ( @unique ) {
> >     chomp $geneid;
> >     ensembl_coords($geneid);
> > }
> >
> > sub ensembl_coords {
> >   my ($id) = @_;
> >
> >   my $adaptor = $registry->get_adaptor( 'Human', 'Core', 'gene' );
> >
> >   my $all_genes = $adaptor->fetch_all_by_external_name($id);
> >
> >   foreach my $gene (@$all_genes) {
> >
> >     $chr = $gene->seq_region_name();
> >     $start = $gene->seq_region_start();
> >     $end = $gene->seq_region_end();
> >     print OUT join("\t", $chr,$start,$end,$id),"\n"; #I have added the
> original $id here
> >   }
> >
> > }
> >
> >
> > I hope the helps
> >
> > Javier
> >
> >
> >
> >
> > On 20/04/12 04:49, Sean O'Keeffe wrote:
> >> Hi,
> >> I've used the code below on multiple occasions to convert external gene
> names to chromosome coords and it worked fine.
> >> However when I tried it just now I get the error for the very first
> gene DNAI2 and the script crashes:
> >>
> >> Can't call method "seq_region_name" on unblessed reference
> >>
> >> When I tried fetch_by_display_label($id) - I get:
> >>
> >> Can't call method "seq_region_name" on an undefined value
> >>
> >> Have I missed something?
> >> Thanks for any help,
> >> Sean.
> >>
> >> p.s. I tried connecting to the useastdb.ensembl.org, as I'm in the
> states, but It gave the following (maybe the 2 issues are related):
> >>
> >> DBI connect('host=useastdb.ensembl.org;port=3306','anonymous',...)
> failed: Can't connect to MySQL server on 'useastdb.ensembl.org' (111) at
> /home/sean/tools/ensembl_53/modules/Bio/EnsEMBL/Registry.pm line 1329
> >> Can't call method "selectall_arrayref" on an undefined value at
> /home/sean/tools/ensembl_53/modules/Bio/EnsEMBL/Registry.pm line 1332.
> >>
> >> ==============
> >>
> >> #!/usr/bin/perl
> >>
> >> use strict;
> >> use lib '/home/sean/tools/ensembl_53/modules';
> >>
> >> use Bio::SeqIO;
> >> use Bio::Root::IO;
> >> use Bio::EnsEMBL::DBSQL::BaseAdaptor;
> >> use Bio::EnsEMBL::Registry;
> >>
> >> my $registry = 'Bio::EnsEMBL::Registry';
> >> #$registry->load_registry_from_db(-host => 'useastdb.ensembl.org',-user
> => 'anonymous');
> >> $registry->load_registry_from_db(-host => 'ensembldb.ensembl.org',-user
> => 'anonymous');
> >>
> >> open OUT, ">$gene_file.coords";
> >> for my $geneid ( @unique ) {
> >>     chomp $geneid;
> >>     ($chr,$start, $end) = ensembl_coords($geneid);
> >>     print OUT join("\t", $chr,$start,$end,$geneid),"\n";
> >> }
> >>
> >> sub ensembl_coords {
> >>   my ($id) = @_;
> >>
> >>   my $adaptor = $registry->get_adaptor( 'Human', 'Core', 'gene' );
> >>
> >>   my $gene = $adaptor->fetch_all_by_external_name($id);
> >>   # my $gene = $adaptor->fetch_by_display_label($id);
> >>
> >>   $chr = $gene->seq_region_name();
> >>   $start = $gene->seq_region_start();
> >>   $end = $gene->seq_region_end();
> >>   return ($chr,$start,$end);
> >>
> >> }
> >>
> >>
> >> _______________________________________________
> >> Dev mailing list
> >> Dev at ensembl.org
> >>
> >> List admin (including subscribe/unsubscribe):
> >> http://lists.ensembl.org/mailman/listinfo/dev
> >>
> >> Ensembl Blog:
> >> http://www.ensembl.info/
> >
> > --
> > Javier Herrero, PhD
> > Ensembl Coordinator and Ensembl Compara Project Leader
> > European Bioinformatics Institute (EMBL-EBI)
> > Wellcome Trust Genome Campus, Hinxton
> > Cambridge - CB10 1SD - UK
> >
> >
> > _______________________________________________
> > Dev mailing list    Dev at ensembl.org
> > List admin (including subscribe/unsubscribe):
> http://lists.ensembl.org/mailman/listinfo/dev
> > Ensembl Blog: http://www.ensembl.info/
> >
> >
> > _______________________________________________
> > Dev mailing list    Dev at ensembl.org
> > List admin (including subscribe/unsubscribe):
> http://lists.ensembl.org/mailman/listinfo/dev
> > Ensembl Blog: http://www.ensembl.info/
>
>
> _______________________________________________
> Dev mailing list    Dev at ensembl.org
> List admin (including subscribe/unsubscribe):
> http://lists.ensembl.org/mailman/listinfo/dev
> Ensembl Blog: http://www.ensembl.info/
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ensembl.org/pipermail/dev_ensembl.org/attachments/20120420/b9d64e48/attachment.html>


More information about the Dev mailing list