-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from tom-and-the-toothfairies/release-2
Release 2
- Loading branch information
Showing
32 changed files
with
23,533 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,82 @@ | ||
def enrich(ddis): | ||
def _enrich(ddi): | ||
result = {'harmful': bool(hash(ddi['uri']) % 2), | ||
'spacing': abs(hash(ddi['uri']))%14 + 1} | ||
result.update(ddi) | ||
return result | ||
from hashlib import sha1 | ||
import csv | ||
import sys | ||
import dinto | ||
import clize | ||
import socket | ||
import time | ||
from clize.parameters import one_of | ||
|
||
UNITS_INTERVAL = { | ||
'sec': 60, | ||
'min': 60, | ||
'hr': 24, | ||
'day': 7, | ||
'week': 52, | ||
'yr': 5, | ||
} | ||
|
||
|
||
def _sha_int(string): | ||
return int(sha1(string.encode()).hexdigest()[-8:], 16) | ||
|
||
|
||
def _enrich(ddi): | ||
uri = ddi['uri'] | ||
sha = _sha_int(uri) | ||
unit = tuple(UNITS_INTERVAL.keys())[sha % len(UNITS_INTERVAL)] | ||
result = { | ||
'harmful': bool(sha % 2), | ||
'spacing': sha % UNITS_INTERVAL[unit] + 1, | ||
'unit': unit, | ||
'agonism': bool(_sha_int(''.join(sorted(uri))) % 2), | ||
} | ||
|
||
result.update(ddi) | ||
return result | ||
|
||
|
||
def enrich(ddis): | ||
return [_enrich(ddi) for ddi in ddis] | ||
|
||
|
||
def main(flavour: one_of('harmful', 'agonism')): | ||
fieldnames = ('Drug 1', 'Drug 2', 'DDI Type', 'Time', 'Unit') | ||
|
||
writer = csv.DictWriter(sys.stdout, fieldnames=fieldnames, | ||
lineterminator='\n') | ||
writer.writeheader() | ||
|
||
for ddi in enrich(dinto.all_ddis()): | ||
ddi['Drug 1'] = ddi['drug_a'] | ||
ddi['Drug 2'] = ddi['drug_b'] | ||
ddi['Time'] = ddi['spacing'] | ||
ddi['Unit'] = ddi['unit'] | ||
|
||
if flavour == 'harmful': | ||
ddi['DDI Type'] = 'bad' if ddi[flavour] else 'good' | ||
if flavour == 'agonism': | ||
ddi['DDI Type'] = 'agonism' if ddi[flavour] else 'antagonism' | ||
|
||
writer.writerow({k: ddi[k] for k in fieldnames}) | ||
|
||
|
||
def block_until_chiron(): | ||
goes = 10 | ||
while goes: | ||
try: | ||
sock = socket.socket() | ||
time.sleep(1) | ||
sock.connect(('chiron', 3030)) | ||
except Exception: | ||
goes -= 1 | ||
continue | ||
else: | ||
return | ||
|
||
sys.exit(1) | ||
|
||
|
||
if __name__ == '__main__': | ||
block_until_chiron() | ||
clize.run(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,6 @@ py==1.4.32 | |
pytest==3.0.6 | ||
requests==2.13.0 | ||
Werkzeug==0.11.15 | ||
clize==3.1.0 | ||
sigtools==2.0.1 | ||
six==1.10.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
process alternative_non_ddis { | ||
selection { | ||
selection sel1 { | ||
action s1 { | ||
requires { drug { "trandolapril" } } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
process foo { | ||
action clash1 { | ||
requires { drug { "paracetamol" } } | ||
} | ||
action clash2 { | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
process foo { | ||
task { | ||
action boo { | ||
requires { drug { "paracetamol" } } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
process parallel_ddis { | ||
branch { | ||
branch br1 { | ||
action b1 { | ||
requires { drug { "trandolapril" } } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.