forked from BIMIB-DISCo/scFBA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getDataScored.m
75 lines (70 loc) · 2.21 KB
/
getDataScored.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
function [datasetRAS] = getDataScored(model, GeneList, TranscData, ColName, parallel)
% Compute RAS with a dataset as input.
%
% USAGE:
%
% [datasetRAS] = getDataScored(model, GeneList, TranscData, ColName, parallel)
%
%
% INPUT:
% model: metabolic model in COBRA format
% GeneList: vector with genes identifier in the same order of TranscData
% TranscData: Dataset genes x sampleas with expression levels.
% Genes must be sorted as GeneList
%
% OPTIONAL INPUTS:
% ColName: Identifier for each samples.
% parallel: TRUE for use parallel toolbox to speed up the function.
% FALSE otherwise. (Default = TRUE)
%
%
% OUTPUTS:
% datasetRAS: Dataset reactions x samples with RAS for each reaction.
% Nan if there is not a rule associated to that reaction
% or all genes have nan as expression level value.
%
%
% .. Author:
% - Davide Maspero 30/01/2018
[~, OrdModGen] = ismember(model.genes, GeneList);
GeneList = GeneList(OrdModGen);
TranscData = TranscData(OrdModGen, :);
nRxn = length(model.rxns);
nSam = size(TranscData, 2);
datasetRAS = table();
vettScore = zeros(nRxn,1);
datasetRAS.Reaction = model.rxns;
AllRules = model.rules;
h = waitbar(0,'Data computed: 0%', 'Name','RAS computing');
for k=1:nSam
TranscData_k = TranscData(:,k);
if parallel
parfor i=1:nRxn
if(strcmp(AllRules(i),''))
Coeff = NaN;
else
rules = AllRules{i};
Coeff = getScore(rules, TranscData_k);
end
vettScore(i) = Coeff;
end
else
for i=1:nRxn
if(strcmp(AllRules(i),''))
Coeff = NaN;
else
rules = AllRules{i};
Coeff = getScore(rules, TranscData_k);
end
vettScore(i) = Coeff;
end
end
if nargin < 4
datasetRAS.(strcat('Var',num2str(k))) = vettScore;
else
datasetRAS.(ColName{k}) = vettScore;
end
waitbar(k/nSam,h,strcat({'Progress: '}, num2str(k/nSam*100, 3), '%'), 'Name','RAS computing');
end
close(h);
end