001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org/ 019 * 020 */ 021 022package org.biojava.bio.program.homologene; 023 024import java.util.Set; 025 026public interface OrthoPairSetFilter 027{ 028 public boolean accept(OrthoPairSet group); 029 030 public final static class AcceptAll implements OrthoPairSetFilter 031 { 032 public boolean accept(OrthoPairSet group) { return true; } 033 } 034 035 public final static class Not implements OrthoPairSetFilter 036 { 037 OrthoPairSetFilter a; 038 039 public Not(OrthoPairSetFilter a) 040 { 041 this.a = a; 042 } 043 044 public boolean accept(OrthoPairSet group) 045 { 046 return !a.accept(group); 047 } 048 } 049 050 public final static class Or implements OrthoPairSetFilter 051 { 052 OrthoPairSetFilter a; 053 OrthoPairSetFilter b; 054 055 public Or(OrthoPairSetFilter a, OrthoPairSetFilter b) 056 { 057 this.a = a; 058 this.b = b; 059 } 060 061 public boolean accept(OrthoPairSet group) 062 { 063 return ((a.accept(group)) || (b.accept(group))); 064 } 065 } 066 067 public final static class And implements OrthoPairSetFilter 068 { 069 OrthoPairSetFilter a; 070 OrthoPairSetFilter b; 071 072 public And(OrthoPairSetFilter a, OrthoPairSetFilter b) 073 { 074 this.a = a; 075 this.b = b; 076 } 077 078 public boolean accept(OrthoPairSet group) 079 { 080 return ((a.accept(group)) && (b.accept(group))); 081 } 082 } 083 084 public final static class Xor implements OrthoPairSetFilter 085 { 086 OrthoPairSetFilter a; 087 OrthoPairSetFilter b; 088 089 public Xor(OrthoPairSetFilter a, OrthoPairSetFilter b) 090 { 091 this.a = a; 092 this.b = b; 093 } 094 095 public boolean accept(OrthoPairSet group) 096 { 097 return ((a.accept(group)) ^ (b.accept(group))); 098 } 099 } 100 101 public final static class ByTaxon implements OrthoPairSetFilter 102 { 103 Taxon taxon; 104 105 public ByTaxon(Taxon taxon) 106 { 107 this.taxon = taxon; 108 } 109 110 public boolean accept(OrthoPairSet group) 111 { 112 Set taxa = group.getTaxa(); 113 114 return taxa.contains(taxon); 115 } 116 } 117 118 public final static class ByMinIdentity implements OrthoPairSetFilter 119 { 120 double minValue; 121 122 public ByMinIdentity(double minValue) 123 { 124 this.minValue = minValue; 125 } 126 127 public boolean accept(OrthoPairSet group) 128 { 129 return (group.getMinIdentity() >= minValue); 130 } 131 } 132 133 /** 134 * all OrthoPairs must meet the requirement 135 * defined by filter. 136 */ 137 public final static class AllPairsInCollection implements OrthoPairSetFilter 138 { 139 OrthoPairFilter filter; 140 141 public AllPairsInCollection(OrthoPairFilter filter) 142 { 143 this.filter = filter; 144 } 145 146 public boolean accept(OrthoPairSet group) 147 { 148 for (OrthoPairSet.Iterator setI = group.iterator(); 149 setI.hasNext(); ) 150 { 151 if (!filter.accept(setI.nextOrthoPair())) return false; 152 } 153 return true; 154 } 155 } 156 157 /** 158 * at least one OrthoPair must meet the requirement 159 * defined by filter. 160 */ 161 public final static class SomePairsInCollection implements OrthoPairSetFilter 162 { 163 OrthoPairFilter filter; 164 165 public SomePairsInCollection(OrthoPairFilter filter) 166 { 167 this.filter = filter; 168 } 169 170 public boolean accept(OrthoPairSet group) 171 { 172 for (OrthoPairSet.Iterator setI = group.iterator(); 173 setI.hasNext(); ) 174 { 175 if (filter.accept(setI.nextOrthoPair())) return true; 176 } 177 return false; 178 } 179 } 180}