<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Dear Sean<br>
    <br>
    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.<br>
    <br>
    Typically, you would use a foreach loop to go through all possible
    returned object:<br>
    <br>
    <div>open OUT, ">$gene_file.coords";</div>
    <div>for my $geneid ( @unique ) {</div>
    <div>    chomp $geneid;</div>
    <div>    ensembl_coords($geneid); </div>
    }
    <div>  </div>
    <div>sub ensembl_coords {</div>
    <div>  my ($id) = @_;</div>
    <div> </div>
    <div>  my $adaptor = $registry->get_adaptor( 'Human', 'Core',
      'gene' );</div>
    <div> </div>
    <div>  my $all_genes = $adaptor->fetch_all_by_external_name($id);</div>
    <br>
      foreach my $gene (@$all_genes) {<br>
    <div>    $chr = $gene->seq_region_name();</div>
    <div>    $start = $gene->seq_region_start();</div>
    <div>    $end = $gene->seq_region_end();</div>
    <div>
      <div>    print OUT join("\t", $chr,$start,$end,$id),"\n"; #I have
        added the original $id here<br>
      </div>
        }<br>
    </div>
    <div><br>
      }</div>
    <br>
    <br>
    I hope the helps<br>
    <br>
    Javier<br>
    <br>
    <fieldset class="mimeAttachmentHeader"></fieldset>
    <br>
    <br>
    On 20/04/12 04:49, Sean O'Keeffe wrote:
    <blockquote
cite="mid:CALTeROx9atS9Uk3+Pju_zzOy43DXziQJT=mKJ7375L18kwJUqw@mail.gmail.com"
      type="cite">
      <div>Hi,</div>
      <div>I've used the code below on multiple occasions to convert
        external gene names to chromosome coords and it worked fine.</div>
      <div>However when I tried it just now I get the error for the very
        first gene DNAI2 and the script crashes:</div>
      <div><br>
      </div>
      <div>Can't call method "seq_region_name" on unblessed reference</div>
      <div><br>
      </div>
      <div>When I tried fetch_by_display_label($id) - I get:</div>
      <div><br>
      </div>
      <div>Can't call method "seq_region_name" on an undefined value</div>
      <div><br>
      </div>
      <div>Have I missed something?</div>
      <div>Thanks for any help,</div>
      <div>Sean.</div>
      <div><br>
      </div>
      <div>p.s. I tried connecting to the <a moz-do-not-send="true"
          href="http://useastdb.ensembl.org/" target="_blank">useastdb.ensembl.org,</a>
        as I'm in the states, but It gave the following (maybe the 2
        issues are related):</div>
      <div><br>
      </div>
      <div>DBI connect('host=<a moz-do-not-send="true"
          href="http://useastdb.ensembl.org/" target="_blank">useastdb.ensembl.org</a>;port=3306','anonymous',...)
        failed: Can't connect to MySQL server on '<a
          moz-do-not-send="true" href="http://useastdb.ensembl.org/"
          target="_blank">useastdb.ensembl.org</a>' (111) at
        /home/sean/tools/ensembl_53/modules/Bio/EnsEMBL/Registry.pm line
        1329</div>
      <div>Can't call method "selectall_arrayref" on an undefined value
        at /home/sean/tools/ensembl_53/modules/Bio/EnsEMBL/Registry.pm
        line 1332.</div>
      <div><br>
      </div>
      <div>==============</div>
      <div><br>
      </div>
      <div>#!/usr/bin/perl</div>
      <div><br>
      </div>
      <div>use strict;</div>
      <div>use lib '/home/sean/tools/ensembl_53/modules';</div>
      <div><br>
      </div>
      <div>use Bio::SeqIO;</div>
      <div>use Bio::Root::IO;</div>
      <div>use Bio::EnsEMBL::DBSQL::BaseAdaptor;</div>
      <div>
        use Bio::EnsEMBL::Registry;</div>
      <div> </div>
      <div>my $registry = 'Bio::EnsEMBL::Registry';</div>
      <div>#$registry->load_registry_from_db(-host => '<a
          moz-do-not-send="true" href="http://useastdb.ensembl.org/"
          target="_blank">useastdb.ensembl.org</a>',-user =>
        'anonymous');</div>
      <div>$registry->load_registry_from_db(-host => '<a
          moz-do-not-send="true" href="http://ensembldb.ensembl.org/"
          target="_blank">ensembldb.ensembl.org</a>',-user =>
        'anonymous');</div>
      <div> </div>
      <div>open OUT, ">$gene_file.coords";</div>
      <div>for my $geneid ( @unique ) {</div>
      <div>    chomp $geneid;</div>
      <div>    ($chr,$start, $end) = ensembl_coords($geneid); </div>
      <div>    print OUT join("\t", $chr,$start,$end,$geneid),"\n";</div>
      <div>
        }</div>
      <div>  </div>
      <div>sub ensembl_coords {</div>
      <div>  my ($id) = @_;</div>
      <div> </div>
      <div>  my $adaptor = $registry->get_adaptor( 'Human', 'Core',
        'gene' );</div>
      <div> </div>
      <div>  my $gene = $adaptor->fetch_all_by_external_name($id);</div>
      <div>  # my $gene = $adaptor->fetch_by_display_label($id);</div>
      <div><br>
      </div>
      <div>  $chr = $gene->seq_region_name();</div>
      <div>  $start = $gene->seq_region_start();</div>
      <div>  $end = $gene->seq_region_end();</div>
      <div>  return ($chr,$start,$end);</div>
      <div><br>
      </div>
      <div>}</div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Dev mailing list    <a class="moz-txt-link-abbreviated" href="mailto:Dev@ensembl.org">Dev@ensembl.org</a>
List admin (including subscribe/unsubscribe): <a class="moz-txt-link-freetext" href="http://lists.ensembl.org/mailman/listinfo/dev">http://lists.ensembl.org/mailman/listinfo/dev</a>
Ensembl Blog: <a class="moz-txt-link-freetext" href="http://www.ensembl.info/">http://www.ensembl.info/</a>
</pre>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 
Javier Herrero, PhD
Ensembl Coordinator and Ensembl Compara Project Leader
European Bioinformatics Institute (EMBL-EBI)
Wellcome Trust Genome Campus, Hinxton
Cambridge - CB10 1SD - UK</pre>
  </body>
</html>