Skip to content

Commit 65a22f1

Browse files
committed
Update and Bugfixes on arImportPEtab
1 parent b32fbe1 commit 65a22f1

File tree

3 files changed

+42
-18
lines changed

3 files changed

+42
-18
lines changed

arFramework3/ImportExport/arImportPEtab.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ function arImportPEtab(PEtabName, doPreEq, model, dataFolder, dataFilenames)
7575
if ~exist(dataFolder, 'dir') % Check if folder does not exist
7676
mkdir(dataFolder); % Create folder
7777
end
78-
dataFilenames = arWriteDataFromPEtab(PEtabName, dataFolder);
78+
dataFilenames = writeDataFromPEtab(PEtabName, dataFolder);
7979
elseif (exist('dataFolder','var') || ~isempty(dataFolder)) & (~exist('dataFilenames','var') || isempty(dataFilenames))
8080
files = dir(fullfile(dataFolder, '*.xls'));
8181
dataFilenames = arrayfun(@(f) f.name(1:end-4), files, 'UniformOutput', false);
8282
elseif (exist('dataFolder','var') || ~isempty(dataFolder)) & (exist('dataFilenames','var') || ~isempty(dataFilenames))
83-
files = dir(fullfile(dataFolder, dataFilenames,[strrep(PEtabName,'.xls','') '.xls']));
84-
dataFilenames = arrayfun(@(f) f.name(1:end-4), files, 'UniformOutput', false);
83+
dataFilenames = fullfile(dataFolder,strrep(dataFilenames,'.xls',''));
84+
dataFilenames = cellfun(@(x) dir([x, '.def']), dataFilenames, 'UniformOutput', false);
8585
end
8686

8787
%%
@@ -113,8 +113,11 @@ function arImportPEtab(PEtabName, doPreEq, model, dataFolder, dataFilenames)
113113
arLoadModel(modelname);
114114
splitedFilenames = split(dataFilenames,filesep);
115115
for i=1:length(dataFilenames)
116-
arLoadData(char(splitedFilenames(1,i,2)),[],[],[],'DataPath',char(splitedFilenames(1,i,1)));
116+
arLoadData(char(splitedFilenames(1,i,2)),[],[],[],'DataPath',char(splitedFilenames(1,i,1)));
117117
end
118+
% for i=1:length(dataFilenames)
119+
% arLoadData(dataFilenames{i}.name,[],[],[],'DataPath',dataFilenames{i}.folder);
120+
% end
118121
arCompileAll;
119122
ar.config.fiterrors = 1;
120123
arLoadParsPEtab(PEparas);
@@ -195,6 +198,8 @@ function arImportPEtab(PEtabName, doPreEq, model, dataFolder, dataFilenames)
195198
% end
196199
% end
197200

201+
arSave(ar.info.name)
202+
198203
end
199204

200205
function [out,numberOfEls] = extractFromStruct(struct, field)

arFramework3/ImportExport/arWriteDataFromPEtab.m renamed to arFramework3/ImportExport/writeDataFromPEtab.m

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
% ToDo:
2-
% \tC\tau\tconc.\t1\t1\t etc
3-
% num2str(max(time)*1.2)
1+
function dataFilenames = writeDataFromPEtab(yamlFile, savePath)
2+
% writeDataFromPEtab(yamlFile, savePath)
3+
%
4+
% This function reads the PEtab files and writes the data to excel (.xls) files and creates the corresponding .def files for each simulation condition.
5+
%
6+
% Inputs:
7+
% yamlFile: string, name of the yaml file in the PEtab folder. If not specified, the function will look for a .yaml file in the PEtab folder. Multiple .yaml files are not allowed.
8+
% savePath: string, path to the folder where the data files should be saved. [default: 'DataPEtab']
9+
%
10+
% Outputs:
11+
% dataFilenames: cell array of strings, filenames of the data files
12+
%
413

5-
function dataFilenames = arWriteDataFromPEtab(yamlFile, savePath)
614

715
%% Filenames
816
if ~exist('yamlFile','var') || isempty(yamlFile)
@@ -97,15 +105,18 @@
97105
end
98106

99107
% only the observableIDs that have uniqueSimConds{i} in their name
100-
observableIdCond = unique(Tdat.observableId(contains(Tdat.observableId, uniqueSimConds{i}))); % find all occurences of uniqueSimConds{i} in observableIds
101-
observableId = regexprep(observableIdCond, ['_',uniqueSimConds{i}],'');
108+
%observableIdCond = unique(Tdat.observableId(contains(Tdat.observableId, uniqueSimConds{i}))); % find all occurences of uniqueSimConds{i} in observableIds
109+
%observableId = regexprep(observableIdCond, ['_',uniqueSimConds{i}],'');
110+
111+
% find observabeles that of simulationConditionId
112+
observableId = unique(Tdat.observableId(contains(Tdat.simulationConditionId, uniqueSimConds{i})));
102113

103-
ind = find(contains(Tdat.observableId, uniqueSimConds{i}));
114+
ind = find(contains(Tdat.simulationConditionId, uniqueSimConds{i}));
104115
timeUni = unique(Tdat.time(ind));
105116
timeMax = [timeUni, NaN(length(timeUni),1)];
106117

107-
for o = 1:length(observableIdCond)
108-
indObs = find(Tdat.observableId == observableIdCond{o});
118+
for o = 1:length(observableId)
119+
indObs = intersect(find(Tdat.observableId == observableId{o}),ind); % observableID and simulationConditionId
109120
tObs = Tdat.time(indObs);
110121

111122
% Compute unique values and counts
@@ -132,8 +143,8 @@
132143
T.(char(observableId(o))) = NaN(length(time), 1); % Fill with NaN for now
133144
end
134145

135-
for o=1:length(observableIdCond)
136-
indObs = find(Tdat.observableId == observableIdCond{o});
146+
for o=1:length(observableId)
147+
indObs = find(Tdat.observableId == observableId{o});
137148
for t = 1:length(indObs)
138149
% find all rows in T where T.time==Tdat.time(indObs(t))
139150
indT = find(T.time == Tdat.time(indObs(t)));
@@ -169,17 +180,21 @@
169180

170181
% Observables
171182
fprintf(fid, '\nOBSERVABLES\n');
172-
indObs = find(contains(Tobs.observableId, uniqueSimConds{i}));
183+
indObs = find(contains(Tobs.observableId, observableId));
173184
for j = 1:length(indObs)
174185
ind = indObs(j);
175-
fprintf(fid, [Tobs.observableName{ind},'\tC\tau\tconc.\t1\t1\t','"',Tobs.observableFormula{ind},'"\n']);
186+
if isfield(Tobs,'observableName')
187+
fprintf(fid, [Tobs.observableId{ind},'\tC\tau\tconc.\t1\t1\t','"',Tobs.observableFormula{ind},'"\t"',Tobs.observableName{ind},'"\n']);
188+
else
189+
fprintf(fid, [Tobs.observableId{ind},'\tC\tau\tconc.\t1\t1\t','"',Tobs.observableFormula{ind},'"\n']);
190+
end
176191
end
177192

178193
% Errors
179194
fprintf(fid, '\nERRORS\n');
180195
for j = 1:length(indObs)
181196
ind = indObs(j);
182-
fprintf(fid, [Tobs.observableName{ind},'\t','"',Tobs.noiseFormula{ind},'"\n']);
197+
fprintf(fid, [Tobs.observableId{ind},'\t','"',Tobs.noiseFormula{ind},'"\n']);
183198
end
184199

185200
% Conditions

arFramework3/arLoadData.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ function arLoadData(name, m, extension, removeEmptyObs, varargin)
102102

103103
global ar
104104

105+
% works also if .xls or .def fileaendings are used
106+
name = strrep(name,'.xls','');
107+
name = strrep(name,'.def','');
108+
105109
arFprintf( 3, 'Parsing input arguments...\n' );
106110

107111
if(isempty(ar))

0 commit comments

Comments
 (0)