<div>Thanks for the response Javier.</div><div><br></div><div>I see the reference to an array of objects and I've implemented this. </div><div>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.</div>
<div>It never gets to implement the loop of array objects. The $variable $id is valid and prints out prior to the script dying.</div><div><br></div><div>...</div><div>print $id,"\n";</div><div>my $adaptor = $registry->get_adaptor( 'Human', 'Core', 'gene' ); </div>
<div><br></div><div>my $gene = $adaptor->fetch_all_by_external_name($id);</div><div><br></div><div>  foreach $g(@$gene){</div><div>    $chr = $g->seq_region_name();</div><div>    $start = $g->seq_region_start();</div>
<div>    $end = $g->seq_region_end();</div><div>    print OUT join("\t", $chr,$start,$end,$id),"\n";</div><div>  }</div><div><br></div><br><div class="gmail_quote">On 20 April 2012 00:49, Javier Herrero <span dir="ltr"><<a href="mailto:jherrero@ebi.ac.uk">jherrero@ebi.ac.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div 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:<div class="im"><br>
    <br>
    <div>open OUT, ">$gene_file.coords";</div>
    <div>for my $geneid ( @unique ) {</div>
    <div>    chomp $geneid;</div>
    </div><div>    ensembl_coords($geneid); </div><div class="im">
    }
    <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><div>  my $all_genes = $adaptor->fetch_all_by_external_name($id);</div>
    <br>
      foreach my $gene (@$all_genes) {<div class="im"><br>
    <div>    $chr = $gene->seq_region_name();</div>
    <div>    $start = $gene->seq_region_start();</div>
    <div>    $end = $gene->seq_region_end();</div>
    </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<div><div class="h5"><br>
    <br>
    <fieldset></fieldset>
    <br>
    <br>
    On 20/04/12 04:49, Sean O'Keeffe wrote:
    </div></div><blockquote type="cite"><div><div class="h5">
      <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 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 href="http://useastdb.ensembl.org/" target="_blank">useastdb.ensembl.org</a>;port=3306','anonymous',...)
        failed: Can't connect to MySQL server on '<a 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 href="http://useastdb.ensembl.org/" target="_blank">useastdb.ensembl.org</a>',-user =>
        'anonymous');</div>
      <div>$registry->load_registry_from_db(-host => '<a 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></fieldset>
      <br>
      </div></div><pre>_______________________________________________
Dev mailing list    <a href="mailto:Dev@ensembl.org" target="_blank">Dev@ensembl.org</a>
List admin (including subscribe/unsubscribe): <a href="http://lists.ensembl.org/mailman/listinfo/dev" target="_blank">http://lists.ensembl.org/mailman/listinfo/dev</a>
Ensembl Blog: <a href="http://www.ensembl.info/" target="_blank">http://www.ensembl.info/</a><span class="HOEnZb"><font color="#888888">
</font></span></pre><span class="HOEnZb"><font color="#888888">
    </font></span></blockquote><span class="HOEnZb"><font color="#888888">
    <br>
    <pre 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>
  </font></span></div>

<br>_______________________________________________<br>
Dev mailing list    <a href="mailto:Dev@ensembl.org">Dev@ensembl.org</a><br>
List admin (including subscribe/unsubscribe): <a href="http://lists.ensembl.org/mailman/listinfo/dev" target="_blank">http://lists.ensembl.org/mailman/listinfo/dev</a><br>
Ensembl Blog: <a href="http://www.ensembl.info/" target="_blank">http://www.ensembl.info/</a><br>
<br></blockquote></div><br>