@@ -37,7 +37,7 @@ class CohdTrapi140(CohdTrapi):
3737 edge_types_negative = ['biolink:negatively_correlated_with' ]
3838 default_negative_predicate = edge_types_negative [0 ]
3939
40- tool_version = f'{ CohdTrapi ._SERVICE_NAME } 6.3.8 '
40+ tool_version = f'{ CohdTrapi ._SERVICE_NAME } 6.3.9 '
4141 schema_version = '1.4.2'
4242 biolink_version = bm_version
4343
@@ -135,24 +135,32 @@ def _check_query_input(self):
135135 query_graph = query_message .get ('query_graph' )
136136 if query_graph is None or not query_graph :
137137 self ._valid_query = False
138- self ._invalid_query_response = ('Unsupported query: query_graph missing from query_message or empty' , 400 )
138+ msg = 'Unsupported query: query_graph missing from query_message or empty'
139+ self .log (msg , level = logging .ERROR )
140+ response = self ._trapi_mini_response (TrapiStatusCode .NO_RESULTS , msg )
141+ self ._invalid_query_response = response , 200
139142 return self ._valid_query , self ._invalid_query_response
140143
141144 # Check the structure of the query graph. Should have 2 nodes and 1 edge (one-hop query)
142145 nodes = query_graph .get ('nodes' )
143146 edges = query_graph .get ('edges' )
144147 if nodes is None or len (nodes ) != 2 or edges is None or len (edges ) != 1 :
145148 self ._valid_query = False
146- self ._invalid_query_response = ('Unsupported query. Only one-hop queries supported.' , 400 )
149+ msg = 'Unsupported query. Only one-hop queries supported.'
150+ self .log (msg , level = logging .WARNING )
151+ response = self ._trapi_mini_response (TrapiStatusCode .NO_RESULTS , msg )
152+ self ._invalid_query_response = response , 200
147153 return self ._valid_query , self ._invalid_query_response
148154
149155 # Check the workflow. Should be at most a single lookup operation
150156 workflow = self ._json_data .get ('workflow' )
151157 if workflow and type (workflow ) is list :
152158 if len (workflow ) > 1 or workflow [0 ]['id' ] != 'lookup' :
153159 self ._valid_query = False
154- self ._invalid_query_response = ('Unsupported workflow. Only a single "lookup" operation is supported' ,
155- 400 )
160+ msg = 'Unsupported workflow. Only a single "lookup" operation is supported'
161+ self .log (msg , level = logging .WARNING )
162+ response = self ._trapi_mini_response (TrapiStatusCode .NO_RESULTS , msg )
163+ self ._invalid_query_response = response , 200
156164 return self ._valid_query , self ._invalid_query_response
157165
158166 # Everything looks good so far
@@ -214,8 +222,8 @@ def _interpret_query(self):
214222 -------
215223 True if input is valid, otherwise (False, message)
216224 """
217- # Log that TRAPI 1.3 was called because there's no clear indication otherwise
218- logging .debug ('Query issued against TRAPI 1.3 ' )
225+ # Log that TRAPI 1.4 was called because there's no clear indication otherwise
226+ logging .debug ('Query issued against TRAPI 1.4 ' )
219227
220228 try :
221229 self ._json_data = self ._request .get_json ()
@@ -260,8 +268,11 @@ def _interpret_query(self):
260268 else :
261269 if self ._method not in CohdTrapi .supported_query_methods :
262270 self ._valid_query = False
263- self ._invalid_query_response = ('Query method "{method}" not supported. Options are: {methods}' .format (
264- method = self ._method , methods = ',' .join (CohdTrapi .supported_query_methods )), 400 )
271+ msg = 'Query method "{method}" not supported. Options are: {methods}' .format (
272+ method = self ._method , methods = ',' .join (CohdTrapi .supported_query_methods ))
273+ self .log (msg , level = logging .ERROR )
274+ response = self ._trapi_mini_response (TrapiStatusCode .NO_RESULTS , msg )
275+ self ._invalid_query_response = response , 200
265276 return self ._valid_query , self ._invalid_query_response
266277
267278 # Get the query_option for dataset ID
@@ -315,7 +326,10 @@ def _interpret_query(self):
315326 edges = self ._query_graph ['edges' ]
316327 if len (edges ) != 1 :
317328 self ._valid_query = False
318- self ._invalid_query_response = (f'{ CohdTrapi ._SERVICE_NAME } reasoner only supports 1-hop queries' , 400 )
329+ msg = f'{ CohdTrapi ._SERVICE_NAME } reasoner only supports 1-hop queries'
330+ self .log (msg , level = logging .WARNING )
331+ response = self ._trapi_mini_response (TrapiStatusCode .NO_RESULTS , msg )
332+ self ._invalid_query_response = response , 200
319333 return self ._valid_query , self ._invalid_query_response
320334
321335 # Check if the edge type is supported by COHD Reasoner and how it should be processed
@@ -368,8 +382,10 @@ def _interpret_query(self):
368382 self ._association_direction = 0
369383 else :
370384 self ._valid_query = False
371- self ._invalid_query_response = (f'None of the predicates in { self ._query_edge_predicates } '
372- f'are supported by { CohdTrapi ._SERVICE_NAME } .' , 400 )
385+ msg = f'None of the predicates in { self ._query_edge_predicates } are supported by { CohdTrapi ._SERVICE_NAME } .'
386+ self .log (msg , level = logging .ERROR )
387+ response = self ._trapi_mini_response (TrapiStatusCode .NO_RESULTS , msg )
388+ self ._invalid_query_response = response , 200
373389 return self ._valid_query , self ._invalid_query_response
374390
375391 if unrecognized_predicates :
@@ -386,13 +402,19 @@ def _interpret_query(self):
386402 subject_qnode = self ._find_query_node (subject_qnode_key )
387403 if subject_qnode is None :
388404 self ._valid_query = False
389- self ._invalid_query_response = (f'QNode id "{ subject_qnode_key } " not found in query graph' , 400 )
405+ msg = f'QNode id "{ subject_qnode_key } " not found in query graph'
406+ self .log (msg , level = logging .ERROR )
407+ response = self ._trapi_mini_response (TrapiStatusCode .NO_RESULTS , msg )
408+ self ._invalid_query_response = response , 200
390409 return self ._valid_query , self ._invalid_query_response
391410 object_qnode_key = self ._query_edge ['object' ]
392411 object_qnode = self ._find_query_node (object_qnode_key )
393412 if object_qnode is None :
394413 self ._valid_query = False
395- self ._invalid_query_response = (f'QNode id "{ object_qnode_key } " not found in query graph' , 400 )
414+ msg = f'QNode id "{ object_qnode_key } " not found in query graph'
415+ self .log (msg , level = logging .ERROR )
416+ response = self ._trapi_mini_response (TrapiStatusCode .NO_RESULTS , msg )
417+ self ._invalid_query_response = response , 200
396418 return self ._valid_query , self ._invalid_query_response
397419
398420 # In COHD queries, concept_id_1 must be specified by ID. Figure out which QNode to use for concept_1
@@ -440,8 +462,10 @@ def _interpret_query(self):
440462 # COHD queries require at least 1 node with a specified ID
441463 if len (node_ids ) == 0 :
442464 self ._valid_query = False
443- self ._invalid_query_response = (f'{ CohdTrapi ._SERVICE_NAME } TRAPI requires at least one node to have an ID' ,
444- 400 )
465+ msg = '{CohdTrapi._SERVICE_NAME} TRAPI requires at least one node to have an ID'
466+ self .log (msg , level = logging .ERROR )
467+ response = self ._trapi_mini_response (TrapiStatusCode .NO_RESULTS , msg )
468+ self ._invalid_query_response = response , 200
445469 return self ._valid_query , self ._invalid_query_response
446470
447471 # Get qnode categories and check the formatting
@@ -1682,8 +1706,8 @@ def _finalize_trapi_response(self, status: TrapiStatusCode = TrapiStatusCode.SUC
16821706 return jsonify (self ._response )
16831707
16841708 def _trapi_mini_response (self ,
1685- status : TrapiStatusCode ,
1686- description : str ):
1709+ status : TrapiStatusCode = TrapiStatusCode . NO_RESULTS ,
1710+ description : str = '' ):
16871711 """ Creates a minimal TRAPI response without creating the knowledge graph or results.
16881712 This is useful for situations where some issue occurred but the TRAPI convention expects an HTTP
16891713 Status Code 200 and TRAPI Response object.
0 commit comments