Skip to content

Commit

Permalink
Refactoring small mol; Fix missing 'entity B's
Browse files Browse the repository at this point in the history
  • Loading branch information
dustine32 committed Jun 17, 2021
1 parent 53e2189 commit 755091d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 26 deletions.
3 changes: 3 additions & 0 deletions entity_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def class_id(self):
def is_complex(self):
return isinstance(self, SignorComplex)

def is_small_mol(self):
return isinstance(self, SignorSmallMolecule)

def __eq__(self, other):
if isinstance(other, SignorEntity):
return self.id == other.id and self.name == other.name
Expand Down
23 changes: 23 additions & 0 deletions pathway_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,19 @@ def __str__(self):
def print(self):
print(self)

def declare_a_to_mechanism(self, model, eco_code):
# Declare entity A and mechanism
self.declare_a(model)
if self.a_is_small_mol():
# Skip enabled_by stmt for small molecules
self.mechanism["uri"] = self.entity_a.uri # Entity A is_activator
return
self.mechanism["uri"] = model.declare_individual(self.mechanism["term"])
# Emit mechanism -enabled_by -> entity_a
self.enabled_by_stmt_a = model.writer.emit(self.mechanism["uri"], ENABLED_BY, self.entity_a.uri)
evidence = self.gocam_evidence(eco_code)
return model.add_axiom(self.enabled_by_stmt_a, evidence=evidence)

def declare_entities(self, model):
self.declare_a(model)
self.declare_b(model)
Expand Down Expand Up @@ -237,6 +250,16 @@ def a_is_complex(self):
def b_is_complex(self):
return self._is_complex(self.entity_b)

@staticmethod
def _is_small_mol(entity: SignorEntity):
return entity.is_small_mol()

def a_is_small_mol(self):
return self._is_small_mol(self.entity_a)

def b_is_small_mol(self):
return self._is_small_mol(self.entity_b)

def clone(self):
new_connection = PathwayConnection(self.entity_a, self.entity_b, self.mechanism["name"], self.effect,
self.direct, self.relation, self.references, self.linenum)
Expand Down
44 changes: 18 additions & 26 deletions pathway_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,8 @@ def generate_model(filename, title):

# fill in regulated activities
for pc in p_connections.connections:

# Declare entity A and mechanism
pc.declare_a(model)
pc.mechanism["uri"] = model.declare_individual(pc.mechanism["term"])
# Emit mechanism -enabled_by -> entity_a
pc.enabled_by_stmt_a = model.writer.emit(pc.mechanism["uri"], ENABLED_BY, pc.entity_a.uri)
date = pc.date
if date is None:
date = str(datetime.date.today())
contributors = []
if pc.annotator:
contributors = [pc.annotator]
evidence = GoCamEvidence(EXP_ECO_CODE, ["PMID:" + pmid for pmid in pc.references],
date=date, contributors=contributors)
axiom_a = model.add_axiom(pc.enabled_by_stmt_a, evidence=evidence)
# model.add_evidence(axiom_a, "EXP", ["PMID:" + pmid for pmid in pc.references])
# Setup
pc.declare_a_to_mechanism(model, EXP_ECO_CODE)

# Now that the a's are declared, go check on the b's.
for pc in p_connections.connections:
Expand All @@ -114,24 +100,30 @@ def generate_model(filename, title):
regulatory_relation = pc.relation
evidence = pc.gocam_evidence(EXP_ECO_CODE)
if len(entity_b_pcs) == 0:
# BPC was likely filtered out due to BPC.entity B not being acceptable type (e.g. phenotype)
# Declare pc.entity B? A and B should be valid by this point
# A protein -> B complex
# A complex -> B phenotype
# Create and load new PC
print("No downstream pathway_connections for", pc)
for bpc in entity_b_pcs:
participant_relation = HAS_INPUT
is_small_mol_catalysis = False
# catalytic activity
if pc.mechanism["term"] == "GO:0003824" and isinstance(pc.entity_b, SignorSmallMolecule):
if pc.mechanism["term"] == "GO:0003824" and pc.b_is_small_mol():
is_small_mol_catalysis = True
if pc.effect.startswith("up-regulates"):
participant_relation = HAS_OUTPUT
# mechanism -has_input/output-> entity_b
has_input_triple = (mechanism_uri, participant_relation, bpc.entity_a.uri)
if len(model.triples_by_ids(*has_input_triple)) == 0:
model.writer.emit(*has_input_triple)
has_input_axiom = model.find_or_create_axiom(*has_input_triple)
model.add_evidence(has_input_axiom, evidence=evidence)
if is_small_mol_catalysis:
# Skip adding causal relation
continue
if not pc.a_is_small_mol():
# mechanism -has_input/output-> entity_b
has_input_triple = (mechanism_uri, participant_relation, bpc.entity_a.uri)
if len(model.triples_by_ids(*has_input_triple)) == 0:
model.writer.emit(*has_input_triple)
has_input_axiom = model.find_or_create_axiom(*has_input_triple)
model.add_evidence(has_input_axiom, evidence=evidence)
if is_small_mol_catalysis:
# Skip adding causal relation
continue

# Add intermediary biological process for these regulatory mechanisms
intermediary_bp = None
Expand Down

0 comments on commit 755091d

Please sign in to comment.