  disp('Markov Chain Examples')
  lw = 2; 
  set(0, 'DefaultAxesFontSize', 14);
  fs = 14;
  msize = 10;  

% Markov Chains
% (1) Nucleotide Transition Matrix
M = [ ...
 0.98   0.01   0.005   0.005;...
 0.01   0.96   0.02     0.01;...
 0.01   0.01   0.97     0.01;...
 0.02   0.03   0.01     0.94];

s0 = [0.0    1.0    0.0    0.0] ;

s1 =  s0 * M;
s2 =  s0 * M^2;
s10 = s0 * M^10;
s100 = s0 * M^100;
s1000 = s0 * M^1000;
s10000 = s0 * M^10000;

[s0'   s1'   s2'   s10'   s100'  s1000'  s10000']  



%          0    0.0100    0.0198    0.0909    0.3548    0.3721
%          1    0.9600    0.9222    0.6854    0.2521    0.2465
%          0    0.0200    0.0388    0.1517    0.2747    0.2651
%          0    0.0100    0.0193    0.0719    0.1184    0.1163


% (2) Nights of Mr Jones

P = [...
     0.4  0.6;
     0.5  0.5];
 
 p0 = [1 0];    %Monday    Night
 p1 = p0 * P;   %Tuesday   Night
 p2 = p0 * P^2; %Wednesday Night
 p3 = p0 * P^3; %Thursday  Night
 p4 = p0 * P^4; %Friday    Night
 
 [p0' p1' p2' p3' p4']
%  
% ans =
% 
%          1    0.4000    0.4600    0.4540    0.4546
%          0    0.6000    0.5400    0.5460    0.5454

%(3) CpG Islands
%CpG islands are regions of non-coding DNA,
%where the proportion of cytosine and guanine residues exceeds 50%.
%Here [A C G T]
 
PH1 =  [0.18 0.27 0.43 0.12;   0.17 0.37  0.27 0.19; ...
              0.16 0.34 0.38 0.12;  0.08 0.36 0.38 0.18];
PH0 =  [0.30 0.20 0.29 0.21;  0.32 0.30 0.08 0.30; ...
              0.25 0.24 0.30 0.21;  0.18 0.24 0.29 0.29];
          
          % score = log P(x|CpG)/P(x|null)
          
          

 