Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read_loom failed #59

Closed
mbuttner opened this issue Sep 5, 2018 · 10 comments
Closed

read_loom failed #59

mbuttner opened this issue Sep 5, 2018 · 10 comments

Comments

@mbuttner
Copy link

mbuttner commented Sep 5, 2018

Hi,
I use scanpy 1.3.1. I have tried the 'read_loom' function, but it produced the following error:

adata = sc.read(filename=path_to_velocyto_files + 'all_controls.loom')

--> This might be very slow. Consider passing `cache=True`, which enables much faster reading from a cache file.
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-52-61a36c9ba297> in <module>()
----> 1 adata = sc.read(filename=path_to_velocyto_files + 'all_controls.loom')

~/anaconda3/lib/python3.6/site-packages/scanpy/readwrite.py in read(filename, backed, sheet, ext, delimiter, first_column_names, backup_url, cache, **kwargs)
     73         return _read(filename, backed=backed, sheet=sheet, ext=ext,
     74                      delimiter=delimiter, first_column_names=first_column_names,
---> 75                      backup_url=backup_url, cache=cache, **kwargs)
     76     # generate filename and read to dict
     77     filekey = filename

~/anaconda3/lib/python3.6/site-packages/scanpy/readwrite.py in _read(filename, backed, sheet, ext, delimiter, first_column_names, backup_url, cache, suppress_cache_warning, **kwargs)
    311             adata = _read_softgz(filename)
    312         elif ext == 'loom':
--> 313             adata = read_loom(filename=filename, **kwargs)
    314         else:
    315             raise ValueError('Unkown extension {}.'.format(ext))

~/anaconda3/lib/python3.6/site-packages/anndata/readwrite/read.py in read_loom(filename, sparse, cleanup, X_name, obs_names, var_names)
    144     filename = fspath(filename)  # allow passing pathlib.Path objects
    145     from loompy import connect
--> 146     with connect(filename, 'r') as lc:
    147 
    148         if X_name not in lc.layers.keys(): X_name = ''

AttributeError: __enter__

I have found that when I try to read the file the interactive console, I have the following result:

> filename =os.fspath(path_to_velocyto_files + 'all_controls.loom')
> lc =connect(filename, 'r')
> lc.layer.keys()
dict_keys(['', 'ambiguous', 'spliced', 'unspliced'])

So for my loom file, it's not 'layers', but 'layer'. Can you consider to include this case in the anndata read function?

@flying-sheep
Copy link
Member

flying-sheep commented Sep 5, 2018

connect returns a LoomConnection object. Support for the with syntax (=the __enter__/__exit__ methods) was added to LoomConnection in linnarsson-lab/loompy@aaafe0c. On top of the commit page, you see which tags (versions) contain this commit:

image

Looks like you have an ancient loompy version <1.1.0, is that correct?

@mbuttner
Copy link
Author

mbuttner commented Sep 5, 2018

Erm, apparently working with loompy 1.0.0. I guess that I may solve my issues by updating?

@falexwolf
Copy link
Member

Yes!

@flying-sheep
Copy link
Member

Great!

@mbuttner
Copy link
Author

mbuttner commented Sep 5, 2018

Ok, updated to loompy 2.0.12:

adata = sc.read_loom(filename=path_to_velocyto_files + 'all_controls.loom')

Variable names are not unique. To make them unique, call `.var_names_make_unique`.
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-8-de63a2957df4> in <module>()
----> 1 adata = sc.read_loom(filename=path_to_velocyto_files + 'all_controls.loom')

~/anaconda3/lib/python3.6/site-packages/anndata/readwrite/read.py in read_loom(filename, sparse, cleanup, X_name, obs_names, var_names)
    172             obs=obs,  # not ideal: make the generator a dict...
    173             var=var,
--> 174             layers=layers)
    175     return adata
    176 

~/anaconda3/lib/python3.6/site-packages/anndata/base.py in __init__(self, X, obs, var, uns, obsm, varm, layers, raw, dtype, shape, filename, filemode, asview, oidx, vidx)
    681                 layers=layers,
    682                 dtype=dtype, shape=shape,
--> 683                 filename=filename, filemode=filemode)
    684 
    685     def _init_as_view(self, adata_ref: 'AnnData', oidx: Index, vidx: Index):

~/anaconda3/lib/python3.6/site-packages/anndata/base.py in _init_as_actual(self, X, obs, var, uns, obsm, varm, raw, layers, dtype, shape, filename, filemode)
    901         self._clean_up_old_format(uns)
    902 
--> 903         self._layers = AnnDataLayers(self, layers, dtype)
    904 
    905     def __sizeof__(self):

~/anaconda3/lib/python3.6/site-packages/anndata/layers.py in __init__(self, adata, layers, dtype, adata_ref, oidx, vidx)
     31                     raise ValueError('Shape does not fit.')
     32                 if layers[key].dtype != np.dtype(dtype):
---> 33                     self._layers[key] = layers[key].astype(dtype, copy=False)
     34                 else:
     35                     self._layers[key] = layers[key]

TypeError: astype() got an unexpected keyword argument 'copy'

@flying-sheep flying-sheep reopened this Sep 5, 2018
@flying-sheep
Copy link
Member

Can you try the newest anndata from git?

pip install -U git+https://github.com/theislab/anndata.git

It should give you a better error message

@mbuttner
Copy link
Author

mbuttner commented Sep 6, 2018

OK, so I updated anndata to '0.6.10+2.ga323978' and re-run the read_loom command.

adata = sc.read_loom(filename=path_to_velocyto_files + 'all_controls.loom')

Variable names are not unique. To make them unique, call `.var_names_make_unique`.
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-de63a2957df4> in <module>()
----> 1 adata = sc.read_loom(filename=path_to_velocyto_files + 'all_controls.loom')

~/anaconda3/lib/python3.6/site-packages/anndata/readwrite/read.py in read_loom(filename, sparse, cleanup, X_name, obs_names, var_names)
    172             obs=obs,  # not ideal: make the generator a dict...
    173             var=var,
--> 174             layers=layers)
    175     return adata
    176 

~/anaconda3/lib/python3.6/site-packages/anndata/base.py in __init__(self, X, obs, var, uns, obsm, varm, layers, raw, dtype, shape, filename, filemode, asview, oidx, vidx)
    681                 layers=layers,
    682                 dtype=dtype, shape=shape,
--> 683                 filename=filename, filemode=filemode)
    684 
    685     def _init_as_view(self, adata_ref: 'AnnData', oidx: Index, vidx: Index):

~/anaconda3/lib/python3.6/site-packages/anndata/base.py in _init_as_actual(self, X, obs, var, uns, obsm, varm, raw, layers, dtype, shape, filename, filemode)
    901         self._clean_up_old_format(uns)
    902 
--> 903         self._layers = AnnDataLayers(self, layers, dtype)
    904 
    905     def __sizeof__(self):

~/anaconda3/lib/python3.6/site-packages/anndata/layers.py in __init__(self, adata, layers, dtype, adata_ref, oidx, vidx)
     35                 raise ValueError('Shape does not fit.')
     36             if layer.dtype != np.dtype(dtype):
---> 37                 self._layers[key] = layer.astype(dtype, copy=False)
     38             else:
     39                 self._layers[key] = layer

TypeError: astype() got an unexpected keyword argument 'copy'

@flying-sheep
Copy link
Member

OK. I test if layer is a np.ndarray (which has .astype with copy) or a scipy.sparse.spmatrix (which also has .astype with copy)

for the sparse matrices, this was added in scipy/scipy@d09dc32, which ended up in scipy 1.0, released almost a year ago. do you also have an old scipy version?

@mbuttner
Copy link
Author

mbuttner commented Sep 6, 2018

OK, my scipy version is 0.19.1.

@mbuttner mbuttner closed this as completed Sep 6, 2018
@yojetsharma
Copy link

Hi, I am facing a similar issue too.
When I processed my spliced and unspliced using Velocyto and loaded those loom files, it worked. But when
I converted my seurat to loom and I tried loading it into velocyto but received the following error:

>>> ls003 = scv.read_loom('/home/praghu/yojetsharma/new/loom_files/ls003/ls003.loom')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/praghu/yojetsharma/.conda/envs/yojet_velo/lib/python3.10/site-packages/anndata/compat/__init__.py", line 305, in inner_f
    return f(*args, **kwargs)
  File "/home/praghu/yojetsharma/.conda/envs/yojet_velo/lib/python3.10/site-packages/anndata/_io/read.py", line 251, in read_loom
    with connect(filename, "r", **kwargs) as lc:
  File "/home/praghu/yojetsharma/.conda/envs/yojet_velo/lib/python3.10/site-packages/loompy/loompy.py", line 1515, in connect
    return LoomConnection(filename, mode, validate=validate)
  File "/home/praghu/yojetsharma/.conda/envs/yojet_velo/lib/python3.10/site-packages/loompy/loompy.py", line 85, in __init__
    if not lv.validate(filename):
  File "/home/praghu/yojetsharma/.conda/envs/yojet_velo/lib/python3.10/site-packages/loompy/loom_validator.py", line 50, in validate
    self.version = get_loom_spec_version(f)
  File "/home/praghu/yojetsharma/.conda/envs/yojet_velo/lib/python3.10/site-packages/loompy/utils.py", line 19, in get_loom_spec_version
    if "attrs" in f and "LOOM_SPEC_VERSION" in f["/attrs"]:
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "/home/praghu/yojetsharma/.conda/envs/yojet_velo/lib/python3.10/site-packages/h5py/_hl/group.py", line 483, in __contains__
    return self._e(name) in self.id
  File "h5py/h5g.pyx", line 466, in h5py.h5g.GroupID.__contains__
  File "h5py/h5g.pyx", line 467, in h5py.h5g.GroupID.__contains__
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py/h5g.pyx", line 540, in h5py.h5g._path_valid
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py/h5l.pyx", line 212, in h5py.h5l.LinkProxy.exists
RuntimeError: Unable to get link info (addr overflow, addr = 12416, size = 176, eoa = 2048)

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants