forked from opencobra/cobratoolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
findRxnsFromGenes.m
117 lines (105 loc) · 3.4 KB
/
findRxnsFromGenes.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
function [results ListResults] = findRxnsFromGenes(model, genes, humanFlag,ListResultsFlag)
%findRxnsFromGenes print every reaction associated with a gene of interest
%
% [results ListResults] = findRxnsFromGenes(model, genes, humanFlag,ListResultsFlag)
%
%INPUTS
% model COBRA model structure
% genes string of single gene or cell array of multiple
% genes for which rxns are desired.
%
%OPTIONAL INPUTS
% humanFlag 1 if using Human Recon (Default = 0)
% ListResultsFlag 1 if you want to output ListResults (Default = 0)
%
%OPUTPUTS
% results structure containing cell arrays for each gene.
% Each cell array has one column of rxn abbreviations
% and one column containing the reaction formulae
% ListResults same as above, but in a cell array
%
% by Nathan Lewis 02/16/08
% edited 04/05/09 (MUCH faster now -- NL)
% edited 06/11/10 (yet even faster now -- NL)
if nargin< 3
humanFlag = 0;
ListResultsFlag = 0;
end
if ~iscell(genes)
gene = genes;
clear genes
genes{1} = gene;
clear gene
end
if iscell(genes{1})
for i = 1:length(genes)
gene(i) = genes{i};
end
clear genes
genes = gene;
clear gene
end
model.genes = regexprep(model.genes,'-','_DASH_');
model.genes = regexprep(model.genes,'\.','_POINT_');
genes = regexprep(genes,'-','_DASH_');
genes = regexprep(genes,'\.','_POINT_');
%find where the genes are located in the rxnGeneMat
GeneID(1) = 0;
for j = 1:length(genes)
Ind = find(~cellfun('isempty', regexp(model.genes,cat(2,'^',genes{j},'$'))));
if ~isempty(Ind)
GeneID(j) = Ind;
end
end
if min(GeneID) == 0
warning('A gene was not found in the model!')
results = struct([]);
if max(GeneID) ==0,results = struct([]);ListResults = {};
return
end
Ind = find(GeneID==0);
GeneID(Ind) = [];
genes(Ind) = [];
end
results = struct([]);
for i = 1:length(GeneID)
k=1;
Ind_rxns = find(model.rxnGeneMat(:,GeneID(i))==1);
for j=1:length(Ind_rxns)
% if model.rxnGeneMat(j,GeneID(i))==1
if isempty(results)
results = struct;
end
if humanFlag == 1
tempGene = cat(2,'gene_',genes{i});
else tempGene = genes{i};
end
results.(tempGene){k,1} = model.rxns(Ind_rxns(j));
results.(tempGene)(k,2) = printRxnFormula(model,model.rxns(Ind_rxns(j)),0);
if isfield(model,'subSystems')
results.(tempGene)(k,3) = model.subSystems(Ind_rxns(j));
end
if isfield(model,'rxnNames')
results.(tempGene){k,4} = model.rxnNames{Ind_rxns(j)};
end
k=k+1;
% end
end
end
ListResults = {};
if isempty(results)
warning('Your gene was not associated with any reactions!')
ListResults = {};
else
if ListResultsFlag ==1
tmp = fieldnames(results);
for i = 1:length(tmp)
tmp2 = results.(tmp{i});
ListResults(end+1:end+length(tmp2(:,1)),1:4) = tmp2;
ListResults(end-length(tmp2(:,1))+1:end,5) = tmp(i);
end
for j = 1:length(ListResults(:,1))
ListResults(j,1) = ListResults{j,1};
end
end
end