无法找出不正确的字符串拼接

问题描述

我正在制作一个函数,它接受一个包含字符串的元组,选择一个字符串,然后选择该字符串中的开始和结束索引。在这个索引中,字符串被切碎并随机排列,然后元组修改后的字符串一起返回。但是,在函数中定义开始和结束索引,然后根据它拼接字符串时,似乎存在某种错误。在某些运行中,它按预期工作,而在其他运行中,它没有,因此引发了我在 while 循环中避免的错误。谁能告诉我这里会发生什么:

def chromothripsist(seqs,keep_frequency = 0.9):
seqs = list(seqs)
c = list(range(len(seqs)))
chrom = random.sample(c,1)
orig_seq = seqs[chrom[0]]
n = len(orig_seq)
NotLongEnough = True
while(NotLongEnough): 
    splits = random.randint(5,10)
    ##IF SPLITS > len(seq) then this bugs 
    print(orig_seq)
    lowbd = int(0.1*n)
    upbd = int(0.9*n)
    distance = int(np.random.uniform(lowbd,upbd))
    stidx = random.randint(0,n-1)
    edidx = max(stidx + distance,n-1)
    dist = edidx - stidx
    print(splits,stidx,edidx)
    if(dist > splits): 
        NotLongEnough = False
        break
first_part = orig_seq[:stidx]
last_part = orig_seq[edidx:]
seq = orig_seq[stidx:edidx]
# THE ABOVE LInes ARE NOT WORKING AS EXPECTED
print(seq)
print(stidx,edidx)
print(len(seq),splits)
breakpoints = np.random.choice(len(seq),splits-1,replace = False)
breakpoints.sort()
subseq = []
curridx = 0
for i in breakpoints: 
    subseq.append(seq[curridx:i])
    curridx = i
subseq.append(seq[breakpoints[-1]:])
rearrange = np.random.permutation(splits)
#n_to_select= int(splits *keep_frequency)
n_to_select = len(rearrange)
rearrange = random.sample(list(rearrange),n_to_select)
build_seq = ''
for i in rearrange: 
    build_seq += subseq[i]
seqs[chrom[0]] = first_part + build_seq + last_part
breakpoints = list(breakpoints)
return tuple(seqs),[stidx,edidx,breakpoints,rearrange,chrom[0]]

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...