tidied up system.out messages and moved many to stderr.
[jalview.git] / src / jalview / datamodel / BinarySequence.java
1 /* Jalview - a java multiple alignment editor\r
2  * Copyright (C) 1998  Michele Clamp\r
3  *\r
4  * This program is free software; you can redistribute it and/or\r
5  * modify it under the terms of the GNU General Public License\r
6  * as published by the Free Software Foundation; either version 2\r
7  * of the License, or (at your option) any later version.\r
8  *\r
9  * This program is distributed in the hope that it will be useful,\r
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
12  * GNU General Public License for more details.\r
13  *\r
14  * You should have received a copy of the GNU General Public License\r
15  * along with this program; if not, write to the Free Software\r
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
17  */\r
18 package jalview.datamodel;\r
19 \r
20 import jalview.io.*;\r
21 import jalview.analysis.PCA;\r
22 import jalview.jbgui.*;\r
23 import jalview.schemes.*;\r
24 \r
25 import java.awt.*;\r
26 \r
27 public class BinarySequence extends Sequence {\r
28   int[] binary;\r
29   double[] dbinary;\r
30 \r
31   public BinarySequence(SequenceI s) {\r
32     super(s.getName(),s.getSequence(),s.getStart(),s.getEnd());\r
33   }\r
34 \r
35   public BinarySequence(String name, String sequence, int start, int end) {\r
36     super(name,sequence,start,end);\r
37   }\r
38 \r
39   public void encode() {\r
40     // Set all matrix to 0\r
41     dbinary = new double[getSequence().length() * 21];\r
42     int nores = 21;\r
43     for (int i = 0; i < dbinary.length; i++) {\r
44       dbinary[i] = 0.0;\r
45     }\r
46 \r
47     for (int i=0; i < getSequence().length(); i++ ) {\r
48       int aanum = 20;\r
49       try {\r
50         aanum = ((Integer)ResidueProperties.getAAHash().get(getSequence().substring(i,i+1))).intValue();\r
51       } catch (NullPointerException e) {\r
52         aanum = 20;\r
53       }\r
54       if (aanum > 20) {\r
55         aanum = 20;\r
56       }\r
57 \r
58       dbinary[i* nores + aanum] = 1.0;\r
59 \r
60     }\r
61   }\r
62 \r
63   public void blosumEncode() {\r
64 \r
65     // Set all matrix to 0\r
66     dbinary = new double[getSequence().length() * 21];\r
67     int nores = 21;\r
68     //for (int i = 0; i < dbinary.length; i++) {\r
69     //  dbinary[i] = 0.0;\r
70     //}\r
71 \r
72     for (int i=0; i < getSequence().length(); i++ ) {\r
73       int aanum = 20;\r
74       try {\r
75         aanum = ((Integer)ResidueProperties.getAAHash().get(getSequence().substring(i,i+1))).intValue();\r
76       } catch (NullPointerException e) {\r
77         aanum = 20;\r
78       }\r
79       if (aanum > 20) {\r
80         aanum = 20;\r
81       }\r
82 \r
83       // Do the blosum thing\r
84       for (int j = 0;j < 20;j++) {\r
85         dbinary[i * nores + j] = ResidueProperties.getBLOSUM62()[aanum][j];\r
86       }\r
87 \r
88     }\r
89   }\r
90 \r
91   public String toBinaryString() {\r
92     String out = "";\r
93     for (int i=0; i < binary.length;i++) {\r
94       out += (new Integer(binary[i])).toString();\r
95       if (i < binary.length-1) {\r
96         out += " ";\r
97       }\r
98     }\r
99     return out;\r
100   }\r
101 \r
102   public double[] getDBinary() {\r
103     return dbinary;\r
104   }\r
105 \r
106   public static void printMemory(Runtime rt) {\r
107     System.out.println("DEBUG: Free memory = " + rt.freeMemory()); // log.\r
108   }\r
109 }\r