question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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…

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:23 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
lkmklsmncommented, Apr 29, 2019

I am getting the same error.

Exception: Data must be 1-dimensional

5reactions
ahy1221commented, Apr 29, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read loom file created in Seurat3 (column index ...
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...
Read more >
Cannot read loom file in scanpy
Try opening the file using loompy directly to check that the loom file is valid. import loompy ds = loompy.connect("filename.loom").
Read more >
python ValueError: column index exceeds matrix dimensions
I can reproduce this error by creating a sparse.coo_matrix with: In [1075]: sparse.coo_matrix(([1,1,1],([0,1,1],[0,1,3])), shape=(2,3)) ...
Read more >
Universal prediction of cell-cycle position using transfer ...
A pre-learned weights matrix learned from proliferating cortical neurospheres enables cell-cycle position estimation in other proliferating ...
Read more >
Extensive transcriptional and chromatin changes underlie ...
Culturing astrocytes in a three-dimensional matrix containing FGF2 induces expression of Rorb, Dbx2 and Lhx2 and improves astrocyte maturity ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found