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!
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