コード例 #1
0
def full_heatfile(disease, network):
    """
    Output tab-separated ENSG and assoc scores for all nodes
    in network, including zero values.  Not needed?
    
    disease = disease of interest (EFO code)
    network = source network (stringdb or omnipath)
    """
    #Read in network info frame
    idFrame = pd.read_csv('./networks/' + network + 'IDFrame.csv')
    idFrame = idFrame.set_index('geneID')
    ot = OpenTargetsClient()
    all_associations = ot.filter_associations(disease=disease)
    #build frame of associations
    assocFrame = pd.DataFrame(columns=['geneID', 'score'])
    for i, r in enumerate(all_associations):
        assocFrame.loc[len(assocFrame)] = [
            r['target']['id'], r['association_score']['overall']
        ]
    #Join with sample data
    idFrame = idFrame.join(assocFrame.set_index('geneID'),
                           how='left').fillna(0.0000000001)
    #Output to heatfile
    with open('./data/heatfile', 'w') as outfile:
        for index, row in idFrame.iterrows():
            if isinstance(index, basestring):
                outfile.write("{} {}\n".format(index, row['score']))
コード例 #2
0
def search_known_drugs(x):
	from opentargets import OpenTargetsClient
	from sys import argv

	client = OpenTargetsClient()
	response = client.get_evidence_for_disease(x)
	return response.to_dataframe()
コード例 #3
0
ファイル: utils.py プロジェクト: GuiltyTargets/phewas
def generate_disease_gene_association_file(disease_id,
                                           outpath,
                                           anno_type: str = 'entrezgene'):
    """Obtain the association scores from the specified disease that are
    stored in the OpenTargets database.

    :param disease_id: The EFO code to the disease.
    :param outpath: The path to the file to be created.
    :param anno_type: `entrezgene` for Entrez Id or `symbol` for Gene symbol.
    :return:
    """
    ot = OpenTargetsClient()
    assoc = ot.get_associations_for_disease(
        disease_id, fields=['association_scoreoverall', 'target.id'])
    assoc_simple = [{
        'id': a['target']['id'],
        'score': a['association_score']['overall']
    } for a in assoc]
    ensembl_list = [a['id'] for a in assoc_simple]

    # Obtain the symbols for the genes associated to disease_id
    id_mappings = get_converter_to_entrez(ensembl_list)

    # Get the symbols and the scores
    ensembl_list = [(id_mappings[a['id']], a['score']) for a in assoc_simple
                    if a['id'] in id_mappings]

    with open(outpath, 'w+') as outfile:
        for symbol, score in ensembl_list:
            print(f'{symbol}\t{score}', file=outfile)
def search_disease(x):
	from opentargets import OpenTargetsClient
	from sys import argv

	client = OpenTargetsClient()
	response = client.get_associations_for_disease(x)
	return response.to_dataframe()
コード例 #5
0
ファイル: assembler.py プロジェクト: GuiltyTargets/phewas
def generate_targets_file(disease_id, outpath, anno_type: str = 'entrezgene') -> None:
    """Creates a disease list

    :param disease_id: EFO code from the disease.
    :param outpath:
    :param anno_type: `entrezgene` for Entrez Id or `symbol` for Gene symbol.
    :return:
    """
    ot = OpenTargetsClient()
    assoc = ot.get_associations_for_disease(
        disease_id,
        fields=['association_scoredatatypes', 'target.id']
    ).filter(
        datatype='known_drug'
    )
    ensembl_list = [a['target']['id'] for a in assoc]

    # TODO use the converters.get_converter_to_entrez
    mg = mygene.MyGeneInfo()
    id_mappings = mg.getgenes(ensembl_list, fields=anno_type)

    with open(outpath, 'w+') as outfile:
        for mapping in id_mappings:
            if anno_type in mapping.keys():
                outfile.write(mapping[anno_type])
                outfile.write('\n')
def search_new_drugs(x):
	from opentargets import OpenTargetsClient
	from sys import argv

	client = OpenTargetsClient()
	response = client.search(x)
	return response.to_dataframe()
コード例 #7
0
def run_analysis(queryType, identifier, verbose = False):
    """ This function will run the actual analysis

    Args:
        queryType (str): based on what we are fetching data either disease or target
        identifier (str): disease ID or target ID depending on the query type.
        verbose (bool): if we want extra information printed to STDOUT
    Returns:
        Dictionary:
        {
            "queryTerm" : <str>
            "target-disease-pairs" : <pandas.dataframe>,
            "score_max" : <float>,
            "score_min" : <float>,
            "score_mean" : <float>,
            "score_std" : <float>
        }

        The analysis values might be None if there are no returned values.
    """

    # Initializing output variable:
    analysisOutput = {
        "queryTerm" : identifier,
        "target-disease-pairs" : None,
        "score_max" : None,
        "score_min" : None,
        "score_mean" : None,
        "score_std" : None
    }

    # Initializing OTAR query object:
    client = OpenTargetsClient()
    otar_results = client.filter_associations()

    # Retrieving queried data:
    x = otar_results.filter(**{queryType : identifier})

    # Submit result to parser:
    OT_parser = OTAR_result_parser(x, verbose=verbose)

    # If the result set is empty, we can't get stats:
    if not len(OT_parser):
        if verbose: print('[Warning] The result set is empty. Can\'t calculate stats.')
        return analysisOutput

    if verbose: print('[Info] Number of associations: {}'.format(len(OT_parser)))

    # Retrieving target-disease pairs:
    analysisOutput['target-disease-pairs'] = OT_parser.get_target_disease_pairs()

    # Retrieving stats of the association scores:
    analysisOutput['score_max'] = OT_parser.get_association_score_max()
    analysisOutput['score_min'] = OT_parser.get_association_score_min()
    analysisOutput['score_mean'] = OT_parser.get_association_score_mean()
    analysisOutput['score_std'] = OT_parser.get_association_score_std()

    return analysisOutput
コード例 #8
0
def simple_heatfile(disease):
    """
    Output tab-separated ENSG and assoc scores for nodes with non-zero assoc scores
    
    disease = disease of interest (EFO code)
    """
    ot = OpenTargetsClient()
    all_associations = ot.filter_associations(disease=disease)
    with open('./data/heatfile', 'w') as outfile:
        for i, r in enumerate(all_associations):
            outfile.write("{} {}\n".format(r['target']['id'],
                                           r['association_score']['overall']))
コード例 #9
0
 def request(self, arg, query_type):
     """
     Requests response from given endpoint
     Args:
         arg (str): Given command line argument to query endpoint with
         query_type (str): Parameter for RESTful api query
         url (str): Given RESTful api endpoint
     Returns:
         response: A JSON response
     """
     ot = OpenTargetsClient()
     a_for_target = ot.get_associations_for_target(arg)
     for a in a_for_target:
         print(a)
コード例 #10
0
def download_for_disease(disease_id, outpath):
    ot = OpenTargetsClient()
    assoc = ot.get_associations_for_disease(
        disease_id, fields=['associationscore.datatypes',
                            'target.id']).filter(datatype='known_drug')
    ensembl_list = [a['target']['id'] for a in assoc]

    mg = mygene.MyGeneInfo()
    id_mappings = mg.getgenes(ensembl_list, fields="entrezgene")

    with open(outpath, 'w+') as outfile:
        for mapping in id_mappings:
            if 'entrezgene' in mapping.keys():
                outfile.write(mapping['entrezgene'])
                outfile.write('\n')
コード例 #11
0
def openTargets2():
    '''
    from opentargets import OpenTargetsClient
    client = OpenTargetsClient()
    response = client.get_associations_for_target('BRAF',
    	fields = ['associations_score.datasource*',
    			'associations_score.overall',
    			'target.gene_info.symbol',
    			'disease.efo_info.*']
    		)
    response.to_excel('BRAF_associated_diseases_by_datasource.xls')
    '''

    client = OpenTargetsClient()
    response = client.get_associations_for_target('ENSG00000157764',
    	fields=['association_score.datasource*','association_score.overall','target.gene_info.symbol','disease.efo_info.*'])
    print(response)
コード例 #12
0
    def setUp(self):

        self.client = OpenTargetsClient()
        self.http2_client = OpenTargetsClient(use_http2=True)
        self.auth_client = OpenTargetsClient(
            auth_app_name='test',
            auth_secret='test',
        )
コード例 #13
0
def download_targets_for_diseases(data_dir: str):
    my_gene_info = MyGeneInfo()
    open_targets_client = OpenTargetsClient()
    for disease_efo_id, disease_abbreviation in zip(disease_efo_ids,
                                                    DISEASE_ABBREVIATIONS):
        path = os.path.join(data_dir, disease_abbreviation,
                            opentargets_file_name)
        if os.path.exists(path):
            continue
        with open(path, 'w+') as file:
            download_targets_for_disease(
                disease_efo_id=disease_efo_id,
                my_gene_info=my_gene_info,
                open_targets_client=open_targets_client,
                file=file,
            )
コード例 #14
0
def drug_info_for_genes(args):
    if not os.path.exists(args.outdir):
        os.makedirs(args.outdir)

    with open(args.genes) as infile:
        genes = [s.strip() for s in infile]

    client = OpenTargetsClient()

    all_results = {}
    all_diseases = defaultdict(int)
    num_genes = len(genes)
    diseases = set(args.disease)
    if args.disease_file is not None:
        with open(args.disease_file) as infile:
            for d in infile:
                diseases.add(d.strip())
    print("Diseases: " + str(diseases))

    for i, g in enumerate(genes):
        print('%s - %d of %d' % (g, i + 1, num_genes))
        result = get_drugs(client, g, all_diseases, diseases, args.trial_phase)
        all_results[g] = result

    with open(os.path.join(args.outdir, 'diseases.tsv'), 'w') as outfile:
        for disease in sorted(all_diseases.keys()):
            outfile.write('%s\t%d\n' % (disease, all_diseases[disease]))

    with open(os.path.join(args.outdir, 'gene_opentargets.json'),
              'w') as outfile:
        json.dump(all_results, outfile)

    # write unique results
    unique_results = uniqify(all_results)
    with open(
            os.path.join(
                os.path.join(args.outdir, 'gene_opentargets_unique.json')),
            'w') as outfile:
        json.dump(unique_results, outfile)

    # write backgrounds
    compute_backgrounds(unique_results, args.outdir)
コード例 #15
0
ファイル: download.py プロジェクト: ashar799/guiltytargets
def download_targets_for_disease(
        disease_efo_id: str,
        open_targets_client: Optional[OpenTargetsClient] = None,
        my_gene_info: Optional[MyGeneInfo] = None,
        file: Optional[TextIO] = None,
) -> None:
    """

    :param disease_efo_id: A disease's EFO identifier
    :param open_targets_client: An OpenTargetsClient
    :param my_gene_info: A MyGeneInfo client
    :param file: Place to output targets for disease
    """
    if open_targets_client is None:
        open_targets_client = OpenTargetsClient()
    associations = open_targets_client.get_associations_for_disease(
        disease_efo_id,
        fields=[
            'associationscore.datatypes',
            'target.id',
        ],
    ).filter(
        datatype='known_drug',
    )
    ensembl_list = [
        association['target']['id']
        for association in associations
    ]

    if my_gene_info is None:
        my_gene_info = MyGeneInfo()

    id_mappings = my_gene_info.getgenes(ensembl_list, fields="entrezgene")

    print('efo', 'ncbigene', file=file, sep='\t')
    for mapping in id_mappings:
        entrez_gene_id = mapping.get('entrezgene')
        if entrez_gene_id is not None:
            print(disease_efo_id, entrez_gene_id, file=file, sep='\t')
コード例 #16
0
ファイル: Client.py プロジェクト: peiyaoli/BioClients
    fout = open(args.ofile, "w+") if args.ofile else sys.stdout

    ids = []
    if args.ifile:
        fin = open(args.ifile)
        while True:
            line = fin.readline()
            if not line: break
            if line.rstrip(): ids.append(line.rstrip())
        fin.close()
    elif args.ids:
        ids = re.split(r'[,\s]+', args.ids)
    if ids: logging.info('Input IDs: {}'.format(len(ids)))

    otclient = OpenTargetsClient()

    logging.debug(otclient.get_stats().info)

    if args.op == 'searchAssociations':
        if not ids: parser.error('--i or --ids required.')
        opentargets.Utils.SearchAssociations(otclient, ids, args.idtype,
                                             args.minscore, args.skip,
                                             args.nmax, fout)

    elif args.op == 'getEvidence':
        parser.error('Unimplemented operation: {}'.format(args.op))
        if not ids: parser.error('--i or --ids required.')
        #opentargets.Utils.Target2Disease_Evidence(otclient, tid, args.did, fout)

    else:
コード例 #17
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
A script for gathering data in format suitable for bulk input into Elasticsearch index.
Combines disease codes with additional disease information from EBI Ontology Lookup Service
and associated drug interactions from Open Targets client.

@author: jderoberts
"""

from opentargets import OpenTargetsClient
import requests
import json

ot = OpenTargetsClient()

data = {}

#codes = ['EFO_0000249', 'EFO_0003885', 'EFO_0000685', 'EFO_0000313', 'EFO_0001071', 'EFO_0000305', 'EFO_0002890', 'EFO_0000478', 'EFO_1001516', 'EFO_0007460', 'Orphanet_2781', 'Orphanet_3261']

#uniqueEFOs - disease id extracted from every OpenTargets evidence object and reduced to set of unique values

codes = set()
with open('uniqueEFOs.txt') as infile:
    for line in infile:
        codes.add(line.rstrip())

otdata = ot.filter_associations()
j = 0
k = len(codes)
for code in codes:
コード例 #18
0
ファイル: get_gwas.py プロジェクト: shraddhapai/SNPNotes
#!/home/shraddhapai/anaconda2/bin/python

from opentargets import OpenTargetsClient
import sys
client = OpenTargetsClient()

disease_ID = sys.argv[1]

print disease_ID

with open('Biomart_ENGSIDs_190405.txt', mode='rU') as fp:
    for line_term in fp:
        line = line_term.rstrip('\n')
        response = client.filter_evidence()
        response.filter(target=line, disease=disease_ID)
        for i, r in enumerate(response):
            src = r['sourceID']
            if src == 'gwas_catalog':
                print(r['target']['gene_info']['symbol'],
                      r['target']['gene_info']['name'],
                      r['disease']['efo_info']['label'],
                      r['unique_association_fields'])
コード例 #19
0
class OpenTargetClientTest(unittest.TestCase):
    _AUTO_GET_TOKEN = 'auto'

    def setUp(self):

        self.client = OpenTargetsClient()
        self.http2_client = OpenTargetsClient(use_http2=True)
        self.auth_client = OpenTargetsClient(
            auth_app_name='test',
            auth_secret='test',
        )

    def tearDown(self):
        self.client.close()

    def testSearchTargetCorrectResult(self):
        target_symbol = 'BRAF'
        response = self.client.search(target_symbol)
        self.assertGreater(len(response), 0)
        result = next(response)
        self.assertEqual(result['type'], 'search-object-target')
        self.assertEqual(result['id'], 'ENSG00000157764')
        self.assertEqual(result['data']['approved_symbol'], target_symbol)

    def testSearchTargetFetchAllResults(self):
        target_symbol = 'BRAF'
        response = self.client.search(target_symbol)
        total_results = len(response)
        self.assertGreater(total_results, 0)
        c = 0
        for i in response:
            c += 1
        self.assertEqual(total_results, c)

    def testSearchTargetFetchAllResultsAuth(self):
        target_symbol = 'BRAF'
        response = self.auth_client.search(target_symbol)
        total_results = len(response)
        self.assertGreater(total_results, 0)
        c = 0
        for i in response:
            c += 1
        self.assertEqual(total_results, c)

    def testSearchTargetCorrectResultHTTP2(self):
        target_symbol = 'BRAF'
        response = self.http2_client.search(target_symbol)
        self.assertGreater(len(response), 0)
        result = next(response)
        self.assertEqual(result['type'], 'search-object-target')
        self.assertEqual(result['id'], 'ENSG00000157764')
        self.assertEqual(result['data']['approved_symbol'], target_symbol)

    def testSearchTargetFetchAllResultsHTTP2(self):
        target_symbol = 'BRAF'
        response = self.http2_client.search(target_symbol)
        total_results = len(response)
        self.assertGreater(total_results, 0)
        c = 0
        for i in response:
            c += 1
        self.assertEqual(total_results, c)

    def testSearchDiseaseCorrectResult(self):
        disease_label = 'cancer'
        response = self.client.search(disease_label)
        self.assertGreater(len(response), 0)
        result = next(response)
        self.assertEqual(result['type'], 'search-object-disease')
        self.assertEqual(result['id'], 'EFO_0000311')

    # #this takes a lot to run
    # def testSearchDiseaseFetchAllResults(self):
    #     disease_label = 'cancer'
    #     response = self.client.search(disease_label, size = 100)
    #     total_results = len(response)
    #     self.assertGreater(total_results,0)
    #     c=0
    #     for i in response:
    #         c+=1
    #     self.assertEqual(total_results, c)
    #     print(total_results, c)

    def testGetAssociation(self):
        association_id = "ENSG00000157764-EFO_0005803"
        response = self.client.get_association(association_id)
        self.assertEquals(len(response), 1)
        self.assertEquals(association_id, response[0]['id'])

    def testFilterAssociations(self):
        response = self.client.filter_associations()
        self.assertGreater(len(response), 0)
        total = response.info.total
        response.filter(target='ENSG00000157764')
        self.assertLess(len(response), total)
        total = response.info.total
        response.filter(direct=True)
        self.assertLess(len(response), total)
        total = response.info.total
        response.filter(scorevalue_min=0.2)
        self.assertLess(len(response), total)
        total = response.info.total
        response.filter(therapeutic_area='efo_0000701')
        self.assertLess(len(response), total)
        results = []
        for i, r in enumerate(response):
            print(i, r['id'], r['association_score']['overall'],
                  r['disease']['efo_info']['label'])
            results.append(r)
        response_multi = self.client.filter_associations(
            target='ENSG00000157764',
            direct=True,
            scorevalue_min=0.2,
            therapeutic_area='efo_0000701')
        self.assertEqual(len(response_multi), response.info.total)
        for i, r in enumerate(response_multi):
            self.assertEqual(results[i]['id'], r['id'])
        response_chained = self.client.filter_associations().filter(
            target='ENSG00000157764').filter(direct=True).filter(
                therapeutic_area='efo_0000701').filter(scorevalue_min=0.2)
        self.assertEqual(len(response_chained), response.info.total)
        for i, r in enumerate(response_chained):
            self.assertEqual(results[i]['id'], r['id'])

    def testGetAssociationsForTarget(self):
        target_symbol = 'BRAF'
        response = self.client.get_associations_for_target(target_symbol,
                                                           size=30)
        self.assertGreater(len(response), 0)
        for i, result in enumerate(response):
            self.assertEqual(result['target']['gene_info']['symbol'],
                             target_symbol)
            if i > 90:
                break

    def testGetAssociationsForDisease(self):
        disease_label = 'cancer'
        response = self.client.get_associations_for_disease(disease_label)
        self.assertGreater(len(response), 0)
        for result in response:
            self.assertEqual(result['disease']['efo_info']['label'],
                             disease_label)

    @unittest.expectedFailure
    def testGetEvidence(self):
        evidence_id = "03fba0599655b9040012b29cf0de8060"
        response = self.client.get_evidence(evidence_id)
        self.assertEquals(len(response), 1)
        self.assertEquals(evidence_id, response[0]['id'])

    def testFilterEvidence(self):
        response = self.client.filter_evidence()
        self.assertGreater(len(response), 0)

    def testGetEvidenceForTarget(self):
        target_symbol = 'BRAF'
        response = self.client.get_evidence_for_target(target_symbol,
                                                       size=1000)
        self.assertGreater(len(response), 0)
        for i, result in enumerate(response):
            self.assertEqual(result['target']['gene_info']['symbol'],
                             target_symbol)
            if i > 100:
                break

    def testGetSimilarTargets(self):
        target_symbol = 'BRAF'
        response = self.client.get_similar_target(target_symbol)
        self.assertGreater(len(response), 0)
        result = next(response)
        self.assertEqual(result['subject']['label'], target_symbol)
        self.assertEqual(result['object']['label'], 'KRAS')

    def testGetSimilarDisease(self):
        disease_label = 'ulcerative colitis'
        response = self.client.get_similar_disease(disease_label)
        self.assertGreater(len(response), 0)
        result = next(response)
        self.assertEqual(result['subject']['label'], disease_label)
        self.assertEqual(result['object']['label'], "Crohn's disease")

    def testGetEvidenceForDisease(self):
        disease_label = 'medulloblastoma'
        response = self.client.get_evidence_for_disease(disease_label)
        self.assertGreater(len(response), 0)
        result = next(response)
        self.assertEqual(result['disease']['efo_info']['label'], disease_label)

    def testSerialiseToJson(self):
        target_symbol = 'BRAF'
        '''test iterable version'''
        response = self.client.get_associations_for_target(target_symbol)
        items = len(response)
        self.assertGreater(len(response), 0)
        json_output = response.to_json()
        parsed_json = [json.loads(i) for i in json_output]
        self.assertEqual(items, len(parsed_json))
        '''test non iterable version'''
        response = self.client.get_associations_for_target(target_symbol)
        items = len(response)
        self.assertGreater(len(response), 0)
        json_output = response.to_json(iterable=False)
        parsed_json = json.loads(json_output)
        self.assertEqual(items, len(parsed_json))

    def testResultToPandasDataFrame(self):
        target_symbol = 'BRAF'
        response = self.client.get_associations_for_target(target_symbol)
        items = len(response)
        self.assertGreater(len(response), 0)
        dataframe = response.to_dataframe()
        self.assertEqual(len(dataframe), items)

    def testResultToPandasCSV(self):
        target_symbol = 'BRAF'
        response = self.client.get_associations_for_target(
            target_symbol,
            fields=[
                'association_score.*', 'target.gene_info.symbol',
                'disease.efo_info.*'
            ])
        items = len(response)
        self.assertGreater(len(response), 0)
        csv = response.to_csv()
        filename = 'braf_associations.csv'
        open(filename, 'wb').write(csv.encode('utf-8'))
        self.assertEqual(len(csv.split('\n')), items + 2)
        self.assertTrue(os.path.isfile(filename))
        os.remove(filename)

    def testResultToPandasExcel(self):
        target_symbol = 'BRAF'
        response = self.client.get_associations_for_target(
            target_symbol,
            fields=[
                'association_score.*', 'target.gene_info.symbol',
                'disease.efo_info.*'
            ])
        self.assertGreater(len(response), 0)
        filename = 'braf_associations.xls'
        response.to_excel(filename)
        self.assertTrue(os.path.isfile(filename))
        os.remove(filename)

    def testResultToFile(self):
        target_symbol = 'BRAF'
        response = self.client.get_associations_for_target(
            target_symbol,
            fields=[
                'association_score.*', 'target.gene_info.symbol',
                'disease.efo_info.*'
            ])
        self.assertGreater(len(response), 0)
        filename = 'braf_associations.json.gz'
        response.to_file(filename)
        self.assertTrue(os.path.isfile(filename))
        os.remove(filename)

    def testSerialiseToObject(self):
        target_symbol = 'BRAF'
        response = self.client.get_associations_for_target(target_symbol)
        items = len(response)
        self.assertGreater(len(response), 0)
        obj_output = list(response.to_object())
        for i, result in enumerate(obj_output):
            self.assertIsNotNone(result.target.id)
        self.assertEqual(items, i + 1)

    def testGetStats(self):
        response = self.client.get_stats()
        self.assertEquals(len(response), 0)

    def testAutodetectPost(self):
        self.assertFalse(
            Connection._auto_detect_post({'target': ['ENSG00000157764']}))
        self.assertTrue(
            Connection._auto_detect_post({
                'target': [
                    'ENSG00000157764',
                    'ENSG00000171862',
                    'ENSG00000136997',
                    'ENSG00000012048',
                    'ENSG00000139618',
                ]
            }))

    def testGetToPost(self):
        response = self.client.conn.get('/platform/public/association/filter',
                                        params={
                                            'target': [
                                                'ENSG00000157764',
                                                'ENSG00000171862',
                                                'ENSG00000136997',
                                                'ENSG00000012048',
                                                'ENSG00000139618',
                                            ]
                                        })
        self.assertGreater(len(response), 0)

    def testCustomScore(self):
        def score_with_datatype_subset(datatypes, results):
            for r in results:
                datatype_scores = r['association_score']['datatypes']
                filtered_scores = [datatype_scores[dt] for dt in datatypes]
                custom_score = HarmonicSumScorer.harmonic_sum(filtered_scores)
                if custom_score:
                    yield (round(custom_score, 3), r['disease']['id'],
                           dict(zip(datatypes, filtered_scores)))

        target_symbol = 'BRAF'
        response = self.client.get_associations_for_target(target_symbol)
        self.assertGreater(len(response), 0)
        for i, filtered_data in enumerate(
                score_with_datatype_subset(
                    ['genetic_association', 'known_drug', 'somatic_mutation'],
                    response)):
            self.assertGreater(filtered_data[0], 0.)

        self.assertLess(i, len(response))

    def testGetAvailableEndpoints(self):
        endpoints = self.client.conn.get_api_endpoints()
        self.assertTrue('/platform/public/search' in endpoints)

    def testGetEndpointDocs(self):
        docs = self.client.conn.api_endpoint_docs('/platform/public/search')
        self.assertGreater(len(docs['get']['parameters']), 0)

    def testPing(self):
        response = self.client.conn.ping()
        if isinstance(response, bool):
            self.assertTrue(response)
        else:
            self.assertIsNotNone(response)
コード例 #20
0
ファイル: externalApiCalls.py プロジェクト: lukasjf/mphp
import pandas as pd
import numpy as np
import os.path
import json
import urllib

from opentargets import OpenTargetsClient
from SPARQLWrapper import SPARQLWrapper, JSON
from xml.dom.minidom import parse, parseString
ot = OpenTargetsClient()

cancer_strings = ("cancer", "melanoma", "carcinoma", "leukemia", "sarcoma", "lymphoma", "Hodgkin", "tumor")


def getCancerGeneCensusData():
    csv_file = 'data/cancer_gene_census.csv'
    return pd.read_csv(csv_file)

def getInvertedEntrezNamesMap():
    inverted_file = "data/gene_names/entrez_names_inverted"

    if not os.path.isfile(inverted_file + ".npy"):
        entrez_labels_map = np.load("data/gene_names/entrez_names.npy").item()
        inverted_entrez_labels_map = {v: k for k, v in entrez_labels_map.items()}
        np.save(inverted_file, inverted_entrez_labels_map)

    return np.load(inverted_file+ ".npy").item()

def lookupDisgenet(gene):
    entrez_file = "data/gene_names/entrez_names.npy"
    entrez_labels_map = np.load(entrez_file).item()
コード例 #21
0
import requests
import pprint
import urllib2
from opentargets import OpenTargetsClient

STRING_API_URL = "https://string-db.org/api"

ot = OpenTargetsClient()
res = ot.search('BRAF')


def getAssociationsForDisease(disease='cancer'):
    return ot.get_associations_for_disease(disease)[0]


def getAssociationsForTarget(target="BRAF"):
    return ot.get_associations_for_target(target)


def getAssociationByID(gene, disease):
    assocs = ot.get_association('{gene}-{disease}'.format(gene=gene,
                                                          disease=disease)[0])
    return assocs


#  STRING DATA
class StringData:
    def __init__(self, url):
        self.url = url

    def getStringIDs(self, lsgenes=[], limit=1):
コード例 #22
0
    def setUp(self):

        self.client = OpenTargetsClient()
コード例 #23
0
ファイル: runOTcli.py プロジェクト: tp175/testbioOT
def main(t, d):

    # Quick Check - arguments (none/both)
    if t == '' and d == '':sys.exit(1)
    if t != '' and d != '':sys.exit(1)

    # Load Func re opentargets querying ( pip install opentargets )
    # https://opentargets.readthedocs.io/en/stable/index.html
    from opentargets import OpenTargetsClient
    ot = OpenTargetsClient()
    # dir(ot)

    # Define Func re statistical analyses
    def doScoreStats(search_score):

        import statistics
        print('-----')
        print('Max:', max(search_score))
        print('Min:', min(search_score))
        print('Ave:', statistics.mean(search_score))
        print('SD:', statistics.stdev(search_score))

    # Run Analysis re TARGET (t)
    if t != '':

        search_id = t;
        a_for_target = ot.get_associations_for_target(search_id)

        # Quick Check - correct 'target' queried
        if a_for_target.info['query']['target'] == [search_id]:

            search_score = []  # initialise list

            # Loop Over Entries
            for a in a_for_target:
                search_score.append(a['association_score']['overall'])
                print(a['target']['id'], a['disease']['id'], a['association_score']['overall'])

            doScoreStats(search_score)

        else:
            print("please check best match (exited) -", [search_id], " vs ", a_for_target.info['query']['target'])
            sys.exit(1)

    # Run Analysis re DISEASE (d)
    elif d != '':

        search_id = d
        a_for_disease = ot.get_associations_for_disease(search_id)

        # Quick Check - correct 'disease' queried
        if a_for_disease.info['query']['disease'] == [search_id]:

            search_score = []  # initialise list

            # Loop Over Entries
            for a in a_for_disease:
                search_score.append(a['association_score']['overall'])
                print(a['target']['id'], a['disease']['id'], a['association_score']['overall'])

            doScoreStats(search_score)

        else:
            print("please check best match (exited) - ", [search_id], " vs ", a_for_disease.info['query']['disease'])
            sys.exit(1)
コード例 #24
0
ファイル: otquery.py プロジェクト: kierenlythgow1/opentargets
import argparse
import sys
import numpy as np
from opentargets import OpenTargetsClient
ot = OpenTargetsClient()

#This script queries the Open Targets REST API using either a target id or disease id.
#This returns the maximum, minimum, mean and standard deviations of the association scores.

__version__ = '0.1'
__date__ = '23Aug2019'
__author__ = '*****@*****.**'

Description = 'version %s, date %s, author %s' % (__version__, __date__,
                                                  __author__)

Parser = argparse.ArgumentParser(description=Description)

Parser.add_argument(
    '-t',
    '--target_id',
    metavar='STRING',
    dest='target_id',
    #required=True,
    help='Please supply gene target id')

Parser.add_argument(
    '-d',
    '--disease_id',
    metavar='STRING',
    dest='disease_id',
コード例 #25
0
ファイル: scriptOT.py プロジェクト: cigdemselli/opentargets
}
disease_id = datadict_disease.get("disease")

#First, print an error message if no argument is provided.
#Then, run appropriat code depending on input argument (target or disase)
if target_id == None and disease_id == None:
    print(
        "Error: target_id or disease_id must be provided. Provide a target_id such as ENSG00000197386 or disease_id such as Orphanet_399."
    )
elif target_id != None and disease_id != None:
    print(
        "Error: One argument should be provided at a time. Provide either a target_id such as ENSG00000197386 or disease_id such as Orphanet_399."
    )
else:
    #get associations
    client = OpenTargetsClient()
    response = client.filter_associations()

    #filter, calculate and print required information for a target or disease
    if target_id != None:
        #filter for target_id. Print target_id, disease_id & association_score.overall.
        filtered = response.filter(target=target_id)
        target_filtered = filtered.to_dataframe()
        target_fin = target_filtered[[
            "target.id", "disease.id", "association_score.overall"
        ]]
        print(target_fin)
        #calculate and print maximum, minimum and average and standard deviation values of association_score.overall
        maximum = target_fin["association_score.overall"].max()
        minimum = target_fin["association_score.overall"].min()
        average = target_fin["association_score.overall"].mean()
コード例 #26
0
def ot_version():
    ot = OpenTargetsClient()
    stats = ot.get_stats()
    return str(stats.info['data_version'])