joblib库产生意外结果

时间:2019-06-18 13:15:05

标签: python-3.6

我正在尝试使用{A,C,G,U}(RNA序列)中的所有可能组合来正确更改长度为L的字符串中的N个字母 在这个例子中N = 2 L = 3 依次运行函数“ create_seqs”时,它可以正常工作,但是在尝试并行化时,它可以正常工作

我试图替换循环顺序,甚至一次只能在并行行中使用一个循环,正如您在循环注释中所看到的那样

import pandas as pd
import itertools
from joblib import Parallel, delayed

def create_seqs(idx,nucs,wt):

    tmp1 = list(wt)
    flag=0
    for loc in range(len(nucs)):
        if tmp1[j[loc]] == nucs[loc]:
            flag = 1
        if flag:
            break
    if not flag:
        print(idx)
        print(nucs)
        for loc in range(len(nucs)):
            tmp1[j[loc]] = nucs[loc]    
    return ''.join(tmp1)

wt = 'AGC'

i=2 #number of nucs to change

#all posible nucleutide combination
Alli = list(itertools.permutations(['A','C','G','U']*i,i))
#all posible indexs combination
IDXperms19 = list(itertools.permutations(list(range(0,len(wt))),i))

tmp1=[]
tmp=[]
tmp1 = Parallel(n_jobs=1)(delayed(create_seqs)(j,nucs,wt)  for j in IDXperms19 for nucs in Alli)

for j in IDXperms19:
    for nucs in Alli:
        tmp.append(create_seqs(j,nucs,wt))
#    tmp1 = Parallel(n_jobs=2)(delayed(create_seqs)(j,nucs,wt) for nucs in Alli)  +tmp1
tmp = list(set(tmp)) 
tmp1 =list(set(tmp1))

按预期,tmp的长度为28(所有可能的替换加上原始的替换),但len(tmp1)= 10

0 个答案:

没有答案