2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.datamodel;
20 import jalview.schemes.*;
28 public class BinarySequence extends Sequence
35 * Creates a new BinarySequence object.
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)];
67 } catch (NullPointerException e)
77 dbinary[(i * nores) + aanum] = 1.0;
82 * 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)];
117 } catch (NullPointerException e)
127 // Do the blosum thing
129 for (int j = 0; j < 20; j++)
131 dbinary[(i * nores) + j] = matrix[aanum][j];
139 * @return DOCUMENT ME!
141 public String toBinaryString()
145 for (int i = 0; i < binary.length; i++)
147 out += (new Integer(binary[i])).toString();
149 if (i < (binary.length - 1))
161 * @return DOCUMENT ME!
163 public double[] getDBinary()