001package org.biopax.paxtools.io.sif.level3; 002 003import org.apache.commons.logging.Log; 004import org.apache.commons.logging.LogFactory; 005import org.biopax.paxtools.io.sif.BinaryInteractionType; 006import org.biopax.paxtools.model.BioPAXElement; 007import org.biopax.paxtools.model.Model; 008import org.biopax.paxtools.model.level3.*; 009 010import java.util.Arrays; 011import java.util.List; 012import java.util.Map; 013 014import static org.biopax.paxtools.io.sif.BinaryInteractionType.INTERACTS_WITH; 015import static org.biopax.paxtools.io.sif.BinaryInteractionType.REACTS_WITH; 016 017/** 018 * Finds pairs of molecules that are participants of the same interaction for the INTERACTS_WITH 019 * type, and participants of the same Conversion for the REACTS_WITH type. 020 * @author Emek Demir 021 * @author Ozgun Babur 022 */ 023public class ParticipatesRule extends InteractionRuleL3Adaptor 024{ 025 /** 026 * Log for logging. 027 */ 028 private final Log log = LogFactory.getLog(ParticipatesRule.class); 029 030 /** 031 * Supported interaction types. 032 */ 033 private static final List<BinaryInteractionType> binaryInteractionTypes = 034 Arrays.asList(BinaryInteractionType.INTERACTS_WITH, REACTS_WITH); 035 036 /** 037 * Option to not to mine REACTS_WITH type. 038 */ 039 private boolean skipConversions; 040 041 /** 042 * Option to not to mine INTERACTS_WITH type. 043 */ 044 private boolean skipInteractions; 045 046 /** 047 * Initializes options. 048 * @param options options map 049 */ 050 @Override public void initOptionsNotNull(Map options) 051 { 052 skipConversions = checkOption(REACTS_WITH,Boolean.FALSE,options); 053 skipInteractions = checkOption(INTERACTS_WITH,Boolean.FALSE,options); 054 } 055 056 /** 057 * Infers interactions starting from the given PhysicalEntity. 058 * @param interactionSet to be populated 059 * @param pe PhysicalEntity that will be the seed of the inference 060 * @param model BioPAX model 061 */ 062 public void inferInteractionsFromPE(InteractionSetL3 interactionSet, PhysicalEntity pe, Model model) 063 { 064 for (Interaction interaction : pe.getParticipantOf()) 065 { 066 BinaryInteractionType type = getType(interaction); 067 068 069 for (Entity participant : interaction.getParticipant()) 070 { 071 processParticipant(interactionSet, participant, type, interaction); 072 } 073 } 074 } 075 076 /** 077 * Decides the type of the binary interaction according to the subclass of the Interaction. 078 * Conversion is used for REACTS_WITH type, Control is ignored, and others are used for 079 * INTERACTS_WITH type. 080 * @param interaction the mediator of the new binary interaction 081 * @return type of the new interaction 082 */ 083 private BinaryInteractionType getType(Interaction interaction) 084 { 085 if (interaction instanceof Conversion) 086 { 087 if (!skipConversions) 088 { 089 return REACTS_WITH; 090 } 091 } else if (interaction instanceof Control) 092 { 093 return null; 094 } else if (!skipInteractions) 095 { 096 return INTERACTS_WITH; 097 } 098 return null; 099 } 100 101 /** 102 * Continues interaction creation with the given elements. 103 * @param interactionSet to be populated 104 * @param entity participant of the Interaction 105 * @param type type of the binary interaction 106 * @param interaction Interaction to use as mediator 107 */ 108 private void processParticipant(InteractionSetL3 interactionSet, Entity entity, 109 BinaryInteractionType type, Interaction interaction) 110 { 111 if (entity instanceof PhysicalEntity) 112 { 113 BioPAXElement source = interactionSet.getGroupMap().getEntityReferenceOrGroup(entity); 114 115 for (Entity participant : interaction.getParticipant()) 116 { 117 if (participant instanceof PhysicalEntity) 118 119 { 120 BioPAXElement target = interactionSet.getGroupMap().getEntityReferenceOrGroup(participant); 121 createAndAdd(source, target, interactionSet, type, interaction); 122 } 123 } 124 } 125 } 126 127 /** 128 * Gets supported interaction types. 129 * @return supported interaction types 130 */ 131 public List<BinaryInteractionType> getRuleTypes() 132 { 133 return binaryInteractionTypes; 134 } 135}