我正在尝试重写fast5 (HDF5)的数据文件到abf格式,我有以下代码,应该能够重写给定的fast5文件到一个通用的数据类型重写到abf的另一个工具。但是,下面的代码会在数字化步骤中产生错误
from uuid import uuid4
import numpy as np
from fast5_research import BulkFast5
filename='test1.fast5'
mean, stdv, n = 40.0, 2.0, 10000
raw_data = np.random.laplace(mean, stdv/np.sqrt(2))
# example of how to digitize data
start, stop = int(min(raw_data - 1)), int(max(raw_data + 1))
rng = stop - start
digitisation = 8192.0
bins = np.arange(start, stop, rng / digitisation)
# np.int16 is required, the library will refuse to write anything other
raw_data = np.digitize(raw_data, bins).astype(np.int16)
# The following are required meta data
channel_id = {
'digitisation': digitisation,
'offset': 0,
'range': rng,
'sampling_rate': 4000,
'channel_number': 1,
}
read_id = {
'start_time': 0,
'duration': len(raw_data),
'read_number': 1,
'start_mux': 1,
'read_id': str(uuid4()),
'scaling_used': 1,
'median_before': 0,
}
tracking_id = {
'exp_start_time': '1970-01-01T00:00:00Z',
'run_id': str(uuid4()).replace('-',''),
'flow_cell_id': 'FAH00000',
}
context_tags = {}
with Fast5.New(filename, 'w', tracking_id=tracking_id, context_tags=context_tags, channel_id=channel_id) as h:
h.set_raw(raw_data, meta=read_id, read_number=1)带错误
/usr/lib/python3/dist-packages/apport/report.py:13: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import fnmatch, glob, traceback, errno, sys, atexit, locale, imp, stat
Traceback (most recent call last):
File "/home/archie/PycharmProjects/Fast5read/Fast5rewrite.py", line 11, in <module>
start, stop = int(min(raw_data - 1)), int(max(raw_data + 1))
TypeError: 'float' object is not iterable当我寻求帮助时,我应该迭代一个范围,但我不知道迭代在哪里,也不知道如何修复这个错误。
发布于 2020-12-11 00:06:26
start, stop = int(min(raw_data - 1)), int(max(raw_data + 1))min()和max()是期望将迭代器作为参数的函数。它们分别在这些迭代器中找到最小和最大的元素。
根据您调用np.random.laplace()的方式,它将返回一个浮点值,这不是一个迭代值。
发布于 2020-12-11 00:10:55
如果你想要一个来自numpy.random.laplace的迭代值,你必须在(可选的)第三个参数中指定你想返回的数组的形状。
https://numpy.org/doc/stable/reference/random/generated/numpy.random.laplace.html
例如,抽取10000个样本:
mean, stdv, n = 40.0, 2.0, 10000
raw_data = np.random.laplace(mean, stdv/np.sqrt(2),n)
# example of how to digitize data
start, stop = int(min(raw_data - 1)), int(max(raw_data + 1))
rng = stop - start
digitisation = 8192.0
bins = np.arange(start, stop, rng / digitisation)https://stackoverflow.com/questions/65238065
复制相似问题