Home > RAVEN > 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)

   Rasmus Agren, 2010-12-16

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 %   Rasmus Agren, 2010-12-16
0017 %
0018 
0019 if nargin<3
0020     deleteUnconnectedMets=true;
0021 end
0022 
0023 %First find the aliases and indexes of all reactions that should be deleted
0024 indexesToDelete=false(numel(pathway.listOfSpecies),1);
0025 aliasesToDelete={};
0026 
0027 for i=1:numel(pathway.listOfSpecies)
0028    if strcmpi(pathway.listOfSpecies(i).type,'PROTEIN')
0029       %Check if the name is in the list of reactions to delete
0030       if ~ismember(pathway.listOfSpecies(i).name,rxnsToKeep)
0031           indexesToDelete(i)=true;
0032           aliasesToDelete=[aliasesToDelete;pathway.listOfSpecies(i).alias];
0033       end
0034    end
0035 end
0036 
0037 %Then go through each of the reactions and delete the ones that only have
0038 %modifiers that are in the aliasesToDelete list
0039 rxnsToDelete=false(numel(pathway.listOfReactions),1);
0040 
0041 for i=1:numel(pathway.listOfReactions)
0042     %Keeps track of which components to delete. -1=enzyme to delete, 0=metabolite,
0043     %1=enzyme to keep
0044     componentsToDelete=zeros(numel(pathway.listOfReactions(i).componentList),1);
0045     for j=1:numel(pathway.listOfReactions(i).componentList)
0046         if strcmpi(pathway.listOfReactions(i).componentList(j).type,'ENZYME')
0047             %If the enzyme alias is not in the list then should it not be
0048             %deleted
0049             if ismember(pathway.listOfReactions(i).componentList(j).alias,aliasesToDelete)
0050                 componentsToDelete(j)=-1;
0051             else
0052                 componentsToDelete(j)=1;
0053             end
0054         end
0055     end
0056     %If all enzymes should be deleted then should the whole reacction be
0057     %deleted. Otherwise only delete those enzymes
0058     if ~any(componentsToDelete==1)
0059         rxnsToDelete(i)=true;
0060     else
0061         pathway.listOfReactions(i).componentList(componentsToDelete==-1)=[];
0062     end
0063 end
0064 
0065 %Delete the reactions and components that should be deleted
0066 pathway.listOfSpecies(indexesToDelete)=[];
0067 pathway.listOfReactions(rxnsToDelete)=[];
0068 
0069 %This is not neat but it goes through all the reactions and adds the
0070 %aliases that should be kept. All other are deleted
0071 aliasesToKeeep={};
0072 if deleteUnconnectedMets==true
0073     for i=1:numel(pathway.listOfReactions)
0074        for j=1:numel(pathway.listOfReactions(i).componentList)
0075            aliasesToKeeep=[aliasesToKeeep;pathway.listOfReactions(i).componentList(j).alias];
0076        end
0077     end
0078     
0079     %Go through the species again and only keep those that are in the
0080     %aliasesToKeeep list
0081     indexesToDelete=true(numel(pathway.listOfSpecies),1);
0082     for i=1:numel(pathway.listOfSpecies)
0083         if ismember(pathway.listOfSpecies(i).alias,aliasesToKeeep)
0084             indexesToDelete(i)=false;
0085         end
0086     end
0087     
0088     pathway.listOfSpecies(indexesToDelete)=[];
0089 end
0090 
0091

Generated on Mon 06-Jan-2014 14:58:12 by m2html © 2005