Пример #1
0
def run_l1000cds2(signature, nr_genes=500, signature_label='', plot_type='interactive'):
    # Define results
    l1000cds2_results = {'signature_label': signature_label}

    # Define upperGenes Function
    upperGenes = lambda genes: [gene.upper() for gene in genes]

    # Get Data
    data = {"upGenes":upperGenes(signature.index[:nr_genes]),"dnGenes":upperGenes(signature.index[-nr_genes:])}

    # Loop through aggravate:
    for aggravate in [True, False]:

        # Send to API
        config = {"aggravate":aggravate,"searchMethod":"geneSet","share":True,"combination":False,"db-version":"latest"}
        r = requests.post('http://amp.pharm.mssm.edu/L1000CDS2/query',data=json.dumps({"data":data,"config":config}),headers={'content-type':'application/json'})
        label = 'mimic' if aggravate else 'reverse'

        # Add results
        resGeneSet = r.json()
        if resGeneSet.get('topMeta'):
            l1000cds2_dataframe = pd.DataFrame(resGeneSet['topMeta'])[['cell_id', 'pert_desc', 'pert_dose', 'pert_dose_unit', 'pert_id', 'pert_time', 'pert_time_unit', 'pubchem_id', 'score', 'sig_id']].replace('-666', np.nan)
            l1000cds2_results[label] = {'url': 'http://amp.pharm.mssm.edu/L1000CDS2/#/result/{}'.format(resGeneSet['shareId']), 'table': l1000cds2_dataframe}
        else:
            l1000cds2_results[label] = None
    l1000cds2_results['plot_type'] = plot_type
    # Return
    return l1000cds2_results
Пример #2
0
def _google_translate(q, source, target, key):
    import requests
    params = {'q': q, 'target': target, 'key': key}
    if source:
        params['source'] = source
    try:
        r = requests.post(
            'https://translation.googleapis.com/language/translate/v2',
            data=params)
    except requests.RequestException:
        return app_log.exception('Cannot connect to Google Translate')
    response = r.json()
    if 'error' in response:
        return app_log.error('Google Translate API error: %s',
                             response['error'])
    return {
        'q':
        q,
        't': [t['translatedText'] for t in response['data']['translations']],
        'source': [
            t.get('detectedSourceLanguage', params.get('source', None))
            for t in response['data']['translations']
        ],
        'target': [target] * len(q),
    }