Skip to content

Commit

Permalink
cleaning up DRY code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanDietzMorris committed Oct 6, 2023
1 parent d43789e commit c597606
Showing 1 changed file with 37 additions and 53 deletions.
90 changes: 37 additions & 53 deletions parsers/Reactome/src/loadReactome.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,20 +307,23 @@ def write_neo4j_result_to_file(self, result: neo4j.Result, reference_entity_mapp
if node_a_id and node_b_id:
if "regulationType" in record_data.keys():
if any("positive" in x.lower() for x in record_data['regulationType']):
if "complex_context" in record_data.keys():
self.process_edge_from_neo4j(node_a_id, record_data['r_type'], node_b_id, regulationType='positive', complex_context=record_data['complex_context'])
else:
self.process_edge_from_neo4j(node_a_id, record_data['r_type'], node_b_id, regulationType='positive')
self.process_edge_from_neo4j(node_a_id,
record_data['r_type'],
node_b_id,
regulationType='positive',
complex_context=record_data.get('complex_context', default=None))
elif any("negative" in x.lower() for x in record_data['regulationType']):
if "complex_context" in record_data.keys():
self.process_edge_from_neo4j(node_a_id, record_data['r_type'], node_b_id, regulationType='negative', complex_context=record_data['complex_context'])
else:
self.process_edge_from_neo4j(node_a_id, record_data['r_type'], node_b_id, regulationType='negative')
self.process_edge_from_neo4j(node_a_id,
record_data['r_type'],
node_b_id,
regulationType='negative',
complex_context=record_data.get('complex_context', default=None))
else:
if "complex_context" in record_data.keys():
self.process_edge_from_neo4j(node_a_id, record_data['r_type'], node_b_id, regulationType=None, complex_context=record_data['complex_context'])
else:
self.process_edge_from_neo4j(node_a_id, record_data['r_type'], node_b_id, regulationType=None)
self.process_edge_from_neo4j(node_a_id,
record_data['r_type'],
node_b_id,
regulationType=None,
complex_context=record_data.get('complex_context', default=None))
record_count += 1
else:
skipped_record_count += 1
Expand Down Expand Up @@ -417,52 +420,33 @@ def process_node_from_neo4j(self, reference_entity_mapping, node_identity, node:
def process_edge_from_neo4j(self, subject_id: str, relationship_type: str, object_id: str, regulationType=None, complex_context=None):
predicate = PREDICATE_MAPPING.get(relationship_type, None)
if predicate:
if regulationType == None:
if complex_context != None:
output_edge = kgxedge(
subject_id=subject_id,
object_id=object_id,
predicate=predicate,
edgeprops = {'complex_context':complex_context},
primary_knowledge_source=self.provenance_id
)
else:
output_edge = kgxedge(
subject_id=subject_id,
object_id=object_id,
predicate=predicate,
primary_knowledge_source=self.provenance_id
)
if regulationType is None:
output_edge = kgxedge(
subject_id=subject_id,
object_id=object_id,
predicate=predicate,
edgeprops={'complex_context': complex_context} if complex_context else None,
primary_knowledge_source=self.provenance_id
)
else:
if regulationType == "positive":
direction = 'increased'
elif regulationType == "negative":
direction = 'decreased'
if complex_context != None:
output_edge = kgxedge(
subject_id=subject_id,
object_id=object_id,
predicate=predicate,
edgeprops={
'qualified_predicate':'biolink:causes',
'object_direction_qualifier':direction,
'object_aspect_qualifier':'expression',
'complex_context':complex_context
},
primary_knowledge_source=self.provenance_id
)
else:
output_edge = kgxedge(
subject_id=subject_id,
object_id=object_id,
predicate=predicate,
edgeprops={
'qualified_predicate':'biolink:causes',
'object_direction_qualifier':direction,
'object_aspect_qualifier':'expression',
},
primary_knowledge_source=self.provenance_id
)
edge_props = {
'qualified_predicate': 'biolink:causes',
'object_direction_qualifier': direction,
'object_aspect_qualifier': 'expression',
}
if complex_context:
edge_props['complex_context'] = complex_context
output_edge = kgxedge(
subject_id=subject_id,
object_id=object_id,
predicate=predicate,
edgeprops=edge_props,
primary_knowledge_source=self.provenance_id
)
self.output_file_writer.write_kgx_edge(output_edge)
else:
self.logger.warning(f'A predicate could not be mapped for relationship type {relationship_type}')
Expand Down

0 comments on commit c597606

Please sign in to comment.