<p>The code looks fine <code>fast5</code> is simply <code>HDF5</code> format (rapid I/O).</p>
<p>The error,</p>
<blockquote>
<p>'Unable to open object (component not found)'</p>
</blockquote>
<p>You are not the only person <a href="https://stackoverflow.com/questions/55473368/h5py-randomly-unable-to-open-object-component-not-found">to have this error</a> and it could be a bug in the code with <code>hdf5</code> in Python. Just to note I use <code>hdf5</code> without a any problem.</p>
<ol>
<li>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 <code>conda</code> installation, but the post implies <code>apt-get</code>?? Just check where the package is located.</li>
</ol>
<pre><code>conda install -c hcc fast5-research
</code></pre>
<p>Then perform a conda environment creation  and activation of the same package as <a href="https://bioinformatics.stackexchange.com/questions/20161/how-to-run-how-are-we-stranded-here">here</a>. I think you've already done that. <code>anaconda3</code> is definitely your Python3 version ... and in that case it might be better to do the full <code>conda</code> installation because it stops things getting mixed up.</p>
<p><strong>NOTE</strong>
There is a Docker container</p>
<pre><code>docker pull quay.io/biocontainers/fast5-research
</code></pre>
<p>I would recommend using this (it will almost certainly work), if you know how to leverage Docker (which is sort of complicated).</p>
<ol start="2">
<li><p>File corruption ... examine the file via the HDFView GUI, here <a href="https://www.hdfgroup.org/downloads/hdfview/" rel="nofollow noreferrer">https://www.hdfgroup.org/downloads/hdfview/</a> . 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.</p>
</li>
<li><p>It can't find the file or a path error (below).</p>
</li>
</ol>
<p>Then kindly try:</p>
<pre><code>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 (&quot;The error codes are {} and {}&quot;.format(err.message, err.args))
</code></pre>
<p>Please execute the code in the same <code>dir</code> as <code>'/home/master/Desktop/'</code> or maybe just <code>'/home/Desktop</code></p>
<p>In <code>Fasta5</code> will almost certainly take a <code>path</code> from <code>pathlib</code> but I've erred in case not. <code>HDF5</code> will certainly accept a <code>pathlib</code> pathway.</p>
<p>I've not tested it but just post back what happens.</p>

CC BY-SA 4.0
2022-12-09T23:18:11.237Z
2022-12-10T16:08:35.553Z
2022-12-10T16:08:35.553Z
M__
<p>I am trying to extract data from fast5-file with python 3.9.13 in Ubuntu. I have found a library &quot;fast5_research&quot;(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 &quot;sudo apt update&quot;. According to <a href="https://nanoporetech.github.io/fast5_research/examples.html" rel="nofollow noreferrer">tutorial</a> I attempted to read fasta5-file with the next code:</p>
<pre><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))
</code></pre>
<p>but as a result, I have an error:</p>
<pre><code>KeyError                                  Traceback (most recent call last)
/tmp/ipykernel_410530/3650860803.py in &lt;module&gt;
      4 from fast5_research import Fast5
      5 filename='/home/master/Desktop/0.fast5'
----&gt; 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
---&gt; 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(&quot;Invalid HDF5 object reference&quot;)
    176         else:
--&gt; 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)'
</code></pre>
<p>How to fix this error?</p>

CC BY-SA 4.0
2022-12-10T20:55:48.997Z
similar too https://stackoverflow.com/questions/28782487/read-hdf5-based-file-as-a-numpy-array-in-python
pippo1980
CC BY-SA 4.0
2022-12-10T23:30:35.953Z
HDF5View should do the same as the post, just more "point and click"
M__
<python><nanopore><jupyter><base-calling><fast5>
Reading a Fast5-file with Python
# Reading a Fast5-file with Python

(Asked by: username_0 on 2022-12-09)

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 
      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?

**Tags:** python, nanopore, jupyter, base-calling, fast5
> **Comments:**
> **username_1**: similar too https://stackoverflow.com/questions/28782487/read-hdf5-based-file-as-a-numpy-array-in-python  
> **username_2**: HDF5View should do the same as the post, just more "point and click"  

---

## 1 answers

### Answer by username_2 on 2022-12-09. Score: 2

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.

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).

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.

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.


---

