Location: cellLib @ 0f94d0bdf02a / Scripts / updateVIO.m

Author:
WeiweiAi <wai484@aucklanduni.ac.nz>
Date:
2022-05-16 13:04:54+12:00
Desc:
Add a merge script and update accordingly
Permanent Source URI:
https://models.physiomeproject.org/workspace/6bc/rawfile/0f94d0bdf02afd16ebe8651a92628c98334ddb1f/Scripts/updateVIO.m

function comp=updateVIO(comp,idx)
cmnames=string(extractfield(comp,'name'));%unique
if length(cmnames)>length(unique(cmnames))
    disp('There are repetitions of component names')
    return
end
ncomp=length(cmnames);
for i=1:ncomp
    vars=comp(i).vars;
    init=vars(:,idx.init);
    pub=vars(:,idx.pub);
    priv=vars(:,idx.priv);
    init = replace(init,"none","");
    pub = replace(pub,"none","");
    priv = replace(priv,"none","");
    firstcomma=strings(length(init),1);
    sedcomma=firstcomma;
    bracket1=firstcomma;
    bracket2=firstcomma;
    
    idxcheck=any([(~(init=="")),(~(pub=="")),(~(priv==""))],2);
    check=find(idxcheck,1);
    if ~isempty(check)
        bracket1(idxcheck,1)="{";
        bracket2(idxcheck,1)="}";
    else
        return
    end
    
    idxcheck=~(init=="");
    check=find(idxcheck,1);
    if ~isempty(check)
        init(idxcheck,1)="init: "+init(idxcheck,1);
        if ~isempty(find(any([(~(pub(idxcheck)=="")),(~(priv(idxcheck)==""))],2),1))
            firstcomma(idxcheck,1)=", ";
        end
    end
    
    idxcheck=~(pub=="");
    check=find(idxcheck,1);
    if ~isempty(check)
        pub(idxcheck,1)="pub: "+pub(idxcheck,1);
    end
    
    idxcheck=~(priv=="");
    check=find(idxcheck,1);
    if ~isempty(check)
        priv(idxcheck,1)="priv: "+priv(idxcheck,1);
        if ~isempty(find(any([(~(pub(idxcheck)=="")),(~(init(idxcheck)==""))],2),1))
            sedcomma(idxcheck,1)=", ";
        end
    end
    
    vio=bracket1+init+firstcomma+pub+sedcomma+priv+bracket2;
    comp(i).vars(:,idx.vio)=vio;
end

end