Skip to content

Commit 278306d

Browse files
committed
Merge branch 'develop' into develop-table-replace
2 parents 6da9c93 + 5f5fc67 commit 278306d

File tree

7 files changed

+42527
-33172
lines changed

7 files changed

+42527
-33172
lines changed

api/openapi/api.yaml

Lines changed: 130 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,9 +528,17 @@ paths:
528528
description: ID of view listing all project data assets. For example, for Synapse this would be the Synapse ID of the fileview listing all data assets for a given project.(i.e. master_fileview in config.yml)
529529
example: syn23643253
530530
required: true
531+
- in: query
532+
name: return_type
533+
schema:
534+
type: string
535+
enum: ["json", "csv"]
536+
description: Type of return
537+
example: 'json'
538+
required: true
531539
responses:
532540
"200":
533-
description: A list of json
541+
description: csv file path or json
534542
"500":
535543
description: Check schematic log.
536544
tags:
@@ -677,4 +685,124 @@ paths:
677685
"500":
678686
description: Check schematic log.
679687
tags:
680-
- Schema Operation
688+
- Schema Operation
689+
690+
691+
/explorer/get_node_dependencies:
692+
get:
693+
summary: Get the immediate dependencies that are related to a given source node
694+
description: Get the immediate dependencies that are related to a given source node
695+
operationId: api.routes.get_node_dependencies
696+
parameters:
697+
- in: query
698+
name: schema_url
699+
schema:
700+
type: string
701+
description: Data Model URL
702+
example: >-
703+
https://raw.githubusercontent.com/Sage-Bionetworks/schematic/develop/tests/data/example.model.jsonld
704+
required: true
705+
- in: query
706+
name: source_node
707+
schema:
708+
type: string
709+
nullable: false
710+
description: The node whose dependencies are needed
711+
example: Patient
712+
required: true
713+
- in: query
714+
name: return_display_names
715+
schema:
716+
type: boolean
717+
nullable: true
718+
description: Return display names or not
719+
required: false
720+
example: true
721+
- in: query
722+
name: return_schema_ordered
723+
schema:
724+
type: boolean
725+
nullable: true
726+
description: Return schema ordered or not
727+
required: false
728+
example: true
729+
responses:
730+
"200":
731+
description: List of nodes that are dependent on the source node.
732+
"500":
733+
description: Check schematic log.
734+
tags:
735+
- Schema Operation
736+
737+
/explorer/get_property_label_from_display_name:
738+
get:
739+
summary: Converts a given display name string into a proper property label string
740+
description: Converts a given display name string into a proper property label string
741+
operationId: api.routes.get_property_label_from_display_name
742+
parameters:
743+
- in: query
744+
name: schema_url
745+
schema:
746+
type: string
747+
description: Data Model URL
748+
example: >-
749+
https://raw.githubusercontent.com/Sage-Bionetworks/schematic/develop/tests/data/example.model.jsonld
750+
required: true
751+
- in: query
752+
name: display_name
753+
schema:
754+
type: string
755+
nullable: false
756+
description: The display name to be converted
757+
example: MolecularEntity
758+
required: true
759+
- in: query
760+
name: strict_camel_case
761+
schema:
762+
type: boolean
763+
nullable: false
764+
description: If true the more strict way of
765+
converting to camel case is used.
766+
responses:
767+
"200":
768+
description: The property label of the display name.
769+
"500":
770+
description: Check schematic log.
771+
tags:
772+
- Schema Operation
773+
774+
/explorer/get_node_range:
775+
get:
776+
summary: Get all the valid values that are associated with a node label.
777+
description: Get all the valid values that are associated with a node label.
778+
operationId: api.routes.get_node_range
779+
parameters:
780+
- in: query
781+
name: schema_url
782+
schema:
783+
type: string
784+
description: Data Model URL
785+
example: >-
786+
https://raw.githubusercontent.com/Sage-Bionetworks/schematic/develop/tests/data/example.model.jsonld
787+
required: true
788+
- in: query
789+
name: node_label
790+
schema:
791+
type: string
792+
nullable: false
793+
description: Node / term for which you need to retrieve the range.
794+
example: FamilyHistory
795+
required: true
796+
- in: query
797+
name: return_display_names
798+
schema:
799+
type: boolean
800+
description: If true returns the display names of the nodes.
801+
required: false
802+
responses:
803+
"200":
804+
description: A list of nodes.
805+
"500":
806+
description: Check schematic log.
807+
tags:
808+
- Schema Operation

api/routes.py

Lines changed: 85 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from email import generator
12
import os
23
import shutil
34
import tempfile
@@ -293,7 +294,7 @@ def download_manifest(input_token, dataset_id, asset_view, as_json, new_manifest
293294

294295
return manifest_local_file_path
295296

296-
def get_asset_view_table(input_token, asset_view):
297+
def get_asset_view_table(input_token, asset_view, return_type):
297298
# call config handler
298299
config_handler(asset_view=asset_view)
299300

@@ -303,12 +304,15 @@ def get_asset_view_table(input_token, asset_view):
303304
# get file view table
304305
file_view_table_df = store.getStorageFileviewTable()
305306

306-
# convert pandas dataframe to csv
307-
path = os.getcwd()
308-
export_path = os.path.join(path, 'tests/data/file_view_table.csv')
309-
file_view_table_df.to_csv(export_path, index=False)
310-
311-
return export_path
307+
# return different results based on parameter
308+
if return_type == "json":
309+
json_res = file_view_table_df.to_json()
310+
return json_res
311+
else:
312+
path = os.getcwd()
313+
export_path = os.path.join(path, 'tests/data/file_view_table.csv')
314+
file_view_table_df.to_csv(export_path, index=False)
315+
return export_path
312316

313317

314318
def get_project_manifests(input_token, project_id, asset_view):
@@ -385,4 +389,77 @@ def find_class_specific_properties(schema_url, schema_class):
385389
# return properties
386390
properties = se.find_class_specific_properties(schema_class)
387391

388-
return properties
392+
return properties
393+
394+
395+
def get_node_dependencies(
396+
schema_url: str,
397+
source_node: str,
398+
return_display_names: bool = True,
399+
return_schema_ordered: bool = True
400+
) -> list[str]:
401+
"""Get the immediate dependencies that are related to a given source node.
402+
403+
Args:
404+
schema_url (str): Data Model URL
405+
source_node (str): The node whose dependencies are needed.
406+
return_display_names (bool, optional):
407+
If True, return list of display names of each of the dependencies.
408+
If False, return list of node labels of each of the dependencies.
409+
Defaults to True.
410+
return_schema_ordered (bool, optional):
411+
If True, return the dependencies of the node following the order of the schema (slower).
412+
If False, return dependencies from graph without guaranteeing schema order (faster).
413+
Defaults to True.
414+
415+
Returns:
416+
list[str]: List of nodes that are dependent on the source node.
417+
"""
418+
gen = SchemaGenerator(path_to_json_ld=schema_url)
419+
dependencies = gen.get_node_dependencies(
420+
source_node, return_display_names, return_schema_ordered
421+
)
422+
return dependencies
423+
424+
425+
def get_property_label_from_display_name(
426+
schema_url: str,
427+
display_name: str,
428+
strict_camel_case: bool = False
429+
) -> str:
430+
"""Converts a given display name string into a proper property label string
431+
432+
Args:
433+
schema_url (str): Data Model URL
434+
display_name (str): The display name to be converted
435+
strict_camel_case (bool, optional): If true the more strict way of
436+
converting to camel case is used.
437+
438+
Returns:
439+
str: The property label of the display name
440+
"""
441+
explorer = SchemaExplorer()
442+
explorer.load_schema(schema_url)
443+
label = explorer.get_property_label_from_display_name(display_name, strict_camel_case)
444+
return label
445+
446+
447+
def get_node_range(
448+
schema_url: str,
449+
node_label: str,
450+
return_display_names: bool = True
451+
) -> list[str]:
452+
"""Get the range, i.e., all the valid values that are associated with a node label.
453+
454+
Args:
455+
schema_url (str): Data Model URL
456+
node_label (str): Node / term for which you need to retrieve the range.
457+
return_display_names (bool, optional): If true returns the display names of the nodes.
458+
Defaults to True.
459+
460+
Returns:
461+
list[str]: A list of nodes
462+
"""
463+
gen = SchemaGenerator(path_to_json_ld=schema_url)
464+
node_range = gen.get_node_range(node_label, return_display_names)
465+
return node_range

0 commit comments

Comments
 (0)