<p>Hello everyone,
I am new to perl API for EnsEMBL. I am even new to perl but doing some readings on both of these, I could write a small code to extract the protein and cDNA sequences of canonical transcript for given Ensembl gene ids. 
I have pasted my code below:</p>

<pre><code>#!/usr/bin/env perl

use strict;
use warnings;

use Bio::EnsEMBL::Registry;
use Data::Dumper;

my $registry = "Bio::EnsEMBL::Registry";
$registry-&gt;load_registry_from_db( -host =&gt;'ensembldb.ensembl.org', -user =&gt; 'anonymous' );
my $gene_adaptor  = $registry-&gt;get_adaptor( 'Human', 'Core', 'Gene' );
my @gene_ids=("ENSG00000001629","ENSG00000001630","ENSG00000001631","ENSG00000002016");

foreach my $gene_id (@gene_ids) {

my $gene = $gene_adaptor-&gt;fetch_by_stable_id($gene_id);
my $cdsseq = $gene-&gt;canonical_transcript()-&gt;translateable_seq();
my $protseq = $gene-&gt;canonical_transcript()-&gt;translate()-&gt;seq();
print $gene_id,"_cDNA\n",$cdsseq,"\n",$gene_id,"_protein\n",$protseq,"\n";
}
</code></pre>

<p>But, what I really want to do is to get all the translatable transcripts (having protein sequence) for a gene including the ensembl protein id and transcript id. (ENSG..............|ENSP...................|ENST...............\n peptide sequence) in a fasta file. And similary, cDNA sequences in another fasta file. Also, my script breaks  when there is no translatable sequence for a gene, how do i set an if clause for that?
Thank you for your help!!</p>

<p>Abhishek</p>

<p>Hello, you may probably check if the translatable sequence is define before your print. If the translatetable sequence is not define, you will not print values and go to next turn. Or if the translatable sequence is define, you print your values but do nothing if not.</p>

<p>For exemple:</p>

<pre><code>#!/usr/bin/env perl

use strict;
use warnings;

use Bio::EnsEMBL::Registry;
use Data::Dumper;

my $registry = "Bio::EnsEMBL::Registry";
$registry-&gt;load_registry_from_db( -host =&gt;'ensembldb.ensembl.org', -user =&gt; 'anonymous' );
my $gene_adaptor  = $registry-&gt;get_adaptor( 'Human', 'Core', 'Gene' );
my @gene_ids=("ENSG00000001629","ENSG00000001630","ENSG00000001631","ENSG00000002016");

foreach my $gene_id (@gene_ids) {
    if ( defined ( $gene-&gt;canonical_transcript()-&gt;translateable_seq() ) ) {
        my $gene = $gene_adaptor-&gt;fetch_by_stable_id($gene_id);
        my $cdsseq = $gene-&gt;canonical_transcript()-&gt;translateable_seq();
        my $protseq = $gene-&gt;canonical_transcript()-&gt;translate()-&gt;seq();
        print $gene_id,"_cDNA\n",$cdsseq,"\n",$gene_id,"_protein\n",$protseq,"\n";
    }
}
</code></pre>

<p>I didn't test this short script but it may works.</p>

<p>Nolwenn</p>
