Exemple #1
0
    def __init__(self, mode, parent=None):
        self.mode = mode
        self.parent = parent
        super().__init__(parent)
        self.setWindowTitle('peakonly: models')

        train_folder_label = QtWidgets.QLabel()
        train_folder_label.setText('Choose a folder with train data:')
        self.train_folder_getter = GetFolderWidget(os.path.join(os.getcwd(), 'data', 'train'), self)

        val_folder_label = QtWidgets.QLabel()
        val_folder_label.setText('Choose a folder with validation data:')
        self.val_folder_getter = GetFolderWidget(os.path.join(os.getcwd(), 'data', 'val'), self)

        continue_button = QtWidgets.QPushButton('Continue')
        continue_button.clicked.connect(self._continue)

        main_layout = QtWidgets.QVBoxLayout()
        main_layout.addWidget(train_folder_label)
        main_layout.addWidget(self.train_folder_getter)
        main_layout.addWidget(val_folder_label)
        main_layout.addWidget(self.val_folder_getter)
        main_layout.addWidget(continue_button)

        self.setLayout(main_layout)
Exemple #2
0
    def __init__(self, model, parent):
        self.parent = parent
        super().__init__(parent)
        self.model = model

        folder_label = QtWidgets.QLabel()
        folder_label.setText('Choose a folder where to save:')
        self.folder_getter = GetFolderWidget(os.path.join(os.getcwd(), 'data', 'weights'), self)

        name_label = QtWidgets.QLabel()
        name_label.setText('Set a name of file: ')
        self.name_getter = QtWidgets.QLineEdit(self)
        self.name_getter.setText('model.pt')

        save_button = QtWidgets.QPushButton('Save')
        save_button.clicked.connect(self.save)

        main_layout = QtWidgets.QVBoxLayout()
        main_layout.addWidget(folder_label)
        main_layout.addWidget(self.folder_getter)
        main_layout.addWidget(name_label)
        main_layout.addWidget(self.name_getter)
        main_layout.addWidget(save_button)

        self.setLayout(main_layout)
Exemple #3
0
class TrainingParameterWindow(QtWidgets.QDialog):
    """
    Training Parameter Window, where one should choose parameters for training

    Parameters
    ----------
    mode : str
        A one of two 'all in one' of 'sequential'
    parent : MainWindow(QtWidgets.QMainWindow)
        -
    Attributes
    ----------
    mode : str
        A one of two 'all in one' of 'sequential'
    parent : MainWindow(QtWidgets.QMainWindow)
        -
    train_folder_getter : GetFolderWidget
        A getter for a path to train data
    val_folder_getter : GetFolderWidget
        A getter for a path to validation data
    """
    def __init__(self, mode, parent=None):
        self.mode = mode
        self.parent = parent
        super().__init__(parent)
        self.setWindowTitle('peakonly: models')

        train_folder_label = QtWidgets.QLabel()
        train_folder_label.setText('Choose a folder with train data:')
        self.train_folder_getter = GetFolderWidget(os.path.join(os.getcwd(), 'data', 'train'), self)

        val_folder_label = QtWidgets.QLabel()
        val_folder_label.setText('Choose a folder with validation data:')
        self.val_folder_getter = GetFolderWidget(os.path.join(os.getcwd(), 'data', 'val'), self)

        continue_button = QtWidgets.QPushButton('Continue')
        continue_button.clicked.connect(self._continue)

        main_layout = QtWidgets.QVBoxLayout()
        main_layout.addWidget(train_folder_label)
        main_layout.addWidget(self.train_folder_getter)
        main_layout.addWidget(val_folder_label)
        main_layout.addWidget(self.val_folder_getter)
        main_layout.addWidget(continue_button)

        self.setLayout(main_layout)

    def _continue(self):
        try:
            train_folder = self.train_folder_getter.get_folder()
            val_folder = self.val_folder_getter.get_folder()
            main_window = TrainingMainWindow(self.mode, train_folder, val_folder, self.parent)
            main_window.show()
            self.close()
        except ValueError:
            # popup window with exception
            msg = QtWidgets.QMessageBox(self)
            msg.setText("Check parameters. Something is wrong!")
            msg.setIcon(QtWidgets.QMessageBox.Warning)
            msg.exec_()
Exemple #4
0
class ReAnnotationParameterWindow(QtWidgets.QDialog):
    def __init__(self, parent: AbtractMainWindow):
        self.mode = 'reannotation'
        self.parent = parent
        super().__init__(parent)
        self.setWindowTitle('peakonly: reannotation')

        save_to_label = QtWidgets.QLabel()
        save_to_label.setText('Choose a folder with annotated ROIs:')
        self.folder_widget = GetFolderWidget()

        self.run_button = QtWidgets.QPushButton('Run reannotation')
        self.run_button.clicked.connect(self.start_reannotation)

        main_layout = QtWidgets.QVBoxLayout()
        main_layout.addWidget(save_to_label)
        main_layout.addWidget(self.folder_widget)
        main_layout.addWidget(self.run_button)

        self.setLayout(main_layout)

    def start_reannotation(self):
        folder = self.folder_widget.get_folder()
        subwindow = AnnotationMainWindow([],
                                         folder,
                                         None,
                                         None,
                                         None,
                                         self.mode,
                                         None,
                                         parent=self.parent)
        subwindow.show()
        self.close()
Exemple #5
0
class SaveModelWindow(QtWidgets.QDialog):
    def __init__(self, model, parent):
        self.parent = parent
        super().__init__(parent)
        self.model = model

        folder_label = QtWidgets.QLabel()
        folder_label.setText('Choose a folder where to save:')
        self.folder_getter = GetFolderWidget(os.path.join(os.getcwd(), 'data', 'weights'), self)

        name_label = QtWidgets.QLabel()
        name_label.setText('Set a name of file: ')
        self.name_getter = QtWidgets.QLineEdit(self)
        self.name_getter.setText('model.pt')

        save_button = QtWidgets.QPushButton('Save')
        save_button.clicked.connect(self.save)

        main_layout = QtWidgets.QVBoxLayout()
        main_layout.addWidget(folder_label)
        main_layout.addWidget(self.folder_getter)
        main_layout.addWidget(name_label)
        main_layout.addWidget(self.name_getter)
        main_layout.addWidget(save_button)

        self.setLayout(main_layout)

    def save(self):
        folder = self.folder_getter.get_folder()
        name = self.name_getter.text()
        shutil.copyfile(os.path.join('data/tmp_weights', self.model.__class__.__name__),
                        os.path.join(folder, name))
Exemple #6
0
    def __init__(self, parent: AbtractMainWindow):
        self.mode = 'reannotation'
        self.parent = parent
        super().__init__(parent)
        self.setWindowTitle('peakonly: reannotation')

        save_to_label = QtWidgets.QLabel()
        save_to_label.setText('Choose a folder with annotated ROIs:')
        self.folder_widget = GetFolderWidget()

        self.run_button = QtWidgets.QPushButton('Run reannotation')
        self.run_button.clicked.connect(self.start_reannotation)

        main_layout = QtWidgets.QVBoxLayout()
        main_layout.addWidget(save_to_label)
        main_layout.addWidget(self.folder_widget)
        main_layout.addWidget(self.run_button)

        self.setLayout(main_layout)
Exemple #7
0
    def _init_ui(self):
        # file and folder selection
        choose_file_label = QtWidgets.QLabel()
        choose_file_label.setText('Choose a file to annotate:')
        self.list_of_files = FileListWidget()
        for file in self.files:
            self.list_of_files.addFile(file)

        save_to_label = QtWidgets.QLabel()
        save_to_label.setText('Choose a folder where to save annotated ROIs:')
        self.folder_widget = GetFolderWidget()

        file_layout = QtWidgets.QVBoxLayout()
        file_layout.addWidget(choose_file_label)
        file_layout.addWidget(self.list_of_files)
        file_layout.addWidget(save_to_label)
        file_layout.addWidget(self.folder_widget)

        # parameters selection

        instrumental_label = QtWidgets.QLabel()
        instrumental_label.setText('Instrumentals description')
        self.instrumental_getter = QtWidgets.QLineEdit(self)
        self.instrumental_getter.setText(
            'Q-oa-TOF, total time=10 min, scan frequency=10Hz')

        prefix_label = QtWidgets.QLabel()
        prefix_label.setText('Prefix of filename: ')
        self.prefix_getter = QtWidgets.QLineEdit(self)
        self.prefix_getter.setText('Example')

        suffix_label = QtWidgets.QLabel()
        suffix_label.setText(
            'Code of file (suffix, will be increased during annotation): ')
        self.suffix_getter = QtWidgets.QLineEdit(self)
        self.suffix_getter.setText('0')

        mz_label = QtWidgets.QLabel()
        mz_label.setText('m/z deviation:')
        self.mz_getter = QtWidgets.QLineEdit(self)
        self.mz_getter.setText('0.005')

        roi_points_label = QtWidgets.QLabel()
        roi_points_label.setText('Minimal length of ROI:')
        self.roi_points_getter = QtWidgets.QLineEdit(self)
        self.roi_points_getter.setText('15')

        if self.mode == 'semi-automatic':
            peak_points_label = QtWidgets.QLabel()
            peak_points_label.setText('Minimal length of peak:')
            self.peak_points_getter = QtWidgets.QLineEdit(self)
            self.peak_points_getter.setText('8')

        dropped_points_label = QtWidgets.QLabel()
        dropped_points_label.setText('Maximal number of zero points in a row:')
        self.dropped_points_getter = QtWidgets.QLineEdit(self)
        self.dropped_points_getter.setText('3')

        run_button = QtWidgets.QPushButton('Run annotation')
        run_button.clicked.connect(self._run_button)

        parameter_layout = QtWidgets.QVBoxLayout()
        parameter_layout.addWidget(instrumental_label)
        parameter_layout.addWidget(self.instrumental_getter)
        parameter_layout.addWidget(prefix_label)
        parameter_layout.addWidget(self.prefix_getter)
        parameter_layout.addWidget(suffix_label)
        parameter_layout.addWidget(self.suffix_getter)
        parameter_layout.addWidget(mz_label)
        parameter_layout.addWidget(self.mz_getter)
        parameter_layout.addWidget(roi_points_label)
        parameter_layout.addWidget(self.roi_points_getter)
        # if self.mode == 'semi-automatic':
        #     parameter_layout.addWidget(peak_points_label)
        #     parameter_layout.addWidget(self.peak_points_getter)
        parameter_layout.addWidget(dropped_points_label)
        parameter_layout.addWidget(self.dropped_points_getter)
        parameter_layout.addWidget(run_button)

        # main layout
        main_layout = QtWidgets.QHBoxLayout()
        main_layout.addLayout(file_layout)
        main_layout.addLayout(parameter_layout)

        self.setLayout(main_layout)
Exemple #8
0
class AnnotationParameterWindow(QtWidgets.QDialog):
    def __init__(self, files, mode, parent: AbtractMainWindow):
        self.mode = mode
        self.parent = parent
        super().__init__(parent)
        self.setWindowTitle('peakonly: manual annotation')

        self.files = files
        self.description = None
        self.file_prefix = None
        self.file_suffix = None
        self.minimum_peak_points = None
        self.folder = None

        self._init_ui()

    def _init_ui(self):
        # file and folder selection
        choose_file_label = QtWidgets.QLabel()
        choose_file_label.setText('Choose a file to annotate:')
        self.list_of_files = FileListWidget()
        for file in self.files:
            self.list_of_files.addFile(file)

        save_to_label = QtWidgets.QLabel()
        save_to_label.setText('Choose a folder where to save annotated ROIs:')
        self.folder_widget = GetFolderWidget()

        file_layout = QtWidgets.QVBoxLayout()
        file_layout.addWidget(choose_file_label)
        file_layout.addWidget(self.list_of_files)
        file_layout.addWidget(save_to_label)
        file_layout.addWidget(self.folder_widget)

        # parameters selection

        instrumental_label = QtWidgets.QLabel()
        instrumental_label.setText('Instrumentals description')
        self.instrumental_getter = QtWidgets.QLineEdit(self)
        self.instrumental_getter.setText(
            'Q-oa-TOF, total time=10 min, scan frequency=10Hz')

        prefix_label = QtWidgets.QLabel()
        prefix_label.setText('Prefix of filename: ')
        self.prefix_getter = QtWidgets.QLineEdit(self)
        self.prefix_getter.setText('Example')

        suffix_label = QtWidgets.QLabel()
        suffix_label.setText(
            'Code of file (suffix, will be increased during annotation): ')
        self.suffix_getter = QtWidgets.QLineEdit(self)
        self.suffix_getter.setText('0')

        mz_label = QtWidgets.QLabel()
        mz_label.setText('m/z deviation:')
        self.mz_getter = QtWidgets.QLineEdit(self)
        self.mz_getter.setText('0.005')

        roi_points_label = QtWidgets.QLabel()
        roi_points_label.setText('Minimal length of ROI:')
        self.roi_points_getter = QtWidgets.QLineEdit(self)
        self.roi_points_getter.setText('15')

        if self.mode == 'semi-automatic':
            peak_points_label = QtWidgets.QLabel()
            peak_points_label.setText('Minimal length of peak:')
            self.peak_points_getter = QtWidgets.QLineEdit(self)
            self.peak_points_getter.setText('8')

        dropped_points_label = QtWidgets.QLabel()
        dropped_points_label.setText('Maximal number of zero points in a row:')
        self.dropped_points_getter = QtWidgets.QLineEdit(self)
        self.dropped_points_getter.setText('3')

        run_button = QtWidgets.QPushButton('Run annotation')
        run_button.clicked.connect(self._run_button)

        parameter_layout = QtWidgets.QVBoxLayout()
        parameter_layout.addWidget(instrumental_label)
        parameter_layout.addWidget(self.instrumental_getter)
        parameter_layout.addWidget(prefix_label)
        parameter_layout.addWidget(self.prefix_getter)
        parameter_layout.addWidget(suffix_label)
        parameter_layout.addWidget(self.suffix_getter)
        parameter_layout.addWidget(mz_label)
        parameter_layout.addWidget(self.mz_getter)
        parameter_layout.addWidget(roi_points_label)
        parameter_layout.addWidget(self.roi_points_getter)
        # if self.mode == 'semi-automatic':
        #     parameter_layout.addWidget(peak_points_label)
        #     parameter_layout.addWidget(self.peak_points_getter)
        parameter_layout.addWidget(dropped_points_label)
        parameter_layout.addWidget(self.dropped_points_getter)
        parameter_layout.addWidget(run_button)

        # main layout
        main_layout = QtWidgets.QHBoxLayout()
        main_layout.addLayout(file_layout)
        main_layout.addLayout(parameter_layout)

        self.setLayout(main_layout)

    def _run_button(self):
        try:
            self.description = self.instrumental_getter.text()
            self.file_prefix = self.prefix_getter.text()
            self.file_suffix = int(self.suffix_getter.text())
            delta_mz = float(self.mz_getter.text())
            required_points = int(self.roi_points_getter.text())
            dropped_points = int(self.dropped_points_getter.text())
            if self.mode == 'semi-automatic':
                self.minimum_peak_points = int(self.peak_points_getter.text())

            self.folder = self.folder_widget.get_folder()
            path2mzml = None
            for file in self.list_of_files.selectedItems():
                path2mzml = self.list_of_files.file2path[file.text()]
            if path2mzml is None:
                raise ValueError

            worker = Worker(get_ROIs, path2mzml, delta_mz, required_points,
                            dropped_points)
            worker.signals.result.connect(self._start_annotation)
            self.parent.run_thread('ROI detection:', worker)

            self.close()
        except ValueError:
            # popup window with exception
            msg = QtWidgets.QMessageBox(self)
            msg.setText("Check parameters. Something is wrong!")
            msg.setIcon(QtWidgets.QMessageBox.Warning)
            msg.exec_()

    def _start_annotation(self, rois):
        self.rois = rois
        subwindow = AnnotationMainWindow(self.rois,
                                         self.folder,
                                         self.file_prefix,
                                         self.file_suffix,
                                         self.description,
                                         self.mode,
                                         self.minimum_peak_points,
                                         parent=self.parent)
        subwindow.show()
Exemple #9
0
class EvaluationParameterWindow(QtWidgets.QDialog):
    """
    Evaluation Parameter Window, where one should choose parameters for evaluation

    Parameters
    ----------
    mode : str
        A one of two 'all in one' of 'sequential'
    parent : MainWindow(QtWidgets.QMainWindow)
        -
    Attributes
    ----------
    mode : str
        A one of two 'all in one' of 'sequential'
    parent : MainWindow(QtWidgets.QMainWindow)
        -
    test_folder_getter : GetFolderWidget
        A getter for a path to test data
    model_weights_getter : GetFileWidget
        A getter for a path to weights for 'all-in-one' model (optional)
    classifier_weights_getter : GetFileWidget
        A getter for a path to weights for 'all-in-one' model (optional)
    peak_points_getter : QtWidgets.QLineEdit
        A getter for peak_minimum_points parameter
    segmentator_weights_getter : GetFileWidget
        A getter for a path to weights for 'all-in-one' model (optional)
    """
    def __init__(self, mode, parent=None):
        self.mode = mode
        self.parent = parent
        super().__init__(parent)
        self.setWindowTitle('peakonly: evaluation')

        test_folder_label = QtWidgets.QLabel()
        test_folder_label.setText('Choose a folder with test data:')
        self.test_folder_getter = GetFolderWidget(
            os.path.join(os.getcwd(), 'data', 'test'), self)

        if mode == 'all in one':
            model_weights_label = QtWidgets.QLabel()
            model_weights_label.setText(
                "Choose weights for 'all-in-one' model")
            # to do: save a pytorch script, not a model state
            self.model_weights_getter = GetFileWidget(
                'pt', os.path.join(os.getcwd(),
                                   'data/weights/RecurrentCNN.pt'), self)
        elif mode == 'sequential':
            classifier_weights_label = QtWidgets.QLabel()
            classifier_weights_label.setText('Choose weights for a classifier')
            # to do: save a pytorch script, not a model state
            self.classifier_weights_getter = GetFileWidget(
                'pt', os.path.join(os.getcwd(), 'data/weights/Classifier.pt'),
                self)
            segmentator_weights_label = QtWidgets.QLabel()
            segmentator_weights_label.setText(
                'Choose weights for a segmentator')
            # to do: save a pytorch script, not a model state
            self.segmentator_weights_getter = GetFileWidget(
                'pt', os.path.join(os.getcwd(), 'data/weights/Segmentator.pt'),
                self)
        else:
            assert False, mode

        peak_points_label = QtWidgets.QLabel()
        peak_points_label.setText('Minimal length of peak:')
        self.peak_points_getter = QtWidgets.QLineEdit(self)
        self.peak_points_getter.setText('8')

        run_button = QtWidgets.QPushButton('Run evaluation')
        run_button.clicked.connect(self._run_evaluation)

        main_layout = QtWidgets.QVBoxLayout()
        main_layout.addWidget(test_folder_label)
        main_layout.addWidget(self.test_folder_getter)
        if mode == 'all in one':
            main_layout.addWidget(model_weights_label)
            main_layout.addWidget(self.model_weights_getter)
        elif mode == 'sequential':
            main_layout.addWidget(classifier_weights_label)
            main_layout.addWidget(self.classifier_weights_getter)
            main_layout.addWidget(segmentator_weights_label)
            main_layout.addWidget(self.segmentator_weights_getter)
        main_layout.addWidget(peak_points_label)
        main_layout.addWidget(self.peak_points_getter)
        main_layout.addWidget(run_button)

        self.setLayout(main_layout)

    def _run_evaluation(self):
        try:
            device = torch.device(
                'cuda:0' if torch.cuda.is_available() else 'cpu')
            # to do: device should be customizable parameter
            test_folder = self.test_folder_getter.get_folder()
            if self.mode == 'all in one':
                # to do: save models as pytorch scripts
                model = RecurrentCNN().to(device)
                path2weights = self.model_weights_getter.get_file()
                model.load_state_dict(
                    torch.load(path2weights, map_location=device))
                model.eval()
                models = [model]
            elif self.mode == 'sequential':
                classifier = Classifier().to(device)
                path2classifier_weights = self.classifier_weights_getter.get_file(
                )
                classifier.load_state_dict(
                    torch.load(path2classifier_weights, map_location=device))
                classifier.eval()
                segmentator = Segmentator().to(device)
                path2segmentator_weights = self.segmentator_weights_getter.get_file(
                )
                segmentator.load_state_dict(
                    torch.load(path2segmentator_weights, map_location=device))
                segmentator.eval()
                models = [classifier, segmentator]
            else:
                assert False, self.mode
            minimum_peak_points = int(self.peak_points_getter.text())

            runner = BasicRunner(self.mode, models, minimum_peak_points,
                                 device)

            main_window = EvaluationMainWindow(test_folder, runner,
                                               self.parent)
            main_window.show()
            self.close()
        except ValueError:
            # popup window with exception
            msg = QtWidgets.QMessageBox(self)
            msg.setText("Check parameters. Something is wrong!")
            msg.setIcon(QtWidgets.QMessageBox.Warning)
            msg.exec_()