Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Help for sample code

Subject: Help for sample code

From: Srikanth

Date: 29 May, 2010 13:02:46

Message: 1 of 5

Hi all,

I know this might be a very simple question but for me it is a bit tough.
I have a string of n characters

for eg:
string s = "ATGCGCGAGACGTCGATAGC"

now i want to replicate the string by replacing each character with each one of the 4 characters [A,T,G,C]

for eg ,

string s = "ATGCGCGAGACGTCGATAGC"

desired out put ;
1st letter changed
"ATGCGCGAGACGTCGATAGC"
"TTGCGCGAGACGTCGATAGC"
"GTGCGCGAGACGTCGATAGC"
"CTGCGCGAGACGTCGATAGC"

2nd letter changed
"ATGCGCGAGACGTCGATAGC"
"AAGCGCGAGACGTCGATAGC"
"AGGCGCGAGACGTCGATAGC"
"ACGCGCGAGACGTCGATAGC"

and so on.........................till the all the characters, that means for a sequence of 30 characters the output will be 120 strings,

Can anyone please tell me how do I code it in matlab as I'm very beginner in coding.


Thanks a lot,
Srikanth

Subject: Help for sample code

From: Roger Stafford

Date: 30 May, 2010 08:27:04

Message: 2 of 5

Srikanth <srikanth.duddela@gmail.com> wrote in message <1541730942.245194.1275138197028.JavaMail.root@gallium.mathforum.org>...
> Hi all,
>
> I know this might be a very simple question but for me it is a bit tough.
> I have a string of n characters
>
> for eg:
> string s = "ATGCGCGAGACGTCGATAGC"
>
> now i want to replicate the string by replacing each character with each one of the 4 characters [A,T,G,C]
>
> for eg ,
>
> string s = "ATGCGCGAGACGTCGATAGC"
>
> desired out put ;
> 1st letter changed
> "ATGCGCGAGACGTCGATAGC"
> "TTGCGCGAGACGTCGATAGC"
> "GTGCGCGAGACGTCGATAGC"
> "CTGCGCGAGACGTCGATAGC"
>
> 2nd letter changed
> "ATGCGCGAGACGTCGATAGC"
> "AAGCGCGAGACGTCGATAGC"
> "AGGCGCGAGACGTCGATAGC"
> "ACGCGCGAGACGTCGATAGC"
>
> and so on.........................till the all the characters, that means for a sequence of 30 characters the output will be 120 strings,
>
> Can anyone please tell me how do I code it in matlab as I'm very beginner in coding.
> Thanks a lot,
> Srikanth
- - - - - - - - - - -
  The original string is to be placed in 'S'. The columns of the 'T' table determine the sequence of replacement of the top character. For example, as defined below, 'C' in the top of the fourth column is to be followed in the column by 'T', 'G', and then 'A'. The requested string matrix will be found in S2.

% Define string & table
S = 'ATGCGCGAGACGTCGATAGC';
T = ['ATGC';
     'TATT';
     'GGAG';
     'CCCA'];

% Create multiple strings in S2
n = length(S);
[D,p,p] = unique([T(:).',A]);
t = reshape(p(1:16),[],4);
s = p(17:16+n);
S2 = reshape(D(repmat(s,4*n,1)),[],n);
[ix,iy] = meshgrid(1:n,1:4);
q = p(1:4);
S2(iy+4*(n+1)*(ix-1)) = D(t(:,q(s(:))));

% Result:
ATGCGCGAGACGTCGATAGC
TTGCGCGAGACGTCGATAGC
GTGCGCGAGACGTCGATAGC
CTGCGCGAGACGTCGATAGC
ATGCGCGAGACGTCGATAGC
AAGCGCGAGACGTCGATAGC
AGGCGCGAGACGTCGATAGC
ACGCGCGAGACGTCGATAGC
ATGCGCGAGACGTCGATAGC
ATTCGCGAGACGTCGATAGC
ATACGCGAGACGTCGATAGC
ATCCGCGAGACGTCGATAGC
......

Roger Stafford

Subject: Help for sample code

From: Bruno Luong

Date: 30 May, 2010 09:04:07

Message: 3 of 5

Is it what you want?

S = 'ATGCGCGAGACGTCGATAGC';

% Engine
template = 'ATGC';
[trash X] = ismember(S,template);
X = mod(bsxfun(@plus, X(:)-1,0:3),4)+1;
X = template(X).'

Bruno

Subject: Help for sample code

From: Roger Stafford

Date: 30 May, 2010 09:52:05

Message: 4 of 5

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <htt7go$3u0$1@fred.mathworks.com>...
> ......
> % Create multiple strings in S2
> n = length(S);
> [D,p,p] = unique([T(:).',A]);
> t = reshape(p(1:16),[],4);
> s = p(17:16+n);
> S2 = reshape(D(repmat(s,4*n,1)),[],n);
> [ix,iy] = meshgrid(1:n,1:4);
> q = p(1:4);
> S2(iy+4*(n+1)*(ix-1)) = D(t(:,q(s(:))));
> ......

  I need to make one change in the above code to make it work for all 'T'. In place of the line

 q = p(1:4);

it should be

 q = 1:4; q(p(1:4:13)) = q;

Roger Stafford

Subject: Help for sample code

From: Srikanth

Date: 30 May, 2010 13:11:13

Message: 5 of 5

Hi

Thanks a lot for the help. That was Awesome.

Thanks again.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us