001package org.biopax.paxtools.pattern.constraint; 002 003import org.biopax.paxtools.model.level3.PhysicalEntity; 004import org.biopax.paxtools.pattern.Match; 005import org.biopax.paxtools.pattern.util.PhysicalEntityChain; 006 007/** 008 * This constraint checks if two chains of linked physical entities are intersecting or not. 009 * 010 * Var0 First (simpler) PhysicalEntity in the first chain 011 * Var1 Last (complexer) PhysicalEntity in the first chain 012 * Var2 First PhysicalEntity in the second chain 013 * Var3 Last PhysicalEntity in the second chain 014 * 015 * @author Ozgun Babur 016 */ 017public class PEChainsIntersect extends ConstraintAdapter 018{ 019 /** 020 * Desired result. 021 */ 022 boolean intersectionDesired; 023 024 /** 025 * Option to ignore intersection at the endpoints of the chains. 026 */ 027 boolean ignoreEndPoints; 028 029 /** 030 * Constructor with the desired result. 031 * @param intersectionDesired desired result 032 */ 033 public PEChainsIntersect(boolean intersectionDesired) 034 { 035 this(intersectionDesired, false); 036 } 037 038 /** 039 * Constructor with the desired result and endpoint ignore option. 040 * @param intersectionDesired desired result 041 * @param ignoreEndPoints option to ignore intersection at the endpoints of the chains 042 */ 043 public PEChainsIntersect(boolean intersectionDesired, boolean ignoreEndPoints) 044 { 045 super(4); 046 this.intersectionDesired = intersectionDesired; 047 this.ignoreEndPoints = ignoreEndPoints; 048 } 049 050 /** 051 * Creates two PhysicalEntity chains with the given endpoints, and checks if they are 052 * intersecting. 053 * @param match current pattern match 054 * @param ind mapped indices 055 * @return true if the chains are intersecting or not intersecting as desired 056 */ 057 @Override 058 public boolean satisfies(Match match, int... ind) 059 { 060 PhysicalEntity pe0 = (PhysicalEntity) match.get(ind[0]); 061 PhysicalEntity pe1 = (PhysicalEntity) match.get(ind[1]); 062 PhysicalEntity pe2 = (PhysicalEntity) match.get(ind[2]); 063 PhysicalEntity pe3 = (PhysicalEntity) match.get(ind[3]); 064 065 PhysicalEntityChain ch1 = new PhysicalEntityChain(pe0, pe1); 066 PhysicalEntityChain ch2 = new PhysicalEntityChain(pe2, pe3); 067 068 return ch1.intersects(ch2, ignoreEndPoints) == intersectionDesired; 069 } 070}