# HG changeset patch # User saketkc # Date 1413619084 14400 # Node ID 85440c755ba8af4ecbc949b8e6210f7d28d44947 Uploaded diff -r 000000000000 -r 85440c755ba8 vep_rest/tool_dependencies.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vep_rest/tool_dependencies.xml Sat Oct 18 03:58:04 2014 -0400 @@ -0,0 +1,7 @@ + + + + + + + diff -r 000000000000 -r 85440c755ba8 vep_rest/vep_rest.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vep_rest/vep_rest.py Sat Oct 18 03:58:04 2014 -0400 @@ -0,0 +1,120 @@ +#!/usr/bin/env python +""" +Script to interact with Ensemble Variant Effect Predictor(VEP) +webservice + + +The MIT License (MIT) + +Copyright (c) 2014 Saket Choudhary + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +""" +import argparse +import requests +import sys +import time +import vcf + +URL = 'http://grch37.rest.ensembl.org/vep/human/region/{}:{}-{}/{}?content-type=application/json&protein=1' + +class VEPRestClient: + + def __init__(self, input_file, output_file): + self.pending_urls = [] + vcf_reader = vcf.Reader(open(input_file, 'r')) + self.output_file = output_file + for record in vcf_reader: + url = URL.format(record.CHROM, record.POS, record.POS, ("").join([str(x) for x in record.ALT])) + key = "{}:{}-{}-{}".format(record.CHROM, record.POS, record.POS, ("").join([str(x) for x in record.ALT])) + self.pending_urls.append((key, url)) + + def submit(self): + protein_variants = {} + for record in self.pending_urls: + vcf_key = record[0] + url = record[1] + request = requests.get(url) + time_delay = None + try: + retry_delay = request.headers['Retry-After'] + time_delay = retry_delay + except KeyError: + pass + response = None + if time_delay: + time.sleep(time_delay) + request = requests.get(url) + try: + response = request.json()[0] + except Exception as e: + #TODO Better error handling + print e + if not response: + continue + variants = response['transcript_consequences'] + consequence = "" + for variant in variants: + consequence = "" + protein_id = None + protein_start = None + try: + protein_id = variant['protein_id'] + except KeyError: + pass + try: + protein_start = variant['protein_start'] + except KeyError: + pass + if protein_id: + if protein_id.startswith('ENSP'): + if variant['protein_id'] not in protein_variants.keys(): + protein_variants[protein_id] = [] + consequence += protein_id + if protein_start: + try: + #TODO Better error handling + amino_acid_original, amino_acid_substituted = variant['amino_acids'].split("/") + substitution = amino_acid_original + str(protein_start) + amino_acid_substituted + if "X" not in substitution: + protein_variants[variant['protein_id']].append(substitution) + consequence += " ," + substitution + except: + pass + + output = "" + for key, value in protein_variants.iteritems(): + if len(value)>0: + output += "{} {}\n".format(key, (",").join(value)) + + with open(self.output_file, 'wb') as f: + f.write(output) + + + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--input_file", type=str, required=True, help="Input file location") + parser.add_argument("--output_file", type=str, required=True, help="Output file location") + args = parser.parse_args(sys.argv[1:]) + vep = VEPRestClient(args.input_file, args.output_file) + vep.submit() + diff -r 000000000000 -r 85440c755ba8 vep_rest/vep_rest.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vep_rest/vep_rest.xml Sat Oct 18 03:58:04 2014 -0400 @@ -0,0 +1,55 @@ + + VEP Web Service + + requests + requests + pyvcf + pyvcf + + + vep_rest.py --input_file $input --output_file $output + + + + + + + + + + + + + + + + + **What it does** + + This script calls VEP Rest webserice for GRCh37(http://grch37.rest.ensembl.org/) to fetch + consequences of variations in the proteins ONLY. Variations in transcripts are IGNORED. + + Input is a VCF file.[http://samtools.github.io/hts-specs/VCFv4.2.pdf] + + Output is a text file with each line beginning with Protein identifier followed by comma separated substituions. + Example: + + ENSP00000393181, S52C,G66W,P77S,R85K,V92M,L107I + ENSP00000471152, G45R,R42T,A40T,G19E,L11F,T3M + ENSP00000411579, S52C,G66W,P77S,R85K,V92M,L107I,E124A,E137K,R153H,R156P,E170K,S171L,P172R + ENSP00000349216, R9K,V16M,L31I,E48A,E61K,R77H,R80P,E94K,S95L,P96R + ENSP00000342313, S52C,G66W,P77S,R85K,V92M,L107I,E124A,E137K,R153H,R156P,E170K,S171L,P172R + + + **Citations** + + If you use this tool in Galaxy, please cite : + McLaren W, Pritchard B, Rios D, Chen Y, Flicek P, Cunningham F. + Deriving the consequences of genomic variants with the Ensembl API and SNP Effect Predictor. + Bioinformatics 26(16):2069-70(2010) + doi:10.1093/bioinformatics/btq330 + + + + +