001package com.hfg.bio.seq;
002
003import java.awt.*;
004
005import com.hfg.bio.Strand;
006
007//------------------------------------------------------------------------------
008/**
009 * An exon in a gene.
010 *
011 * @author J. Alex Taylor, hairyfatguy.com
012 */
013//------------------------------------------------------------------------------
014// com.hfg XML/HTML Coding Library
015//
016// This library is free software; you can redistribute it and/or
017// modify it under the terms of the GNU Lesser General Public
018// License as published by the Free Software Foundation; either
019// version 2.1 of the License, or (at your option) any later version.
020//
021// This library is distributed in the hope that it will be useful,
022// but WITHOUT ANY WARRANTY; without even the implied warranty of
023// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
024// Lesser General Public License for more details.
025//
026// You should have received a copy of the GNU Lesser General Public
027// License along with this library; if not, write to the Free Software
028// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
029//
030// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
031// jataylor@hairyfatguy.com
032//------------------------------------------------------------------------------
033
034public class Exon implements Comparable
035{
036
037   //##########################################################################
038   // PRIVATE FIELDS
039   //##########################################################################
040
041   private int    mStartLocation;
042   private int    mEndLocation;
043   private Strand mStrand;
044   private Color  mColor;
045
046   //##########################################################################
047   // CONSTRUCTORS
048   //##########################################################################
049
050   //--------------------------------------------------------------------------
051   public Exon(int inStart, int inEnd)
052   {
053      mStartLocation = inStart;
054      mEndLocation   = inEnd;
055   }
056
057   //--------------------------------------------------------------------------
058   public Exon(int inStart, int inEnd, Strand inStrand)
059   {
060      mStartLocation = inStart;
061      mEndLocation   = inEnd;
062      mStrand = inStrand;
063   }
064
065
066   //##########################################################################
067   // PUBLIC METHODS
068   //##########################################################################
069
070   //--------------------------------------------------------------------------
071   public int getStartLocation()
072   {
073      return mStartLocation;
074   }
075
076   //--------------------------------------------------------------------------
077   public int getEndLocation()
078   {
079      return mEndLocation;
080   }
081
082
083   //--------------------------------------------------------------------------
084   public int getLeft()
085   {
086      return Math.min(mStartLocation, mEndLocation);
087   }
088
089   //--------------------------------------------------------------------------
090   public int getRight()
091   {
092      return Math.max(mStartLocation, mEndLocation);
093   }
094
095
096
097   //--------------------------------------------------------------------------
098   public Strand getStrand()
099   {
100      return mStrand;
101   }
102
103   //--------------------------------------------------------------------------
104   public void setStrand(Strand inValue)
105   {
106      mStrand = inValue;
107   }
108
109
110
111   //--------------------------------------------------------------------------
112   public Exon setColor(Color inValue)
113   {
114      mColor = inValue;
115      return this;
116   }
117
118   //--------------------------------------------------------------------------
119   public Color getColor()
120   {
121      return mColor;
122   }
123
124   //--------------------------------------------------------------------------
125   public int compareTo(Object o2)
126   {
127      Exon exon2 = (Exon) o2;
128
129      int returnValue = 0;
130
131      if (mStartLocation > exon2.mStartLocation)
132      {
133         returnValue = 1;
134      }
135      else if (mStartLocation < exon2.mStartLocation)
136      {
137         returnValue = -1;
138      }
139      else
140      {
141         if (mEndLocation > exon2.mEndLocation)
142         {
143            returnValue = 1;
144         }
145         else if (mEndLocation < exon2.mEndLocation)
146         {
147            returnValue = -1;
148         }
149      }
150
151      return returnValue;
152   }
153
154}