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