1
$\begingroup$

I am trying to extract data from fast5-file with python 3.9.13 in Ubuntu. I have found a library "fast5_research"(This package comprises an API to HDF containers used by the research groups within Oxford Nanopore Technologies), installed on my PC and updated my software with "sudo apt update". According to tutorial I attempted to read fasta5-file with the next code:

from fast5_research import Fast5
filename='/home/master/Desktop/0.fast5'
with Fast5(filename) as fh:
    raw = fh.get_read(raw=True)
    summary = fh.summary()
print('Raw is {} samples long.'.format(len(raw)))
print('Summary {}.'.format(summary))

but as a result, I have an error:

KeyError                                  Traceback (most recent call last)
/tmp/ipykernel_410530/3650860803.py in <module>
      4 from fast5_research import Fast5
      5 filename='/home/master/Desktop/0.fast5'
----> 6 with Fast5(filename) as fh:
      7     raw = fh.get_read(raw=True)
      8     summary = fh.summary()

~/anaconda3/lib/python3.9/site-packages/fast5_research/fast5.py in __init__(self, fname, read)
     85 
     86         # Attach channel_meta as attributes, slightly redundant
---> 87         for k, v in _clean_attrs(self[self.__channel_meta_path__].attrs).items():
     88             setattr(self, k, v)
     89         # Backward compat.

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

~/anaconda3/lib/python3.9/site-packages/h5py/_hl/group.py in __getitem__(self, name)
    175                 raise ValueError("Invalid HDF5 object reference")
    176         else:
--> 177             oid = h5o.open(self.id, self._e(name), lapl=self._lapl)
    178 
    179         otype = h5i.get_type(oid)

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/h5o.pyx in h5py.h5o.open()

KeyError: 'Unable to open object (component not found)'

How to fix this error?

$\endgroup$
2

1 Answer 1

0
$\begingroup$

The code looks fine fast5 is simply HDF5 format (rapid I/O).

The error,

'Unable to open object (component not found)'

You are not the only person to have this error and it could be a bug in the code with hdf5 in Python. Just to note I use hdf5 without a any problem.

  1. Problem with the installation (?), this is the best guess to resolve it but I notice from your error log .. the errors are coming from Anaconda, I assume you made a conda installation, but the post implies apt-get?? Just check where the package is located.
conda install -c hcc fast5-research

Then perform a conda environment creation and activation of the same package as here. I think you've already done that. anaconda3 is definitely your Python3 version ... and in that case it might be better to do the full conda installation because it stops things getting mixed up.

NOTE There is a Docker container

docker pull quay.io/biocontainers/fast5-research

I would recommend using this (it will almost certainly work), if you know how to leverage Docker (which is sort of complicated).

  1. File corruption ... examine the file via the HDFView GUI, here https://www.hdfgroup.org/downloads/hdfview/ . If you can't see within the file via the viewer - I think the file has a problem. Perhaps examine via hdf5 ... wait no that gets complicated.

  2. It can't find the file or a path error (below).

Then kindly try:

from fast5_research import Fast5
import pathlib as Path
import sys

filename=Path('/home/master/Desktop/0.fast5')
if filename.exists():
    print ('Okay {} is fine.'.format(filename))
    filename='/home/master/Desktop/0.fast5'
else:
    pathway = Path(__file__).absolute().parent
    if not Path(pathway, '0.fast5').is_file():
        raise ValueError ('Sorry filename has not been found')
        sys.exit()
    filename = str(Path(pathway, '0.fast5'))
try:
    if Path(filename).exists():
        with Fast5(filename) as fh:
            raw = fh.get_read(raw=True)
            summary = fh.summary()
        print('Raw is {} samples long.'.format(len(raw)))
        print('Summary {}.'.format(summary))
except Exception as err:
    print ("The error codes are {} and {}".format(err.message, err.args))

Please execute the code in the same dir as '/home/master/Desktop/' or maybe just '/home/Desktop

In Fasta5 will almost certainly take a path from pathlib but I've erred in case not. HDF5 will certainly accept a pathlib pathway.

I've not tested it but just post back what happens.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.