001package com.hfg.bio.seq;
002
003
004import java.util.ArrayList;
005import java.util.List;
006
007import com.hfg.math.Range;
008
009//------------------------------------------------------------------------------
010/**
011 1-based biological sequence location object.
012 <div>
013  @author J. Alex Taylor, hairyfatguy.com
014 </div>
015 */
016//------------------------------------------------------------------------------
017// com.hfg Library
018//
019// This library is free software; you can redistribute it and/or
020// modify it under the terms of the GNU Lesser General Public
021// License as published by the Free Software Foundation; either
022// version 2.1 of the License, or (at your option) any later version.
023//
024// This library is distributed in the hope that it will be useful,
025// but WITHOUT ANY WARRANTY; without even the implied warranty of
026// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
027// Lesser General Public License for more details.
028//
029// You should have received a copy of the GNU Lesser General Public
030// License along with this library; if not, write to the Free Software
031// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
032//
033// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
034// jataylor@hairyfatguy.com
035//------------------------------------------------------------------------------
036
037public class SeqLocation extends Range<Integer>
038{
039   private String  mChainId;
040
041
042   //###########################################################################
043   // CONSTRUCTORS
044   //###########################################################################
045
046   //--------------------------------------------------------------------------
047   public SeqLocation()
048   {
049      super();
050   }
051
052   //--------------------------------------------------------------------------
053   public SeqLocation(Integer inStart, Integer inEnd)
054   {
055      super(inStart, inEnd);
056   }
057
058   //--------------------------------------------------------------------------
059   public SeqLocation(Range<Integer> inRange)
060   {
061      super(inRange != null ? inRange.getStart() : null,
062            inRange != null ? inRange.getEnd() : null);
063   }
064
065   //--------------------------------------------------------------------------
066   public SeqLocation(String inChainId, Integer inStart, Integer inEnd)
067   {
068      super(inStart, inEnd);
069      mChainId = inChainId;
070   }
071
072
073   //###########################################################################
074   // PUBLIC METHODS
075   //###########################################################################
076
077   //---------------------------------------------------------------------------
078   @Override
079   public SeqLocation clone()
080   {
081      return (SeqLocation) super.clone();
082   }
083
084   //--------------------------------------------------------------------------
085   @Override
086   public SeqLocation setStart(Integer inValue)
087   {
088      return (SeqLocation) super.setStart(inValue);
089   }
090
091   //--------------------------------------------------------------------------
092   @Override
093   public SeqLocation setEnd(Integer inValue)
094   {
095      return (SeqLocation) super.setEnd(inValue);
096   }
097
098   //--------------------------------------------------------------------------
099   public SeqLocation setChainId(String inValue)
100   {
101      mChainId = inValue;
102      return this;
103   }
104
105   //--------------------------------------------------------------------------
106   public String getChainId()
107   {
108      return mChainId;
109   }
110
111   //--------------------------------------------------------------------------
112   public void addOffset(int inValue)
113   {
114      if (getStart() != null)
115      {
116         setStart(getStart() + inValue);
117      }
118
119      if (getEnd() != null)
120      {
121         setEnd(getEnd() + inValue);
122      }
123   }
124
125   //--------------------------------------------------------------------------
126   public List<SeqLocation> subtract(SeqLocation inLoc2)
127   {
128      List<Range<Integer>> rangeResults = super.subtract(inLoc2);
129
130      List<SeqLocation> seqLocResults = new ArrayList<>(rangeResults.size());
131      for (Range<Integer> result : rangeResults)
132      {
133         seqLocResults.add(new SeqLocation(result.getStart(), result.getEnd()));
134      }
135
136      return seqLocResults;
137   }
138
139}