Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python h5py无法读取fast5文件_Python_Hdf5_H5py - Fatal编程技术网

Python h5py无法读取fast5文件

Python h5py无法读取fast5文件,python,hdf5,h5py,Python,Hdf5,H5py,我正在尝试将数据从fast5文件写入txt文件。我可以通过进入文件所在的目录并使用以下代码来执行此操作: for filename in os.listdir(os.getcwd()): if filename.endswith('.fast5'): with h5py.File(filename, 'r') as hdf: with open(new_txt, 'a') as myfile: myfile.write

我正在尝试将数据从fast5文件写入txt文件。我可以通过进入文件所在的目录并使用以下代码来执行此操作:

for filename in os.listdir(os.getcwd()):
    if filename.endswith('.fast5'):
        with h5py.File(filename, 'r') as hdf:
            with open(new_txt, 'a') as myfile:
               myfile.write('%s \t' % (filename))
for root, dirs, files in os.walk(path):     
    for d in dirs:
        if d.startswith('pass') or d.startswith('fail')
            for rootfolder, blankdirs, fast5files in os.walk(d):                                                                                                                                                                                                          
                for filename in fast5files:
                    if filename.endswith('.fast5'):
                        with h5py.File(filename, 'r') as hdf:                
                            with open(new_txt, 'a') as myfile:                    
                                myfile.write('%s \t' % (filename))
但是,我现在尝试通过主目录访问文件,方法是循环访问文件所在的特定子文件夹,并使用以下代码以这种方式访问文件:

for filename in os.listdir(os.getcwd()):
    if filename.endswith('.fast5'):
        with h5py.File(filename, 'r') as hdf:
            with open(new_txt, 'a') as myfile:
               myfile.write('%s \t' % (filename))
for root, dirs, files in os.walk(path):     
    for d in dirs:
        if d.startswith('pass') or d.startswith('fail')
            for rootfolder, blankdirs, fast5files in os.walk(d):                                                                                                                                                                                                          
                for filename in fast5files:
                    if filename.endswith('.fast5'):
                        with h5py.File(filename, 'r') as hdf:                
                            with open(new_txt, 'a') as myfile:                    
                                myfile.write('%s \t' % (filename))
此代码给出了错误信息:

IOError: Unable to open file (Unable to open file: name = 'minion2_chip61_re_n90_yt2_2644_1_ch108_file0_strand.fast5', errno = 2, error message = 'no such file or directory', flags = 0, o_flags = 0) 
这让我很困惑,因为它可以获取文件名,但不知何故无法从中读取,而在原始代码下它可以读取。错误发生在此行:

with h5py.File(filename, 'r') as hdf: 

为什么h5py不能以这种方式打开/读取文件

您需要添加目录
os.walk
当前正在遍历的文件名:

....
if filename.endswith('.fast5'):
    hdf5_path = os.path.join(root, filename)
    with h5py.File(hdf5_path, 'r') as hdf: 
        ...

哈哈,在我读到你的答案之前,我就明白了。你的方法比我的方法干净多了,谢谢!