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 OrthologueFilter
026{
027    public boolean accept(Orthologue ortho);
028
029    public final static class AcceptAll implements OrthologueFilter
030    {
031        public boolean accept(Orthologue ortho) { return true; }
032    }
033
034    public final static class Not implements OrthologueFilter
035    {
036        OrthologueFilter a;
037
038        public Not(OrthologueFilter a)
039        {
040            this.a = a;
041        }
042
043        public boolean accept(Orthologue ortho)
044        {
045            return !a.accept(ortho);
046        }
047    }
048
049    public final static class Or implements OrthologueFilter
050    {
051        OrthologueFilter a;
052        OrthologueFilter b;
053
054        public Or(OrthologueFilter a, OrthologueFilter b)
055        {
056            this.a = a;
057            this.b = b;
058        }
059
060        public boolean accept(Orthologue ortho)
061        {
062            return ((a.accept(ortho)) || (b.accept(ortho)));
063        }
064    }
065
066    public final static class And implements OrthologueFilter
067    {
068        OrthologueFilter a;
069        OrthologueFilter b;
070
071        public And(OrthologueFilter a, OrthologueFilter b)
072        {
073            this.a = a;
074            this.b = b;
075        }
076
077        public boolean accept(Orthologue ortho)
078        {
079            return ((a.accept(ortho)) && (b.accept(ortho)));
080        }
081    }
082
083    public final static class Xor implements OrthologueFilter
084    {
085        OrthologueFilter a;
086        OrthologueFilter b;
087
088        public Xor(OrthologueFilter a, OrthologueFilter b)
089        {
090            this.a = a;
091            this.b = b;
092        }
093
094        public boolean accept(Orthologue ortho)
095        {
096            return ((a.accept(ortho)) ^ (b.accept(ortho)));
097        }
098    }
099
100    public class ByTaxonID implements OrthologueFilter
101    {
102        int taxonID;
103
104        public ByTaxonID(int taxonID)
105        {
106            this.taxonID = taxonID;
107        }
108
109        public boolean accept(Orthologue ortho)
110        {
111            try {
112                return (taxonID == ortho.getTaxonID());
113            }
114            catch (Exception e) {
115                return false;
116            }
117        }
118    }
119
120    public class ByTaxon implements OrthologueFilter
121    {
122        Taxon taxon;
123
124        public ByTaxon(Taxon taxon)
125        {
126            this.taxon = taxon;
127        }
128
129        public boolean accept(Orthologue ortho)
130        {
131            try {
132                return (taxon == ortho.getTaxon());
133            }
134            catch (Exception e) {
135                return false;
136            }
137        }
138    }
139
140    public class ByLocusID implements OrthologueFilter
141    {
142        String locusID;
143
144        public ByLocusID(String locusID)
145        {
146            this.locusID = locusID;
147        }
148
149        public boolean accept(Orthologue ortho)
150        {
151            try {
152                return (locusID.equals(ortho.getLocusID()));
153            }
154            catch (Exception e) {
155                return false;
156            }
157        }
158    }
159
160    public class ByHomologeneID implements OrthologueFilter
161    {
162        String homologeneID;
163
164        public ByHomologeneID(String homologeneID)
165        {
166            this.homologeneID = homologeneID;
167        }
168
169        public boolean accept(Orthologue ortho)
170        {
171            try {
172                return (homologeneID.equals(ortho.getHomologeneID()));
173            }
174            catch (Exception e) {
175                return false;
176            }
177        }
178    }
179
180    public class ByAccession implements OrthologueFilter
181    {
182        String regex;
183
184        public ByAccession(String regex)
185        {
186            this.regex = regex;
187        }
188
189        public boolean accept(Orthologue ortho)
190        {
191            try {
192                return ortho.getAccession().matches(regex);
193            }
194            catch (Exception e) {
195                return false;
196            }
197        }
198    }
199
200    public class ByTitle implements OrthologueFilter
201    {
202        String regex;
203
204        public ByTitle(String regex)
205        {
206            this.regex = regex;
207        }
208
209        public boolean accept(Orthologue ortho)
210        {
211            try {
212                return ortho.getTitle().matches(regex);
213            }
214            catch (Exception e) {
215                return false;
216            }
217        }
218    }
219}
220