Skip to content

Commit

Permalink
Merge branch 'main' into openchallenges/filter-challenges-by-operation
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaffter authored May 10, 2024
2 parents 27d29eb + d19da69 commit de912e7
Show file tree
Hide file tree
Showing 32 changed files with 867 additions and 227 deletions.
2 changes: 2 additions & 0 deletions apps/schematic/api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ target/
#secrets
*secrets*
schematic_service_account_creds.json
private_localhost_certificate.crt
private_localhost.key

#config files
config.yaml
Expand Down
3 changes: 3 additions & 0 deletions apps/schematic/api/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ schematic_api/models/__init__.py
schematic_api/models/asset_type.py
schematic_api/models/base_model_.py
schematic_api/models/basic_error.py
schematic_api/models/component_requirement_array.py
schematic_api/models/component_requirement_graph.py
schematic_api/models/component_requirement_subgraph.py
schematic_api/models/connected_node_pair.py
schematic_api/models/connected_node_pair_array.py
schematic_api/models/connected_node_pair_page.py
Expand Down
10 changes: 5 additions & 5 deletions apps/schematic/api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/schematic/api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ python = "3.10.14"
connexion = {version = "2.14.1", extras = ["swagger-ui"]}
swagger-ui-bundle = "0.0.9"
python-dateutil = "2.8.2"
Flask = "2.1.3"
Flask = "2.2.5"
Flask-Cors = "3.0.10"
schematicpy = "24.4.1"
# jsonschema isn't a direct import, but is used by connexion.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def generate_google_sheet_manifests(
manifest_title=None,
data_type_array=None,
display_label_type=None,
asset_view_id=None,
use_strict_validation=None,
asset_view_id=None,
generate_all_manifests=None,
): # noqa: E501
"""Generates a list of google sheet links
Expand All @@ -37,10 +37,10 @@ def generate_google_sheet_manifests(
:type data_type_array: List[str]
:param display_label_type: The type of label to display
:type display_label_type: str
:param asset_view_id: ID of view listing all project data assets. E.g. for Synapse this would be the Synapse ID of the fileview listing all data assets for a given project
:type asset_view_id: str
:param use_strict_validation: If true, users are blocked from entering incorrect values. If false, users will get a warning when using incorrect values.
:type use_strict_validation: bool
:param asset_view_id: ID of view listing all project data assets. E.g. for Synapse this would be the Synapse ID of the fileview listing all data assets for a given project
:type asset_view_id: str
:param generate_all_manifests: If true, a manifest for all components will be generated, datasetIds will be ignored. If false, manifests for each id in datasetIds will be generated.
:type generate_all_manifests: bool
Expand All @@ -53,7 +53,7 @@ def generate_google_sheet_manifests(
manifest_title,
data_type_array,
display_label_type,
asset_view_id,
use_strict_validation,
asset_view_id,
generate_all_manifests,
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
handle_exceptions,
get_access_token,
download_schema_file_as_jsonld,
InvalidValueError,
)


Expand All @@ -22,10 +21,10 @@ def generate_google_sheet_manifests(
dataset_id_array: list[str] | None,
manifest_title: str | None,
data_type_array: list[str] | None,
display_label_type: DisplayLabelType = "class_label",
asset_view_id: str | None = None,
use_strict_validation: bool = True,
generate_all_manifests: bool = False,
display_label_type: DisplayLabelType,
use_strict_validation: bool,
asset_view_id: str | None,
generate_all_manifests: bool,
) -> tuple[GoogleSheetLinks | BasicError, int]:
"""Generates a list of links to manifests in google sheet form
Expand Down Expand Up @@ -57,38 +56,9 @@ def generate_google_sheet_manifests(
"""

if generate_all_manifests:
if dataset_id_array:
raise InvalidValueError(
"When generate_all_manifests is True dataset_id_array must be None",
{"dataset_id_array": dataset_id_array},
)
if data_type_array:
raise InvalidValueError(
"When generate_all_manifests is True data_type_array must be None",
{"data_type_array": data_type_array},
)
data_type_array = ["all manifests"]

else:
if not data_type_array:
raise InvalidValueError(
(
"When generate_all_manifests is False data_type_array must be a list with "
"at least one item"
),
{"data_type_array": data_type_array},
)
if dataset_id_array and len(dataset_id_array) != len(data_type_array):
raise InvalidValueError(
(
"When generate_all_manifests is False data_type_array and dataset_id_array "
"must both lists with the same length"
),
{
"data_type_array": data_type_array,
"dataset_id_array": dataset_id_array,
},
)
if not data_type_array:
data_type_array = []

access_token = get_access_token()
if asset_view_id:
Expand Down
48 changes: 48 additions & 0 deletions apps/schematic/api/schematic_api/controllers/schema_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
from typing import Union

from schematic_api.models.basic_error import BasicError # noqa: E501
from schematic_api.models.component_requirement_array import (
ComponentRequirementArray,
) # noqa: E501
from schematic_api.models.component_requirement_graph import (
ComponentRequirementGraph,
) # noqa: E501
from schematic_api.models.connected_node_pair_array import (
ConnectedNodePairArray,
) # noqa: E501
Expand Down Expand Up @@ -42,6 +48,48 @@ def get_component(
)


def get_component_requirements_array(
component_label, schema_url, display_label_type=None
): # noqa: E501
"""Given a source model component (see https://w3id.org/biolink/vocab/category for definnition of component), return all components required by it in array form.
Given a source model component (see https://w3id.org/biolink/vocab/category for definnition of component), return all components required by it in array form. # noqa: E501
:param component_label: The label of a component in a schema
:type component_label: str
:param schema_url: The URL of a schema in jsonld or csv form
:type schema_url: str
:param display_label_type: The type of label to display
:type display_label_type: str
:rtype: Union[ComponentRequirementArray, Tuple[ComponentRequirementArray, int], Tuple[ComponentRequirementArray, int, Dict[str, str]]
"""
return schema_controller_impl.get_component_requirements_array(
component_label, schema_url, display_label_type
)


def get_component_requirements_graph(
component_label, schema_url, display_label_type=None
): # noqa: E501
"""Given a source model component (see https://w3id.org/biolink/vocab/category for definnition of component), return all components required by it in graph form.
Given a source model component (see https://w3id.org/biolink/vocab/category for definnition of component), return all components required by it in graph form. # noqa: E501
:param component_label: The label of a component in a schema
:type component_label: str
:param schema_url: The URL of a schema in jsonld or csv form
:type schema_url: str
:param display_label_type: The type of label to display
:type display_label_type: str
:rtype: Union[ComponentRequirementGraph, Tuple[ComponentRequirementGraph, int], Tuple[ComponentRequirementGraph, int, Dict[str, str]]
"""
return schema_controller_impl.get_component_requirements_graph(
component_label, schema_url, display_label_type
)


def get_connected_node_pair_array(
schema_url, relationship_type, display_label_type=None
): # noqa: E501
Expand Down
121 changes: 81 additions & 40 deletions apps/schematic/api/schematic_api/controllers/schema_controller_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from schematic.utils.schema_utils import DisplayLabelType # type: ignore

from schematic_api.models.basic_error import BasicError
from schematic_api.models.component_requirement_subgraph import (
ComponentRequirementSubgraph,
)
from schematic_api.models.node_property_array import NodePropertyArray
from schematic_api.models.validation_rule import ValidationRule
from schematic_api.models.validation_rule_array import ValidationRuleArray
Expand All @@ -27,6 +30,29 @@
from schematic_api.controllers.paging import Page


def create_data_model_graph_explorer(
schema_url: str, display_label_type: DisplayLabelType
) -> DataModelGraphExplorer:
"""Creates a DataModelGraphExplorer for use in variopus endpoints
Args:
schema_url (str): The URL of the schema in json form
display_label_type (DisplayLabelType):
The type of label to use as display
Returns:
DataModelGraphExplorer: _description_
"""
data_model_parser = DataModelParser(path_to_data_model=schema_url)
parsed_data_model = data_model_parser.parse_model()
data_model_grapher = DataModelGraph(
attribute_relationships_dict=parsed_data_model,
data_model_labels=display_label_type,
)
graph_data_model = data_model_grapher.generate_data_model_graph()
return DataModelGraphExplorer(graph_data_model)


@handle_exceptions
def get_component(
component_label: str,
Expand Down Expand Up @@ -66,6 +92,56 @@ def get_component(
return result, status


@handle_exceptions
def get_component_requirements_array(
component_label: str,
schema_url: str,
display_label_type: DisplayLabelType,
) -> tuple[Union[list[str], BasicError], int]:
"""Gets the input components required components
Args:
component_label (str): The label of the component
schema_url (str): The URL of the schema in json form
display_label_type (DisplayLabelType):
The type of label to use as display
Returns:
tuple[Union[ComponentRequirementArray, BasicError], int]: A tuple
item 1 is either the required coponents or an error
item 2 is the status
"""
dmge = create_data_model_graph_explorer(schema_url, display_label_type)
result = dmge.get_component_requirements(source_component=component_label)
status = 200
return result, status


@handle_exceptions
def get_component_requirements_graph(
component_label: str,
schema_url: str,
display_label_type: DisplayLabelType,
) -> tuple[Union[list[ComponentRequirementSubgraph], BasicError], int]:
"""Gets the input components required components
Args:
component_label (str): The label of the component
schema_url (str): The URL of the schema in json form
display_label_type (DisplayLabelType):
The type of label to use as display
Returns:
tuple[Union[ComponentRequirementGrpah, BasicError], int]: A tuple
item 1 is either the required coponents or an error
item 2 is the status
"""
dmge = create_data_model_graph_explorer(schema_url, display_label_type)
graph = dmge.get_component_requirements_graph(source_component=component_label)
edges: list[tuple[str, str]] = graph.edges()
result = [ComponentRequirementSubgraph(edge[0], edge[1]) for edge in edges]
status = 200
return result, status


def get_connected_node_pairs_from_schematic(
relationship_type: str,
schema_url: str,
Expand All @@ -83,14 +159,7 @@ def get_connected_node_pairs_from_schematic(
Returns:
list[ConnectedNodePair]: A list of connected node pairs
"""
data_model_parser = DataModelParser(path_to_data_model=schema_url)
parsed_data_model = data_model_parser.parse_model()
data_model_grapher = DataModelGraph(
attribute_relationships_dict=parsed_data_model,
data_model_labels=display_label_type,
)
graph_data_model = data_model_grapher.generate_data_model_graph()
dmge = DataModelGraphExplorer(graph_data_model)
dmge = create_data_model_graph_explorer(schema_url, display_label_type)
relationship_subgraph = dmge.get_subgraph_by_edge_type(relationship_type)
lst = [list(edge) for edge in relationship_subgraph.edges]

Expand Down Expand Up @@ -188,14 +257,7 @@ def get_node_is_required_from_schematic(
Returns:
bool: Whether or no the node is required
"""
data_model_parser = DataModelParser(path_to_data_model=schema_url)
parsed_data_model = data_model_parser.parse_model()
data_model_grapher = DataModelGraph(
attribute_relationships_dict=parsed_data_model,
data_model_labels=display_label_type,
)
graph_data_model = data_model_grapher.generate_data_model_graph()
dmge = DataModelGraphExplorer(graph_data_model)
dmge = create_data_model_graph_explorer(schema_url, display_label_type)
return dmge.get_node_required(node_display)


Expand Down Expand Up @@ -294,14 +356,7 @@ def get_node_properties_from_schematic(
Returns:
list[str]: A list of properties of the node
"""
data_model_parser = DataModelParser(path_to_data_model=schema_url)
parsed_data_model = data_model_parser.parse_model()
data_model_grapher = DataModelGraph(
attribute_relationships_dict=parsed_data_model,
data_model_labels=display_label_type,
)
graph_data_model = data_model_grapher.generate_data_model_graph()
dmge = DataModelGraphExplorer(graph_data_model)
dmge = create_data_model_graph_explorer(schema_url, display_label_type)
properties = dmge.find_class_specific_properties(node_label)
return properties

Expand Down Expand Up @@ -352,14 +407,7 @@ def get_node_validation_rules_from_schematic(
Returns:
list[ValidationRule]: A list of validation_rules of the node
"""
data_model_parser = DataModelParser(path_to_data_model=schema_url)
parsed_data_model = data_model_parser.parse_model()
data_model_grapher = DataModelGraph(
attribute_relationships_dict=parsed_data_model,
data_model_labels=display_label_type,
)
graph_data_model = data_model_grapher.generate_data_model_graph()
dmge = DataModelGraphExplorer(graph_data_model)
dmge = create_data_model_graph_explorer(schema_url, display_label_type)
rules: list[str] = dmge.get_node_validation_rules(node_display) # type: ignore
return [ValidationRule(rule) for rule in rules]

Expand Down Expand Up @@ -418,14 +466,7 @@ def get_node_dependencies_from_schematic(
list[Node]: A list of nodes
"""
data_model_parser = DataModelParser(path_to_data_model=schema_url)
parsed_data_model = data_model_parser.parse_model()
data_model_grapher = DataModelGraph(
attribute_relationships_dict=parsed_data_model,
data_model_labels=display_label_type,
)
graph_data_model = data_model_grapher.generate_data_model_graph()
dmge = DataModelGraphExplorer(graph_data_model)
dmge = create_data_model_graph_explorer(schema_url, display_label_type)
nodes = dmge.get_node_dependencies(
node_label, return_display_names, return_ordered_by_schema
)
Expand Down
Loading

0 comments on commit de912e7

Please sign in to comment.