Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## A basic API client implementation for [api.varsome.com](https://api.varsome.com)

This tool contains examples for the Varsome API usage. It can be used against either the production server ([api.varsome.com](https://api.varsome.com)) or the staging server ( ([staging-api.varsome.com](https://staging-api.varsome.com)))
This tool contains examples for the Varsome API usage. It can be used against the production server ([api.varsome.com](https://api.varsome.com)), the staging server ([staging-api.varsome.com](https://staging-api.varsome.com)) or the stable api server ([stable-api.varsome.com](https://stable-api.varsome.com))

### Staging-api environment

Expand Down Expand Up @@ -69,6 +69,13 @@ Notice, however, that not all available annotations will be present in the `anno
of the returned annotations will be available when running this script. See the "Using the client in your code"
section below for how to annotate a VCF file with the annotations that are of interest to you.

*Warning*: varsome_api_annotate_vcf.py can only deal with:

- SNPs
- small indels (up to 200bp)

If you want to use this script please remove any variant from your VCF that does not meet the above criteria.

### Using the client in your code

Using the API client is quite straightforward. Just install the API client package and use the following in your code:
Expand All @@ -77,7 +84,7 @@ Using the API client is quite straightforward. Just install the API client packa
from varsome_api.client import VarSomeAPIClient
# API key is not required for single variant lookups
api_key = 'Your token'
api = VarSomeAPIClient(api_key)
api = VarSomeAPIClient(api_key, api_url="https://stable-api.varsome.com")
# fetch information about a variant into a dictionary
result = api.lookup('chr7-140453136-A-T', params={'add-source-databases': 'gnomad-exomes,refseq-transcripts'}, ref_genome='hg19')
# access results e.g. the transcripts of the variant
Expand Down Expand Up @@ -105,7 +112,7 @@ except VarSomeAPIException as e:

To view available request parameters (used by the `params` method parameter), refer to an example at [api.varsome.com](https://api.varsome.com).

To understand how annotation properties are included in the JSON response, please refer to the relevant [schema](https://api.varsome.com/lookup/schema).
To understand how annotation properties are included in the JSON response, please refer to the relevant [schema](https://api.varsome.com/docs/variants/).

#### JSON response wrapper

Expand Down Expand Up @@ -171,7 +178,7 @@ To annotate the VCF file with the annotations that you are interested in, you ne

```python
from varsome_api.vcf import VCFAnnotator
from vcf.parser import _Info
from vcf.parser import _Info, _encode_type
class MyVCFAnnotator(VCFAnnotator):

def annotate_record(self, record, variant_result):
Expand All @@ -192,8 +199,9 @@ class MyVCFAnnotator(VCFAnnotator):
:param vcf_template: vcf reader object
:return:
"""
vcf_template.infos['gnomad_exomes_AN'] = _Info('gnomad_exomes_AN', '.', 'Integer',
'GnomAD exomes allele number value', None, None)
vcf_template.infos['gnomad_exomes_AN'] = _Info('gnomad_exomes_AN', 1, 'Integer',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the second parameter change from '.' to 1? If yes ignore my comment. If no, there are other places in the code that this has changed

'GnomAD exomes allele number value',
None, None, _encode_type("Integer"),)
# if you wish to also include the default headers
# super().add_vcf_header_info(vcf_template)

Expand All @@ -217,9 +225,9 @@ To obtain an API key please [contact us](mailto:support@saphetor.com).

Clone the repository, after creating a virtual environment, and run:

python setup.py test
pip install tox
tox

Running the tests will install [nose](https://nose.readthedocs.io/en/latest/) in your virtual environment.
To run the tests, set the `VARSOME_API_KEY` environment variable to your API token. Otherwise,
tests will fail because the API will return a 401 (not authenticated) error.
Be advised as well that running the tests will count towards your account request limit depending on the
Expand Down
82 changes: 59 additions & 23 deletions scripts/varsome_api_annotate_vcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,78 @@
# limitations under the License.

import argparse
import sys

from varsome_api.vcf import VCFAnnotator

__author__ = 'ckopanos'


def annotate_vcf(argv):
parser = argparse.ArgumentParser(description='VCF Annotator command line')
parser.add_argument('-k', help='Your key to the API', type=str, metavar='API Key', required=True)
parser.add_argument('-g', help='Reference genome either hg19 or hg38', type=str, metavar='Reference Genome',
required=False, default='hg19')
parser.add_argument('-i',
help='Path to vcf file',
type=str, metavar='Input VCF File', required=True)
parser.add_argument('-o',
help='Path to output vcf file',
type=str, metavar='Output VCF File', required=False)
parser.add_argument('-p',
help='Request parameters e.g. add-all-data=1 expand-pubmed-articles=0',
type=str, metavar='Request Params', required=False, nargs='+')
parser.add_argument('-t', help='Run vcf annotator using x threads', type=int, default=3, required=False,
metavar='Number of threads')
def annotate_vcf():
parser = argparse.ArgumentParser(description="VCF Annotator command line")
parser.add_argument(
"-k", help="Your key to the API", type=str, metavar="API Key", required=True
)
parser.add_argument(
"-g",
help="Reference genome either hg19 or hg38",
type=str,
metavar="Reference Genome",
required=False,
default="hg19",
)
parser.add_argument(
"-i", help="Path to vcf file", type=str, metavar="Input VCF File", required=True
)
parser.add_argument(
"-o",
help="Path to output vcf file",
type=str,
metavar="Output VCF File",
required=False,
)
parser.add_argument(
"-p",
help="Request parameters e.g. add-all-data=1 add-ACMG-annotation=1",
type=str,
metavar="Request Params",
required=False,
nargs="+",
)
parser.add_argument(
"-t",
help="Run vcf annotator using x threads",
type=int,
default=3,
required=False,
metavar="Number of threads",
)
parser.add_argument(
"-u",
help="Use specific VarSome API host url "
"(e.g. https://api.varsome.com or https://stable-api.varsome.com",
type=str,
required=False,
metavar="VarSome API host url",
)
args = parser.parse_args()
api_key = args.k
vcf_file = args.i
output_vcf_file = args.o
ref_genome = args.g
num_threads = args.t
api_url = args.u
request_parameters = None
if args.p:
request_parameters = {param[0]: param[1] for param in [param.split("=") for param in args.p]}
vcf_annotator = VCFAnnotator(api_key=api_key, ref_genome=ref_genome, get_parameters=request_parameters,
max_threads=num_threads)
request_parameters = {
param[0]: param[1] for param in [param.split("=") for param in args.p]
}
vcf_annotator = VCFAnnotator(
api_key=api_key,
api_url=api_url,
ref_genome=ref_genome,
get_parameters=request_parameters,
max_threads=num_threads,
)
vcf_annotator.annotate(vcf_file, output_vcf_file)


if __name__ == "__main__":
annotate_vcf(sys.argv[1:])
annotate_vcf()
Loading