scverse / mudata

Multimodal Data (.h5mu) implementation for Python
https://mudata.rtfd.io
BSD 3-Clause "New" or "Revised" License
75 stars 17 forks source link

select one modality after subsetting mudata by var (or obs) #32

Closed bio-la closed 1 year ago

bio-la commented 1 year ago

Hello! I would like to be able to select a mudata layer after subsetting the object by var (or by obs). However, this is currently not implemented and it also breaks the mudata object (see issue #31 ) minimal example below, last line is the functionality i would like to have that breaks the mudata. thanks!

import scanpy as sc
import mudata as md
from mudata import MuData

import anndata as ad
import numpy as np
import pandas as pd
import warnings 
warnings.simplefilter(action='ignore', category=FutureWarning)

np.random.seed(1979)

import mudatasets as mds
mds.list_datasets()
mds.info('pbmc5k_citeseq')
pbmc5k=mds.load('pbmc5k_citeseq',files=['filtered_feature_bc_matrix.h5'])
pbmc5k
rna_raw = pbmc5k["rna"].copy()
rna_raw.var_names_make_unique()
rna_a = rna_raw[np.sort(np.random.choice(np.arange(300), 300, replace=False)),:].copy()

rna_b = rna_raw[np.sort(np.random.choice(np.arange(700), 500, replace=False)),:].copy()

mdata = MuData({"raw": rna_raw, "preproc_1": rna_a, "preproc_2": rna_b}, axis=-1)
mdata[:,mdata.var_names.str.startswith("MT-")]
mdata[:,mdata.var_names.str.startswith("MT-")]["preproc_1"]
gtca commented 1 year ago

Hey @bio-la,

Thanks for discovering this, and sorry it took a while to be fixed. There was a bug in subsetting indeed but now it should be resolved.