Find a specific characters in a string

조회 수: 4 (최근 30일)
Miriam Contreras Castillo
Miriam Contreras Castillo 2022년 11월 25일
편집: Stephen23 2022년 11월 26일
Hello, I am trying to I get certain amino acids from my sequence, however, my output only gives that there are 3 of the amino acids I am looking for but I want it to tell me the amino acid name and create a new string.
I would also want my code to run other larger sequences if need be.
I am not sure if a swich case was the best approach to do this task. Can someone please help me, thank you!
aminoacids = 'MetArgGlyLeuAspTrpAspGlyAsn'
for d = 1:3:(length(aminoacids)-2)
rgroup = aminoacids(d:(d+2));
switch (rgroup)
case {'Arg', 'Asp', 'Cys', 'Glu','Lys','Tyr'}
disp(aminoacids)
end
end

채택된 답변

Stephen23
Stephen23 2022년 11월 25일
C = {'Arg', 'Asp', 'Cys', 'Glu','Lys','Tyr'};
T = 'MetArgGlyLeuAspTrpAspGlyAsn';
R = join(string(C),'|');
A = regexp(T,R,'match')
A = 1×3 cell array
{'Arg'} {'Asp'} {'Asp'}
  댓글 수: 4
Miriam Contreras Castillo
Miriam Contreras Castillo 2022년 11월 26일
편집: Miriam Contreras Castillo 2022년 11월 26일
Thank you! But this only works for cell type data? What if it is just a string?
Stephen23
Stephen23 2022년 11월 26일
편집: Stephen23 2022년 11월 26일
"But this only works for cell type data? What if it is just a string?"
It works for string arrays too:
S = ["Arg", "Asp", "Cys", "Glu", "Lys", "Tyr"];
T = "MetArgGlyLeuAspTrpAspGlyAsn";
R = join(S,'|');
A = regexp(T,R,'match')
A = 1×3 string array
"Arg" "Asp" "Asp"

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Paul
Paul 2022년 11월 26일
편집: Paul 2022년 11월 26일
Hi Miriam
I'm not quite sure what you're looking for. However, transforming everything to strings might offer a path forward via standard Matlab functions and indexing. For example
aminoacids = 'MetArgGlyLeuAspTrpAspGlyAsn';
C = string({'Arg', 'Asp', 'Cys', 'Glu','Lys','Tyr'})
S = string(reshape(aminoacids,3,[]).')
Find all the acids in S that are present in C
S(ismember(S,C))
ans = 3×1 string array
"Arg" "Asp" "Asp"

카테고리

Help CenterFile Exchange에서 Protein and Amino Acid Sequence Analysis에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by