Description of RxnAdjuster

Home > BiKEGG > RxnAdjuster.m

# RxnAdjuster

## PURPOSE

RxnAdjuster

## SYNOPSIS

function [OverlayMe,Allx4Arrow,Ally4Arrow] = RxnAdjuster(PostData,Mdl,RefID)

## DESCRIPTION

     RxnAdjuster
     is a subfunction of MapAdjuster for displaying reaction
     details on created maps by NetDraw.

     Inputs:
     PostData: All necessary data from NetDraw
     Mdl: COBRA model for which in silico simulations are performed.
     RefID: A string; 'bigg' or 'kegg'.

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

- MapAdjuster MapAdjuster(GUI)

## SOURCE CODE

    0001 function [OverlayMe,Allx4Arrow,Ally4Arrow] = RxnAdjuster(PostData,Mdl,RefID)
    0002 % RxnAdjuster
    0003 % is a subfunction of MapAdjuster for displaying reaction
    0004 % details on created maps by NetDraw.
    0005 %
    0006 % Inputs:
    0007 % PostData: All necessary data from NetDraw
    0008 % Mdl: COBRA model for which in silico simulations are performed.
    0009 % RefID: A string; 'bigg' or 'kegg'.
    0010
    0011 % O. Jamialahmadi
    0012 % TMU, Chem. Eng. Dept., Biotech. Group
    0013 % July 2016
    0014
    0015 Allx4Arrow = PostData.Allx4Arrow;
    0016 Ally4Arrow = PostData.Ally4Arrow;
    0017 field_intsect = PostData.field_intsect;
    0018 Idxs = PostData.field_intsect_overlay;
    0019 rxnCds = PostData.rxnCds;
    0020 [~,n2] = ismember(Idxs,field_intsect);
    0021 OrxnCds = rxnCds(n2);
    0022 ArXo = PostData.ArXo;
    0023 ArYo = PostData.ArYo;
    0024 RefOverlapData = PostData.RefOverlapData;
    0025 [~,Idx1,~] = unique(RefOverlapData);
    0026 Chck1 = setdiff(1:size(RefOverlapData,1),Idx1);
    0027
    0028 for m2 = 1:numel(Chck1)
    0029     WhrC = ismember(RefOverlapData,RefOverlapData{Chck1(m2)});
    0030     RedundantIdx = field_intsect(WhrC);
    0031     if any(ismember(Idxs,RedundantIdx))
    0032         if sum(ismember(Idxs,RedundantIdx)) < numel(RedundantIdx)
    0033             Allx4Arrow(WhrC) = {''}; Ally4Arrow(WhrC) = {''};
    0034             field_intsect(WhrC) = {''};
    0035             WhrAdd = find(ismember(Idxs,RedundantIdx));
    0036             for m3 = 1:numel(WhrAdd)
    0037                 Allx4Arrow{end+1} = ArXo{WhrAdd(m3)};
    0038                 Ally4Arrow{end+1} = ArYo{WhrAdd(m3)};
    0039                 field_intsect(end+1) = Idxs(WhrAdd(m3));
    0040             end
    0041         end
    0042     end
    0043 end
    0044 emrmv = ~cellfun('isempty',field_intsect);
    0045 Allx4Arrow = Allx4Arrow(emrmv);
    0046 Ally4Arrow = Ally4Arrow(emrmv);
    0047 field_intsect = field_intsect(emrmv); NewRefData = ({});
    0048 for i1 =1:numel(Allx4Arrow)
    0049     NewRefData{i1} = [num2str(numel(Allx4Arrow{i1})),',',...
    0050         num2str(mean(Allx4Arrow{i1})),',',num2str(numel(Ally4Arrow{i1})),',',...
    0051         num2str(mean(Ally4Arrow{i1}))];
    0052 end
    0053 [~,Idx1,~] = unique(NewRefData); clear WhrC
    0054 Chck1 = setdiff(1:size(NewRefData,2),Idx1);
    0055 [~,N2] = ismember(field_intsect,PostData.field_intsect);
    0056 switch RefID
    0057     case 'kegg'
    0058         OverlayMe = rxnCds(N2);
    0059     case 'bigg'
    0060         K1 = Mdl.B2Kegg.K;
    0061         B1 = Mdl.B2Kegg.B;
    0062         Chk = which('UniModelKEGG.mat');
    0063         if isempty(Chk)
    0064             msgbox({'UniModelKEGG.mat cannot be found!';...
    0065                 'Make sure the file is present in BiGG2KEGG folder'},'Error','error');
    0066             return
    0067         end
    0068         CRxns = getappdata(0,'CRxns');
    0069         OverlayMe = rxnCds(N2);
    0070         if ~isempty(CRxns) % Correct for consistent reaction correspondences
    0071             for cnter = 1:numel(CRxns.C)
    0072                 OverlayMe(ismember(OverlayMe,CRxns.C{cnter})) = ...
    0073                     CRxns.O(cnter);
    0074                 OrxnCds(ismember(OrxnCds,CRxns.C{cnter})) = ...
    0075                     CRxns.O(cnter);
    0076             end
    0077         end
    0078
    0079         Uni = load(which('UniModelKEGG.mat'));
    0080         K = Uni.B2Kegg.K;
    0081         B = Uni.B2Kegg.B;
    0082         for i1 = 1:numel(OverlayMe)
    0083             if any(strcmp(OverlayMe{i1},OrxnCds))
    0084                 WhrK = find(ismember(K1,OverlayMe{i1}));
    0085                 if isempty(WhrK)
    0086                     WhrK = find(ismember(K,OverlayMe{i1}));
    0087                     Tmpchk = B(WhrK);
    0088                 else
    0089                     Tmpchk = B1(WhrK);
    0090                 end
    0091             else
    0092                 WhrK = find(ismember(K,OverlayMe{i1}));
    0093                 Tmpchk = B(WhrK);
    0094             end
    0095             if isempty(WhrK)
    0096                 OverlayMe(i1) = {''};
    0097                 continue
    0098             end
    0099             if numel(WhrK)>1
    0100                 C1 = regexp(Tmpchk,'\w*p\>'); C1 = ~cellfun('isempty',C1);
    0101                 if sum(C1) < numel(Tmpchk)
    0102                     Tmpchk(C1) = [];
    0103                 end
    0104                 C1 = regexp(Tmpchk,'\w*copy\d\>'); C1 = ~cellfun('isempty',C1);
    0105                 if sum(C1) < numel(Tmpchk)
    0106                     Tmpchk(C1) = [];
    0107                 end
    0108                 C1 = regexp(Tmpchk,'\w*f\>'); C1 = ~cellfun('isempty',C1);
    0109                 if sum(C1) < numel(Tmpchk)
    0110                     Tmpchk(C1) = [];
    0111                 end
    0112                 C1 = regexp(Tmpchk,'\w*m\>'); C1 = ~cellfun('isempty',C1);
    0113                 if sum(C1) < numel(Tmpchk)
    0114                     Tmpchk(C1) = [];
    0115                 end
    0116                 C1 = regexp(Tmpchk,'ICDHhr'); C1 = ~cellfun('isempty',C1);
    0117                 if sum(C1) < numel(Tmpchk)
    0118                     Tmpchk(C1) = [];
    0119                 end
    0120             end
    0121             OverlayMe(i1) = Tmpchk(1);
    0122         end
    0123 end
    0124 Allx4Arrow = PostData.Allx4Arrow(N2);
    0125 Ally4Arrow = PostData.Ally4Arrow(N2);
    0126 overlayMetemp = OverlayMe;
    0127 for m2 = 1:numel(Chck1)
    0128     WhrC = find(ismember(NewRefData,NewRefData{Chck1(m2)}));
    0129     for m3 = 1:numel(WhrC)
    0130         OverlayMe{WhrC(m3)} = strjoin(overlayMetemp(WhrC),',');
    0131         if ~isempty(OverlayMe{WhrC(m3)})
    0132             if strcmp(OverlayMe{WhrC(m3)}(1),',')
    0133                 OverlayMe{WhrC(m3)}(1) = [];
    0134             end
    0135         end
    0136         if ~isempty(OverlayMe{WhrC(m3)})
    0137             if strcmp(OverlayMe{WhrC(m3)}(end),',')
    0138                 OverlayMe{WhrC(m3)}(end) = [];
    0139             end
    0140         end
    0141     end
    0142 end
    0143 [~,N1] = unique(OverlayMe);
    0144 OverlayMe = OverlayMe(N1); Allx4Arrow = Allx4Arrow(N1); Ally4Arrow = Ally4Arrow(N1);