Skip to content

Commit

Permalink
Merge pull request #56 from GeneDx/develop
Browse files Browse the repository at this point in the history
update master
  • Loading branch information
rebecca810 authored Nov 11, 2021
2 parents 51c46ee + 603e84b commit 5df5182
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
- name: Test with unittest
run: |
pytest tests
python -m unittest
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pytest = "*"
pytest-cov = "*"

[packages]
nltk = "==3.4.5"
nltk = "==3.6.5"
spacy = "==2.2.4"
scispacy = "==0.2.4"
negspacy = "==0.1.9"
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ print(result.hpids)
```

`txt2hpo` handles negation using [negspaCy](https://spacy.io/universe/project/negspacy). To remove negated phenotypes set `remove_negated` flag to True.
Both the extracted and negated HPO terms can be retrieved.


```python
from txt2hpo.extract import Extractor
extract = Extractor(remove_negated=True)
Expand All @@ -62,7 +62,10 @@ result = extract.hpo("patient has developmental delay but no hypotonia")
print(result.hpids)

["HP:0001263"]


print(result.negated_hpids)

["HP:0001252"]

```

Expand Down
30 changes: 30 additions & 0 deletions tests/test_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,33 @@ def test_handling_term_hyphenation(self):
# replace hyphens with space
hpids = extract.hpo(test[0].replace('-', ' ')).hpids
self.assertEqual(hpids, [test[1]])

def test_negated_hpo_retention(self):
extract = Extractor(correct_spelling=False,
remove_overlapping=True,
resolve_conflicts=True,
max_neighbors=2,
phenotypes_only=False,
remove_negated=True)

resp = extract.hpo("Patient has developmental delay but no hypotonia")
self.assertEqual(["HP:0001252"], resp.negated_hpids)

resp = extract.hpo("developmental delay and a wide mouth")
self.assertEqual([], resp.negated_hpids)

resp = extract.hpo("developmental delay with no wide mouth")
self.assertEqual(['HP:0000154'], resp.negated_hpids)

resp = extract.hpo("developmental delay without a wide mouth")
self.assertEqual(['HP:0000154'], resp.negated_hpids)

resp = extract.hpo("no developmental delay, but has a wide mouth")
self.assertEqual(['HP:0001263'], resp.negated_hpids)

resp = extract.hpo("the patient has a wide mouth but no developmental delay.")
self.assertEqual(['HP:0001263'], resp.negated_hpids)

resp = extract.hpo("the patient does not have either a wide mouth or developmental delay.")
self.assertEqual(set(['HP:0000154', 'HP:0001263']), set(resp.negated_hpids))

2 changes: 1 addition & 1 deletion txt2hpo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__project__ = 'txt2hpo'
__version__ = '0.2.3'
__version__ = '2021.0'
6 changes: 6 additions & 0 deletions txt2hpo/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self, entries=None, model=None, negation_model=None):
self.entries = entries
self.model = model
self.negation_model = negation_model
self.negated_entries = []

def add(self,entry):
self.entries += entry
Expand All @@ -36,6 +37,7 @@ def remove_tagged(self, tag, state=True, status=True):
to_remove = [entry for entry in self.entries if entry[tag] != state]
for element in to_remove:
self.remove(element)
self.negated_entries.append(element)

def detect_negation(self):
for entry in self.entries:
Expand Down Expand Up @@ -124,6 +126,10 @@ def resolve_conflicts(self):
def hpids(self):
return list(set(np.array([x['hpid'] for x in self.entries]).flatten()))

@property
def negated_hpids(self):
return list(set(np.array([x['hpid'] for x in self.negated_entries]).flatten()))

@property
def json(self):
result = self.entries_sans_context.copy()
Expand Down

0 comments on commit 5df5182

Please sign in to comment.