Home > pathway > trimPathway.m

trimPathway

PURPOSE ^

trimPathway

SYNOPSIS ^

function pathway=trimPathway(pathway, rxnsToKeep, deleteUnconnectedMets)

DESCRIPTION ^

 trimPathway
   Delete reactions from a pathway object

   pathway                   map structure as generated by 
                             constructPathwayFromCelldesigner
   rxnsToKeep                cell array with the IDs of the reactions to
                             keep
   deleteUnconnectedMets     delete metabolites that are no longer connected
                             by any reactions (opt, default true)

     pathway                   an updated pathway object

   Usage: pathway=trimPathway(pathway, rxnsToKeep, deleteUnconnectedMets)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function pathway=trimPathway(pathway, rxnsToKeep, deleteUnconnectedMets)
0002 % trimPathway
0003 %   Delete reactions from a pathway object
0004 %
0005 %   pathway                   map structure as generated by
0006 %                             constructPathwayFromCelldesigner
0007 %   rxnsToKeep                cell array with the IDs of the reactions to
0008 %                             keep
0009 %   deleteUnconnectedMets     delete metabolites that are no longer connected
0010 %                             by any reactions (opt, default true)
0011 %
0012 %     pathway                   an updated pathway object
0013 %
0014 %   Usage: pathway=trimPathway(pathway, rxnsToKeep, deleteUnconnectedMets)
0015 
0016 if nargin<3
0017     deleteUnconnectedMets=true;
0018 end
0019 
0020 %First find the aliases and indexes of all reactions that should be deleted
0021 indexesToDelete=false(numel(pathway.listOfSpecies),1);
0022 aliasesToDelete={};
0023 
0024 for i=1:numel(pathway.listOfSpecies)
0025     if strcmpi(pathway.listOfSpecies(i).type,'PROTEIN')
0026         %Check if the name is in the list of reactions to delete
0027         if ~ismember(pathway.listOfSpecies(i).name,rxnsToKeep)
0028             indexesToDelete(i)=true;
0029             aliasesToDelete=[aliasesToDelete;pathway.listOfSpecies(i).alias];
0030         end
0031     end
0032 end
0033 
0034 %Then go through each of the reactions and delete the ones that only have
0035 %modifiers that are in the aliasesToDelete list
0036 rxnsToDelete=false(numel(pathway.listOfReactions),1);
0037 
0038 for i=1:numel(pathway.listOfReactions)
0039     %Keeps track of which components to delete. -1=enzyme to delete,
0040     %0=metabolite, 1=enzyme to keep
0041     componentsToDelete=zeros(numel(pathway.listOfReactions(i).componentList),1);
0042     for j=1:numel(pathway.listOfReactions(i).componentList)
0043         if strcmpi(pathway.listOfReactions(i).componentList(j).type,'ENZYME')
0044             %If the enzyme alias is not in the list then should it not be
0045             %deleted
0046             if ismember(pathway.listOfReactions(i).componentList(j).alias,aliasesToDelete)
0047                 componentsToDelete(j)=-1;
0048             else
0049                 componentsToDelete(j)=1;
0050             end
0051         end
0052     end
0053     %If all enzymes should be deleted then should the whole reacction be
0054     %deleted. Otherwise only delete those enzymes
0055     if ~any(componentsToDelete==1)
0056         rxnsToDelete(i)=true;
0057     else
0058         pathway.listOfReactions(i).componentList(componentsToDelete==-1)=[];
0059     end
0060 end
0061 
0062 %Delete the reactions and components that should be deleted
0063 pathway.listOfSpecies(indexesToDelete)=[];
0064 pathway.listOfReactions(rxnsToDelete)=[];
0065 
0066 %This is not neat but it goes through all the reactions and adds the
0067 %aliases that should be kept. All other are deleted
0068 aliasesToKeeep={};
0069 if deleteUnconnectedMets==true
0070     for i=1:numel(pathway.listOfReactions)
0071         for j=1:numel(pathway.listOfReactions(i).componentList)
0072             aliasesToKeeep=[aliasesToKeeep;pathway.listOfReactions(i).componentList(j).alias];
0073         end
0074     end
0075     
0076     %Go through the species again and only keep those that are in the
0077     %aliasesToKeeep list
0078     indexesToDelete=true(numel(pathway.listOfSpecies),1);
0079     for i=1:numel(pathway.listOfSpecies)
0080         if ismember(pathway.listOfSpecies(i).alias,aliasesToKeeep)
0081             indexesToDelete(i)=false;
0082         end
0083     end
0084     
0085     pathway.listOfSpecies(indexesToDelete)=[];
0086 end
0087 end

Generated by m2html © 2005