MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

0

Counting the number of occurrence of a particolar letter in a string iteratively with a moving window like process

Bio_Ing_Sapienza さんによって質問されました 2018 年 12 月 4 日
最新アクティビティ Bio_Ing_Sapienza さんによって 回答されました 2018 年 12 月 4 日
HI! I have this kind of problem:
STR='AAAQQQPPPTTTCCCPPAAANNNDDDAAATTPPPPNNNAAA'
%Random Amino acidic sequence
Having this kind of sequence I want to count the number of occurrences that I would find using a sliding window process.
Like I give you my window's length and slinding this i get for each iteration a new pattern of aa where i count a new number of a particular residue. In my particular problem I have a cellarray containing 5000 and more sequences so I would prefer to avoid a double for loop. Anyone knows some kind of function or itaration that can be usefull?
Thanks very much!

  2 件のコメント

Don't worry about a few thousand iterations - it will be very very fast.
So you want some kind of histogram (count) of the letters at each window location as the window slides along? So you'd have thousands of histograms?
Have you tried reshape() to shape it into a 2-D matrix and then sum across the matrix?
I don't think reshape() would be so usefull to me. I'm thinking about entering in source code of movmean and starting from there creating a new function doing the same kind of sliding that it does but doing the same thing that couunt() does. Do you know how to get the source code for an inbuilt MATLAB function?Because when I do
open movmean
I get only a description of this funtion and not the code itself

サインイン to comment.

2 件の回答

回答者: Bio_Ing_Sapienza 2018 年 12 月 4 日

Here some kind of script I'm looking for
str={'AQQATPLAALTPAALLTTPPAALLTTPPALQQQQCCC' 'AAAPPPTLLLQQQCCCAAAPPPAAATTTCCC'};
w=15;
sum=0
for i=1:2
for j=1:numel(str{1,i})
sum=sum+1
A=count(str{1,i}(1,j:1:w+sum),'A')
Q=count(str{1,i}(1,j:1:w+sum),'Q')
T=count(str{1,i}(1,j:1:w+sum),'T')
L=count(str{1,i}(1,j:1:w+sum),'L')
end
end
Now the problem it's that MATLAB justly says: index exceeds array bound so I want to have a similar mechanism to what I get in movaverage or movsum that make finish the sliding as soon as the window arrives at the end of the string.

  1 件のコメント

movmean() slides over by one element. reshape() will let you, in effect, move in "jumps" of the window size. How much do you want the window to slide over each time?

サインイン to comment.


回答者: Bio_Ing_Sapienza 2018 年 12 月 4 日

typically 15

  0 件のコメント

サインイン to comment.



Translated by