ChoBioLab / corescpy

A wrapper to simplify the execution of Single Cell analysis with the sc verse
Other
3 stars 0 forks source link

MCP (Dialogue) with confounder variable: AttributeError: 'numpy.ndarray' object has no attribute 'A1' #9

Open easlinger opened 1 year ago

easlinger commented 1 year ago

AttributeError Traceback (most recent call last) /home/elizabeth/elizabeth/crispr/examples/multicellular_programs.ipynb Cell 7 line 2 1 # out_2c = self.run_dialogue(n_programs=3, copy=True) ----> 2 out_confounder = self.run_dialogue(n_programs=2, col_confounder="gender", 3 cmap="coolwarm", vcenter=0, copy=True)

File ~/crispr/crispr/class_sc.py:520, in Omics.run_dialogue(self, n_programs, col_confounder, col_cell_type, cmap, vcenter, layer, copy, **kws_plot) 518 for i in ct_subs: # avoid numpy no attribute 'A1' error 519 ct_subs[i].X = ct_subs[i].X.tocsr() --> 520 res, mcps_new = d_l.multilevel_modeling( 521 ct_subs=ct_subs, mcp_scores=mcps, ws_dict=w_s, 522 confounder=col_confounder) 523 if copy is False: 524 if col_confounder:

File ~/miniconda3/envs/py-bio/lib/python3.10/site-packages/pertpy/tools/_dialogue.py:793, in Dialogue.multilevel_modeling(self, ct_subs, mcp_scores, ws_dict, confounder, formula) 785 ct_data_2 = ct_data_2[ct_data_2.obs[self.sample_id].isin(sample_ids)] 787 # TODO: shouldn't need this aligning step for cells. corresponds to @scores / y 788 # scores_1 = cca_scores[cell_type_1].loc[ct_data_1.obs.index] 789 # scores_2 = cca_scores[cell_type_2].loc[ct_data_2.obs.index] 790 791 # indexes into the average sample expression per gene with the sample id per cell. corresponds to @tme / x 792 # TODO: Why is the sample_id type check failing? --> 793 tme_1 = self._get_pseudobulks(ct_data_2, groupby=self.sample_id, strategy="mean").loc[ 794 :, ct_data_1.obs[self.sample_id] 795 ] # unclear why we do this 796 tme_1.columns = ct_data_1.obs.index 797 tme_2 = self._get_pseudobulks(ct_data_1, groupby=self.sample_id, strategy="mean").loc[ 798 :, ct_data_2.obs[self.sample_id] 799 ]

File ~/miniconda3/envs/py-bio/lib/python3.10/site-packages/pertpy/tools/_dialogue.py:72, in Dialogue._get_pseudobulks(self, adata, groupby, strategy) 70 pseudobulk[category] = adata[temp].X.median(axis=0).A1 71 elif strategy == "mean": ---> 72 pseudobulk[category] = adata[temp].X.mean(axis=0).A1 74 pseudobulk = pd.DataFrame(pseudobulk).set_index("Genes") 76 return pseudobulk

AttributeError: 'numpy.ndarray' object has no attribute 'A1'

easlinger commented 1 year ago

Potential Solution? Upgrade to numpy 1.24.4 Didn't quite fix it.