-
Notifications
You must be signed in to change notification settings - Fork 0
/
boolCell.m
120 lines (103 loc) · 4.41 KB
/
boolCell.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
classdef boolCell < matlab.mixin.Copyable
% Boolean cell: this object models a cell with a boolean network
properties
% Set by the caller
numGenes % The number of genes in the cell
k % The number of connections each node has
p % Probability of function value taking on value of 1
bandwidth % The number of external connections the cell makes
Ttable % The truth table for the network
varF % Which intracellular connections a cell makes
outCells % Which cells produce intercellular output
inCells % Which cells receive intercellular input
perturb % Perturbation
% Generated if a grid is set up
neighbors % The neighbors of the cell
cellPos % Position of the cell
% Generated every step
states
end
methods
% Constructor
function obj = boolCell(numGenes,k,p,bandwidth,Ttable,varF,outCells,inCells, perturb)
% Set some defaults
if nargin == 0
obj.numGenes = 15;
obj.k = 0;
obj.p = 0;
obj.bandwidth = 0;
obj.Ttable = [];
obj.varF = [];
obj.outCells = [];
obj.inCells = [];
obj.perturb = [];
else
obj.numGenes = numGenes;
obj.k = k;
obj.p = p;
obj.bandwidth = bandwidth;
obj.Ttable = Ttable;
obj.varF = varF;
obj.outCells = outCells;
obj.inCells = inCells;
obj.perturb = perturb;
end
end
function thisCell = setPos(thisCell, cellPos)
thisCell.cellPos = cellPos;
end
function setState(thisCell, state, timestep)
%Used to set the initial state
thisCell.states(:,timestep) = state;
end
function perturb_genes(thisCell, timestep)
%------------ Perturbation Update for all cells -------------%
perturbProb = thisCell.perturb;
% Add gamma
newRand = rand;
if ((1-(1-perturbProb)^(thisCell.numGenes)) > newRand);
% Creating the perturbation gamma array
gamma = zeros(1, thisCell.numGenes);
for gene = 1:length(gamma)
r = rand;
if (perturbProb > rand)
gamma(gene) = 1;
else
% do nothing
end
end
thisCell.states(:,timestep) = mod(thisCell.states(:,timestep)+gamma',2);
else
% No perturbation
end
end
function page_rank(thisCell, timestep)
%------------ Page Rank Update for all cells -------------%
thisCell.states(:,timestep) = randi([0,1],thisCell.numGenes,1);
end
function update_genes(thisCell,timestep)
%-------------- Boolean update for all cells ------------%
for genecol = 1:thisCell.numGenes
tempVarf = [];
for generow = 1:size(thisCell.varF,1)
if (thisCell.varF(generow, genecol) == -1)
% do nothing
else
%This is the list of nodes we will be making
% connections to
tempVarf = [tempVarf, thisCell.varF(generow,genecol)];
end
end
if (isempty(tempVarf) == 0)
wiringnode = 0;
for wire = 1:length(tempVarf)
% The wiring of input nodes to compute
% thisCell's state at t+1
wiringnode = wiringnode + 2^(length(tempVarf)-wire) * thisCell.states(tempVarf(wire),timestep-1);
end
thisCell.states(genecol,timestep) = thisCell.Ttable(wiringnode+1, genecol);
end
end
end
end
end