You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from varsome_api.models.variant import AnnotatedVariant
103
-
# API key is not required for single variant lookups
104
-
api_key = 'Your token'
105
-
api = VarSomeAPIClient(api_key)
106
-
# fetch information about a variant into a dictionary
107
-
result = api.lookup('chr7-140453136-A-T', params={'add-source-databases': 'gnomad-exomes,refseq-transcripts'}, ref_genome='hg19')
108
-
annotated_variant = AnnotatedVariant(**result)
103
+
```python
104
+
from varsome_api.client import VarSomeAPIClient
105
+
from varsome_api.models.variant import AnnotatedVariant
106
+
# API key is not required for single variant lookups
107
+
api_key ='Your token'
108
+
api = VarSomeAPIClient(api_key)
109
+
# fetch information about a variant into a dictionary
110
+
result = api.lookup('chr7-140453136-A-T', params={'add-source-databases': 'gnomad-exomes,refseq-transcripts'}, ref_genome='hg19')
111
+
annotated_variant = AnnotatedVariant(**result)
112
+
```
109
113
110
114
You now have access to a set of shortcut attributes (these will be updated over time in the code base):
111
115
112
-
annotated_variant.chromosome
113
-
annotated_variant.alt
114
-
annotated_variant.genes # directly get the genes related to the variant
115
-
annotated_variant.gnomad_exomes_af # etc
116
-
116
+
```python
117
+
annotated_variant.chromosome
118
+
annotated_variant.alt
119
+
annotated_variant.genes # directly get the genes related to the variant
120
+
annotated_variant.gnomad_exomes_af # etc
121
+
```
117
122
Or you may access other inner properties of other available properties:
118
123
119
-
# get gnomad exomes allele number
120
-
allele_number = [gnomad_exome.an for gnomad_exome in annotated_variant.gnomad_exomes]
124
+
```python
125
+
# get gnomad exomes allele number
126
+
allele_number = [gnomad_exome.an for gnomad_exome in annotated_variant.gnomad_exomes]
127
+
```
121
128
122
129
JSON model-type objects that contain a `version` property, like `annotated_variant.gnomad_exomes`, are
123
130
always returned as lists of objects. This is because the API has the ability to return multiple versions of
124
131
annotation databases (although this is not currently publicly available). For consistency, therefore,
125
132
these are always lists, though it is safe to assume that they will only include a single item. So it is safe
126
133
to rewrite as:
127
-
128
-
try:
129
-
allele_number = [gnomad_exome.an for gnomad_exome in annotated_variant.gnomad_exomes][0]
130
-
except IndexError:
131
-
pass # no gnomad exomes annotation for the variant
132
-
134
+
135
+
```python
136
+
try:
137
+
allele_number = [gnomad_exome.an for gnomad_exome in annotated_variant.gnomad_exomes][0]
138
+
exceptIndexError:
139
+
pass# no gnomad exomes annotation for the variant
140
+
```
141
+
133
142
#### Annotating a VCF using the client
134
143
135
144
To annotate a VCF you can base your code on the VCFAnnotator object. This provides a basic implementation that
136
145
will annotate a VCF file using a set of the available annotations. It uses [PyVCF](https://github.com/jamescasbon/PyVCF) to read and write to VCF files.
0 commit comments