Commit a0ee2306 authored by Sascha Herzinger's avatar Sascha Herzinger
Browse files

First steps of implementing ETLs for transmart

parent 625bb2f1
Pipeline #2231 failed with stage
in 3 minutes and 10 seconds
......@@ -50,7 +50,7 @@ class ETLHandler(metaclass=abc.ABCMeta):
@staticmethod
@abc.abstractmethod
def make_label(descriptor):
def make_label(descriptor: dict) -> str:
"""Create a label for the given data descriptor. This label will be
used to display the loaded data in the front end.
:param descriptor: Describes the data and is used to download them.
......
......@@ -15,7 +15,7 @@ class DateETL(ETL):
produces = 'numerical'
@staticmethod
def can_handle(handler, descriptor):
def can_handle(handler: str, descriptor: dict) -> bool:
return handler == 'ada' and \
descriptor['dictionary']['fieldType'] and \
descriptor['dictionary']['fieldType'] == 'Date'
......
......@@ -7,6 +7,7 @@ from fractalis.data.etlhandler import ETLHandler
class AdaHandler(ETLHandler):
"""This ETLHandler provides integration with ADA.
'Ada provides key infrastructure for secured integration, visualization,
and analysis of anonymized clinical and experimental data stored in CSV
and tranSMART format, or provided by RedCAP and Synapse apps.'
......@@ -20,7 +21,7 @@ class AdaHandler(ETLHandler):
raise NotImplementedError()
@staticmethod
def make_label(descriptor):
def make_label(descriptor: dict) -> str:
return '{} ({})'.format(descriptor['dictionary']['label'],
descriptor['data_set'])
......
"""Provides numerical concept ETL for tranSMART."""
from typing import List
import requests
from pandas import DataFrame
from fractalis.data.etl import ETL
class NumericalETL(ETL):
"""NumericalETL implements support for tranSMARTs 'numerical' type."""
name = 'transmart_numerical_etl'
produces = 'numerical'
@staticmethod
def can_handle(handler: str, descriptor: dict) -> bool:
return handler == 'transmart' and descriptor['dataType'] == 'numerical'
def extract(self, server: str, token: str, descriptor: dict) -> List[dict]:
r = requests.get(url='{}/v2/observations'
'?constraint={"type":"concept","path":{}}'
'&type=clinical'.format(server,
descriptor['path']),
headers={'Accept': 'application/json',
'Authorization': 'Bearer {}'.format(token)})
if r.status_code != 200:
raise ValueError(
"Data extraction failed. Target server responded with "
"status code {}.".format(r.status_code))
return r
def transform(self, raw_data: List[dict], descriptor: dict) -> DataFrame:
return raw_data
\ No newline at end of file
"""This module provides TransmartHandler, an implementation of ETLHandler for
tranSMART."""
import requests
from fractalis.data.etlhandler import ETLHandler
class TransmartHandler(ETLHandler):
"""This ETLHandler provides integration with tranSMART.
'tranSMART is a knowledge management platform that enables scientists to
develop and refine research hypotheses by investigating correlations between
genetic and phenotypic data, and assessing their analytical results in the
context of published literature and other work.'
Project URL: https://github.com/transmart
"""
_handler = 'transmart'
def _heartbeat(self):
raise NotImplementedError()
@staticmethod
def make_label(descriptor: dict) -> str:
return 'test'
def _get_token_for_credentials(self, server: str,
user: str, passwd: str) -> str:
r = requests.get(url='{}/oauth/token?grant_type=password'
'&client_id=glowingbear-js'
'&client_secret='
'&username={}'
'&password={}'.format(server, user, passwd),
headers={'Accept': 'application/json'})
if r.status_code != 200:
raise ValueError("Could not authenticate. Reason: [{}]: {}"
.format(r.status_code, r.text))
return r
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment