Beispiel #1
0
    def __init__(self,
                 email=DEFAULT_EMAIL,
                 password=DEFAULT_PASSWD,
                 url=DEFAULT_URL):

        self._gen = Genesis(email, password, url)
        self.email = email
 def __init__(self,
              email=DEFAULT_EMAIL,
              password=DEFAULT_PASSWD,
              url=DEFAULT_URL):
     self._gen = Genesis(email, password, url)
     self.email = email
     self._data_endpoint = url + '/data/'
Beispiel #3
0
 def __init__(self, id, mid, library, type, d_list, nsm=0.0):
     Genesis.__init__(self)
     self.id = int(id)
     self.mid = int(mid)
     self.library = library.strip()
     self.type = type.strip()
     self.d_list = d_list
     self.nsm = nsm
Beispiel #4
0
    def test_get_hash(self):

        pearl_owners = [
            PearlBase(Pearl(0), b'\xF0' * 33),
            PearlBase(Pearl(1), b'\xF1' * 33),
        ]
        genesis = Genesis(pearl_owners)
        gh = genesis.get_hash()

        h = sha3.sha3_256(b'\x00' + (b'\xF0' * 33) + b'\x01' +
                          (b'\xF1' * 33)).digest()
        self.assertEqual(h, gh)
Beispiel #5
0
    def __init__(self,
                 email=DEFAULT_EMAIL,
                 password=DEFAULT_PASSWD,
                 url=DEFAULT_URL):
        """ Python module that leverages Genesis PyAPI (Python API for accsess to DictyExpress database).

        It supports connection to the server and data retrieval functionalities.

        Args:
            email (str):
            password (str):
            url (str):
        """

        self._gen = Genesis(email, password, url)
        self.email = email
        self._data_endpoint = url + '/data/'
Beispiel #6
0
def main():
    create_dir(NETWORK_DIR)

    # delete old data
    print("=== reset old data ===")
    reset = Reset(NODE_DIR)
    reset.reset()

    # Create new data folder
    print("=== create env folder ===")
    env = Env(NUM_OF_NODE, NODE_DIR)
    env.create()

    # Create Account
    print("=== create accounts ===")
    account = Account(NODE_DIR, NETWORK_DIR)
    account.create()

    # Init Geth(Genesis)
    print("=== init genesis ===")
    genesis = Genesis(GENESIS_FILE, NETWORK_ID, NODE_DIR, INITIAL_BALANCE)
    genesis.create_genesis_json(account.public_key_list)
    genesis.init_geth()

    # Create_network
    print("=== create network ===")
    network = Network(**NETWORK_PARAMS)
    network.create_network()

    # Validate network
    print("=== validate network ===")
    rpc_ip = NETWORK_PARAMS["rpc"]["ip"]
    w3 = Web3(HTTPProvider(f"http://{rpc_ip}:10000"))
    print(w3.net.peerCount)
Beispiel #7
0
    def __init__(self, email=DEFAULT_EMAIL, password=DEFAULT_PASSWD, url=DEFAULT_URL):

        self._gen = Genesis(email, password, url)
        self.email = email
Beispiel #8
0
class GenAPI(object):
    """
    Python module that leverages Genesis PyAPI (Python API for accsess to DictyExpress database).
    It supports connection to the server and data retrieval functionalities.
    """
    def __init__(self, email=DEFAULT_EMAIL, password=DEFAULT_PASSWD, url=DEFAULT_URL):

        self._gen = Genesis(email, password, url)
        self.email = email

    def fetch_etc_objects(self, callback=lambda: None):
        """ Function downloads all available :obj:`GenData` etc objects from DictyExpress database.

        Returns:
            :obj:`list`: of :obj:`GenData` objects

        """
        cbc = CallBack(1, callback)
        try:
            list_of_experiments = self._gen.api.data.get(case_ids__contains='5535115cfad58d5e03006217', status='done',
                                                         type__startswith='data:etc:')['objects']

        except requests.exceptions.ConnectionError as e:
            raise requests.exceptions.ConnectionError('Server not accessible, check your connection.') from e

        cbc()
        store_experiments = [GenData(exp, self._gen) for exp in list_of_experiments]
        cbc.end()
        return store_experiments

    def download_etc_data(self, gen_data_id, callback=lambda: None):
        """ Function downloads etc data of a chosen experiment from the server.

        Args:
            gen_data_id (str): id of :obj:`GenData` object to download.

        Returns:
             :obj:`dict`: data in json like format


        """
        cbc = CallBack(3, callback, callbacks=70)

        try:
            response = next(self._gen.download([gen_data_id], 'output.etcfile'))
        except requests.exceptions.ConnectionError as e:
            raise requests.exceptions.ConnectionError('Server not accessible, check your connection.') from e

        cbc()
        if not response.ok:
            response.raise_for_status()

        response_gzipped = io.BytesIO(response.content)
        cbc()
        response_content = io.TextIOWrapper(gzip.GzipFile(fileobj=response_gzipped), encoding="utf-8")
        cbc()

        try:
            json_object = json.load(response_content)
        except ValueError as e:
            raise ValueError('Downloaded data is not a valid JSON') from e

        cbc.end()
        return json_object

    def etc_to_table(self, etc_json, time_var=False, callback=lambda: None):
        """ Converts data from Json to :obj:`Orange.data.table`

        Args:
            etc_json (dict): Data in json like format
            time_var (bool): Create column of time points. Default is set to False.
        Returns:
            :obj:`Orange.data.Table`
        """
        cbc = CallBack(2, callback, callbacks=30)

        variables = []
        time_point = 1
        for time in etc_json['etc']['timePoints']:
            var = ContinuousVariable('TP ' + str(time_point))
            var.attributes['Time'] = str(time)
            variables.append(var)
            time_point += 1

        meta_attr = StringVariable.make('Gene')
        domain = Domain(variables, metas=[meta_attr])
        cbc()

        table = []
        for row in etc_json['etc']['genes']:
            gene_expression = [exp for exp in etc_json['etc']['genes'][row]]
            gene_expression.append(row)
            table.append(gene_expression)

        orange_table = Table(domain, table)

        if time_var:
            orange_table = transpose_table(orange_table)
            cbc()

        cbc.end()
        return orange_table
Beispiel #9
0
class GenAPI:
    def __init__(self,
                 email=DEFAULT_EMAIL,
                 password=DEFAULT_PASSWD,
                 url=DEFAULT_URL):
        """ Python module that leverages Genesis PyAPI (Python API for accsess to DictyExpress database).

        It supports connection to the server and data retrieval functionalities.

        Args:
            email (str):
            password (str):
            url (str):
        """

        self._gen = Genesis(email, password, url)
        self.email = email
        self._data_endpoint = url + '/data/'

    def get_cached_ids(self):
        with requests_cache.enabled(cache_name=cache_name,
                                    backend=cache_backend):
            cached_object = requests_cache.core.get_cache()
            responses = [
                cached_object.get_response_and_time(response)
                for response in cached_object.responses
            ]
            gen_ids = []

            for url in [response.url for response, _ in responses]:
                gen_id = re.search(r'{}(.*?)/'.format(self._data_endpoint),
                                   url)

                if gen_id is not None:
                    gen_ids.append(gen_id.group(1))

            return gen_ids

    def fetch_etc_objects(self, **kwargs):
        """ Function downloads all available :obj:`GenData` etc objects from DictyExpress database.

        Returns:
            :obj:`list`: :obj:`GenData` objects

        """

        callback = kwargs.get("progress_callback", None)
        with requests_cache.enabled(cache_name=cache_name,
                                    backend=cache_backend):
            try:
                # Note: this is hardcoded for now. When we port this module to Resolwe platform
                #       data retrieval will be different
                list_of_experiments = self._gen.api.data.get(
                    case_ids__contains='5535115cfad58d5e03006217',
                    status='done',
                    type__startswith='data:etc:')['objects']
                if callback:
                    callback.emit()

            except requests.exceptions.ConnectionError as e:
                raise requests.exceptions.ConnectionError(
                    'Server not accessible, check your connection.') from e

            store_experiments = [
                GenData(exp, self._gen) for exp in list_of_experiments
            ]

            if callback:
                callback.emit()

            return store_experiments

    def download_etc_data(self, gen_data_id, **kwargs):
        """ Function downloads etc data of a chosen experiment from the server.

        Args:
            gen_data_id (str): id of :obj:`GenData` object to download.

        Returns:
             :obj:`dict`: data in json like format


        """
        callback = kwargs.get("progress_callback", None)
        table_name = kwargs.get("table_name", '')

        with requests_cache.enabled(cache_name=cache_name,
                                    backend=cache_backend):
            try:

                response = next(
                    self._gen.download([gen_data_id], 'output.etcfile'))
                # TODO: maybe edit Genesis module to support callback?
                if callback:
                    callback.emit()

            except requests.exceptions.ConnectionError as e:
                raise requests.exceptions.ConnectionError(
                    'Server not accessible, check your connection.') from e

            return response_to_json(response), table_name
Beispiel #10
0
class GenAPI:
    """Python module that leverages Genesis PyAPI (Python API for accsess to DictyExpress database).

    It supports connection to the server and data retrieval functionalities.
    """
    def __init__(self,
                 email=DEFAULT_EMAIL,
                 password=DEFAULT_PASSWD,
                 url=DEFAULT_URL):
        self._gen = Genesis(email, password, url)
        self.email = email
        self._data_endpoint = url + '/data/'

    @staticmethod
    def clear_cache():
        with requests_cache.enabled(cache_name=GENAPI_CACHE,
                                    backend=CACHE_BACKEND):
            requests_cache.clear()

    def get_cached_ids(self):
        with requests_cache.enabled(cache_name=GENAPI_CACHE,
                                    backend=CACHE_BACKEND):
            cached_object = requests_cache.get_cache()
            responses = [
                cached_object.get_response(response)
                for response in cached_object.responses
            ]
            gen_ids = []

            for url in [response.url for response in responses]:
                gen_id = re.search(r'{}(.*?)/'.format(self._data_endpoint),
                                   url)

                if gen_id is not None:
                    gen_ids.append(gen_id.group(1))

            return gen_ids

    def fetch_etc_objects(self, *args, **kwargs):
        """Function downloads all available :obj:`GenData` etc objects from DictyExpress database.

        :rtype: list of GenData objects
        """

        with requests_cache.enabled(cache_name=GENAPI_CACHE,
                                    backend=CACHE_BACKEND):
            try:
                # Note: this is hardcoded for now. When we port this module to Resolwe platform
                #       data retrieval will be different
                list_of_experiments = self._gen.api.data.get(
                    case_ids__contains='5535115cfad58d5e03006217',
                    status='done',
                    type__startswith='data:etc:')['objects']

            except requests.exceptions.ConnectionError as e:
                raise requests.exceptions.ConnectionError(
                    'Server not accessible, check your connection.') from e

            store_experiments = [
                GenData(exp, self._gen) for exp in list_of_experiments
            ]

            return store_experiments

    def download_etc_data(self, gen_data_id, *args, **kwargs):
        """Function downloads etc data of a chosen experiment from the server.

        :param gen_data_id: id of GeneData object
        :type gen_data_id: str

        :rtype: data in json like format
        """
        table_name = kwargs.get("table_name", '')

        with requests_cache.enabled(cache_name=GENAPI_CACHE,
                                    backend=CACHE_BACKEND):
            try:
                response = next(
                    self._gen.download([gen_data_id], 'output.etcfile'))

            except requests.exceptions.ConnectionError as e:
                raise requests.exceptions.ConnectionError(
                    'Server not accessible, check your connection.') from e

            return response_to_json(response), table_name
Beispiel #11
0
class GenAPI(object):
    """
    Python module that leverages Genesis PyAPI (Python API for accsess to DictyExpress database).
    It supports connection to the server and data retrieval functionalities.
    """
    def __init__(self,
                 email=DEFAULT_EMAIL,
                 password=DEFAULT_PASSWD,
                 url=DEFAULT_URL):

        self._gen = Genesis(email, password, url)
        self.email = email

    def fetch_etc_objects(self, callback=lambda: None):
        """ Function downloads all available :obj:`GenData` etc objects from DictyExpress database.

        Returns:
            :obj:`list`: of :obj:`GenData` objects

        """
        cbc = CallBack(1, callback)
        try:
            list_of_experiments = self._gen.api.data.get(
                case_ids__contains='5535115cfad58d5e03006217',
                status='done',
                type__startswith='data:etc:')['objects']

        except requests.exceptions.ConnectionError as e:
            raise requests.exceptions.ConnectionError(
                'Server not accessible, check your connection.') from e

        cbc()
        store_experiments = [
            GenData(exp, self._gen) for exp in list_of_experiments
        ]
        cbc.end()
        return store_experiments

    def download_etc_data(self, gen_data_id, callback=lambda: None):
        """ Function downloads etc data of a chosen experiment from the server.

        Args:
            gen_data_id (str): id of :obj:`GenData` object to download.

        Returns:
             :obj:`dict`: data in json like format


        """
        cbc = CallBack(3, callback, callbacks=70)

        try:
            response = next(self._gen.download([gen_data_id],
                                               'output.etcfile'))
        except requests.exceptions.ConnectionError as e:
            raise requests.exceptions.ConnectionError(
                'Server not accessible, check your connection.') from e

        cbc()
        if not response.ok:
            response.raise_for_status()

        response_gzipped = io.BytesIO(response.content)
        cbc()
        response_content = io.TextIOWrapper(
            gzip.GzipFile(fileobj=response_gzipped), encoding="utf-8")
        cbc()

        try:
            json_object = json.load(response_content)
        except ValueError as e:
            raise ValueError('Downloaded data is not a valid JSON') from e

        cbc.end()
        return json_object

    def etc_to_table(self, etc_json, time_var=False, callback=lambda: None):
        """ Converts data from Json to :obj:`Orange.data.table`

        Args:
            etc_json (dict): Data in json like format
            time_var (bool): Create column of time points. Default is set to False.
        Returns:
            :obj:`Orange.data.Table`
        """
        cbc = CallBack(2, callback, callbacks=30)

        variables = []
        time_point = 1
        for time in etc_json['etc']['timePoints']:
            var = ContinuousVariable('TP ' + str(time_point))
            var.attributes['Time'] = str(time)
            variables.append(var)
            time_point += 1

        meta_attr = StringVariable.make('Gene')
        domain = Domain(variables, metas=[meta_attr])
        cbc()

        table = []
        for row in etc_json['etc']['genes']:
            gene_expression = [exp for exp in etc_json['etc']['genes'][row]]
            gene_expression.append(row)
            table.append(gene_expression)

        orange_table = Table(domain, table)

        if time_var:
            orange_table = transpose_table(orange_table)
            cbc()

        cbc.end()
        return orange_table
Beispiel #12
0
from genesis import Genesis

if __name__ == "__main__":
    Genesis().main()
Beispiel #13
0
 def test_login(self):
     Genesis('*****@*****.**', 'admin', 'http://gendev:10180')