I'm trying to create a random sequence of 100 DNA bases, with an equal number of A,C,G and T, but I can't make it happen.

2 views (last 30 days)

I'm trying to create a random sequence of 100 DNA bases, with an equal number of A,C,G and T, but I can't make it happen. My code is:

total_bp=10000;
%open file
fid=fopen('Seq_Out.txt','w');
for i=1:total_bp
%random DNA sequence
SeqLength=100;
Seq=randseq(SeqLength,'Weights',[0.25 0.25 0.25 0.25]);
%write to file
fprintf(fid,'%s\n',Seq);
end
fclose('all');

Accepted Answer

Walter Roberson
Walter Roberson on 19 Apr 2018

Before the loop:

SeqLength=100;
bases = repmat('ACGT', 1, SeqLength/4);

The replace your

SeqLength=100;
Seq=randseq(SeqLength,'Weights',[0.25 0.25 0.25 0.25]);

with

Seq = bases(randperm(SeqLength));
  3 Comments
Image Analyst
Image Analyst on 23 Nov 2022
@Radhwan Jawad start a new question for this.
@Nitzan Kahn If this solves the question for you then please click the "Accept this answer" link to award @Walter Roberson "reputation points" for the answer. Thanks in advance. 🙂

Sign in to comment.

More Answers (0)

Categories

Find more on Genomics and Next Generation Sequencing in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!