Skip to content

Commit

Permalink
Merge branch 'main' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-gricourt committed Feb 21, 2023
2 parents e3b1771 + 28a2fc0 commit d9267da
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/neo4jsbml/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__app_name__ = "neo4jsbml"
__version__ = "0.8.3"
__version__ = "0.9.0"
15 changes: 9 additions & 6 deletions src/neo4jsbml/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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(),
Expand Down
23 changes: 23 additions & 0 deletions src/neo4jsbml/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/neo4jsbml/sbml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit d9267da

Please sign in to comment.