001package com.hfg.bio.seq;
002
003import java.io.*;
004import java.lang.reflect.Constructor;
005import java.util.Collection;
006
007import com.hfg.bio.HfgBioXML;
008import com.hfg.chem.Matter;
009import com.hfg.util.StringUtil;
010import com.hfg.xml.XMLNode;
011
012
013//------------------------------------------------------------------------------
014/**
015 Interface for a biological Protein, DNA, or RNA sequence.
016 <div>
017  @author J. Alex Taylor, hairyfatguy.com
018 </div>
019 */
020//------------------------------------------------------------------------------
021// com.hfg XML/HTML Coding Library
022//
023// This library is free software; you can redistribute it and/or
024// modify it under the terms of the GNU Lesser General Public
025// License as published by the Free Software Foundation; either
026// version 2.1 of the License, or (at your option) any later version.
027//
028// This library is distributed in the hope that it will be useful,
029// but WITHOUT ANY WARRANTY; without even the implied warranty of
030// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
031// Lesser General Public License for more details.
032//
033// You should have received a copy of the GNU Lesser General Public
034// License along with this library; if not, write to the Free Software
035// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
036//
037// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
038// jataylor@hairyfatguy.com
039//------------------------------------------------------------------------------
040
041
042public interface BioSequence extends Cloneable, Comparable, Matter
043{
044
045   //##########################################################################
046   // PUBLIC METHODS
047   //##########################################################################
048
049   //--------------------------------------------------------------------------
050   public BioSequence clone();
051
052   //--------------------------------------------------------------------------
053   /**
054    Sets the id or name for the sequence.
055    Returns 'this' which can be useful for method chaining.
056    @param inValue the id to use for this sequence
057    @return this BioSequence to enable method chaining
058    */
059   public BioSequence setID(String inValue);
060
061   //--------------------------------------------------------------------------
062   public String getID();
063
064   //--------------------------------------------------------------------------
065   public BioSequenceType getType();
066
067   //--------------------------------------------------------------------------
068   public BioSequence setDescription(CharSequence inValue);
069
070   //--------------------------------------------------------------------------
071   public String getDescription();
072
073   //--------------------------------------------------------------------------
074   public BioSequence setSequence(CharSequence inValue);
075
076   //--------------------------------------------------------------------------
077   public BioSequence setSequence(Reader inReader);
078
079   //--------------------------------------------------------------------------
080   public String getSequence();
081
082   //--------------------------------------------------------------------------
083   public String getSubSequence(SeqLocation inSeqLocation);
084
085   //--------------------------------------------------------------------------
086   public int length();
087
088   //--------------------------------------------------------------------------
089   /**
090    Returns the residue character at the specified (1-based) sequence location.
091    @param inIndex the 1-based sequence location at which to retrieve the residue
092    @return the residue at the specified index
093    */
094   public char residueAt(int inIndex);
095
096   //--------------------------------------------------------------------------
097   public Reader getSequenceReader();
098
099   //--------------------------------------------------------------------------
100   public Reader getSubSequenceReader(SeqLocation inSeqLocation);
101
102   //--------------------------------------------------------------------------
103   public InputStream getSequenceStream();
104
105
106   //--------------------------------------------------------------------------
107   public byte[] getMD5Checksum();
108
109   //--------------------------------------------------------------------------
110   public byte[] getSHA1Checksum();
111
112
113   //--------------------------------------------------------------------------
114   public void setAttribute(String inName, Object inValue);
115
116   //--------------------------------------------------------------------------
117   public Object getAttribute(String inName);
118
119   //--------------------------------------------------------------------------
120   public boolean hasAttribute(String inName);
121
122   //--------------------------------------------------------------------------
123   public Collection<String> getAttributeNames();
124
125   //--------------------------------------------------------------------------
126   public Object removeAttribute(String inName);
127
128
129
130   //--------------------------------------------------------------------------
131   public XMLNode toXMLNode();
132
133
134   //--------------------------------------------------------------------------
135   public static BioSequence instantiate(XMLNode inXMLNode)
136   {
137      String classname = inXMLNode.getAttributeValue(HfgBioXML.CLASS_ATT);
138      if (! StringUtil.isSet(classname))
139      {
140         throw new RuntimeException("No " + HfgBioXML.CLASS_ATT + " specified on sequence's XML tag!");
141      }
142
143      BioSequence seq = null;
144
145      try
146      {
147         Class clazz = Class.forName(classname);
148         Constructor constructor = clazz.getConstructor(XMLNode.class);
149         seq = (BioSequence) constructor.newInstance(inXMLNode);
150      }
151      catch (Exception e)
152      {
153         throw new RuntimeException("Error during sequence instantiation from its XML tag!", e);
154      }
155
156      return seq;
157   }
158}