Skip to content

Commit

Permalink
Upgrade gocamgen dependency; some typing
Browse files Browse the repository at this point in the history
  • Loading branch information
dustine32 committed Apr 29, 2020
1 parent 67e915f commit efb589a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 51 deletions.
26 changes: 16 additions & 10 deletions pathway_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, mapping_file=None):
self.mappings = []
if mapping_file:
with open(mapping_file) as mf:
mappings = yaml.load(mf)
mappings = yaml.safe_load(mf)
for m in mappings:
self.mappings.append(MechanismToGoMapping(
mechanism=m["MECHANISM"],
Expand All @@ -42,10 +42,16 @@ def go_id_by_mechanism(self, mechanism):


class AnnotatorOrcidMapping:
def __init__(self, annotator_name, orcid):
def __init__(self, annotator_name, orcid: str):
self.annotator_name = annotator_name
self.orcid = orcid

def full_orcid_uri(self):
orcid_prefix = "http://orcid.org/"
if self.orcid.startswith(orcid_prefix):
return self.orcid
return orcid_prefix + self.orcid

class AnnotatorOrcidMappingSet:
def __init__(self, file=None):
self.mappings = []
Expand All @@ -61,7 +67,7 @@ def __init__(self, file=None):
def orcid_by_name(self, annotator_name):
for m in self.mappings:
if m.annotator_name == annotator_name:
return m.orcid
return m.full_orcid_uri()

# TODO: Refactor `PathwayConnection`
# * Connect causal statements together in networkx graph
Expand Down Expand Up @@ -94,6 +100,7 @@ def __init__(self, entity_a: SignorEntity, entity_b: SignorEntity, mechanism, ef
"term": None
}

self.annotator = None
if annotator:
self.annotator = self.ANNOTATOR_ORCID_MAPPING.orcid_by_name(annotator)

Expand Down Expand Up @@ -247,9 +254,9 @@ def upper_first(iterator):
return itertools.chain([next(iterator).upper()], iterator)


class PathwayConnectionSet():
class PathwayConnectionSet:
def __init__(self):
self.connections = []
self.connections: List[PathwayConnection] = []

@staticmethod
def parse_file(filename):
Expand All @@ -273,22 +280,21 @@ def parse_file(filename):

return pc_set


def add(self, pathway_connection):
def add(self, pathway_connection: PathwayConnection):
existing_connection = self.find(pathway_connection)
if existing_connection:
# Causal statement already exists so just add reference
existing_connection.references = set(existing_connection.references) | set(pathway_connection.references)
else:
self.connections.append(pathway_connection)

def contains(self, pathway_connection, check_ref=False):
def contains(self, pathway_connection: PathwayConnection, check_ref=False):
for connection in self.connections:
if connection.equals(pathway_connection, check_ref=check_ref):
return True
return False

def find(self, pathway_connection, check_ref=False):
def find(self, pathway_connection: PathwayConnection, check_ref=False):
for connection in self.connections:
if connection.equals(pathway_connection, check_ref=check_ref):
return connection
Expand Down Expand Up @@ -325,4 +331,4 @@ def remove_list(self, pc_list):
new_connection_list = self.connections
for dead_pc in pc_list:
new_connection_list = [pc for pc in new_connection_list if not pc.equals(dead_pc)]
self.connections = new_connection_list
self.connections = new_connection_list
17 changes: 13 additions & 4 deletions pathway_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
ro = OboRO()
ENABLED_BY = URIRef(expand_uri(ro.enabled_by))
HAS_INPUT = URIRef(expand_uri("RO:0002233"))
EXP_ECO_CODE = "ECO:0000269"

parser = argparse.ArgumentParser()
parser.add_argument('-f', "--filename", type=str, required=True,
Expand Down Expand Up @@ -80,9 +81,13 @@ def generate_model(filename, title):
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)
axiom_a = model.add_axiom(pc.enabled_by_stmt_a,
GoCamEvidence("EXP", ["PMID:" + pmid for pmid in pc.references]))
model.add_evidence(axiom_a, "EXP", ["PMID:" + pmid for pmid in pc.references])
contributors = []
if pc.annotator:
contributors = [pc.annotator]
evidence = GoCamEvidence(EXP_ECO_CODE, ["PMID:" + pmid for pmid in pc.references],
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])

# Now that the a's are declared, go check on the b's.
for pc in p_connections.connections:
Expand All @@ -105,7 +110,11 @@ def generate_model(filename, title):
regulation_triple = (mechanism_uri, URIRef(expand_uri(pc.relation)), regulated_activity_uri)
model.writer.emit(*regulation_triple)
regulation_axiom = model.writer.emit_axiom(*regulation_triple)
model.add_evidence(regulation_axiom, "EXP", ["PMID:" + pmid for pmid in pc.references])
if pc.annotator:
contributors = [pc.annotator]
evidence = GoCamEvidence(EXP_ECO_CODE, ["PMID:" + pmid for pmid in pc.references],
contributors=contributors)
model.add_evidence(regulation_axiom, evidence=evidence)

print(skipped_count, "causal statements skipped")
print(len(p_connections.connections), "pathway_connections at finish")
Expand Down
36 changes: 1 addition & 35 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,2 @@
argh==0.26.2
astroid==1.6.1
cachier==1.2.2
certifi==2018.1.18
chardet==3.0.4
click==6.7
decorator==4.2.1
gocamgen==0.0.4
idna==2.6
isodate==0.6.0
isort==4.3.4
jsobject==0.10.2
lazy-object-proxy==1.3.1
marshmallow==2.15.0
mccabe==0.6.1
networkx==1.11
numpy==1.14.2
ontobio==0.2.36
pandas==0.22.0
pathtools==0.1.2
portalocker==1.2.0
prefixcommons==0.1.4
pylint==1.8.2
pyparsing==2.2.0
pysolr==3.7.0
python-dateutil==2.7.2
pytz==2018.3
PyYAML==3.12
rdflib==4.2.2
gocamgen==0.0.5
requests==2.18.4
scipy==1.0.1
six==1.11.0
SPARQLWrapper==1.8.1
urllib3==1.22
watchdog==0.8.3
wrapt==1.10.11
3 changes: 1 addition & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TestSignor2Gocam(unittest.TestCase):

def test_mechanism_map_loading(self):
with open(M_FILE) as mf:
mappings = yaml.load(mf)
mappings = yaml.safe_load(mf)
self.assertGreater(len(mappings), 1)

def test_mechanism_mapping_set(self):
Expand Down Expand Up @@ -127,7 +127,6 @@ def test_distinct_entity_instance_per_stmt(self):

# TODO: Now check how many instances of most_prominent_entity are in model. Should this == input count?
print(most_prominent_entity, entity_counts[most_prominent_entity])
pass


if __name__ == '__main__':
Expand Down

1 comment on commit efb589a

@dustine32
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit also now sets contributor field on evidence with an ORCID. For issue #19.

Please sign in to comment.