def setUp(self):
     super(ServiceTest, self).setUp()
     api = KnowledgeHubAPI()
     api.set_server('DEV')
     api.login(self.username, self.password)
     self.services = Services(
         api, 'https://dev.toxhub.etransafe.eu/registry.kh.svc/api/v1')
Exemple #2
0
def main():
    parser = argparse.ArgumentParser(
        description=
        'Process parameters for collecting findings from primitive adapter')
    parser.add_argument('-username', required=True, help='username')
    parser.add_argument('-password', required=True, help='password')
    args = parser.parse_args()

    api = KnowledgeHubAPI(server='TEST',
                          client_secret='39c644b3-1f23-4d94-a71f-e0fb43ebd760')
    api.login(args.username, args.password)

    compoundSmile = api.ChemistryService().getSMILESByName('omeprazole')
    similar_compounds = api.SimilarityService().get(compoundSmile[0])

    names = []
    smiles = []
    similarities = []

    if similar_compounds is not None:
        for similar_compound in similar_compounds:
            names.append(similar_compound['name'])
            smiles.append(similar_compound['smiles'])
            similarities.append(similar_compound['distance'])

    studies = filterStudies(api.eToxSys().getStudiesByCompoundNames(names))
    print(f'Found {len(studies)} studies.')
    for study in studies:
        print(study)

    api.SemanticService().getSocs(studies)
    otherStudies = [
        study for study in studies if study['FINDING']['__soc'] == 'Other'
    ]
    print(f'#others:{len(otherStudies)}')
def test():
	parser = argparse.ArgumentParser(description='test similarity service')
	parser.add_argument('-username', required=True, help='username')
	parser.add_argument('-password', required=True, help='password')
	args = parser.parse_args()

	api = KnowledgeHubAPI()
	api.set_service('DEV')
	status = api.login(args.username, args.password)
	print(status)
	terms = api.SemanticService().lookup('Terbinafine', 'RxNorm')
	print(json.dumps(terms, indent=4, sort_keys=True))
	#if len(terms['terms']) > 0:
		#concepts = api.SemanticService().normalize(terms['terms'][0], 'RxNorm')
		#print(json.dumps(concepts, indent=4, sort_keys=True))

		#if len(concepts['concepts']) == 1:
	compounds = [
							  "Minoxidil","Estradiol","Anastrozole","Felodipine","Amphetamine",",Adenosine","Azathioprine","Levamisole",
							  #"Zolmitriptan","Lidocaine","Alprazolam","Ropivacaine","Foscarnet","Rimonabant","Remoxipride","Cyclophosphamide",
							  #"Aripiprazole","Bambuterol","Sulfamethoxazole","Rosiglitazone","Clozapine","Budesonide","Omeprazole","Raltitrexed",
							  #"Clonidine","Gefitinib","Ximelagatran","Diazepam","Olanzapine","Zafirlukast","Nifedipine","Indomethacin","Erlotinib",
							  #"Formoterol","Diclofenac","Metoprolol","Enprofylline","Bicalutamide","Chlordiazepoxide","Simvastatin","Ranitidine",
							  #"Ticagrelor","Sulfinpyrazone","Phenylbutazone","Benazepril","Isosorbide Mononitrate","Deferoxamine","Guanfacine",
							  #"Naftifine","Chlorthalidone","Guanethidine","Valproic Acid","Clozapine","Baclofen","Maprotiline","Thioridazine",
							  #"Aminoglutethimide","Bromocriptine","Phentolamine","Amantadine","Thiethylperazine","Pindolol","Lidocaine",
							  #"Linezolid","Prednisolone","Candoxatril","Diazepam","Orlistat","Carprofen","Cilazapril"
							  ]
Exemple #4
0
def main():
    parser = argparse.ArgumentParser(description='test similarity service')
    parser.add_argument('-username', required=True, help='username')
    parser.add_argument('-password', required=True, help='password')
    args = parser.parse_args()

    api = KnowledgeHubAPI()
    api.set_server('DEV')
    api = KnowledgeHubAPI(server='TEST', client_secret='39c644b3-1f23-4d94-a71f-e0fb43ebd760')
    api.login('*****@*****.**', 'Crosby99!')
    status = api.SimilarityService().spaces()
    print(f'status={status}')
    omeprazole = 'COc1ccc2[nH]c([S+]([O-])Cc3ncc(C)c(OC)c3C)nc2c1'
    # omeprazole = 'CCC1=C(C)CN(C(=O)NCCC2=CC=C(C=C2)S(=O)(=O)NC(=O)NC2CCC(C)CC2)C1-Cl'
    similar_compounds = api.SimilarityService().get(omeprazole)

    pprint.pprint(similar_compounds)
Exemple #5
0
def main():
    parser = argparse.ArgumentParser(
        description=
        'Process parameters for collecting findings from primitive adapter')
    parser.add_argument('-username', required=True, help='username')
    parser.add_argument('-password', required=True, help='password')
    args = parser.parse_args()

    api = KnowledgeHubAPI(server='DEV',
                          client_secret='3db5a6d7-4694-48a4-8a2e-e9c30d78f9ab')
    api.login(args.username, args.password)

    socs = {}

    studies = api.eToxSys().getStudiesByCompoundNames(['omeprazole'])
    #studies = api.eToxSys().getStudiesBySMILES(['COc1ccc2[nH]c([S+]([O-])Cc3ncc(C)c(OC)c3C)nc2c1'])
    print(f'#studies:{len(studies)}')
    #print(studies[0])

    findings_per_specimen_organ = {}

    for study in studies:
        if study['FINDING']['finding'] != None and study['FINDING'][
                'finding'] != 'No abnormalities detected' and len(
                    study['FINDING']['finding']) > 0:
            specimenOrgans = api.SemanticService().getSocs(
                study['FINDING']['specimenOrgan'])
            for specimenOrgan in specimenOrgans:
                if len(specimenOrgan) > 0:
                    finding = study['FINDING']['specimenOrgan']

                    if specimenOrgan not in findings_per_specimen_organ:
                        findings_per_specimen_organ[specimenOrgan] = []
                    if finding not in findings_per_specimen_organ[
                            specimenOrgan]:
                        findings_per_specimen_organ[specimenOrgan].append(
                            finding)

    for specimen_organ in findings_per_specimen_organ:
        print(
            f'{specimen_organ}: {len(findings_per_specimen_organ[specimen_organ])}'
        )
        for finding in findings_per_specimen_organ[specimen_organ]:
            print('     ' + finding)
Exemple #6
0
def test():
    parser = argparse.ArgumentParser(description='test similarity service')
    parser.add_argument('-username', required=True, help='username')
    parser.add_argument('-password', required=True, help='password')
    args = parser.parse_args()
    #api = KnowledgeHubAPI(server='TEST', client_secret='39c644b3-1f23-4d94-a71f-e0fb43ebd760')
    api = KnowledgeHubAPI(server='DEV',
                          client_secret='3db5a6d7-4694-48a4-8a2e-e9c30d78f9ab')
    status = api.login(args.username, args.password)
    print(status)

    findings = api.eToxSys().getAllFindings(10)
Exemple #7
0
def main():
    parser = argparse.ArgumentParser(
        description=
        'Process parameters for collecting findings from primitive adapter')
    parser.add_argument('-username', required=True, help='username')
    parser.add_argument('-password', required=True, help='password')
    parser.add_argument('-host', required=True, help='mysql server')
    parser.add_argument('-database', required=True, help='mysql database')
    parser.add_argument('-dbuser', required=True, help='mysql database user')
    parser.add_argument('-dbpass',
                        required=True,
                        help='mysql database password')
    parser.add_argument('-drug_mappings', required=False, help='password')
    args = parser.parse_args()

    api = KnowledgeHubAPI(server='DEV',
                          client_secret='3db5a6d7-4694-48a4-8a2e-e9c30d78f9ab')

    mapper = Mapper(api)

    status = api.login(args.username, args.password)
    if status:
        print('logged in')
    else:
        sys.exit(0)

    if args.drug_mappings is None:
        drugs = getDrugsMapping(api, getClinicalDatabases(api),
                                getPreclinicalDatabases(api))
    else:
        if os.path.isfile(args.drug_mappings):
            with open(args.drug_mappings, 'r') as drug_file:
                drugs = json.loads(drug_file.read())
        else:
            drugs = getDrugsMapping(api, getClinicalDatabases(api),
                                    getPreclinicalDatabases(api))
            with open(args.drug_mappings, 'x') as drug_file:
                drug_file.write(json.dumps(drugs))

    print(f'#drugs found: {len(drugs.keys())}')

    db = mysql.connector.connect(host=args.host,
                                 database=args.database,
                                 username=args.dbuser,
                                 password=args.dbpass)

    ClinicalDatabases = getClinicalDatabases(api)
    PreclinicalDatabases = getPreclinicalDatabases(api)

    groups = {}
    # get first the list of SOCs

    preclinical_pts = {}
    clinical_pts = {}
    for drug in drugs:
        preclinical_pts[drug] = getPTDrugFindings(
            db=db,
            drugInfo=drugs[drug],
            databases=PreclinicalDatabases.keys(),
            table='preclinical_meddra')
        clinical_pts[drug] = getPTDrugFindings(
            db=db,
            drugInfo=drugs[drug],
            databases=ClinicalDatabases.keys(),
            table='clinical_meddra')

    c = 0
    all_preclinical_clinical_pts = getAllPreClinicalClinicalPTs(
        db=db, tables=['preclinical_meddra', 'clinical_meddra'])
    for pt in all_preclinical_clinical_pts:
        c += 1
        print(f'{c}/{len(all_preclinical_clinical_pts)}: {pt}')
        groups[pt] = {'tp': 0, 'fp': 0, 'fn': 0, 'tn': 0}
        for drug in drugs:

            if pt in preclinical_pts[drug]:
                if pt in clinical_pts[drug]:
                    groups[pt]['tp'] += 1
                else:
                    groups[pt]['fp'] += 1
            else:
                if pt in clinical_pts[drug]:
                    groups[pt]['fn'] += 1
                else:
                    groups[pt]['tn'] += 1
from knowledgehub.api import KnowledgeHubAPI

api = KnowledgeHubAPI(server='DEV',
                      client_secret='3db5a6d7-4694-48a4-8a2e-e9c30d78f9ab')
api.login('tester', 'tester')
compoundSmile = api.ChemicalService().getSMILESByName('omeprazole')
print(f'Found SMILES {compoundSmile[0]} for {"omeprazole"}')
similar_compounds = api.SimilarityService().get(compoundSmile)
print(f'similar compounds:{similar_compounds}')
def main():
    parser = argparse.ArgumentParser(
        description=
        'Process parameters for collecting findings from primitive adapter')
    parser.add_argument('-username', required=True, help='username')
    parser.add_argument('-password', required=True, help='password')
    parser.add_argument('-host', required=True, help='mysql server')
    parser.add_argument('-database', required=True, help='mysql database')
    parser.add_argument('-dbuser', required=True, help='mysql database user')
    parser.add_argument('-dbpass',
                        required=True,
                        help='mysql database password')
    parser.add_argument('-drug_mappings', required=False, help='password')
    parser.add_argument('-clear',
                        required=False,
                        action='store_true',
                        help='clear database')
    args = parser.parse_args()

    api = KnowledgeHubAPI(server='DEV',
                          client_secret='3db5a6d7-4694-48a4-8a2e-e9c30d78f9ab')
    mapper = Mapper(api)

    logged_in = api.login(args.username, args.password)
    if logged_in:
        print(f'logged in')
    else:
        print(f'not logged in')
        sys.exit(0)

    db = mysql.connector.connect(host=args.host,
                                 database=args.database,
                                 username=args.dbuser,
                                 password=args.dbpass)

    if args.clear:
        cursor = db.cursor(prepared=True)
        cursor.execute("DELETE FROM preclinical_meddra")
        cursor.execute("DELETE FROM clinical_meddra")
        db.commit()

    records = []

    # retrieve the preclinical records and map them to MedDRA
    maximum = 0
    cursor = db.cursor(prepared=True)
    cursor.execute(
        'SELECT distinct id, findingCode, specimenOrganCode FROM preclinical_findings WHERE mapped > -1'
    )
    for r in cursor.fetchall():
        mapped_clinical_findings = mapper.mapToClinical([{
            'findingCode':
            r[1],
            'specimenOrganCode':
            r[2]
        }])
        preclinical_code = mapper.getKey({
            'findingCode': r[1],
            'specimenOrganCode': r[2]
        })

        # find the mapping(s) with the minimal absolute distance
        values = [
            item['distance']
            for item in mapped_clinical_findings[preclinical_code]
        ]
        if len(values) > 0:
            minimum = min(values)
            min_values = [
                item for item in mapped_clinical_findings[preclinical_code]
                if item['distance'] == minimum
            ]
            if len(min_values) > maximum:
                maximum = len(min_values)
            for min_value in min_values:
                records.append((r[0], r[1], r[2], min_value['findingCode'],
                                min_value['name'], min_value['distance']))

    # store the mappings
    try:
        cursor = db.cursor(prepared=True)
        cursor.executemany(
            'INSERT INTO preclinical_meddra (id, findingCode, specimenOrganCode, PTCode, name, distance) VALUES (%s, %s, %s, %s, %s, %s)',
            records)
        db.commit()
    except mysql.connector.errors.InterfaceError as e:
        print(e)

    # retrieve the clinical records and store them in the database
    try:
        cursor = db.cursor(prepared=True)
        cursor2 = db.cursor(prepared=True)
        cursor.execute(
            'SELECT distinct id, findingCode, specimenOrganCode, findingCode, finding, mapped FROM clinical_findings WHERE mapped > -1'
        )
        cursor2.executemany(
            'INSERT INTO clinical_meddra (id, findingCode, specimenOrganCode, PTCode, name, distance) VALUES (%s, %s, %s, %s, %s, %s)',
            cursor.fetchall())
        db.commit()
    except mysql.connector.errors.InterfaceError as e:
        print(e)
Exemple #10
0
"""
test how the response from eToxSys looks like
"""

# api = KnowledgeHubAPI(server='TEST', client_secret='39c644b3-1f23-4d94-a71f-e0fb43ebd760')
from knowledgehub.api import KnowledgeHubAPI
import sys
from Concordance.condordance_utils import getPreclinicalCompounds

api = KnowledgeHubAPI(server='DEV',
                      client_secret='3db5a6d7-4694-48a4-8a2e-e9c30d78f9ab')

status = api.login('tester', 'tester')
drugs = getPreclinicalCompounds(api)
for drug in drugs:
    print(drug)