Skip to content

Commit

Permalink
Fix get_relations function
Browse files Browse the repository at this point in the history
  • Loading branch information
STIRLIN6 authored and bgyori committed Aug 29, 2021
1 parent 2a6f221 commit 3f05008
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,5 @@ dmypy.json
.pyre/
import.report


.idea
.idea/*
48 changes: 26 additions & 22 deletions src/indra_cogex/sources/clinicaltrials/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from indra_cogex.representation import Node, Relation

drug_pattern = re.compile(r"^Drug: ([a-zA-Z ]|\d)+$")
#id_pattern = re.compile(r'^https://ClinicalTrials.gov/show/NCT(\d+)$')


class ClinicaltrialsProcessor(Processor):
Expand Down Expand Up @@ -36,27 +37,30 @@ def get_nodes(self):
)

def get_relations(self):
for conditions in self.df["Conditions"]:
for condition in conditions.split("|"):
for index, row in self.df.iterrows():
for condition in row["Conditions"].split("|"):
cond_matches = gilda.ground(condition)
if cond_matches:
for interventions in self.df["Interventions"]:
if not pd.isna(interventions):
for intervention in interventions.split("|"):
if drug_pattern.match(intervention):
int_matches = gilda.ground(intervention[6:])
if int_matches:
yield Relation(
source_ns=cond_matches[0].term.db,
source_id=cond_matches[0].term.id,
target_ns=int_matches[0].term.db,
target_id=int_matches[0].term.id,
rel_type="has_trial",
)
yield Relation(
source_ns=cond_matches[0].term.db,
source_id=cond_matches[0].term.id,
target_ns=int_matches[0].term.db,
target_id=int_matches[0].term.id,
rel_type="tested_in",
)
source_ns = cond_matches[0].term.db
source_id = cond_matches[0].term.id
if not pd.isna(row["Interventions"]):
for intervention in row["Interventions"].split("|"):
if drug_pattern.match(intervention):
int_matches = gilda.ground(intervention[6:])
if int_matches:
target_ns = int_matches[0].term.db
target_id = row["URL"][32:]
yield Relation(
source_ns=source_ns,
source_id=source_id,
target_ns=target_ns,
target_id=target_id,
rel_type="has_trial"
)
yield Relation(
source_ns=source_ns,
source_id=source_id,
target_ns=target_ns,
target_id=target_id,
rel_type="tested_in"
)
7 changes: 7 additions & 0 deletions tests/test_clinicaltrials.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ def test_get_nodes():
cp = ClinicaltrialsProcessor(path)
nodes = list(cp.get_nodes())
assert len(nodes) is not 0


def test_get_nodes():
path = os.path.join(os.path.dirname(__file__), "test_search_results.tsv")
cp = ClinicaltrialsProcessor(path)
relations = list(cp.get_relations())
# TODO: Test get_relations

0 comments on commit 3f05008

Please sign in to comment.