2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 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.*;
31 public class BinarySequence extends Sequence
37 * Creates a new BinarySequence object.
39 * @param s DOCUMENT ME!
41 public BinarySequence(String s)
43 super("", s, 0, s.length());
51 // Set all matrix to 0
52 dbinary = new double[getSequence().length * 21];
56 for (int i = 0; i < dbinary.length; i++)
61 for (int i = 0; i < getSequence().length; i++)
67 aanum = ResidueProperties.aaIndex[getCharAt(i)];
69 catch (NullPointerException e)
79 dbinary[(i * nores) + aanum] = 1.0;
83 * ancode using substitution matrix given in matrix
86 public void matrixEncode(ScoreMatrix matrix) {
87 matrixEncode(matrix.isDNA()?ResidueProperties.nucleotideIndex: ResidueProperties.aaIndex, matrix.getMatrix());
92 public void blosumEncode()
94 matrixEncode(ResidueProperties.aaIndex, ResidueProperties.getBLOSUM62());
96 private void matrixEncode(int[] aaIndex, int[][] matrix) {
97 // Set all matrix to 0
98 dbinary = new double[getSequence().length * 21];
102 //for (int i = 0; i < dbinary.length; i++) {
105 for (int i = 0; i < getSequence().length; i++)
111 aanum = aaIndex[getCharAt(i)];
113 catch (NullPointerException e)
123 // Do the blosum thing
125 for (int j = 0; j < 20; j++)
127 dbinary[(i * nores) + j] = matrix[aanum][j];
135 * @return DOCUMENT ME!
137 public String toBinaryString()
141 for (int i = 0; i < binary.length; i++)
143 out += (new Integer(binary[i])).toString();
145 if (i < (binary.length - 1))
157 * @return DOCUMENT ME!
159 public double[] getDBinary()