Location: SinglePASMC @ 4d9f1500c38c / Components / assembleModel.m

Author:
WeiweiAi <wai484@aucklanduni.ac.nz>
Date:
2022-04-14 19:02:38+12:00
Desc:
update Lib; add models
Permanent Source URI:
https://staging.physiomeproject.org/workspace/83f/rawfile/4d9f1500c38c05427831e95e102c318d45f89d4c/Components/assembleModel.m

clear
addpath(genpath('../cellLib/Scripts/'))
file='Vars.csv';
% build new components from the .csv
comp_dir=pwd;

filename='PASMC.cellml';
compRead=readComp(filename);
[comp,idx]=newComp([comp_dir filesep file]);
txtfiles=[];

% copy the existing components if need
% read the existing model and get the existing components
%comp=copyComp(comp,listComp,idx);

% Encapsuate new components
encap=["Cai"];
chdname=["JVOCCi","JNCXi","JSERCAi","JCICRi","JPMCAi","Jleaki"];
labels=cell(length(chdname),1);
chd={};
for i=1:length(chdname)
    chd(i).name= chdname(i);
    chd(i).def= chdname(i);
    chd(i).label=labels{i,1};
end
comp=encapNew(comp,encap,chd,idx);

encap=["Casr"];
chdname=["JSERCAi","JCICRi","Jleaki"];
labels=cell(length(chdname),1);
chd={};
for i=1:length(chdname)
    chd(i).name= chdname(i);
    chd(i).def= chdname(i);
    chd(i).label=labels{i,1};
end
comp=encapNew(comp,encap,chd,idx);

encap=["Vm"];
chdname=["JNKA","JCli","JVOCCi","JNCXi","JKi"];
labels=cell(length(chdname),1);
chd={};
for i=1:length(chdname)
    chd(i).name= chdname(i);
    chd(i).def= chdname(i);
    chd(i).label=labels{i,1};
end
comp=encapNew(comp,encap,chd,idx);

comp=getPara(comp,idx);
comp=updateVIO(comp,idx);
% Add equations to components
Eqs=["J_VOCCi=G_Ca*((v_Ca1-v_i)/(1{dimensionless}+exp((v_Ca2-v_i)/R_Ca)));",...
    "J_NCXi=G_NCX*(c_i/(c_i+c_NCX))*(v_NCX-v_i);",...
    "J_SERCAi=B*(pow(c_i,2{dimensionless})/(pow(c_i,2{dimensionless})+pow(c_b,2{dimensionless})));",...
    "J_CICRi=C*(pow(s_i,2{dimensionless})/(pow(s_i,2{dimensionless})+pow(s_c,2{dimensionless})))*(pow(c_i,4{dimensionless})/(pow(c_i,4{dimensionless})+pow(c_c,4{dimensionless})));",...
    "J_PMCAi=D*c_i*(1{dimensionless}+(v_i-v_d)/(R_d));",...
    "J_leaki=L*s_i;",...
    "J_NKA=C_NKA*(K_out/(K_mK+K_out));",...
    "J_Cli=G_Cl*(v_i-v_Cl);",...
    "J_Ki=G_Ki*w_i*(v_i-v_K);",...
    "ode(w_i,t)=lambda*(K_activationi-w_i);",...
    "ode(c_i,t)=J_VOCCi-J_NCXi-J_SERCAi+J_CICRi-J_PMCAi+J_leaki;",...
    "ode(s_i,t)=J_SERCAi-J_CICRi-J_leaki;",...
    "ode(v_i,t)=gamma*(-J_NKAi-J_Cli+2{dimensionless}*J_VOCCi+J_NCXi-J_Ki);"];

for i=1:8
    comp(i).Eqs=Eqs(i);
end
comp(9).Eqs=Eqs(9:10);
for i=10:12
    comp(i).Eqs=Eqs(i+1);
end

% Build models
cmnames=string(extractfield(comp,'name'));
modelnames=cmnames([1:9,13]);
listComp={};
labels=cell(length(modelnames),1);

for i=1:length(modelnames)
    modelname=modelnames(i);
    listComp.name=modelname;
    listComp.def=modelname;
    listComp.from="";
    listComp.impComp="";
    listComp.defaultVars="Y";
    listComp.label=labels{i,1};
    listMap=strings(0,2);
    model=buildModel(modelname,comp,listComp,listMap,idx);
    modelfile=strcat(modelname,'.txt');
    txtfiles=[txtfiles,modelfile];
    writeModel(model,comp,modelfile,idx)
end

modelname="PASMC";
parentnames=cmnames(10:12);
nm=0;
listComp={};
labels={};
listMap=strings(0,2);
chd=[];
for n=1:length(parentnames)
  icomp=comp(cmnames==parentnames(n));
  chd=[chd;icomp.children];  
end
uni_chd=unique(chd);

for m=1:length(uni_chd)
    ichd=uni_chd(m);   
    listComp(m).name=ichd;
    listComp(m).def=ichd;
    listComp(m).from=strcat(ichd,".cellml");
    listComp(m).impComp=ichd;
    listComp(m).defaultVars="Y";
    listComp(m).label=[]; 
end

for n=1:length(parentnames)
icomp=comp(cmnames==parentnames(n));
chd=icomp.children;
for i=1:length(chd)   
    nm=nm+1;
    ichd=chd(i);    
    listMap(nm,:)=[parentnames(n),ichd];
end
m=m+1;
listComp(m).name=parentnames(n);
listComp(m).def=parentnames(n);
listComp(m).from="";
listComp(m).impComp="";
listComp(m).defaultVars="Y";
listComp(m).label=[];
end
model=buildModel(modelname,comp,listComp,listMap,idx);
modelfile=strcat(modelname,'.txt');
txtfiles=[txtfiles,modelfile];
writeModel(model,comp,modelfile,idx)