def _load_data(self):
        self.available_db_sources = get_available_db_sources()
        file_name = self.available_db_sources[
            self.selected_db_source]['filename']

        try:
            serverfiles.update(serverfiles_domain, file_name)
        except ConnectionError:
            raise ConnectionError('Can not connect to {}. '
                                  'Using only local files.'.format(
                                      serverfiles.server_url))
        finally:
            file_path = serverfiles.localpath_download(serverfiles_domain,
                                                       file_name)
            data = Table(file_path)

            # enforce order
            old_domain = data.domain
            new_domain = Domain(
                [],
                metas=[
                    old_domain['Organism'],
                    old_domain['Name'],
                    old_domain['Entrez ID'],
                    old_domain['Cell Type'],
                    old_domain['Function'],
                    old_domain['Reference'],
                    old_domain['URL'],
                ],
            )
            data = data.transform(new_domain)
            self.data = data
Beispiel #2
0
    def setUpClass(cls):
        """Code executed only once for all tests"""
        super().setUpClass()
        file_name = "panglao_gene_markers.tab"
        serverfiles.update(SERVER_FILES_DOMAIN, file_name)
        file_path = serverfiles.localpath_download(SERVER_FILES_DOMAIN, file_name)
        cls.panglao = Table.from_file(file_path)

        file_name = "cellMarker_gene_markers.tab"
        serverfiles.update(SERVER_FILES_DOMAIN, file_name)
        file_path = serverfiles.localpath_download(SERVER_FILES_DOMAIN, file_name)
        cls.cell_markers = Table.from_file(file_path)
    def _load_data(self):
        self.Warning.using_local_files.clear()

        found_sources = {}
        try:
            found_sources.update(
                serverfiles.ServerFiles().allinfo(serverfiles_domain))
        except requests.exceptions.ConnectionError:
            found_sources.update(serverfiles.allinfo(serverfiles_domain))
            self.Warning.using_local_files()

        self.available_db_sources = {
            item.get('title').split(': ')[-1]: item
            for item in found_sources.values()
        }

        if self.available_db_sources:
            file_name = self.available_db_sources[
                self.selected_db_source]['filename']

            try:
                serverfiles.update(serverfiles_domain, file_name)
            except requests.exceptions.ConnectionError:
                # try to update file. Ignore network errors.
                pass

            try:
                file_path = serverfiles.localpath_download(
                    serverfiles_domain, file_name)
            except requests.exceptions.ConnectionError as err:
                # Unexpected error.
                raise err

            data = Table(file_path)
            # enforce order
            old_domain = data.domain
            new_domain = Domain(
                [],
                metas=[
                    old_domain['Organism'],
                    old_domain['Name'],
                    old_domain['Entrez ID'],
                    old_domain['Cell Type'],
                    old_domain['Function'],
                    old_domain['Reference'],
                    old_domain['URL'],
                ],
            )
            data = data.transform(new_domain)
            self.data = data
    def _source_changed(self) -> None:
        """
        Respond on change of the source and download the data.
        """
        if self.available_sources:
            file_name = self.available_sources[self.selected_source]['filename']

            try:
                serverfiles.update(SERVER_FILES_DOMAIN, file_name)
            except requests.exceptions.ConnectionError:
                # try to update file. Ignore network errors.
                pass

            try:
                file_path = serverfiles.localpath_download(SERVER_FILES_DOMAIN, file_name)
            except requests.exceptions.ConnectionError as err:
                # Unexpected error.
                raise err
            self.data = Table.from_file(file_path)
    def load_matcher_file(self, domain, filename):
        # this starts download if files are not on local machine
        file_path = serverfiles.localpath_download(domain, filename)
        # download new version before using this file for gene name matching
        serverfiles.update(domain, filename)

        def case_insensitive_keys(matcher_dict):
            updated_dict = {MAP_SOURCES:  matcher_dict[MAP_SOURCES],
                            MAP_GENE_ID: matcher_dict[MAP_GENE_ID],
                            MAP_LOCUS:    matcher_dict[MAP_LOCUS],
                            MAP_SYNONYMS: defaultdict(list),
                            MAP_SYMBOL:  defaultdict(list),
                            MAP_NOMENCLATURE: defaultdict(list)}

            for key, value in matcher_dict[MAP_SYMBOL].items():
                # ensure string, we are using string methods (upper, lower)
                key = ensure_type(str(key), str)
                updated_dict[MAP_SYMBOL][key] = value
                updated_dict[MAP_SYMBOL][key.upper()] = value
                updated_dict[MAP_SYMBOL][key.lower()] = value

            for key, value in matcher_dict[MAP_SYNONYMS].items():
                key = ensure_type(str(key), str)
                updated_dict[MAP_SYNONYMS][key] = value
                updated_dict[MAP_SYNONYMS][key.upper()] = value
                updated_dict[MAP_SYNONYMS][key.lower()] = value

            for key, value in matcher_dict[MAP_NOMENCLATURE].items():
                key = ensure_type(str(key), str)
                updated_dict[MAP_NOMENCLATURE][key] = value
                updated_dict[MAP_NOMENCLATURE][key.upper()] = value
                updated_dict[MAP_NOMENCLATURE][key.lower()] = value

            return updated_dict

        with open(file_path, 'rb') as pickle_file:
            if not self._case_insensitive:
                return pickle.load(pickle_file)
            else:
                return case_insensitive_keys(pickle.load(pickle_file))