variantgrid-api 0.2.0__py2-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- variantgrid_api/__init__.py +2 -0
- variantgrid_api/add_classification.py +18 -0
- variantgrid_api/annotation.py +18 -0
- variantgrid_api/api.py +166 -0
- variantgrid_api/classifications.py +120 -0
- variantgrid_api/gene_list.py +15 -0
- variantgrid_api/shariant_classification.py +18 -0
- variantgrid_api/shariant_classification_modify.py +15 -0
- variantgrid_api/variant_classification_vcf.py +25 -0
- variantgrid_api/vcf_utils.py +48 -0
- variantgrid_api-0.2.0.data/scripts/vg_api +127 -0
- variantgrid_api-0.2.0.dist-info/DESCRIPTION.rst +3 -0
- variantgrid_api-0.2.0.dist-info/METADATA +17 -0
- variantgrid_api-0.2.0.dist-info/RECORD +17 -0
- variantgrid_api-0.2.0.dist-info/WHEEL +5 -0
- variantgrid_api-0.2.0.dist-info/metadata.json +1 -0
- variantgrid_api-0.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from __future__ import print_function
|
|
2
|
+
|
|
3
|
+
from variantgrid_api.api import VariantGridAPI
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def add_classification_handle_args(args):
|
|
7
|
+
api = VariantGridAPI.from_args(args)
|
|
8
|
+
|
|
9
|
+
classification = None
|
|
10
|
+
if args.dbsnp:
|
|
11
|
+
classification = api.add_classifications_for_dbsnp(args.dbsnp, args.classification, args.public)
|
|
12
|
+
elif args.variant:
|
|
13
|
+
classification = api.add_classifications_for_variant(args.variant, args.classification, args.public)
|
|
14
|
+
|
|
15
|
+
if classification:
|
|
16
|
+
pk = classification["id"]
|
|
17
|
+
gvc_url = "%s/variantclassification/view_genomic_variant_classification/%d" % (api.url, pk)
|
|
18
|
+
print("Created classification: %s" % gvc_url)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from __future__ import print_function
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from variantgrid_api.api import VariantGridAPI
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def annotation_handle_args(args):
|
|
8
|
+
api = VariantGridAPI.from_args(args)
|
|
9
|
+
ret = None
|
|
10
|
+
if args.gene_id:
|
|
11
|
+
ret = api.gene_annotation(args.gene_id)
|
|
12
|
+
elif args.gene:
|
|
13
|
+
ret = api.gene_annotations(args.gene)
|
|
14
|
+
elif args.variant:
|
|
15
|
+
ret = api.variant_annotation(args.variant)
|
|
16
|
+
|
|
17
|
+
print(json.dumps(ret, indent=4, sort_keys=True))
|
|
18
|
+
|
variantgrid_api/api.py
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import logging
|
|
3
|
+
import os
|
|
4
|
+
import requests
|
|
5
|
+
from requests_oauthlib.oauth2_auth import OAuth2
|
|
6
|
+
from requests_oauthlib.oauth2_session import OAuth2Session
|
|
7
|
+
from oauthlib.oauth2 import LegacyApplicationClient
|
|
8
|
+
|
|
9
|
+
class VariantGridAPI(object):
|
|
10
|
+
def __init__(self,
|
|
11
|
+
user = None,
|
|
12
|
+
password = None,
|
|
13
|
+
host = 'https://shariant.org.au',
|
|
14
|
+
basic_auth = False,
|
|
15
|
+
oauth_url = 'https://shariant.org.au/auth/realms/agha/protocol/openid-connect/token',
|
|
16
|
+
client_id = 'shariant-client-tools',
|
|
17
|
+
verbose=False):
|
|
18
|
+
|
|
19
|
+
if user and password and basic_auth:
|
|
20
|
+
self.auth = (user, password)
|
|
21
|
+
elif user and password and oauth_url and client_id:
|
|
22
|
+
oauth = OAuth2Session(client=LegacyApplicationClient(client_id=client_id))
|
|
23
|
+
if verbose:
|
|
24
|
+
print(user)
|
|
25
|
+
print(password)
|
|
26
|
+
print(client_id)
|
|
27
|
+
print(oauth_url)
|
|
28
|
+
token = oauth.fetch_token(token_url=oauth_url, username=user, password=password, client_id=client_id)
|
|
29
|
+
self.auth = OAuth2(client_id = client_id, token = token)
|
|
30
|
+
else:
|
|
31
|
+
self.auth = None
|
|
32
|
+
self.host = host
|
|
33
|
+
self.verbose = verbose
|
|
34
|
+
|
|
35
|
+
@staticmethod
|
|
36
|
+
def from_args(args):
|
|
37
|
+
return VariantGridAPI(user = args.user,
|
|
38
|
+
password = args.password,
|
|
39
|
+
host = args.host,
|
|
40
|
+
basic_auth = args.basic_auth,
|
|
41
|
+
oauth_url = args.oauth_url,
|
|
42
|
+
client_id = args.client_id,
|
|
43
|
+
verbose = args.verbose)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@property
|
|
47
|
+
def url(self):
|
|
48
|
+
u = "%s" % self.host
|
|
49
|
+
return u
|
|
50
|
+
|
|
51
|
+
def get(self, path, extension = '.json'):
|
|
52
|
+
# extension defaults to .json for variantgrid methods that expect it
|
|
53
|
+
# maybe should add .json to the end of shariant methods for consistancy?
|
|
54
|
+
url_path = os.path.join(self.url, path) + extension
|
|
55
|
+
r = requests.get(url_path, auth=self.auth)
|
|
56
|
+
r.raise_for_status()
|
|
57
|
+
try:
|
|
58
|
+
return json.loads(r.text)
|
|
59
|
+
except Exception as e:
|
|
60
|
+
logging.error("Couldn't decode: %s" % r.text)
|
|
61
|
+
logging.error(e)
|
|
62
|
+
return None
|
|
63
|
+
|
|
64
|
+
def _send(self, path, method, data):
|
|
65
|
+
url_path = os.path.join(self.url, path)
|
|
66
|
+
r = None
|
|
67
|
+
if data is not None:
|
|
68
|
+
data = json.loads(data)
|
|
69
|
+
|
|
70
|
+
if method == 'POST':
|
|
71
|
+
r = requests.post(url_path, auth=self.auth, data=data)
|
|
72
|
+
elif method == 'PUT':
|
|
73
|
+
r = requests.put(url_path, auth=self.auth, data=data)
|
|
74
|
+
elif method == 'PATCH':
|
|
75
|
+
r = requests.patch(url_path, auth=self.auth, data=data)
|
|
76
|
+
elif method == 'DELETE':
|
|
77
|
+
r = requests.put(url_path, auth=self.auth, data=data)
|
|
78
|
+
else:
|
|
79
|
+
raise ValueError('Unsupported method ' + str(method))
|
|
80
|
+
|
|
81
|
+
r.raise_for_status()
|
|
82
|
+
try:
|
|
83
|
+
return json.loads(r.text)
|
|
84
|
+
except Exception as e:
|
|
85
|
+
logging.error("Couldn't decode: %s" % r.text)
|
|
86
|
+
logging.error(e)
|
|
87
|
+
raise e
|
|
88
|
+
|
|
89
|
+
def put(self, path, data):
|
|
90
|
+
return self._send(path, 'PUT', data)
|
|
91
|
+
|
|
92
|
+
def patch(self, path, data):
|
|
93
|
+
return self._send(path, 'PATCH', data)
|
|
94
|
+
|
|
95
|
+
def post(self, path, data):
|
|
96
|
+
return self._send(path, 'POST', data)
|
|
97
|
+
|
|
98
|
+
def delete(self, path, data):
|
|
99
|
+
return self._send(path, 'PUT', data)
|
|
100
|
+
|
|
101
|
+
# shariant stuff below
|
|
102
|
+
|
|
103
|
+
def shariant_classification_all(self):
|
|
104
|
+
'''
|
|
105
|
+
Retrieves a list of shariant classifications the user has access to, will just provide ids
|
|
106
|
+
'''
|
|
107
|
+
return self.get('variantclassification/api/shariant/classification', extension = '')
|
|
108
|
+
|
|
109
|
+
def shariant_classification(self, record_id, version = None):
|
|
110
|
+
'''
|
|
111
|
+
Retrieves a shariant classification
|
|
112
|
+
@param record_id either number that match internal id or previously posted lab id prefixed with 'L_'
|
|
113
|
+
@param version optional, load the classification at this version (or latest if None)
|
|
114
|
+
'''
|
|
115
|
+
if version is None:
|
|
116
|
+
return self.get('variantclassification/api/shariant/classification/' + str(record_id), extension = '')
|
|
117
|
+
else:
|
|
118
|
+
return self.get('variantclassification/api/shariant/classification/' + str(record_id) + '?version=' + str(version), extension = '')
|
|
119
|
+
|
|
120
|
+
def shariant_classification_modify(self, record_id = None, method = 'POST', change = {}):
|
|
121
|
+
'''
|
|
122
|
+
Lets you update or create a shariant classification.
|
|
123
|
+
If POST, record_id can be left blank or to use an internal code prefix any string with 'L_'
|
|
124
|
+
If PATCH or PUT record_id can be it's internal id number or a previously used lab id prefixed with 'L_'
|
|
125
|
+
'''
|
|
126
|
+
#FIXME escape record_id in case it has a slash in it
|
|
127
|
+
return self._send('variantclassification/api/shariant/classification/' + str(record_id) + '?overwrite=true', method, change)
|
|
128
|
+
|
|
129
|
+
def shariant_keys(self):
|
|
130
|
+
'''
|
|
131
|
+
Returns all the currently registered key values for classification evidence and meta data about them.
|
|
132
|
+
'''
|
|
133
|
+
return self.get('variantclassification/api/shariant/keys', extension = '')
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
# variant grid stuff below
|
|
137
|
+
|
|
138
|
+
def loci_variants(self, variant_string):
|
|
139
|
+
''' returns a list of variant objects for this loci '''
|
|
140
|
+
pass
|
|
141
|
+
|
|
142
|
+
def gene_annotation(self, ensembl_gene__id, version=None):
|
|
143
|
+
return self.get('annotation/api/gene_id/%(ensembl_gene__id)s' % {'ensembl_gene__id' : ensembl_gene__id})
|
|
144
|
+
|
|
145
|
+
def gene_annotations(self, gene_symbol, version=None):
|
|
146
|
+
''' This may return multiple annotations for multiple genes '''
|
|
147
|
+
return self.get('annotation/api/gene/%(gene_symbol)s' % {'gene_symbol' : gene_symbol})
|
|
148
|
+
|
|
149
|
+
def variant_annotation(self, variant_string, version=None):
|
|
150
|
+
''' variant_string can be ID, rsId, HGVS '''
|
|
151
|
+
return self.get('annotation/api/variant/%(variant_string)s' % {'variant_string' : variant_string})
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def get_gene_list_genes(self, pk=None, category=None, name=None, version=None):
|
|
155
|
+
''' Use either PK or both (category, name) '''
|
|
156
|
+
too_many = pk and any([category, name])
|
|
157
|
+
too_few = pk is None and not all([category, name])
|
|
158
|
+
if too_many or too_few:
|
|
159
|
+
msg = "You need to supply either 'pk' OR both ('category' AND 'name') arguments"
|
|
160
|
+
raise ValueError(msg)
|
|
161
|
+
|
|
162
|
+
if pk:
|
|
163
|
+
gene_list = self.get('snpdb/gene_list/%s' % pk)
|
|
164
|
+
else:
|
|
165
|
+
gene_list = self.get('snpdb/named_gene_list/%s/%s' % (category, name))
|
|
166
|
+
return gene_list["genelistgene_set"]
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
from __future__ import print_function
|
|
2
|
+
|
|
3
|
+
from collections import defaultdict
|
|
4
|
+
from datetime import datetime
|
|
5
|
+
import variantgrid_api
|
|
6
|
+
from variantgrid_api.api import VariantGridAPI
|
|
7
|
+
|
|
8
|
+
from variantgrid_api.variant_classification_vcf import VARIANTCLASSIFICATION_ID, \
|
|
9
|
+
VARIANTCLASSIFICATION_ZYGOSITY, VARIANTCLASSIFICATION_GROUP, CLASSIFICATION, \
|
|
10
|
+
VARIANT_GRID_INFO_DICT, INFO_SEPARATOR
|
|
11
|
+
from variantgrid_api.vcf_utils import get_vcf_header_lines, get_info
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def write_variant(classifications_for_variant):
|
|
15
|
+
# All loci should be the same
|
|
16
|
+
variant = classifications_for_variant[0]["variant"]
|
|
17
|
+
locus = variant["locus"]
|
|
18
|
+
|
|
19
|
+
columns = [locus["chrom"],
|
|
20
|
+
locus["position"],
|
|
21
|
+
'.', # ID
|
|
22
|
+
locus["ref"],
|
|
23
|
+
variant["alt"],
|
|
24
|
+
'.', # qual
|
|
25
|
+
'.', ] # filter
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
MERGE_COLUMNS = {"id" : VARIANTCLASSIFICATION_ID,
|
|
29
|
+
"zygosity" : VARIANTCLASSIFICATION_ZYGOSITY,
|
|
30
|
+
"classification_group" : VARIANTCLASSIFICATION_GROUP,
|
|
31
|
+
"classification_id" : CLASSIFICATION}
|
|
32
|
+
merged_columns = defaultdict(list)
|
|
33
|
+
for c in classifications_for_variant:
|
|
34
|
+
for k, info_col in MERGE_COLUMNS.items():
|
|
35
|
+
merged_columns[info_col].append(c.get(k))
|
|
36
|
+
|
|
37
|
+
info_dict = {} # "VARIANT_GRID_ID" : variant["id"]}
|
|
38
|
+
for (k, values_list) in merged_columns.items():
|
|
39
|
+
if any(values_list):
|
|
40
|
+
strings_list = map(str, [i or '' for i in values_list])
|
|
41
|
+
info_dict[k] = INFO_SEPARATOR.join(strings_list)
|
|
42
|
+
columns.append(get_info(info_dict))
|
|
43
|
+
print(*columns, sep='\t')
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def get_classifications(args):
|
|
48
|
+
api = VariantGridAPI.from_args(args)
|
|
49
|
+
|
|
50
|
+
classifications = []
|
|
51
|
+
if args.all:
|
|
52
|
+
classifications = api.variant_classifications_all(args.classification)
|
|
53
|
+
elif args.gene:
|
|
54
|
+
classifications = api.variant_classifications_for_gene(args.gene, args.classification)
|
|
55
|
+
elif args.dbsnp:
|
|
56
|
+
classifications = api.variant_classifications_for_dbsnp(args.dbsnp, args.classification)
|
|
57
|
+
elif args.locus:
|
|
58
|
+
classifications = api.variant_classifications_for_locus(args.locus, args.classification)
|
|
59
|
+
elif args.variant:
|
|
60
|
+
classifications = api.variant_classifications_for_variant(args.variant, args.classification)
|
|
61
|
+
return classifications
|
|
62
|
+
|
|
63
|
+
def get_private_command_line(args):
|
|
64
|
+
''' private means don't show password '''
|
|
65
|
+
|
|
66
|
+
SECRET_PARAMS = ["password", "command"]
|
|
67
|
+
GLOBAL_PARAMS = ["host", "port", "login"]
|
|
68
|
+
|
|
69
|
+
global_options_list = []
|
|
70
|
+
for p in GLOBAL_PARAMS:
|
|
71
|
+
v = getattr(args, p)
|
|
72
|
+
if v:
|
|
73
|
+
global_options_list.append("--%s=%s" % (p, v))
|
|
74
|
+
|
|
75
|
+
params = set(vars(args)) - set(SECRET_PARAMS + GLOBAL_PARAMS)
|
|
76
|
+
options_list = []
|
|
77
|
+
for p in params:
|
|
78
|
+
v = getattr(args, p)
|
|
79
|
+
if v:
|
|
80
|
+
options_list.append("--%s=%s" % (p, v))
|
|
81
|
+
|
|
82
|
+
params = {"global_options" : ' '.join(global_options_list),
|
|
83
|
+
"command" : args.command,
|
|
84
|
+
"options" : ' '.join(options_list)}
|
|
85
|
+
return "vg_api %(global_options)s %(command)s %(options)s" % params
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def write_vcf(top_lines, classifications):
|
|
89
|
+
info_dict = VARIANT_GRID_INFO_DICT.copy()
|
|
90
|
+
|
|
91
|
+
header_lines = get_vcf_header_lines(top_lines=top_lines, info_dict=info_dict)
|
|
92
|
+
print('\n'.join(header_lines))
|
|
93
|
+
|
|
94
|
+
# Group by variant_id
|
|
95
|
+
classifications_for_variant = []
|
|
96
|
+
last_variant_id = None
|
|
97
|
+
for classification in classifications:
|
|
98
|
+
variant_id = classification["variant"]["id"]
|
|
99
|
+
if last_variant_id and last_variant_id != variant_id: # Different
|
|
100
|
+
write_variant(classifications_for_variant)
|
|
101
|
+
classifications_for_variant = []
|
|
102
|
+
|
|
103
|
+
classifications_for_variant.append(classification)
|
|
104
|
+
last_variant_id = variant_id
|
|
105
|
+
|
|
106
|
+
if classifications_for_variant: # leftovers
|
|
107
|
+
write_variant(classifications_for_variant)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def classifications_handle_args(args):
|
|
113
|
+
classifications = get_classifications(args)
|
|
114
|
+
vg_api_str = "##generated_by=%s by vg_api v%s" % (datetime.now(), variantgrid_api.__version__)
|
|
115
|
+
command_line = "##command_line=%s" % get_private_command_line(args)
|
|
116
|
+
top_lines = [vg_api_str, command_line]
|
|
117
|
+
|
|
118
|
+
write_vcf(top_lines, classifications)
|
|
119
|
+
|
|
120
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from __future__ import print_function
|
|
2
|
+
|
|
3
|
+
from variantgrid_api.api import VariantGridAPI
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def gene_list_handle_args(args):
|
|
7
|
+
api = VariantGridAPI.from_args(args)
|
|
8
|
+
|
|
9
|
+
if args.pk:
|
|
10
|
+
genes = api.get_gene_list_genes(pk=args.pk)
|
|
11
|
+
elif args.name:
|
|
12
|
+
genes = api.get_gene_list_genes(category=args.category, name=args.name)
|
|
13
|
+
|
|
14
|
+
for gene in genes:
|
|
15
|
+
print(gene)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from __future__ import print_function
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
from variantgrid_api.api import VariantGridAPI
|
|
5
|
+
|
|
6
|
+
def get_classifications(args):
|
|
7
|
+
api = VariantGridAPI.from_args(args)
|
|
8
|
+
|
|
9
|
+
if args.keys:
|
|
10
|
+
return api.shariant_keys()
|
|
11
|
+
elif args.id:
|
|
12
|
+
return api.shariant_classification(args.id, args.version)
|
|
13
|
+
if args.all:
|
|
14
|
+
return api.shariant_classification_all()
|
|
15
|
+
|
|
16
|
+
def shariant_classifications_handle_args(args):
|
|
17
|
+
classifications = get_classifications(args)
|
|
18
|
+
print(json.dumps(classifications))
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from __future__ import print_function
|
|
2
|
+
import sys
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
from variantgrid_api.api import VariantGridAPI
|
|
6
|
+
|
|
7
|
+
def modify_classifications(args):
|
|
8
|
+
api = VariantGridAPI.from_args(args)
|
|
9
|
+
upload = sys.stdin.read() or {}
|
|
10
|
+
return api.shariant_classification_modify(args.id, args.method, upload)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def shariant_classifications_modify_handle_args(args):
|
|
14
|
+
classifications = modify_classifications(args)
|
|
15
|
+
print(json.dumps(classifications))
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
INFO_SEPARATOR = '|'
|
|
2
|
+
|
|
3
|
+
VARIANT_GRID_ID = 'VARIANT_GRID_ID'
|
|
4
|
+
VARIANTCLASSIFICATION_ID = "VARIANTCLASSIFICATION_ID"
|
|
5
|
+
VARIANTCLASSIFICATION_ZYGOSITY = "VARIANTCLASSIFICATION_ZYGOSITY"
|
|
6
|
+
VARIANTCLASSIFICATION_GROUP = "VARIANTCLASSIFICATION_GROUP"
|
|
7
|
+
CLASSIFICATION = "CLASSIFICATION"
|
|
8
|
+
|
|
9
|
+
MULTIPLES = " multiple values joined with a %s" % INFO_SEPARATOR
|
|
10
|
+
|
|
11
|
+
VARIANT_GRID_INFO_DICT = {VARIANT_GRID_ID : {'number' : 1,
|
|
12
|
+
'type' : 'Integer',
|
|
13
|
+
'description' : 'VariantGrid primary column',},
|
|
14
|
+
VARIANTCLASSIFICATION_ID : {'number' : 1,
|
|
15
|
+
'type' : 'String',
|
|
16
|
+
'description' : 'Unique Classification ID' + MULTIPLES,},
|
|
17
|
+
VARIANTCLASSIFICATION_ZYGOSITY : {'number' : 1,
|
|
18
|
+
'type' : 'String',
|
|
19
|
+
'description' : 'Sample Zygosity of classification (E=HET, O=HOM)' + MULTIPLES,},
|
|
20
|
+
VARIANTCLASSIFICATION_GROUP : {'number' : 1,
|
|
21
|
+
'type' : 'String',
|
|
22
|
+
'description' : 'Group performing classification' + MULTIPLES,},
|
|
23
|
+
CLASSIFICATION : {'number' : 1,
|
|
24
|
+
'type' : 'String',
|
|
25
|
+
'description' : 'Pathogenicity according to ACMG guidelines. 1-Benign, 2-Likely Benign, 3-VUS, 4-Likely Pathogenic, 5-Pathogenic' + MULTIPLES,},}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'''
|
|
2
|
+
Created on 13Feb.,2018
|
|
3
|
+
|
|
4
|
+
@author: dlawrence
|
|
5
|
+
'''
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def get_vcf_header_lines(top_lines=[], info_dict={}, formats=[], contigs=[], samples=[]):
|
|
9
|
+
''' info_dict - values of ('number', 'type', 'description')
|
|
10
|
+
contigs - tuples of (contig, length, assembly)
|
|
11
|
+
'''
|
|
12
|
+
|
|
13
|
+
header_lines = ['##fileformat=VCFv4.1']
|
|
14
|
+
header_lines.extend(top_lines)
|
|
15
|
+
for (info_id, data) in info_dict.items():
|
|
16
|
+
data['id'] = info_id
|
|
17
|
+
line_template = '##INFO=<ID=%(id)s,Number=%(number)s,Type=%(type)s,Description="%(description)s">'
|
|
18
|
+
line = line_template % data
|
|
19
|
+
header_lines.append(line)
|
|
20
|
+
|
|
21
|
+
use_format = samples and formats
|
|
22
|
+
if use_format:
|
|
23
|
+
header_lines.extend(formats)
|
|
24
|
+
|
|
25
|
+
for (contig, length, assembly) in contigs:
|
|
26
|
+
line = '##contig=<ID=%s,length=%d,assembly=%s>' % (contig, length, assembly)
|
|
27
|
+
header_lines.append(line)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
colnames = ['CHROM', 'POS', 'ID', 'REF', 'ALT', 'QUAL', 'FILTER', 'INFO']
|
|
31
|
+
if use_format:
|
|
32
|
+
colnames += ['FORMAT'] + samples
|
|
33
|
+
|
|
34
|
+
header_lines.append('#' + '\t'.join(colnames))
|
|
35
|
+
|
|
36
|
+
return header_lines
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def get_info(info_dict):
|
|
40
|
+
if info_dict:
|
|
41
|
+
infos_list = []
|
|
42
|
+
for info_name, info_data in info_dict.items():
|
|
43
|
+
infos_list.append('%s=%s' % (info_name, info_data))
|
|
44
|
+
info = ';'.join(infos_list)
|
|
45
|
+
else:
|
|
46
|
+
info = '.'
|
|
47
|
+
|
|
48
|
+
return info
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#!python
|
|
2
|
+
|
|
3
|
+
from __future__ import print_function
|
|
4
|
+
|
|
5
|
+
from configargparse import Action, ArgParser
|
|
6
|
+
from requests.exceptions import ConnectionError
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
from variantgrid_api.add_classification import add_classification_handle_args
|
|
10
|
+
from variantgrid_api.annotation import annotation_handle_args
|
|
11
|
+
from variantgrid_api.classifications import classifications_handle_args
|
|
12
|
+
from variantgrid_api.shariant_classification import shariant_classifications_handle_args
|
|
13
|
+
from variantgrid_api.shariant_classification_modify import shariant_classifications_modify_handle_args
|
|
14
|
+
from variantgrid_api.gene_list import gene_list_handle_args
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ClassificationAction(Action):
|
|
18
|
+
VALID_CLASSIFICATIONS = range(1, 6)
|
|
19
|
+
def __call__(self, parser, namespace, values, option_string=None):
|
|
20
|
+
if values not in self.VALID_CLASSIFICATIONS:
|
|
21
|
+
valid_classifications_str = ','.join(map(str, self.VALID_CLASSIFICATIONS))
|
|
22
|
+
raise ValueError("classification must be one of %s" % valid_classifications_str)
|
|
23
|
+
setattr(namespace, self.dest, values)
|
|
24
|
+
|
|
25
|
+
def add_authentication(parser, required):
|
|
26
|
+
parser.add("--user", required=required, env_var='VG_USER')
|
|
27
|
+
parser.add("--password", required=required, env_var='VG_PASSWORD')
|
|
28
|
+
parser.add("--basic_auth", action='store_true', env_var='VG_BASIC_AUTH', help='(Only needed for non shariant server) Set to true to just use username and password, otherwise oauth will be attempted')
|
|
29
|
+
parser.add("--oauth_url", default='https://shariant.org.au/auth/realms/agha/protocol/openid-connect/token', env_var='VG_OAUTH', help='(Only needed for non shariant server) Address of where to get the token for oauth')
|
|
30
|
+
parser.add("--client_id", default='shariant-client-tools', env_var="VG_CLIENT_ID", help='(Only needed for non shariant server) OAuth Client ID to request token against')
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def get_args():
|
|
34
|
+
# CLASSIFICATION_HELP = 'HGNC classifications: 1 - Benign, 2 - Likely benign, 3 - VUS, 4 - Likely Pathogenic, 5 - Pathogenic'
|
|
35
|
+
|
|
36
|
+
parser = ArgParser(default_config_files=['~/.vg_api'])
|
|
37
|
+
parser.add('-c', '--config', is_config_file=True, help='config file path')
|
|
38
|
+
|
|
39
|
+
# Global settings
|
|
40
|
+
|
|
41
|
+
parser.add("--host", default='https://shariant.org.au', env_var='VG_HOST', help='Server Address (default=https://shariant.org.au)')
|
|
42
|
+
parser.add("--verbose", action='store_true', env_var='VG_VERBOSE', help='Print debugging information')
|
|
43
|
+
|
|
44
|
+
subparsers = parser.add_subparsers(help='sub-command help', dest='command')
|
|
45
|
+
|
|
46
|
+
# Add Classification
|
|
47
|
+
# add_classification_parser = subparsers.add_parser('add_classification', help='Add new classification for a variant')
|
|
48
|
+
# add_authentication(add_classification_parser, required=True)
|
|
49
|
+
# variant_group = add_classification_parser.add_mutually_exclusive_group(required=True)
|
|
50
|
+
# variant_group.add_argument('--variant', help='hg19 coordinate eg "1:169519049 T>C"')
|
|
51
|
+
# variant_group.add_argument('--dbsnp', help='dbSNP rsId eg "rs6025"')
|
|
52
|
+
# variant_group.add_argument('--hgvs', help='HGVS string eg "F5 (NM_000130) p.Gln534Arg/c.1601A>G"')
|
|
53
|
+
# add_classification_parser.add_argument('--classification', type=int, action=ClassificationAction, help=CLASSIFICATION_HELP)
|
|
54
|
+
# add_classification_parser.add_argument('--public', action='store_true', default=False, help="Classification is public (default=False)")
|
|
55
|
+
|
|
56
|
+
classification_upload_parser = subparsers.add_parser('classification_upload', help="Create/Update a classification in Shariant")
|
|
57
|
+
add_authentication(classification_upload_parser, required=True)
|
|
58
|
+
classification_upload_parser.add_argument("--method", default="POST", help="POST or PATCH")
|
|
59
|
+
classification_upload_parser.add_argument("--id", help="Id of the record, for new record provide own id prefixed by L_ or omit")
|
|
60
|
+
|
|
61
|
+
# Classifications
|
|
62
|
+
# classifications_parser = subparsers.add_parser('classifications', help='Get classification from VariantGrid')
|
|
63
|
+
# add_authentication(classifications_parser, required=False)
|
|
64
|
+
# classifications_parser.add_argument("--classification", type=int, action=ClassificationAction)
|
|
65
|
+
# group = classifications_parser.add_mutually_exclusive_group(required=True)
|
|
66
|
+
# group.add_argument("--all", action='store_true')
|
|
67
|
+
# group.add_argument("--dbsnp")
|
|
68
|
+
# group.add_argument("--gene")
|
|
69
|
+
# group.add_argument("--locus")
|
|
70
|
+
# group.add_argument("--variant")
|
|
71
|
+
|
|
72
|
+
# Classifications
|
|
73
|
+
classifications_parser = subparsers.add_parser('classifications', help="Retrieve classifications from Shariant")
|
|
74
|
+
add_authentication(classifications_parser, required=True)
|
|
75
|
+
classifications_parser.add_argument("--version", default=None, help="Version of the record")
|
|
76
|
+
group = classifications_parser.add_mutually_exclusive_group(required=True)
|
|
77
|
+
group.add_argument("--all", action='store_true')
|
|
78
|
+
group.add_argument("--keys", action='store_true')
|
|
79
|
+
group.add_argument("--id")
|
|
80
|
+
|
|
81
|
+
group = classifications_parser.add
|
|
82
|
+
|
|
83
|
+
# Annotation
|
|
84
|
+
annotation_parser = subparsers.add_parser('annotation', help='Get VariantGrid Annotations')
|
|
85
|
+
|
|
86
|
+
group = annotation_parser.add_mutually_exclusive_group(required=True)
|
|
87
|
+
group.add_argument("--gene-id")
|
|
88
|
+
group.add_argument("--gene")
|
|
89
|
+
group.add_argument("--variant")
|
|
90
|
+
# TODO: Annotation Versions??
|
|
91
|
+
|
|
92
|
+
# Gene List
|
|
93
|
+
gene_list_parser = subparsers.add_parser('gene_list', help='Get Gene List')
|
|
94
|
+
add_authentication(gene_list_parser, required=False)
|
|
95
|
+
gene_list_parser.add_argument("--category", default='Uploaded', help="One of 'Diagnostic', 'Uploaded'")
|
|
96
|
+
group = gene_list_parser.add_mutually_exclusive_group(required=True)
|
|
97
|
+
group.add_argument("--pk")
|
|
98
|
+
group.add_argument("--name")
|
|
99
|
+
|
|
100
|
+
return parser.parse_args()
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def main(args):
|
|
104
|
+
SUBCOMMAND_HANDLERS = {
|
|
105
|
+
"annotation" : annotation_handle_args,
|
|
106
|
+
"add_classification" : add_classification_handle_args,
|
|
107
|
+
"classifications": shariant_classifications_handle_args,
|
|
108
|
+
"classification_upload": shariant_classifications_modify_handle_args,
|
|
109
|
+
# "classifications" : classifications_handle_args,
|
|
110
|
+
"gene_list" : gene_list_handle_args,
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
handler = SUBCOMMAND_HANDLERS[args.command or '<no command given>']
|
|
114
|
+
try:
|
|
115
|
+
return handler(args)
|
|
116
|
+
except ConnectionError as nce:
|
|
117
|
+
if args.verbose:
|
|
118
|
+
msg = str(nce)
|
|
119
|
+
else:
|
|
120
|
+
msg = "Could not connect to server."
|
|
121
|
+
print(msg, file=sys.stderr)
|
|
122
|
+
return 1
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
if __name__ == "__main__":
|
|
126
|
+
args = get_args()
|
|
127
|
+
main(args)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.0
|
|
2
|
+
Name: variantgrid-api
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: API to connect to VariantGrid
|
|
5
|
+
Home-page: https://github.com/SACGF/vg_api
|
|
6
|
+
Author: David Lawrence
|
|
7
|
+
Author-email: davmlaw@gmail.com
|
|
8
|
+
License: MIT License
|
|
9
|
+
Platform: UNKNOWN
|
|
10
|
+
Requires-Dist: configargparse
|
|
11
|
+
Requires-Dist: oauthlib
|
|
12
|
+
Requires-Dist: requests
|
|
13
|
+
Requires-Dist: requests-oauthlib
|
|
14
|
+
|
|
15
|
+
UNKNOWN
|
|
16
|
+
|
|
17
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
variantgrid_api/__init__.py,sha256=PWIPGZ2Gs_4sDGBGaBOXa4H_6vJzYFizkEbUm2E_aSk,23
|
|
2
|
+
variantgrid_api/add_classification.py,sha256=_-42iyMN1SsnGeAtzaF59YPIHPmAauuXeXuZ0_2Esnc,667
|
|
3
|
+
variantgrid_api/annotation.py,sha256=cc5YIBHjdOs42TP6EIsCEMuZF9WIXpY-zBK29lIX7WU,457
|
|
4
|
+
variantgrid_api/api.py,sha256=QptZMcDFxHvrtDyveJ4tXWinh_e1h_FNA65DK2a2d8A,6638
|
|
5
|
+
variantgrid_api/classifications.py,sha256=DEgdhLVv6Rn1bC4CSKnrV1mPN__1_wngzJ9eGBIDJFA,4244
|
|
6
|
+
variantgrid_api/gene_list.py,sha256=AcYXT72ve-CJ7geT6lV81E0I4DSC9Tk2bj6QoNsNxbE,378
|
|
7
|
+
variantgrid_api/shariant_classification.py,sha256=fe_gbfmDkwo5Yed7fLF94iQ7_fQa6FhQtRKynCmyQRc,510
|
|
8
|
+
variantgrid_api/shariant_classification_modify.py,sha256=2h6x9LyTRB0g0Ho-jZTi41We2_BSK79CS6ORrijIbwo,443
|
|
9
|
+
variantgrid_api/variant_classification_vcf.py,sha256=IcuzNnKeOdGSQs-5NBWDgYSDki68ZQkz8WKrB0opPxQ,1685
|
|
10
|
+
variantgrid_api/vcf_utils.py,sha256=n8m3LFUCZKJUDTWh2VC-FQhmXE9m9-5bsKL6oe67rwA,1350
|
|
11
|
+
variantgrid_api-0.2.0.data/scripts/vg_api,sha256=q6jzufxjesK-46t9xe7GflKzC0-K51hibWjrBaBajro,6457
|
|
12
|
+
variantgrid_api-0.2.0.dist-info/DESCRIPTION.rst,sha256=OCTuuN6LcWulhHS3d5rfjdsQtW22n7HENFRh6jC6ego,10
|
|
13
|
+
variantgrid_api-0.2.0.dist-info/METADATA,sha256=84G2sDXcBvzrNi1pPr9_gq4VVrWEmj30AJCJfwLzGAg,357
|
|
14
|
+
variantgrid_api-0.2.0.dist-info/RECORD,,
|
|
15
|
+
variantgrid_api-0.2.0.dist-info/WHEEL,sha256=hZvi-8L6mc2COqhOUWREM_h2lvnJbaHycZt8eohtmso,92
|
|
16
|
+
variantgrid_api-0.2.0.dist-info/metadata.json,sha256=gIr4UIuniFCAub1nQIXhq4Sit1IkpZv4f2yLeLYveUs,533
|
|
17
|
+
variantgrid_api-0.2.0.dist-info/top_level.txt,sha256=OYR1C394miMgIXa_BJxaqrS_8cA_2OZoOwzrT-zUbbM,16
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"extensions": {"python.details": {"contacts": [{"email": "davmlaw@gmail.com", "name": "David Lawrence", "role": "author"}], "document_names": {"description": "DESCRIPTION.rst"}, "project_urls": {"Home": "https://github.com/SACGF/vg_api"}}}, "extras": [], "generator": "bdist_wheel (0.30.0)", "license": "MIT License", "metadata_version": "2.0", "name": "variantgrid-api", "run_requires": [{"requires": ["configargparse", "oauthlib", "requests", "requests-oauthlib"]}], "summary": "API to connect to VariantGrid", "version": "0.2.0"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
variantgrid_api
|