JAL-4124 decouple mappable contact matrix mapping logic from underlying contact matri...
[jalview.git] / src / jalview / datamodel / FloatContactMatrix.java
diff --git a/src/jalview/datamodel/FloatContactMatrix.java b/src/jalview/datamodel/FloatContactMatrix.java
new file mode 100644 (file)
index 0000000..5fb156f
--- /dev/null
@@ -0,0 +1,133 @@
+package jalview.datamodel;
+
+public class FloatContactMatrix extends GroupSetHolder implements ContactMatrixI
+{
+
+  int maxrow = 0, maxcol = 0;
+
+
+  float[][] elements;
+
+  float maxscore;
+
+
+  public FloatContactMatrix(float[][] matrix)
+  {
+    maxcol = 0;
+    for (float[] row : matrix)
+    {
+      if (row.length > maxcol)
+      {
+        maxcol = row.length;
+      }
+      maxscore = row[0];
+      for (float f : row)
+      {
+        if (maxscore < f)
+        {
+          maxscore = f;
+        }
+      }
+    }
+    maxrow = matrix.length;
+    elements = matrix;
+  }
+
+  public FloatContactMatrix(float[][] elements2, GroupSet grps2)
+  {
+    this(elements2);
+    setGroupSet(grps2);
+  }
+
+  /**
+   * getContactList(column) @returns the vector of predicted alignment errors
+   * for reference position given by column
+   */
+  @Override
+  public ContactListI getContactList(final int column)
+  {
+    if (column < 0 || column >= elements.length)
+    {
+      return null;
+    }
+
+    return new ContactListImpl(new ContactListProviderI()
+    {
+      @Override
+      public int getPosition()
+      {
+        return column;
+      }
+
+      @Override
+      public int getContactHeight()
+      {
+        return maxcol - 1;
+      }
+
+      @Override
+      public double getContactAt(int mcolumn)
+      {
+        if (mcolumn < 0 || mcolumn >= elements[column].length)
+        {
+          return -1;
+        }
+        return elements[column][mcolumn];
+      }
+    });
+  }
+
+  /**
+   * getElementAt(column, i) @returns the predicted superposition error for the
+   * ith position when column is used as reference
+   */
+  @Override
+  public double getElementAt(int _column, int i)
+  {
+    return elements[_column][i];
+  }
+
+  @Override
+  public float getMin()
+  {
+    return 0;
+  }
+
+  @Override
+  public float getMax()
+  {
+    return maxscore;
+  }
+
+  @Override
+  public String getAnnotDescr()
+  {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public String getAnnotLabel()
+  {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public String getType()
+  {
+    return null;
+  }
+
+  @Override
+  public int getWidth()
+  {
+    return maxcol;
+  }
+
+  @Override
+  public int getHeight()
+  {
+    return maxrow;
+  }
+}