如何在matlab中生成随机DNA序列

时间:2018-04-20 17:50:33

标签: matlab random sequence

我是Matlab的新手,我正在尝试创建随机DNA序列生成器,到目前为止,我只找到了生成具有相同概率的A,C,G,T的方法,如何为每个字母分配不同的概率?所有概率必须加起来为1。

total_bp=10;
%open file
SeqLength=100;
bases = repmat('ACGT', 1, SeqLength/4);
for i=1:total_bp
%random DNA sequence
SeqLength=100;
Seq = bases(randperm(SeqLength));
display(num2str(Seq))
end
fclose('all');

1 个答案:

答案 0 :(得分:2)

定义碱基的细胞阵列

bases = {'A', 'C', 'G', 'T'};

一系列概率;

probs = [0.1,0.5,0.3,0.1];

然后你可以绘制一个统一的随机数并将其分开:

bin = discretize(rand,[0,cumsum(probs)]);

然后翻译成一封信:

seq = bases(bin);

总计:

n = 10;
bases = {'A', 'C', 'G', 'T'};
probs = [0.1,0.5,0.3,0.1];
seq = bases(discretize(rand(1,n),[0,cumsum(probs)]));
disp(strjoin(seq)) %Join to single string.