11"""Provide abstraction for a VLM-to-AnyVar connection."""
22
3+ import logging
4+
35import requests
46from anyvar .utils .types import VrsVariation
57from ga4gh .vrs import models
68
7- from anyvlm .anyvar .base_client import AnyVarClientError , BaseAnyVarClient
9+ from anyvlm .anyvar .base_client import (
10+ AnyVarClientError ,
11+ BaseAnyVarClient ,
12+ UnidentifiedObjectError ,
13+ )
14+
15+ _logger = logging .getLogger (__name__ )
816
917
1018class HttpAnyVarClient (BaseAnyVarClient ):
@@ -21,36 +29,35 @@ def __init__(
2129 self .hostname = hostname
2230 self .request_timeout = request_timeout
2331
24- def put_objects (self , objects : list [VrsVariation ]) -> list [ VrsVariation ] :
32+ def put_objects (self , objects : list [VrsVariation ]) -> None :
2533 """Register objects with AnyVar
2634
27- This method is intentionally naive. Future improvements could include
28- * A better way to batch requests together to mitigate HTTP latency
29- * A smarter dispatch for reconstructing variation model instances
35+ All input objects must have a populated ID field. A validation check for this is
36+ performed before any variants are registered.
3037
3138 :param objects: variation objects to register
3239 :return: completed VRS objects
3340 :raise AnyVarClientError: if connection is unsuccessful during registration request
41+ :raise UnidentifiedObjectError: if *any* provided object lacks a VRS ID
3442 """
35- results = []
43+ objects_to_submit = []
3644 for vrs_object in objects :
45+ if not vrs_object .id :
46+ _logger .error ("Provided variant %s has no VRS ID: %s" )
47+ raise UnidentifiedObjectError
48+ objects_to_submit .append (
49+ vrs_object .model_dump (exclude_none = True , mode = "json" )
50+ )
51+ for vrs_object in objects_to_submit :
3752 response = requests .put (
3853 f"{ self .hostname } /vrs_variation" ,
39- json = vrs_object . model_dump ( exclude_none = True , mode = "json" ) ,
54+ json = vrs_object ,
4055 timeout = self .request_timeout ,
4156 )
4257 try :
4358 response .raise_for_status ()
4459 except requests .HTTPError as e :
4560 raise AnyVarClientError from e
46- result_object = response .json ()["object" ]
47- if result_object .get ("type" ) == "Allele" :
48- results .append (models .Allele (** result_object ))
49- else :
50- raise NotImplementedError (
51- f"Unsupported object type: { result_object .get ('type' )} "
52- )
53- return results
5461
5562 def search_by_interval (
5663 self , accession : str , start : int , end : int
0 commit comments