2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.datamodel;
21 import jalview.schemes.*;
29 public class BinarySequence
36 * Creates a new BinarySequence object.
38 * @param s DOCUMENT ME!
40 public BinarySequence(String s)
42 super("", s, 0, s.length());
50 // Set all matrix to 0
51 dbinary = new double[getSequence().length * 21];
55 for (int i = 0; i < dbinary.length; i++)
60 for (int i = 0; i < getSequence().length; i++)
66 aanum = ResidueProperties.aaIndex[getCharAt(i)];
68 catch (NullPointerException e)
78 dbinary[ (i * nores) + aanum] = 1.0;
83 * ancode using substitution matrix given in matrix
86 public void matrixEncode(ScoreMatrix matrix)
88 matrixEncode(matrix.isDNA() ? ResidueProperties.nucleotideIndex :
89 ResidueProperties.aaIndex, matrix.getMatrix());
95 public void blosumEncode()
97 matrixEncode(ResidueProperties.aaIndex, ResidueProperties.getBLOSUM62());
100 private void matrixEncode(int[] aaIndex, int[][] matrix)
102 // Set all matrix to 0
103 dbinary = new double[getSequence().length * 21];
107 //for (int i = 0; i < dbinary.length; i++) {
110 for (int i = 0; i < getSequence().length; i++)
116 aanum = aaIndex[getCharAt(i)];
118 catch (NullPointerException e)
128 // Do the blosum thing
130 for (int j = 0; j < 20; j++)
132 dbinary[ (i * nores) + j] = matrix[aanum][j];
140 * @return DOCUMENT ME!
142 public String toBinaryString()
146 for (int i = 0; i < binary.length; i++)
148 out += (new Integer(binary[i])).toString();
150 if (i < (binary.length - 1))
162 * @return DOCUMENT ME!
164 public double[] getDBinary()