def concat_data(self, modality: str = "rna"): """ Used for raw data, Ignore multiarrays and only consider one matrix per unidata """ genomes = [] unidata_arr = [] for key in list(self.data): unidata = self.data.pop(key) assert unidata.get_modality() == modality genomes.append(unidata.get_genome()) unidata_arr.append(unidata) unikey = None if len(genomes) == 1: unikey = unidata_arr[0].get_uid() self.data[unikey] = unidata_arr[0] else: genome = ",".join(genomes) feature_metadata = pd.concat( [unidata.feature_metadata for unidata in unidata_arr], axis=0) feature_metadata.reset_index(inplace=True) feature_metadata.fillna(value="N/A", inplace=True) X = hstack([unidata.matrices["X"] for unidata in unidata_arr], format="csr") unidata = UnimodalData(unidata_arr[0].barcode_metadata, feature_metadata, {"X": X}, { "genome": genome, "modality": "rna" }) unikey = unidata.get_uid() self.data[unikey] = unidata del unidata_arr gc.collect() self._selected = unikey self._unidata = self.data[unikey]
def _generate_filter_plots(unidata: UnimodalData, plot_filt: str, plot_filt_figsize: str = None, min_genes_before_filt: int = 100) -> None: """ This function generates filtration plots, only used in command line. """ group_key = unidata.get_uid() from pegasus.plotting import qcviolin kwargs = {"return_fig": True, "dpi": 500} if plot_filt_figsize is not None: width, height = plot_filt_figsize.split(",") kwargs["panel_size"] = (int(width), int(height)) fig = qcviolin(unidata, "count", **kwargs) fig.savefig(f"{plot_filt}.{group_key}.filt.UMI.pdf") fig = qcviolin(unidata, "gene", **kwargs) fig.savefig(f"{plot_filt}.{group_key}.filt.gene.pdf") fig = qcviolin(unidata, "mito", **kwargs) if fig is not None: fig.savefig(f"{plot_filt}.{group_key}.filt.mito.pdf") logger.info("Filtration plots are generated.")
def add_data(self, unidata: UnimodalData) -> None: """ Add data, if _selected is not set, set as the first added dataset """ key = unidata.get_uid() assert key is not None if key in self.data: raise ValueError(f"Key '{key}' already exists!") self.data[key] = unidata if self._selected is None: self._selected = key self._unidata = unidata