def set_attr(self, name: str, values: np.ndarray, axis: int = 0, dtype: str = None) -> None: """ **DEPRECATED** - Use `ds.ra.key = values` or `ds.ca.key = values` instead """ deprecated("'set_attr' is deprecated. Use 'ds.ra.key = values' or 'ds.ca.key = values' instead") if axis == 0: self.ra[name] = values else: self.ca[name] = values
def delete_attr(self, name: str, axis: int = 0) -> None: """ **DEPRECATED** - Use `del ds.ra.key` or `del ds.ca.key` instead, where `key` is replaced with the attribute name """ deprecated("'delete_attr' is deprecated. Use 'del ds.ra.key' or 'del ds.ca.key' instead") if axis == 0: del self.ra[name] else: del self.ca[name]
def batch_scan_layers(self, cells: np.ndarray = None, genes: np.ndarray = None, axis: int = 0, batch_size: int = 1000, layers: Iterable = None) -> Iterable[Tuple[int, np.ndarray, Dict]]: """ **DEPRECATED** - Use `scan` instead """ deprecated("'batch_scan_layers' is deprecated. Use 'scan' instead") if cells is None: cells = np.fromiter(range(self.shape[1]), dtype='int') if genes is None: genes = np.fromiter(range(self.shape[0]), dtype='int') if layers is None: layers = self.layers.keys() if axis == 1: cols_per_chunk = batch_size ix = 0 while ix < self.shape[1]: cols_per_chunk = min(self.shape[1] - ix, cols_per_chunk) selection = cells - ix # Pick out the cells that are in this batch selection = selection[np.where(np.logical_and(selection >= 0, selection < cols_per_chunk))[0]] if selection.shape[0] == 0: ix += cols_per_chunk continue # Load the whole chunk from the file, then extract genes and cells using fancy indexing vals = dict() for key in layers: vals[key] = self.layers[key][:, ix:ix + cols_per_chunk] vals[key] = vals[key][genes, :] vals[key] = vals[key][:, selection] yield (ix, ix + selection, vals) ix += cols_per_chunk if axis == 0: rows_per_chunk = batch_size ix = 0 while ix < self.shape[0]: rows_per_chunk = min(self.shape[0] - ix, rows_per_chunk) selection = genes - ix # Pick out the genes that are in this batch selection = selection[np.where(np.logical_and(selection >= 0, selection < rows_per_chunk))[0]] if selection.shape[0] == 0: ix += rows_per_chunk continue # Load the whole chunk from the file, then extract genes and cells using fancy indexing vals = dict() for key in layers: vals[key] = self.layers[key][ix:ix + rows_per_chunk, :] vals[key] = vals[key][selection, :] vals[key] = vals[key][:, cells] yield (ix, ix + selection, vals) ix += rows_per_chunk
def list_edges(self, *, axis: int) -> List[str]: """ **DEPRECATED** - Use `ds.row_graphs.keys()` or `ds.col_graphs.keys()` instead """ deprecated("'list_edges' is deprecated. Use 'ds.row_graphs.keys()' or 'ds.col_graphs.keys()' instead") if axis == 0: return self.row_graphs.keys() elif axis == 1: return self.col_graphs.keys() else: return []
def delete_attr(self, name: str, axis: int = 0) -> None: """ DEPRECATED """ deprecated( "'delete_attr' is deprecated. Use 'del ds.ra.key' or 'del ds.ca.key' instead" ) if axis == 0: del self.ra[name] else: del self.ca[name]
def get_edges(self, name: str, *, axis: int) -> Tuple[np.ndarray, np.ndarray, np.ndarray]: """ **DEPRECATED** - Use `ds.row_graphs[name]` or `ds.col_graphs[name]` instead """ deprecated("'get_edges' is deprecated. Use 'ds.row_graphs[name]' or 'ds.col_graphs[name]' instead") if axis == 0: g = self.row_graphs[name] return (g.row, g.col, g.data) if axis == 1: g = self.col_graphs[name] return (g.row, g.col, g.data) raise ValueError("Axis must be 0 or 1")
def set_layer(self, name: str, matrix: np.ndarray, chunks: Tuple[int, int] = (64, 64), chunk_cache: int = 512, dtype: str = "float32", compression_opts: int = 2) -> None: """ DEPRECATED. """ deprecated( "'set_layer' is deprecated. Use 'ds.layer.Name = matrix' or 'ds.layer['Name'] = matrix' instead" ) self.layers[name] = matrix
def set_edges(self, name: str, a: np.ndarray, b: np.ndarray, w: np.ndarray, *, axis: int) -> None: """ **DEPRECATED** - Use `ds.row_graphs[name] = g` or `ds.col_graphs[name] = g` instead """ deprecated("'set_edges' is deprecated. Use 'ds.row_graphs[name] = g' or 'ds.col_graphs[name] = g' instead") try: g = scipy.sparse.coo_matrix((w, (a, b)), (self.shape[axis], self.shape[axis])) except Exception: raise ValueError("Input arrays could not be converted to a sparse matrix") if axis == 0: self.row_graphs[name] = g elif axis == 1: self.col_graphs[name] = g else: raise ValueError("axis must be 0 (rows) or 1 (columns)")