diff --git a/CHANGELOG.md b/CHANGELOG.md index 85f7938..7e27ab3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ # Changelog -## [0.8.2](https://github.com/brsynth/neo4jsbml/tree/0.8.2) (2023-01-16) +## [0.8.3](https://github.com/brsynth/neo4jsbml/tree/0.8.3) (2023-01-16) -[Full Changelog](https://github.com/brsynth/neo4jsbml/compare/0.8.0...0.8.2) +[Full Changelog](https://github.com/brsynth/neo4jsbml/compare/0.8.0...0.8.3) ## [0.8.0](https://github.com/brsynth/neo4jsbml/tree/0.8.0) (2023-01-16) diff --git a/src/neo4jsbml/_version.py b/src/neo4jsbml/_version.py index 42d1392..dec8ed3 100644 --- a/src/neo4jsbml/_version.py +++ b/src/neo4jsbml/_version.py @@ -1,2 +1,2 @@ __app_name__ = "neo4jsbml" -__version__ = "0.8.3" +__version__ = "0.9.0" diff --git a/src/neo4jsbml/connect.py b/src/neo4jsbml/connect.py index 3e8d856..3eb3fcd 100644 --- a/src/neo4jsbml/connect.py +++ b/src/neo4jsbml/connect.py @@ -135,9 +135,9 @@ def create_nodes(self, nodes: List[snode.SNode]) -> None: query = ( "MERGE (n:" + ":".join(node.labels) - + ' {id:"' - + node.id - + '"}) ON CREATE SET n += ' + + " " + + node.id_to_neo4j() + + ") ON CREATE SET n += " + node.properties_to_neo4j() + " ON MATCH SET n += " + node.properties_to_neo4j() @@ -161,13 +161,16 @@ def create_relationships( query = ( "MATCH (a:" + rel.from_label - + ' {id: $rel["from_id"]}) MATCH (b:' + + " " + + rel.id_to_neo4j(id='$rel["from_id"]') + + ") MATCH (b:" + rel.to_label - + ' {id: $rel["to_id"]}) MERGE (a)-[r:' + + " " + + rel.id_to_neo4j(id='$rel["to_id"]') + + ") MERGE (a)-[r:" + rel.label + ']->(b) ON CREATE SET r += $rel["properties"] RETURN r' ) - res = session.run( query, rel=rel.to_dict(), diff --git a/src/neo4jsbml/entity.py b/src/neo4jsbml/entity.py index 139514b..9f10683 100644 --- a/src/neo4jsbml/entity.py +++ b/src/neo4jsbml/entity.py @@ -30,6 +30,9 @@ class Entity(metaclass=ABCMeta): clean_properties(self) Remove empty values + id_to_neo4j(self) -> str + Format id to query Neo4j + properties_to_neo4j() -> str Format properties to insert in query """ @@ -89,6 +92,26 @@ def add_property(self, label: str, value: str, overwrite: bool = True) -> None: ): self.properties[label] = value + def id_to_neo4j(self, id: Optional[str] = None) -> str: + """Format ids to insert in query + + Parameters + ---------- + id: str (default: None + Return + ------ + str + """ + data = "{id: " + if id is None: + data += '"' + self.id + '"' + else: + data += id + if "tag" in self.properties.keys(): + data += ', tag: "' + self.properties["tag"] + '"' + data += "}" + return data + def properties_to_neo4j(self) -> str: """Format properties to insert in query diff --git a/src/neo4jsbml/sbml.py b/src/neo4jsbml/sbml.py index 262b50f..e03a0bb 100644 --- a/src/neo4jsbml/sbml.py +++ b/src/neo4jsbml/sbml.py @@ -499,6 +499,9 @@ def format_relationships( "No method was found for entities: %s and %s, belongs to the relationships: %s" % (from_label, to_label, arrow_rel.label) ) + if self.tag is not None: + for srel in res: + srel.add_property(label="tag", value=self.tag) return res def validate_id(self, value: Any) -> bool: