Mercurial > repos > saketkc > vep_rest
changeset 0:85440c755ba8 draft
Uploaded
author | saketkc |
---|---|
date | Sat, 18 Oct 2014 03:58:04 -0400 |
parents | |
children | 2c1c5a425af1 |
files | vep_rest/tool_dependencies.xml vep_rest/vep_rest.py vep_rest/vep_rest.xml |
diffstat | 3 files changed, 182 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /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 @@ +<?xml version="1.0"?> +<tool_dependency> + <package name="requests" version="2.2.1"> + <repository changeset_revision="570c2648d96d" name="package_requests_2_2_1" owner="saketkc" toolshed="http://testtoolshed.g2.bx.psu.edu" /> + <repository changeset_revision="0a9eff2b87c3" name="package_pyvcf_0_6_7" owner="saketkc" toolshed="http://testtoolshed.g2.bx.psu.edu" /> + </package> +</tool_dependency>
--- /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<saketkc@gmail.com, skchoudh@usc.edu> + +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() +
--- /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 @@ +<tool id="vep_rest" name="VEP Rest"> + <description>VEP Web Service</description> + <requirements> + <requirement type="package" version="2.2.1">requests</requirement> + <requirement type="python-module">requests</requirement> + <requirement type="package" version="2.2.1">pyvcf</requirement> + <requirement type="python-module">pyvcf</requirement> + </requirements> + <command interpreter="python"> + vep_rest.py --input_file $input --output_file $output + </command> + <inputs> + <param name="input" format="vcf" type="data" label="Input variants" /> + </inputs> + <outputs> + <data name="output" format="txt"/> + </outputs> + <tests> + <test> + <param name="input" value="vep_input.vcf"/> + <output name="output" file="vep_output.txt"/> + </test> + </tests> + <help> + + + **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 + + + </help> +</tool> +