def get_fairshake_client(api_key=None,
                         username=None,
                         email=None,
                         password=None):
    ''' Using either the api_key directly, or with fairshake
  user credentials, create an authenticated swagger client to fairshake.
  '''
    from pyswaggerclient import SwaggerClient
    fairshake = SwaggerClient(
        'https://fairshake.cloud/swagger?format=openapi', )
    if not api_key:
        fairshake_auth = fairshake.actions.auth_login_create.call(
            data=dict({
                'username': username,
                'password': password,
            }, **({
                'email': email
            } if email else {})))
        api_key = fairshake_auth['key']
    # FAIRshake expects a Token in the Authorization request header for
    #  authenticated calls
    fairshake.update(headers={
        'Authorization': 'Token ' + api_key,
    })
    return fairshake
Exemple #2
0
def ask_fairsharing(doi):
    from pyswaggerclient import SwaggerClient
    client = SwaggerClient(
        'https://fairsharing.org/api/?format=openapi',
        headers={'Api-Key': os.environ.get('FAIRSHARING_API_KEY')})
    results = client.actions.database_summary_list.call(doi=doi)['results']

    return {
        'keywords':
        list(
            filter(None,
                   [result.get('user_defined_tags') for result in results])),
        'doi':
        list(filter(None, [result.get('doi') for result in results])),
        'name':
        list(filter(None, [result.get('name') for result in results])),
        'description':
        list(filter(None, [result.get('description') for result in results])),
        'indexed':
        list(
            filter(None, [('https://fairsharing.org/' +
                           result['bsg_id']) if result.get('bsg_id') else None
                          for result in results])),
        'url':
        list(filter(None, [result.get('homepage') for result in results])),
        'license':
        list(filter(None, [result.get('licence') for result in results])),
        'taxonomy':
        list(filter(None, [result.get('taxonomies') for result in results])),
        'domain':
        list(filter(None, [result.get('domains') for result in results])),
    }
def get_harmonizome_client(harmonizome_spec):
  ''' Create a swagger client for harmonizome.
  '''

  harmonizome = SwaggerClient(
    'https://raw.githubusercontent.com/MaayanLab/smartAPIs/master/harmonizome_smartapi.yml',
  )
  return harmonizome
Exemple #4
0
def get_fairsharing_client(api_key):
    ''' Using the api_key, create an authenticated swagger client to fairsharing.
  '''
    # FAIRSharing expects an Api-Key in the request header for
    #  authenticated calls
    fairsharing = SwaggerClient('https://fairsharing.org/api?format=openapi',
                                headers={
                                    'Api-Key': api_key,
                                })
    return fairsharing
Exemple #5
0
def _fairsharing_client_singleton():
    global client
    try:
        client = SwaggerClient('https://fairsharing.org/api/?format=openapi',
                               headers={
                                   'Api-Key':
                                   os.environ['FAIRSHARING_API_KEY'],
                               })
    except Exception as e:
        import traceback
        traceback.print_exc()
        client = False
    return client
Exemple #6
0
    def perform(kls, inputs):
        urls = inputs['target:url']
        dois = [m.group(1) for m in map(url_re.match, urls) if m]

        if dois:
            client = SwaggerClient(
                'https://fairsharing.org/api/?format=openapi',
                headers={
                    'Api-Key':
                    settings.ASSESSMENT_CONFIG['fairsharing']['api-key'],
                })

            results = [
                result for doi in dois for result in
                client.actions.database_summary_list.call(doi=doi, )['results']
            ]

            if len(results) > 1:
                logging.warn(
                    'More than 1 DOI was identified in the fairsharing database! (%s)'
                    % (url))
            if len(results) >= 1:
                data = results[0]
            else:
                data = None
        else:
            data = None

        return {
            key: {
                'answer': 'yes' if data.get(attr) else 'no',
                'comment': data.get(attr),
            }
            for key, attr in metric_to_attr.items()
        } if data else {key: {}
                        for key in metric_to_attr.keys()}
def get_dockstore_client():
    ''' Create a swagger client for dockstore.
  '''
    dockstore = SwaggerClient('https://dockstore.org/swagger.json')
    return dockstore
Exemple #8
0
def get_smartapi_client():
  ''' Create a swagger client for smartapi.
  '''
  smartapi = SwaggerClient('https://smart-api.info/api/metadata/27a5b60716c3a401f2c021a5b718c5b1?format=yaml')
  return smartapi
https://fairsharing.github.io/FAIR-Evaluator-FrontEnd/#!/metrics
'''

import re
import json
import urllib.request
from functools import wraps
from pyswaggerclient import SwaggerClient
from fairshake_assessments.core import metric

metrics = json.load(
    urllib.request.urlopen(
        'https://fair-evaluator.semanticscience.org/FAIR_Evaluator/metrics.json'
    ))


def metric_id_to_name(id):
    return re.match('^https://w3id.org/(.+)', id).group(1).replace('/', '_')


for fair_metric in metrics:
    fair_metric_client = SwaggerClient(fair_metric['smarturl'])
    for action in dir(fair_metric_client.actions):
        if action.startswith('_'):
            continue
        func = getattr(fair_metric_client.actions, action).call
        wrap_func = wraps(func)(
            lambda content: func(content=dict(subject=content)))
        globals()[metric_id_to_name(
            fair_metric['@id'])] = metric(fair_metric)(wrap_func)
        '$.."x-externalResources"[@."x-url"]',
        'ratio': [[
            '$.."x-externalResources"[@."x-type" is not None]',
            '$.."x-externalResources"[@."x-description" is not None]'
        ], '$.."x-externalResources"[@."x-url" is not None]', 'all'],
        'desc':
        'x-url (smartAPI fields all described w/ x-type and x-description)',
        'metric':
        128,
        'pattern':
        re.compile(r'.+'),
    },
]

SmartAPI = SwaggerClient(
    'https://smart-api.info/api/metadata/27a5b60716c3a401f2c021a5b718c5b1?format=yaml'
)


def get_all(**kwargs):
    n_results = 0
    while True:
        resp = SmartAPI.actions.query_get.call(**kwargs, **{'from': n_results})
        for hit in resp['hits']:
            n_results += 1
            yield hit
        if n_results >= resp['total']:
            break
        else:
            resp = SmartAPI.actions.query_get.call(**kwargs)