nanoporetech / ont_fast5_api

Oxford Nanopore Technologies fast5 API software
Other
144 stars 28 forks source link

How to get info from fast5? #37

Closed renzilin closed 4 years ago

renzilin commented 4 years ago

Hi, developers!

I've installed a ont_fast5_api package in my python. And I tried to use your code example to extract some information from fast5 file.

from ont_fast5_api.fast5_interface import get_fast5_file
with get_fast5_file(fast5_file, mode="r") as f5:
    for read in f5.get_reads():
        raw_data = read.get_raw_data()
        print(read.read_id, raw_data, len(raw_data))
        break

And then I ran read.get_channel_info and it returned <bound method Fast5Read.get_channel_info of <ont_fast5_api.fast5_read.Fast5Read object at 0x2aab61126ba8>>

So how can I extract the information from the object like channel_number?

Thanks for your help!

-Zilin

iiSeymour commented 4 years ago

Hey @renzilin

That is because get_channel_info is a method bound to the read object (that is it's a function that you need to call):

>>> read.get_channel_info()
{'offset': -230.0, 'channel_number': 1106, 'range': 598.8641328090869, 'digitisation': 2048.0, 'sampling_rate': 4000.0}

It returns a Python dictionary with a few different values - you can access the channel number like so:

>>> read.get_channel_info()['channel_number']
1106

HTH,

Chris.

renzilin commented 4 years ago

Hey @renzilin

That is because get_channel_info is a method bound to the read object (that is it's a function that you need to call):

>>> read.get_channel_info()
{'offset': -230.0, 'channel_number': 1106, 'range': 598.8641328090869, 'digitisation': 2048.0, 'sampling_rate': 4000.0}

It returns a Python dictionary with a few different values - you can access the channel number like so:

>>> read.get_channel_info()['channel_number']
1106

HTH,

Chris.

Yes, I got it. Thank you. When I ran it in a for loop, it works. But it didn't not work if I ran a single line. Anyway, it solves my problem. Much appreciated!

I attached the error. image