コード例 #1
0
 def _load_dataset_and_samples(self):
     """ """
     try:
         datasets = plankton_core.PlanktonCounterManager(
         ).get_dataset_names()
         for dataset in datasets:
             samples = plankton_core.PlanktonCounterManager(
             ).get_sample_names(dataset)
             for sample in samples:
                 datasetsample = dataset + ': ' + sample
                 self._datasetsample_dict[datasetsample] = (dataset, sample)
         #
         self._datasetsample_list.addItems(
             sorted(self._datasetsample_dict.keys()))
     #
     except Exception as e:
         debug_info = self.__class__.__name__ + ', row  ' + str(
             sys._getframe().f_lineno)
         toolbox_utils.Logging().error('Exception: (' + debug_info + '): ' +
                                       str(e))
コード例 #2
0
 def _change_sample_name(self):
     """ """
     try:
         self.save_data()
         dialog = RenameSampleDialog(self, self._current_sample)
         if dialog.exec_():
             new_sample_name = dialog.get_new_sample_name()
             if new_sample_name:
                 self.save_data()
                 plankton_core.PlanktonCounterManager().rename_sample(
                     self._current_dataset, self._current_sample,
                     new_sample_name)
                 # Close dialog.
                 self._parentwidget.reject()
     #
     except Exception as e:
         debug_info = self.__class__.__name__ + ', row  ' + str(
             sys._getframe().f_lineno)
         toolbox_utils.Logging().error('Exception: (' + debug_info + '): ' +
                                       str(e))
コード例 #3
0
 def _copy_sample_info_from(self):
     """ """
     try:
         dialog = CopyFromTemplateDialog(self)
         if dialog.exec_():
             dataset = dialog.get_dataset()
             sample = dialog.get_sample()
             if dataset and sample:
                 dir_path = plankton_core.PlanktonCounterManager(
                 ).get_dataset_dir_path()
                 sample_object = plankton_core.PlanktonCounterSample(
                     dir_path, dataset, sample)
                 metadata_dict = sample_object.get_sample_info()
                 self._from_dict_to_fields(metadata_dict)
     #
     except Exception as e:
         debug_info = self.__class__.__name__ + ', row  ' + str(
             sys._getframe().f_lineno)
         toolbox_utils.Logging().error('Exception: (' + debug_info + '): ' +
                                       str(e))
コード例 #4
0
 def __init__(self, parentwidget, dataset, sample):
     """ """
     self._current_dataset = dataset
     self._current_sample = sample
     # Create sample object.
     dir_path = plankton_core.PlanktonCounterManager().get_dataset_dir_path(
     )
     self._current_sample_object = plankton_core.PlanktonCounterSample(
         dir_path, self._current_dataset, self._current_sample)
     #
     super(PlanktonCounterDialog, self).__init__(parentwidget)
     self.setWindowTitle("Plankton counter")
     #
     #         self.resize(1500, 900)
     self.resize(1500, 845)
     #         self.resize(1000, 750)
     #
     self.metadata_widget = None
     self.methods_widget = None
     self.count_widget = None
     self.sample_data_widget = None
     self._current_tab_index = 0
     #
     self._create_content()
コード例 #5
0
    def read_excel_file(self, excel_file_path=None):
        """ """
        if excel_file_path == None:
            raise UserWarning('Excel file is missing.')
        #
        dir_path = plankton_core.PlanktonCounterManager().get_dataset_dir_path(
        )
        #
        if (not excel_file_path) or (not os.path.isfile(excel_file_path)):
            raise UserWarning('Excel file does not exists.')
        #
        self._dataset_metadata = {}
        self._sample_info = {}
        self._sample_header = []
        self._sample_rows = []
        self._sample_method_dict = {}

        # Dataset metadata as <key>:<value>.
        #         try:
        #             tablefilereader = toolbox_utils.TableFileReader(
        #                     excel_file_name = excel_file_path,
        #                     excel_sheet_name = 'dataset_metadata.txt',
        #                     )
        #             # Merge header and rows. Create dict.
        #             dataset_metadata = [tablefilereader.header()] + tablefilereader.rows()
        #             for row in dataset_metadata:
        #                 if len(row) >= 2:
        #                     self._dataset_metadata[row[0].strip()] = row[1].strip()
        #         except:
        #             pass

        # Sample info as <key>:<value>.
        tablefilereader = toolbox_utils.TableFileReader(
            excel_file_name=excel_file_path,
            excel_sheet_name='sample_info.txt',
        )
        # Merge header and rows. Create dict from ':'-separated rows.
        sample_info = [tablefilereader.header()] + tablefilereader.rows()
        for row in sample_info:
            if len(row) >= 2:
                self._sample_info[row[0].strip()] = row[1].strip()

        # Sample data on table format.
        tablefilereader = toolbox_utils.TableFileReader(
            excel_file_name=excel_file_path,
            excel_sheet_name='sample_data.txt',
        )
        self._sample_header = tablefilereader.header()
        self._sample_rows = tablefilereader.rows()

        # Sample method on table format.
        tablefilereader = toolbox_utils.TableFileReader(
            excel_file_name=excel_file_path,
            excel_sheet_name='counting_method.txt',
        )
        self._sample_method_header = tablefilereader.header()
        self._sample_method_rows = tablefilereader.rows()
        # Create dictionary with method step as key.
        self._sample_method_dict = {}
        for row in self._sample_method_rows:
            method_dict = dict(zip(self._sample_method_header, row))
            if 'counting_method_step' in method_dict:
                self._sample_method_dict[
                    method_dict['counting_method_step']] = method_dict
コード例 #6
0
    def read_file(self, dataset_name=None, sample_name=None):
        """ """
        if dataset_name == None:
            raise UserWarning('Dataset name is missing.')
        if sample_name == None:
            raise UserWarning('Sample name is missing.')
        #
        dir_path = plankton_core.PlanktonCounterManager().get_dataset_dir_path(
        )
        dataset_path = os.path.join(dir_path, dataset_name)
        sample_path = os.path.join(dataset_path, sample_name)
        #
        if (not dataset_path) or (not os.path.exists(dataset_path)):
            raise UserWarning('Dataset files are missing.')
        if (not sample_path) or (not os.path.exists(sample_path)):
            raise UserWarning('Sample files are missing.')
        #
        self._dataset_metadata = {}
        self._sample_info = {}
        self._sample_header = []
        self._sample_rows = []
        self._sample_method_dict = {}

        # Dataset metadata as <key>:<value>.
        try:
            tablefilereader = toolbox_utils.TableFileReader(
                file_path=dataset_path,
                text_file_name='dataset_metadata.txt',
            )
            # Merge header and rows. Create dict.
            dataset_metadata = [tablefilereader.header()
                                ] + tablefilereader.rows()
            for row in dataset_metadata:
                if len(row) >= 2:
                    self._dataset_metadata[row[0].strip()] = row[1].strip()
        except:
            pass

        # Sample info as <key>:<value>.
        tablefilereader = toolbox_utils.TableFileReader(
            file_path=sample_path,
            text_file_name='sample_info.txt',
        )
        # Merge header and rows. Create dict from ':'-separated rows.
        sample_info = [tablefilereader.header()] + tablefilereader.rows()
        for row in sample_info:
            if len(row) >= 2:
                self._sample_info[row[0].strip()] = row[1].strip()

        # Sample data on table format.
        tablefilereader = toolbox_utils.TableFileReader(
            file_path=sample_path,
            text_file_name='sample_data.txt',
        )
        self._sample_header = tablefilereader.header()
        self._sample_rows = tablefilereader.rows()

        # Sample method on table format.
        tablefilereader = toolbox_utils.TableFileReader(
            file_path=sample_path,
            text_file_name='counting_method.txt',
        )
        self._sample_method_header = tablefilereader.header()
        self._sample_method_rows = tablefilereader.rows()
        # Create dictionary with method step as key.
        self._sample_method_dict = {}
        for row in self._sample_method_rows:
            method_dict = dict(zip(self._sample_method_header, row))
            if 'counting_method_step' in method_dict:
                self._sample_method_dict[
                    method_dict['counting_method_step']] = method_dict