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.biojavax.bio.seq;
023
024/**
025 * Resolves a position that is fuzzy or covers a range of bases by
026 * converting it to a single base.
027 * @author Richard Holland
028 * @since 1.5
029 */
030public interface PositionResolver {
031    
032    /**
033     * Resolves the minimum possible base for this position.
034     * @param start the position to resolve
035     * @return the minimum possible base this resolver can return.
036     */
037    public int getMin(Position start);   
038    
039    /**
040     * Resolves the maximum possible base for this position. 
041     * @param end the position to resolve
042     * @return the maximum possible base this resolver can return.
043     */
044    public int getMax(Position end);
045    
046    /**
047     * The maximal resolver returns the base which provides the
048     * largest possible range. 
049     */
050    public static class MaximalResolver implements PositionResolver {
051        
052        /**
053         * {@inheritDoc}
054         * ALWAYS RETURNS s.getStart()
055         */
056        public int getMin(Position s) {
057            return s.getStart();
058        }
059        
060        /**
061         * {@inheritDoc}
062         * ALWAYS RETURNS e.getEnd()
063         */
064        public int getMax(Position e) {
065            return e.getEnd();
066        }
067    }
068        
069    /**
070     * The minimal resolver returns the base which provides the
071     * smallest possible range. 
072     */
073    public static class MinimalResolver implements PositionResolver {
074        
075        /**
076         * {@inheritDoc}
077         * ALWAYS RETURNS s.getEnd()
078         */
079        public int getMin(Position s) {
080            return s.getEnd();
081        }
082        
083        /**
084         * {@inheritDoc}
085         * ALWAYS RETURNS e.getStart()
086         */
087        public int getMax(Position e) {
088            return e.getStart();
089        }
090    }    
091        
092    /**
093     * The minimal resolver returns the base which provides the
094     * average range, halfway between maximal and minimal. 
095     */
096    public static class AverageResolver implements PositionResolver {
097        
098        /**
099         * {@inheritDoc}
100         * ALWAYS RETURNS s.getStart()+s.getEnd() / 2
101         */
102        public int getMin(Position s) {
103            int min = s.getStart();
104            int max = s.getEnd();
105            return (min+max) / 2;
106        }
107        
108        /**
109         * {@inheritDoc}
110         * ALWAYS RETURNS e.getStart()+e.getEnd() / 2
111         */
112        public int getMax(Position e) {
113            int min = e.getStart();
114            int max = e.getEnd();
115            return (min+max) / 2;
116        }
117    }
118}