필터 지우기
필터 지우기

the number of occurences of each character of one string,in another

조회 수: 4 (최근 30일)
hiva
hiva 2014년 12월 28일
편집: Luuk van Oosten 2015년 1월 24일
i have a string of more than 100 characters (fasta format of a protein sequence. like
'MEQNGLDHDSRSSIDTTINDTQKTFLEFRSYTQLSEKLASSSSYTAPPLNEDGPKGVASAVSQGSESVVSWTTLTHVYSILGAYGGPTCLYPTATYFLMGTSKGCVLIFNYNEHLQTILVPTLSEDPSIH'
which is being shortened here for simplicity) and i want to find out whether or not it is hydrophobic. so i have to check the number of occurrences of each of the characters in the set 'A C F I L M P V W Y'(hydrophob amino acids) in my fasta string. considering the very long length of fasta strings, is there any easy way to do that by matlab string functions?

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 12월 28일
편집: Azzi Abdelmalek 2014년 12월 28일
str='MEQNGLDHDSRSSIDTTINDTQKTFLEFRSYTQLSEKLASSSSYTAPPLNEDGPKGVASAVSQGSESVVSWTTLTHVYSILGAYGGPTCLYPTATYFLMGTSKGCVLIFNYNEHLQTILVPTLSEDPSIH'
p={'A' 'C' 'F' 'I' 'L' 'M' 'P' 'V' 'W' 'Y'}'
out=[p cellfun(@(x) nnz(ismember(str,x)),p,'un',0)]
  댓글 수: 2
hiva
hiva 2014년 12월 29일
thanks a lot.i guess this works well for a lot of similar cases that are supposed to work the same way in my code(since it is feature extraction and there are lots of features). also tells me how much i don't know from matlab.thanks.
Stephen23
Stephen23 2014년 12월 30일
편집: Stephen23 2014년 12월 30일
This could be simplified and speeded-up by using arrayfun instead of cellfun, and removing the ismember:
>> t = 'ACFILMPVWY';
>> arrayfun(@(x)sum(str==x), t)
ans =
6 2 4 6 13 2 7 7 1 7

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

추가 답변 (4개)

Peter Perkins
Peter Perkins 2014년 12월 29일
Another possibility:
>> s = 'MEQNGLDHDSRSSIDTTINDTQKTFLEFRSYTQLSEKLASSSSYTAPPLNEDGPKGVASAVSQGSESVVSWTTLTHVYSILGAYGGPTCLYPTATYFLMGTSKGCVLIFNYNEHLQTILVPTLSEDPSIH';
>> t = 'ACFILMPVWY';
>> n = hist(double(s),1:90);
>> n(t)
ans =
6 2 4 6 13 2 7 7 1 7
  댓글 수: 1
Jan
Jan 2014년 12월 30일
This is a histogram problem, so histc is an efficient and direct solution.

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


Luuk van Oosten
Luuk van Oosten 2015년 1월 24일
편집: Luuk van Oosten 2015년 1월 24일
I reckon you are using the BioInformatics Toolbox. In that case you can probably use:
aacount('SEQ')
Where SEQ is of course your sequence of interest: MEQNGLDHDSRSSIDTTINDTQKTFLEF....
and using
nr_A = All.A
nr_C = All.C
nr_F = All.F
etc. (you get the idea)
you get the numbers of your hydrophobic residues. Sum these and you have your hydrophobic score. You might want to 'normalize' this number by dividing this number by the total amount of amino acids in the sequence.
Of course you can write a loop for this and calculate the hydrophobic score for all your sequences in your FASTA file.

Shoaibur Rahman
Shoaibur Rahman 2014년 12월 28일
s = 'MEQNGLDHDSRSSIDTTINDTQKTFLEFRSYTQLSEKLASSSSYTAPPLNEDGPKGVASAVSQGSESVVSWTTLTHVYSILGAYGGPTCLYPTATYFLMGTSKGCVLIFNYNEHLQTILVPTLSEDPSIH';
numA = sum(s=='A')
numC = sum(s=='C')
numF = sum(s=='F')
numI = sum(s=='I')
numL = sum(s=='L')
numM = sum(s=='M')
numP = sum(s=='P')
numV = sum(s=='V')
numW = sum(s=='W')
numY = sum(s=='Y')

Stephen23
Stephen23 2014년 12월 30일
편집: Stephen23 2014년 12월 30일
A neat solution using bsxfun :
>> s = 'MEQNGLDHDSRSSIDTTINDTQKTFLEFRSYTQLSEKLASSSSYTAPPLNEDGPKGVASAVSQGSESVVSWTTLTHVYSILGAYGGPTCLYPTATYFLMGTSKGCVLIFNYNEHLQTILVPTLSEDPSIH';
>> t = 'ACFILMPVWY';
>> sum(bsxfun(@eq,s.',t))
ans =
6 2 4 6 13 2 7 7 1 7
  댓글 수: 1
hiva
hiva 2014년 12월 30일
편집: hiva 2014년 12월 30일
wow!!! just wonderful. it works pretty well.thanks a lot.

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by