0

I have to import a processed h5ad file, but it seems that X has been passed as a numpy array instead of a numpy matrix. See below:

# Read the data 
data_path = "/home/bbb5130/snOMICS/maria/msrna.h5ad"
adata = sn.pp.read_h5ad(data_path, pr_process="Yes")
adata

But the output was:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In [15], line 3
      1 # Read the data 
      2 data_path = "/home/bbb5130/snOMICS/maria/msrna.h5ad"
----> 3 adata = sn.pp.read_h5ad(data_path, pr_process="Yes")
      4 adata

File ~/miniconda3/envs/snOMICS/lib/python3.9/site-packages/scanet/preprocessing.py:54, in Preprocessing.read_h5ad(cls, filename, pr_process)
     51     return sc.read_h5ad(filename)
     52 else:
     53     # initial preprocessing as it is required later
---> 54     return cls._intial(adata)

File ~/miniconda3/envs/snOMICS/lib/python3.9/site-packages/scanet/preprocessing.py:35, in Preprocessing._intial(adata)
     33 adata.var['mt'] = adata.var_names.str.startswith('MT-') 
     34 mito_genes = adata.var_names.str.startswith('MT-')
---> 35 adata.obs['percent_mito'] = np.sum(adata[:, mito_genes].X, axis=1).A1 / np.sum(adata.X, axis=1).A1  
     36 sc.pp.calculate_qc_metrics(adata, qc_vars=['mt'], percent_top=None, inplace=True)
     37 sc.pp.filter_cells(adata, min_genes=0)

AttributeError: 'ArrayView' object has no attribute 'A1'

Is there anyway I can change the format, so the file can be read? Thanks in advance.

Maria
  • 1
  • How much of this is your code? The only class that has an `A1` property is `np.matrix`. What it does is converted itself to a regular `ndarray`, and then applies `ravel()`. A `np.matrix` is inherently 2d, so a plain `ravel` returns a `(1,n)` shape. The purpose of `A1` then is return a (n,) shape array. I don't know anything about this `scannet`. – hpaulj Nov 04 '22 at 18:10
  • What's the source for this code? – hpaulj Nov 04 '22 at 18:37
  • Okay, thank you. I do not have the source code for scannet, but I thought I could change the input data instead. I just tried with adata = np.matrix(adata) in the hope it would the correct shape, but it did not work. – Maria Nov 04 '22 at 18:47
  • The error occurs in the `read_h5ad` function, and the only thing you give it is a filename. – hpaulj Nov 04 '22 at 19:43

0 Answers0