问题描述
我正在尝试制作一个返回唯一读取和 %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(),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__
谁能告诉我我的代码有什么问题?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)