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 024 025public interface OrthoPairFilter 026{ 027 public boolean accept(OrthoPair pair); 028 029 030 public final static class AcceptAll implements OrthoPairFilter 031 { 032 public boolean accept(OrthoPair pair) { return true; } 033 } 034 035 public final static class Not implements OrthoPairFilter 036 { 037 OrthoPairFilter a; 038 039 public Not(OrthoPairFilter a) 040 { 041 this.a = a; 042 } 043 044 public boolean accept(OrthoPair pair) 045 { 046 return !a.accept(pair); 047 } 048 } 049 050 public final static class Or implements OrthoPairFilter 051 { 052 OrthoPairFilter a; 053 OrthoPairFilter b; 054 055 public Or(OrthoPairFilter a, OrthoPairFilter b) 056 { 057 this.a = a; 058 this.b = b; 059 } 060 061 public boolean accept(OrthoPair pair) 062 { 063 return ((a.accept(pair)) || (b.accept(pair))); 064 } 065 } 066 067 public final static class And implements OrthoPairFilter 068 { 069 OrthoPairFilter a; 070 OrthoPairFilter b; 071 072 public And(OrthoPairFilter a, OrthoPairFilter b) 073 { 074 this.a = a; 075 this.b = b; 076 } 077 078 public boolean accept(OrthoPair pair) 079 { 080 return ((a.accept(pair)) && (b.accept(pair))); 081 } 082 } 083 084 public final static class Xor implements OrthoPairFilter 085 { 086 OrthoPairFilter a; 087 OrthoPairFilter b; 088 089 public Xor(OrthoPairFilter a, OrthoPairFilter b) 090 { 091 this.a = a; 092 this.b = b; 093 } 094 095 public boolean accept(OrthoPair pair) 096 { 097 return ((a.accept(pair)) ^ (b.accept(pair))); 098 } 099 } 100 101 public class ByMinIdentity implements OrthoPairFilter 102 { 103 double lowLimit; 104 105 public ByMinIdentity(double lowLimit) 106 { 107 this.lowLimit = lowLimit; 108 } 109 110 public boolean accept(OrthoPair pair) 111 { 112 // it is possible that an OrthoPair 113 // may not have the percentIdentity 114 // defined, e.g. curated orthologies 115 // the method will return false then. 116 117 // check that the SimilarityType is acceptable 118 SimilarityType pairType = pair.getSimilarity(); 119 120 if ( (pairType == SimilarityType.TWIN) 121 || (pairType == SimilarityType.MULTIPLE) ) { 122 123 return (pair.getPercentIdentity() >= lowLimit); 124 } 125 else 126 return false; 127 } 128 } 129 130 public class ByMaxIdentity implements OrthoPairFilter 131 { 132 double hiLimit; 133 134 public ByMaxIdentity(double hiLimit) 135 { 136 this.hiLimit = hiLimit; 137 } 138 139 public boolean accept(OrthoPair pair) 140 { 141 // it is possible that an OrthoPair 142 // may not have the percentIdentity 143 // defined, e.g. curated orthologies 144 // the method will return false then. 145 146 // check that the SimilarityType is acceptable 147 SimilarityType pairType = pair.getSimilarity(); 148 149 if ( (pairType == SimilarityType.TWIN) 150 || (pairType == SimilarityType.MULTIPLE) ) { 151 152 return (pair.getPercentIdentity() < hiLimit); 153 } 154 else 155 return false; 156 } 157 } 158 159 public class BySimilarityType implements OrthoPairFilter 160 { 161 SimilarityType type; 162 163 public BySimilarityType(SimilarityType type) 164 { 165 this.type = type; 166 } 167 168 public boolean accept(OrthoPair pair) 169 { 170 return (pair.getSimilarity() == type); 171 } 172 } 173 174 public class ByRef implements OrthoPairFilter 175 { 176 String regex; 177 178 public ByRef(String regex) 179 { 180 this.regex = regex; 181 } 182 183 public boolean accept(OrthoPair pair) 184 { 185 if (pair.getSimilarity() == SimilarityType.CURATED) { 186 return pair.getRef().matches(regex); 187 } 188 else 189 return false; 190 } 191 } 192 193}