-2

我正在尝试编写一个程序来尽可能地打乱 dna 序列以破坏序列中的顺序。我写了matlab代码,但是太慢了。此外,我正在研究汉明距离测量或列文斯坦测量,以及如何结合这些测量以确保正确的洗牌。我在洗牌时遵循的规则

  • 规则 1:第 i 个残差不应靠近 i-1,i-2,i-3,i+1,i+2,i+3
  • 规则2:在接下来的安排中,我的新位置和旧位置必须相差20位。即,如果 A 在 shuffled 字符串中的字符串中排名第 1,则它必须大于等于第 21 位。
function seq=shuffling(str)

len=length(str);
t1=0.4;
seqlen=1:len;
if(len>150)
t1=0.90;
elseif(len>=100)
t1=0.7;
end
while 1
shufseq=randperm(len);
temp1=diff([seqlen;shufseq]);%differences between order indices of original and shuffled arrangement
if(isempty(find(temp1==0)) && isempty(find(diff(shufseq)==1|diff(shufseq)==2 |diff(shufseq)==3 |diff(shufseq)==4 |diff(shufseq)==-1|diff(shufseq)==-2 |diff(shufseq)==-3 |diff(shufseq)==-4)))% rule 1
        if((length(find(temp1>20|temp1<-20))/len)>t1)%rule 2 if ratio of (counts of arrangements/length of the string) should be more than one after certain length threshhold(=t1)
    break
        else
        continue
        end
else
continue
end
end
seq=str(shufseq);
4

1 回答 1

0

我想出了一个替代方案。即知道字符串中唯一字母的组成或计数。然后在这些字母中随机选择,并在每次迭代中将它们的计数减 1。此迭代超过了序列的长度。

function seq=newshuffle(str)
%#codegen
len=length(str);
seq=[];
ndict= ['A';'C';'G';'T'];
ncomp=struct2array(count(str))';
for l=1:len
    while 1
        x=randi(4,1,1);
        if ncomp(x)~=0
            break;
        end
    end
    seq=[seq,ndict(x)];
    ncomp(x)=ncomp(x)-1;
end
end
于 2015-05-13T17:35:48.647 回答