Merge branch 'releases/Release_2_11_3_Branch'
[jalview.git] / src / jalview / datamodel / FloatContactMatrix.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
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
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.datamodel;
22
23 public class FloatContactMatrix extends GroupSetHolder
24         implements ContactMatrixI
25 {
26
27   int maxrow = 0, maxcol = 0;
28
29   float[][] elements;
30
31   float maxscore;
32
33   public FloatContactMatrix(float[][] matrix)
34   {
35     maxcol = 0;
36     for (float[] row : matrix)
37     {
38       if (row.length > maxcol)
39       {
40         maxcol = row.length;
41       }
42       maxscore = row[0];
43       for (float f : row)
44       {
45         if (maxscore < f)
46         {
47           maxscore = f;
48         }
49       }
50     }
51     maxrow = matrix.length;
52     elements = matrix;
53   }
54
55   public FloatContactMatrix(float[][] elements2, GroupSet grps2)
56   {
57     this(elements2);
58     setGroupSet(grps2);
59   }
60
61   /**
62    * getContactList(column) @returns the vector of predicted alignment errors
63    * for reference position given by column
64    */
65   @Override
66   public ContactListI getContactList(final int column)
67   {
68     if (column < 0 || column >= elements.length)
69     {
70       return null;
71     }
72
73     return new ContactListImpl(new ContactListProviderI()
74     {
75       @Override
76       public int getPosition()
77       {
78         return column;
79       }
80
81       @Override
82       public int getContactHeight()
83       {
84         return maxcol - 1;
85       }
86
87       @Override
88       public double getContactAt(int mcolumn)
89       {
90         if (mcolumn < 0 || mcolumn >= elements[column].length)
91         {
92           return -1;
93         }
94         return elements[column][mcolumn];
95       }
96     });
97   }
98
99   /**
100    * getElementAt(column, i) @returns the predicted superposition error for the
101    * ith position when column is used as reference
102    */
103   @Override
104   public double getElementAt(int _column, int i)
105   {
106     return elements[_column][i];
107   }
108
109   @Override
110   public float getMin()
111   {
112     return 0;
113   }
114
115   @Override
116   public float getMax()
117   {
118     return maxscore;
119   }
120
121   @Override
122   public String getAnnotDescr()
123   {
124     // TODO Auto-generated method stub
125     return null;
126   }
127
128   @Override
129   public String getAnnotLabel()
130   {
131     // TODO Auto-generated method stub
132     return null;
133   }
134
135   @Override
136   public String getType()
137   {
138     return null;
139   }
140
141   @Override
142   public int getWidth()
143   {
144     return maxcol;
145   }
146
147   @Override
148   public int getHeight()
149   {
150     return maxrow;
151   }
152 }