Annotate variants with ensembl rest api
1
1
Entering edit mode
11 months ago
Andrews ▴ 10

I have a variant file (.vcf.gz), and I want to annotate this file using the Ensembl Rest API, particularly the Vep Rest API. I am new to this variant annotation; however, I have seen a couple of codes from the Ensembl page on how to do this, but I do not know where to input my data (sample.vcf.gz):

  import requests, sys

    server = "https://rest.ensembl.org"
    ext = "/vep/human/hgvs/9:g.22125504G>C?"

    r = requests.get(server+ext, headers={ "Content-Type" : "application/json"})

    if not r.ok:
      r.raise_for_status()
      sys.exit()

    decoded = r.json()
    print(repr(decoded))

I did try my hands on some codes as well but I always get this error message: Error: Failed to retrieve data from Ensembl REST API. Status code: 500.

    def annotate_variants_with_ensembl_rest_api(input_vcf, output_tsv):
    # Ensembl REST API URL for VEP
    server = "https://rest.ensembl.org/vep/human/hgvs"

    # Load compressed VCF file
    with gzip.open(input_vcf, 'rt') as vcf_file:
        vcf_content = vcf_file.read()

    # Define headers for the HTTP request
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    }

    # Define data for the HTTP POST request
    data = {
        'hgvs_notations': vcf_content,
        'assembly_name': 'GRCh38',
        'plugin': ['human']
    }

    # Make an HTTP POST request to Ensembl REST API
    response = requests.post(server, headers=headers, json=data)

Any help will be much appreciated!

Ensembl • 824 views
ADD COMMENT
0
Entering edit mode

loop over each variant of the VCF file and build a REST request for each variant, get the response for each variant, annotate each variant. Here is an old java code: https://github.com/lindenb/jvarkit/blob/master/src/main/java/com/github/lindenb/jvarkit/tools/ensembl/VcfEnsemblVepRest.java#L525

ADD REPLY
1
Entering edit mode
11 months ago
Ben Moore ★ 2.4k

Hi andrewsf.adu,

From the script you shared, it seems that you have used the VEP endpoint that requires HGVS formatted variants as input:

ext = "/vep/human/hgvs/9:g.22125504G>C?"

However, it seems that your input is in VCF format. You'll need to parse your VCF file to ensure your input data matches the required

Also, when specifying the extension for the POST endpoint, you don't need to include any data as you have done if your example:

/vep/human/hgvs

You can check the example request in the documentation page for each endpoint to see the formatting and required parameters for each VEP endpoint. E.g: https://rest.ensembl.org/documentation/info/vep_hgvs_post

We have a freely available online course for using the Ensembl REST API: https://www.ebi.ac.uk/training/online/courses/ensembl-rest-api/take-the-course/

Module 6 covers POST queries although the other modules also include examples of using the VEP endpoints.

ADD COMMENT

Login before adding your answer.

Traffic: 2019 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6