Hello all

I have some gene IDs from Ensembl and I want to get their transcripts' exons and introns (sequences) so that later I can determine exon/intron boundaries and do some analyses.

I've discovered Ensembl Rest API, which is a really easy and clean way of getting data and played around with it a bit. Using this API, I could get coding transcripts of the genes and then sequences of these transcripts. However, I couldn't find any way to distinguish exonic and intronic regions in these sequences.

Here is my script that gets sequences of transcripts of "ENSG00000197568" gene in FASTA format. And I want to get exons and introns like Ensembl gives us in [here][1].

 [1]: http://www.ensembl.org/Homo_sapiens/Transcript/Exons?db=core;g=ENSG00000197568;r=1:70820488-70851022;t=ENST00000359875

```
#!/usr/local/bin/python

import httplib2, sys, re, json

def check_response(response):
    if not response.status == 200:
        print "Invalid response: ", response.status
        sys.exit()

http = httplib2.Http(".cache")
server = "http://beta.rest.ensembl.org/"
gene_id = "ENSG00000197568"
query = "sequence/id/" + gene_id + "?type=cds;multiple_sequences=1"
content_type = "text/x-fasta"

response, content = http.request(server + query, method="GET", headers={"Content-Type":content_type})
check_response(response)

transcripts = re.findall(">(.*)", content)
f = open("output.fasta", "wa")

for transcript in transcripts:
    query = "sequence/id/" + transcript
    response, content = http.request(server + query, method="GET", headers={"Content-Type":content_type})
    check_response(response)
    f.write(content)

f.close()
```

Thanks in advance
Hi Gungor,

We have taken your suggestion into account and added an option to softmask intronic regions

This option is available on our new rest server, http://rest.ensembl.org, along with improved performance.

The following: http://rest.ensembl.org/sequence/id/ENSG00000157764?content-type=text/plain;mask_feature=1

will return the whole gene sequence, with intron sequences in lower case.

In your example, http://rest.ensembl.org/sequence/id/ENSG00000197568?content-type=text/plain;type=cds;multiple_sequences=1

you are already retrieving only the coding sequence for each transcript in the gene. Hence, there are no intronic regions.

I hope this helps and please do not hesitate to contact us if you have any further enquiries.

Regards,  
Magali