Skip to content

Commit 487c890

Browse files
authored
Merge pull request #100 from netZoo/devel
Devel
2 parents 3608481 + 5f75d79 commit 487c890

File tree

10 files changed

+3112
-5
lines changed

10 files changed

+3112
-5
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Macos[![MAC](https://travis-ci-job-status.herokuapp.com/badge/netZoo/netZooM/mas
1111
netZooM is a MATLAB package of network methods.
1212

1313
## Zoo animals
14-
(gpu)PANDA, (gpu)LIONESS, PUMA, SPIDER, and optPANDA.
14+
(gpu)PANDA, (gpu)LIONESS, PUMA, SPIDER, optPANDA, and OTTER.
1515

1616
## Quick guide
1717
`git clone https://github.com/netZoo/netZooM.git` into your local disk.

netZooM/lioness/lioness_run.m

+4-3
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,13 @@ function lioness_run(exp_file, motif_file, ppi_file, panda_file, save_dir,...
112112
if isequal(computing,'gpu')
113113
parpool(gpuDeviceCount);
114114
parfor i = indexes
115-
ExpGPU = Exp;
115+
ExpGPU = gpuArray(Exp);
116116
fprintf('Running LIONESS for sample %d:\n', i);
117117
idx = [1:(i-1), (i+1):NumConditions]; % all samples except i
118118

119-
disp('Computing coexpresison network:');
119+
disp('Computing coexpression network:');
120120
tic; GeneCoReg = Coexpression(ExpGPU(idx,:)); toc;
121+
GeneCoReg = gather(GeneCoReg);
121122

122123
disp('Normalizing Networks:');
123124
tic; GeneCoReg = NormalizeNetwork(GeneCoReg); toc;
@@ -134,7 +135,7 @@ function lioness_run(exp_file, motif_file, ppi_file, panda_file, save_dir,...
134135
fprintf('Running LIONESS for sample %d:\n', i);
135136
idx = [1:(i-1), (i+1):NumConditions]; % all samples except i
136137

137-
disp('Computing coexpresison network:');
138+
disp('Computing coexpression network:');
138139
tic; GeneCoReg = Coexpression(Exp(idx,:)); toc;
139140

140141
disp('Normalizing Networks:');

netZooM/otter/otter.m

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
function W = otter(W,P,C,lambda,gamma,Imax,eta)
2+
% Description:
3+
% OTTER infers gene regulatory networks using TF DNA binding
4+
% motif (W), TF PPI (P), and gene coexpression (C) through
5+
% minimzing the following objective:
6+
% min f(W)
7+
% with f(W) = (1-lambda)*||WW' - P||^2 + lambda*||W'W - C||^2 + (gamma/2)*||W||^2
8+
%
9+
% Inputs:
10+
% W : TF-gene regulatory network based on TF motifs as a
11+
% matrix of size (t,g), g=number of genes, t=number of TFs
12+
% P : TF-TF protein interaction network as a matrix of size (t,t)
13+
% C : gene coexpression as a matrix of size (g,g)
14+
% lambda: tuning parameter in [0,1] (higher gives more weight to C)
15+
% gamma : regularization parameter
16+
% Imax : number of iterations of the algorithm
17+
% eta : learning rate
18+
% bexp : exponent influencing learning rate (higher means smaller)
19+
%
20+
%
21+
% Outputs:
22+
% W : Predicted TF-gene complete regulatory network as an adjacency matrix of size (t,g).
23+
%
24+
% Authors:
25+
% Rebekka Burkholz 4/2020
26+
27+
%global parameters
28+
if nargin<4
29+
lambda = 0.0035;
30+
end
31+
if nargin<5
32+
gamma = 0.335;
33+
end
34+
if nargin<6
35+
Imax = 300;
36+
end
37+
if nargin<7
38+
eta = 0.00001;
39+
end
40+
%ADAM parameters
41+
b1 = 0.9;
42+
b2 = 0.999;
43+
eps = 0.00000001;
44+
%initial transformation
45+
C = C/trace(C);
46+
P = P/trace(P) + 0.0013;
47+
W = P*W;
48+
W = W/sqrt(trace(W*W'));
49+
50+
[t, g] = size(W);
51+
m = zeros(t, g);
52+
v = m;
53+
b1t = b1;
54+
b2t = b2;
55+
%To save computations:
56+
P = -P*(1-lambda) + gamma*eye(t);
57+
C = -C*lambda;
58+
%ADAM gradient descent
59+
for i = 1:Imax
60+
%gradient
61+
grad = (P*W + W*C + W*W'*W);
62+
m = b1*m + ((1-b1)*4)*grad;
63+
v = b2*v + ((1-b2)*16)*grad.^2;
64+
b1t = b1t*b1;
65+
b2t = b2t*b2;
66+
alpha = sqrt(1-b2t)/(1-b1t)*eta;
67+
epst = eps*sqrt((1-b2t));
68+
%update of gene ragulatory matrix
69+
W = W - alpha*(m./(epst+sqrt(v)));
70+
end
71+
end

netZooM/panda/panda_run.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
% 1 saves memory on the GPU (slower)
6767
%
6868
% Outputs:
69-
% AgNet : Predicted TF-gene gene complete regulatory network using PANDA as a matrix of size (t,g).
69+
% AgNet : Predicted TF-gene complete regulatory network using PANDA as a matrix of size (t,g).
7070
%
7171
% Authors:
7272
% cychen, marieke, kglass

netZooM/tools/gpuPANDA.m

+1
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@
209209
runtime = toc;
210210
if isequal(computing,'gpu')
211211
RegNet=gather(RegNet);
212+
gpuDevice(1);%Clear GPU device memory
212213
end
213214
fprintf('Running PANDA on %d Genes and %d TFs took %f seconds!\n', NumGenes, NumTFs, runtime);
214215
end

tests/testOtter.m

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
function test_suite=testOtter()
2+
initTestSuite;
3+
end
4+
5+
function testOtterSimple()
6+
% Tell if this is Octave (Unit tests) or Matlab
7+
isOctave = exist('OCTAVE_VERSION', 'builtin') ~= 0;
8+
9+
% Load statistics package from Octave
10+
if isOctave
11+
%we need the nan package because it has a fast implementation of corrcoeff
12+
%pkg load statistics
13+
pkg load nan;
14+
end
15+
16+
% Set Program Parameters
17+
generatePriors=0;
18+
if generatePriors==1
19+
exp_file = 'test_data/expression.txt';
20+
motif_file = 'test_data/motifTest.txt';
21+
ppi_file = 'test_data/ppi.txt';
22+
[Exp,RegNet,TFCoop,TFNames,GeneNames]=processData(exp_file,motif_file,ppi_file,'intersection');
23+
tic; GeneCoReg = Coexpression(Exp); toc;
24+
csvwrite('c.csv',GeneCoReg);
25+
csvwrite('p.csv',TFCoop);
26+
csvwrite('w.csv',RegNet);
27+
elseif generatePriors==0
28+
C=csvread('tests/test_data/otter/c.csv');
29+
P=csvread('tests/test_data/otter/p.csv');
30+
W=csvread('tests/test_data/otter/w.csv');
31+
end
32+
33+
% Add path
34+
addpath(genpath(fullfile(pwd,'tests')));
35+
36+
% Call Otter
37+
Imax=1;
38+
lambda = 0.0035;
39+
gamma = 0.335;
40+
tic;W = otter(W,P,C,lambda,gamma,Imax);toc;
41+
42+
% Load the expected result
43+
filename = 'tests/test_data/otter/test_otter.csv';
44+
W_test = csvread(filename);
45+
46+
% Compare the outputs
47+
tolMat =1e-6;
48+
deltaMat=max(max(abs(W-W_test)));
49+
assertTrue( deltaMat < tolMat );
50+
51+
end

tests/test_data/otter/c.csv

+1,000
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)