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 */
021package org.biojava.nbio.structure.secstruc;
022
023import java.io.Serializable;
024
025import org.biojava.nbio.structure.ResidueNumber;
026import org.biojava.nbio.structure.ResidueRangeAndLength;
027
028/**
029 * A secondary structure element (SSE) is an object representing a block of
030 * sequential residues that share the same secondary structure type.
031 *
032 * @author Aleix Lafita
033 * @since 4.1.1
034 *
035 */
036public class SecStrucElement implements Serializable  {
037
038        private static final long serialVersionUID = -8485685793171396131L;
039
040        private final SecStrucType type;
041        private final ResidueRangeAndLength range;
042        private final int index;
043
044        /**
045         * Create a new SSE object. The start and end residue numbers cannot be the
046         * same.
047         *
048         * @param type
049         *            object describing the type of SS
050         * @param start
051         *            first residue of the SSE
052         * @param end
053         *            final residue of the SSE
054         * @param length
055         *            number of residues included in the SSE
056         * @param index
057         * @param chainID
058         *            the chain ID
059         */
060        public SecStrucElement(SecStrucType type, ResidueNumber start,
061                        ResidueNumber end, int length, int index, String chainID) {
062
063                this.type = type;
064                this.index = index;
065                range = new ResidueRangeAndLength(chainID, start, end, length);
066        }
067
068        /**
069         * Returns the {@link SecStrucType} of this element.
070         *
071         * @return
072         */
073        public SecStrucType getType() {
074                return type;
075        }
076
077        /**
078         * Returns the index of the SSE for its type. This is, the sequential
079         * position of this SSE relative to the other SSE of the same type.
080         *
081         * @return
082         */
083        public int getIndex() {
084                return index;
085        }
086
087        /**
088         * Return the length (number of residues) in the SSE.
089         *
090         * @return
091         */
092        public int getLength() {
093                return range.getLength();
094        }
095
096        /**
097         * Returns the ID of this element. The ID is the concatenation of the type
098         * letter and the numerical element identifier (e.g. H1, S1, ...).
099         *
100         * @return
101         */
102        public String getId() {
103                return type.toString() + index + "";
104        }
105
106        /**
107         * Returns the residue range of this SSE.
108         *
109         * @return
110         */
111        public ResidueRangeAndLength getRange() {
112                return range;
113        }
114
115        @Override
116        public String toString() {
117                return getId() + ": " + range.toString();
118        }
119
120}