-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotiffinder.m
31 lines (25 loc) · 1.12 KB
/
motiffinder.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function [nmersFound, freqDiffSorted] = motiffinder(seq, seq0, W)
% Copyright 2007 The MathWorks, Inc.
%this function is used under the from the Mathworks site https://www.mathworks.com/help/bioinfo/examples/identifying-over-represented-regulatory-motifs.html
%function was last accessed on 11/27/2017.
%=== find and count words of length W
nmers0 = nmercount(seq0, W);
nmers = nmercount(seq, W);
%=== compute frequency of words
f = [nmers{:,2}]/(length(seq) - W + 1);
f0 = [nmers0{:,2}]/(length(seq0) - W + 1);
%=== determine words common to both set
[nmersInt, i1, i2] = intersect(nmers(:,1),nmers0(:,1));
freqDiffInt = (f(i1) - f0(i2))';
%=== determine words specific to one set only
[nmersXOr, i3, i4] = setxor(nmers(:,1),nmers0(:,1));
c0 = nmers(i3,1);
d0 = nmers0(i4,1);
nmersXOr = [c0; d0];
freqDiffXOr = [f(i3) -f0(i4)]';
%=== define all words and their difference in frequency (margin)
nmersAll = [nmersInt; nmersXOr];
freqDiff = [freqDiffInt; freqDiffXOr];
%=== sort according to descending difference in frequency
[freqDiffSorted, freqDiffSortedIndex] = sort(freqDiff,'descend');
nmersFound = nmersAll(freqDiffSortedIndex);