python - Python ray get TypeError: no default __reduce__ due to non-trivial __cinit__
问题描述
我正在尝试制作一个返回唯一读取和 %GC 的 pysam 脚本,其中一部分是列出每个染色体的读取列表(因为我需要稍后读取每个染色体用于其他目的)。为了节省时间,我希望脚本使用 ray 在 4 个线程中并行运行分析:
import pysam
import ray
ray.init()
nst = []
for x in range(1,25):
if x == 23:
nst.append('chrX')
elif x == 24:
nst.append('chrY')
else:
nst.append('chr%d'%x)
filebam = 'sample.bam'
bam = pysam.AlignmentFile(filebam, 'rb')
f = open('readandgc.txt','w')
f.write('chr\tgc\ttotal')
f.close()
def analyze(r):
begin = int(self.r.split('-')[0])
end = int(self.r.split('-')[1])
total = 0
gc = 0
for x in range(begin, end):
c = nst[x]
print('Reading %s'%c)
read_data = bam.fetch(c)
for read in read_data:
seq = read.query_sequence
total += len(seq)
gc += len([x for x in seq if x == 'C' or x == 'G'])
f = open(tempdir + '/' + 'readandgc.txt','a')
f.write(chr + '\t' + str(gc) + '\t' + str(total))
f.close()
@ray.remote
def core1():
analyze('1-7')
@ray.remote
def core2():
analyze('7-13')
@ray.remote
def core3():
analyze('13-19')
@ray.remote
def core4():
analyze('19-24')
values = ray.get([core1.remote(), core2.remote(), core3.remote(), core4.remote()])
但我对这个错误日志感到震惊:
2021-04-19 15:39:49,840 INFO services.py:1174 -- View the Ray dashboard at ←[1m←[32mhttp://127.0.0.1:8265←[39m←[22m
Traceback (most recent call last):
File "gccount.py", line 45, in <module>
values = ray.get([core1.remote(), core2.remote(), core3.remote(), core4.remote()])
File "C:\ProgramData\Anaconda3\lib\site-packages\ray\remote_function.py", line 101, in _remote_proxy
return self._remote(args=args, kwargs=kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\ray\remote_function.py", line 201, in _remote
self._pickled_function = pickle.dumps(self._function)
File "C:\ProgramData\Anaconda3\lib\site-packages\ray\cloudpickle\cloudpickle_fast.py", line 73, in dumps
cp.dump(obj)
File "C:\ProgramData\Anaconda3\lib\site-packages\ray\cloudpickle\cloudpickle_fast.py", line 574, in dump
return Pickler.dump(self, obj)
File "stringsource", line 2, in pysam.libcalignmentfile.AlignmentFile.__reduce_cython__
TypeError: no default __reduce__ due to non-trivial __cinit__
有人可以告诉我我的代码有什么问题吗?
解决方案
推荐阅读
- angular - 更改 Moment 变量的小时数时,this.moment.hours() 不是函数错误
- php - 在评论中用名称替换 id 而不替换错误的大小写
- c++ - 处理自定义 Qt 小部件中的输入事件
- mybatis - SqlProvider 重载
- python - 如何在openpyxl中设置单元格语言以获得良好的数字格式?
- mongodb - 如何在 mongodb 中使用查找来匹配数组字段?
- python - python打印表格程序中{1:>2}的含义
- python - 如果没有引发异常,您如何以 Python 方式告诉程序始终执行某些操作
- gcloud - gcloud functions deploy 总是说:--region: NAME must be specified
- c++ - 在支持多种类型的宏中使用 printf