def test_load_data_xls(self): kwargs = {"header_rows": 0, "header_cols": 0} xls_path = os.path.join(os.path.dirname(__file__), "data/data.xlsx") xls_loader = ExcelLoader(xls_path) xls_attrs, xls_X, xls_M, xls_M_index = xls_loader._load_data(**kwargs) csv_loader = Loader( os.path.join(os.path.dirname(__file__), "data/DATA_MATRIX_LOG_TPM.txt")) csv_attrs, csv_X, csv_M, csv_M_index = csv_loader._load_data(**kwargs) self.assertEqual(xls_attrs, csv_attrs) npt.assert_array_almost_equal(xls_X, csv_X) npt.assert_array_equal(xls_M, csv_M) npt.assert_array_equal(xls_M_index, csv_M_index)
def test_file_summary_gz(self): file_name = os.path.join(os.path.dirname(__file__), "data/data.txt.gz") loader = Loader(file_name) self.assertEqual(loader.file_size, 361) self.assertEqual(loader.n_rows, 10) self.assertEqual(loader.n_cols, 15) self.assertEqual(round(loader.sparsity, 2), 0.86)
def test_file_summary_broad(self): file_name = os.path.join(os.path.dirname(__file__), "data/DATA_MATRIX_LOG_TPM.txt") loader = Loader(file_name) self.assertAlmostEqual(loader.file_size, 1084, delta=15) self.assertEqual(loader.n_rows, 10) self.assertEqual(loader.n_cols, 15) self.assertEqual(round(loader.sparsity, 2), 0.86)
def __init__(self): super().__init__() self._current_path = "" self._data_loader = Loader() icon_open_dir = self.style().standardIcon(QStyle.SP_DirOpenIcon) # Top grid with file selection combo box self.file_layout = grid = QGridLayout() lb = QLabel("File:") lb.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.recent_combo = cb = QComboBox( sizeAdjustPolicy=QComboBox.AdjustToMinimumContentsLengthWithIcon, minimumContentsLength=20, toolTip="Select a recent file") self.recent_model = cb.model() # type: QStandardItemModel self.recent_combo.activated[int].connect(self._select_recent) browse = QPushButton("...", autoDefault=False, icon=icon_open_dir, clicked=self.browse) # reload = QPushButton("Reload", autoDefault=False, icon=icon_reload) grid.addWidget(lb, 0, 0, Qt.AlignVCenter) grid.addWidget(cb, 0, 1) grid.addWidget(browse, 0, 2) # grid.addWidget(reload, 0, 3) self.summary_label = label = QLabel("", self) label.ensurePolished() f = label.font() if f.pointSizeF() != -1: f.setPointSizeF(f.pointSizeF() * 5 / 6) else: f.setPixelSize(f.pixelSize() * 5 / 6) label.setFont(f) grid.addWidget(label, 1, 1, 1, 3) self.controlArea.layout().addLayout(grid) box = gui.widgetBox(self.controlArea, "Headers and Row Labels", spacing=-1) hl = QHBoxLayout() hl.setContentsMargins(0, 0, 0, 0) self.header_rows_spin = spin = QSpinBox(box, minimum=0, maximum=3, value=self._header_rows_count, keyboardTracking=False) spin.valueChanged.connect(self.set_header_rows_count) hl.addWidget(QLabel("Data starts with", box)) hl.addWidget(self.header_rows_spin) hl.addWidget(QLabel("header row(s)", box)) hl.addStretch(10) box.layout().addLayout(hl) hl = QHBoxLayout() hl.setContentsMargins(0, 0, 0, 0) self.header_cols_spin = spin = QSpinBox(box, minimum=0, maximum=3, value=self._header_cols_count, keyboardTracking=False) spin.valueChanged.connect(self.set_header_cols_count) hl.addWidget(QLabel("First", box)) hl.addWidget(self.header_cols_spin) hl.addWidget(QLabel("column(s) are row labels", box)) hl.addStretch(10) box.layout().addLayout(hl) self.data_struct_box = box = gui.widgetBox(self.controlArea, "Input Data Structure") gui.radioButtons(box, self, "_cells_in_rows", [ "Genes in rows, cells in columns", "Cells in rows, genes in columns" ], callback=self._cells_in_rows_changed) box = gui.widgetBox(self.controlArea, "Sample Data", spacing=-1) grid = QGridLayout() grid.setContentsMargins(0, 0, 0, 0) box.layout().addLayout(grid) self.sample_rows_cb = cb = QCheckBox(checked=self._sample_rows_enabled) self.sample_rows_p_spin = spin = QSpinBox(minimum=0, maximum=100, value=self._sample_rows_p) spin.valueChanged.connect(self.set_sample_rows_p) suffix = QLabel("% of cells") cb.toggled.connect(self.set_sample_rows_enabled) grid.addWidget(cb, 0, 0) grid.addWidget(spin, 0, 1) grid.addWidget(suffix, 0, 2) self.sample_cols_cb = cb = QCheckBox(checked=self._sample_cols_enabled) self.sample_cols_p_spin = spin = QSpinBox(minimum=0, maximum=100, value=self._sample_cols_p) spin.valueChanged.connect(self.set_sample_cols_p) suffix = QLabel("% of genes") cb.toggled.connect(self.set_sample_cols_enabled) grid.addWidget(cb, 1, 0) grid.addWidget(spin, 1, 1) grid.addWidget(suffix, 1, 2) grid.setColumnStretch(3, 10) self.annotation_files_box = box = gui.widgetBox( self.controlArea, "Cell && Gene Annotation Files") form = QFormLayout( formAlignment=Qt.AlignLeft, rowWrapPolicy=QFormLayout.WrapAllRows, ) box.layout().addLayout(form) self.row_annotations_cb = cb = QCheckBox( "Cell annotations", checked=self._row_annotations_enabled) self._row_annotations_w = w = QWidget( enabled=self._row_annotations_enabled) cb.toggled.connect(self.set_row_annotations_enabled) cb.toggled.connect(w.setEnabled) hl = QHBoxLayout() hl.setContentsMargins(0, 0, 0, 0) w.setLayout(hl) self.row_annotations_combo = QComboBox( sizeAdjustPolicy=QComboBox.AdjustToMinimumContentsLengthWithIcon, minimumContentsLength=18) self.row_annotations_combo.activated.connect( self._row_annotations_combo_changed) hl.addWidget(self.row_annotations_combo) hl.addWidget( QPushButton("...", box, autoDefault=False, icon=icon_open_dir, clicked=self.browse_row_annotations)) # hl.addWidget(QPushButton("Reload", box, autoDefault=False, # icon=icon_reload)) form.addRow(cb, w) self.col_annotations_cb = cb = QCheckBox( "Gene annotations", checked=self._col_annotations_enabled) self._col_annotations_w = w = QWidget( enabled=self._col_annotations_enabled) cb.toggled.connect(self.set_col_annotations_enabled) cb.toggled.connect(w.setEnabled) hl = QHBoxLayout() hl.setContentsMargins(0, 0, 0, 0) w.setLayout(hl) self.col_annotations_combo = QComboBox( sizeAdjustPolicy=QComboBox.AdjustToMinimumContentsLengthWithIcon, minimumContentsLength=18) self.col_annotations_combo.activated.connect( self._col_annotations_combo_changed) hl.addWidget(self.col_annotations_combo) hl.addWidget( QPushButton("...", box, autoDefault=False, icon=icon_open_dir, clicked=self.browse_col_annotations)) # hl.addWidget(QPushButton("Reload", box, autoDefault=False, # icon=icon_reload)) form.addRow(cb, w) self.controlArea.layout().addStretch(10) self.load_data_button = button = VariableTextPushButton( "Load data", autoDefault=True, textChoiceList=["Load data", "Reload"]) self.load_data_button.setAutoDefault(True) button.clicked.connect(self.commit, Qt.QueuedConnection) self.controlArea.layout().addWidget(button, alignment=Qt.AlignRight) init_recent_paths_model( self.recent_model, [self.resolve_path(p) for p in self._recent], ) init_recent_paths_model( self.row_annotations_combo.model(), [self.resolve_path(p) for p in self._recent_row_annotations]) init_recent_paths_model( self.col_annotations_combo.model(), [self.resolve_path(p) for p in self._recent_col_annotations]) self._update_summary() self._update_warning() if self._last_path != "" and os.path.exists(self._last_path): QTimer.singleShot(0, lambda: self.set_current_path(self._last_path)) else: self.recent_combo.setCurrentIndex(-1)
def remove_item(self, index): self.view.model().removeRows(index.row(), 1) self.commit() if not self.view.model().rowCount(): self.set_current_loader(Loader(), "")