scanpy: Cannot read loom file created in Seurat3 (column index exceeds matrix dimensions)

I have a loom file created from Seurat object by using as.loom function in Seurat3. After closing the file with $close.all(), I’m trying to read loom file by read_loom function in scanpy, but I have this error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-aed61d3d5eef> in <module>
      1 import scanpy as sc
----> 2 a = sc.read_loom('brain10x.loom')

/opt/conda/lib/python3.7/site-packages/anndata/readwrite/read.py in read_loom(filename, sparse, cleanup, X_name, obs_names, var_names, dtype)
    156 
    157         if X_name not in lc.layers.keys(): X_name = ''
--> 158         X = lc.layers[X_name].sparse().T.tocsr() if sparse else lc.layers[X_name][()].T
    159 
    160         layers = OrderedDict()

/opt/conda/lib/python3.7/site-packages/loompy/loom_layer.py in sparse(self, rows, cols)
    109                 col: List[np.ndarray] = []
    110                 i = 0
--> 111                 for (ix, selection, view) in self.ds.scan(items=cols, axis=1, layers=[self.name]):
    112                         if rows is not None:
    113                                 vals = view.layers[self.name][rows, :]

/opt/conda/lib/python3.7/site-packages/loompy/loompy.py in scan(self, items, axis, layers, key, batch_size)
    597                                 for key, layer in vals.items():
    598                                         lm[key] = loompy.MemoryLoomLayer(key, layer)
--> 599                                 view = loompy.LoomView(lm, self.ra[ordering], self.ca[ix + selection], self.row_graphs[ordering], self.col_graphs[ix + selection], filename=self.filename, file_attrs=self.attrs)
    600                                 yield (ix, ix + selection, view)
    601                                 ix += cols_per_chunk

/opt/conda/lib/python3.7/site-packages/loompy/graph_manager.py in __getitem__(self, thing)
     96                 if type(thing) is slice or type(thing) is np.ndarray or type(thing) is int:
     97                         gm = GraphManager(None, axis=self.axis)
---> 98                         for key, g in self.items():
     99                                 # Slice the graph matrix properly without making it dense
    100                                 (a, b, w) = (g.row, g.col, g.data)

/opt/conda/lib/python3.7/site-packages/loompy/graph_manager.py in items(self)
     55         def items(self) -> Iterable[Tuple[str, sparse.coo_matrix]]:
     56                 for key in self.keys():
---> 57                         yield (key, self[key])
     58 
     59         def __len__(self) -> int:

/opt/conda/lib/python3.7/site-packages/loompy/graph_manager.py in __getitem__(self, thing)
    116                         raise AttributeError(f"'{type(self)}' object has no attribute {thing}")
    117                 else:
--> 118                         return self.__getattr__(thing)
    119 
    120         def __getattr__(self, name: str) -> sparse.coo_matrix:

/opt/conda/lib/python3.7/site-packages/loompy/graph_manager.py in __getattr__(self, name)
    127                                 c = self.ds._file[a][name]["b"]
    128                                 w = self.ds._file[a][name]["w"]
--> 129                                 g = sparse.coo_matrix((w, (r, c)), shape=(self.ds.shape[self.axis], self.ds.shape[self.axis]))
    130                                 self.__dict__["storage"][name] = g
    131                         return g

/opt/conda/lib/python3.7/site-packages/scipy/sparse/coo.py in __init__(self, arg1, shape, dtype, copy)
    190             self.data = self.data.astype(dtype, copy=False)
    191 
--> 192         self._check()
    193 
    194     def reshape(self, *args, **kwargs):

/opt/conda/lib/python3.7/site-packages/scipy/sparse/coo.py in _check(self)
    279                 raise ValueError('row index exceeds matrix dimensions')
    280             if self.col.max() >= self.shape[1]:
--> 281                 raise ValueError('column index exceeds matrix dimensions')
    282             if self.row.min() < 0:
    283                 raise ValueError('negative row index found')

ValueError: column index exceeds matrix dimensions

I can read loom file with loompy seamlessly. They are in the latest versions (Seurat_3.0.0.9000, loomR_0.2.1.9000, scanpy==1.4).

Am I doing wrong by typing that reading code below?:

a = scanpy.read_loom('brain10x.loom', sparse=True)

Thanks…

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 23 (2 by maintainers)

Most upvoted comments

I am getting the same error.

Exception: Data must be 1-dimensional

Hi, the graph slot is assumed to be list . Just do that: pbmc_small@graphs <- list()

Hi, that’s interesting. I’m also using scanpy v1.4.1. Which anndata and loompy versions are you using?