0341cf2451a829c2b4fa43c60127b26740934b39
[jalview.git] / src / jalview / datamodel / FloatContactMatrix.java
1 package jalview.datamodel;
2
3 public class FloatContactMatrix extends GroupSetHolder
4         implements ContactMatrixI
5 {
6
7   int maxrow = 0, maxcol = 0;
8
9   float[][] elements;
10
11   float maxscore;
12
13   public FloatContactMatrix(float[][] matrix)
14   {
15     maxcol = 0;
16     for (float[] row : matrix)
17     {
18       if (row.length > maxcol)
19       {
20         maxcol = row.length;
21       }
22       maxscore = row[0];
23       for (float f : row)
24       {
25         if (maxscore < f)
26         {
27           maxscore = f;
28         }
29       }
30     }
31     maxrow = matrix.length;
32     elements = matrix;
33   }
34
35   public FloatContactMatrix(float[][] elements2, GroupSet grps2)
36   {
37     this(elements2);
38     setGroupSet(grps2);
39   }
40
41   /**
42    * getContactList(column) @returns the vector of predicted alignment errors
43    * for reference position given by column
44    */
45   @Override
46   public ContactListI getContactList(final int column)
47   {
48     if (column < 0 || column >= elements.length)
49     {
50       return null;
51     }
52
53     return new ContactListImpl(new ContactListProviderI()
54     {
55       @Override
56       public int getPosition()
57       {
58         return column;
59       }
60
61       @Override
62       public int getContactHeight()
63       {
64         return maxcol - 1;
65       }
66
67       @Override
68       public double getContactAt(int mcolumn)
69       {
70         if (mcolumn < 0 || mcolumn >= elements[column].length)
71         {
72           return -1;
73         }
74         return elements[column][mcolumn];
75       }
76     });
77   }
78
79   /**
80    * getElementAt(column, i) @returns the predicted superposition error for the
81    * ith position when column is used as reference
82    */
83   @Override
84   public double getElementAt(int _column, int i)
85   {
86     return elements[_column][i];
87   }
88
89   @Override
90   public float getMin()
91   {
92     return 0;
93   }
94
95   @Override
96   public float getMax()
97   {
98     return maxscore;
99   }
100
101   @Override
102   public String getAnnotDescr()
103   {
104     // TODO Auto-generated method stub
105     return null;
106   }
107
108   @Override
109   public String getAnnotLabel()
110   {
111     // TODO Auto-generated method stub
112     return null;
113   }
114
115   @Override
116   public String getType()
117   {
118     return null;
119   }
120
121   @Override
122   public int getWidth()
123   {
124     return maxcol;
125   }
126
127   @Override
128   public int getHeight()
129   {
130     return maxrow;
131   }
132 }