Merge branch 'develop' into patch/JAL-3855_fixup_pae
authorJames Procter <j.procter@dundee.ac.uk>
Tue, 18 Jul 2023 19:57:44 +0000 (20:57 +0100)
committerJames Procter <j.procter@dundee.ac.uk>
Tue, 18 Jul 2023 19:57:44 +0000 (20:57 +0100)
src/jalview/datamodel/ContactListImpl.java
src/jalview/gui/AnnotationPanel.java
src/jalview/renderer/ContactMapRenderer.java
src/jalview/viewmodel/AlignmentViewport.java
src/jalview/ws/datamodel/alphafold/PAEContactMatrix.java
test/jalview/project/Jalview2xmlTests.java

index 69dcf71..bb31c5d 100644 (file)
@@ -55,9 +55,9 @@ public class ContactListImpl implements ContactListI
     {
       from_column = 0;
     }
-    if (to_column > getContactHeight())
+    if (to_column >= getContactHeight())
     {
-      to_column = getContactHeight();
+      to_column = getContactHeight()-1;
     }
     ContactRange cr = new ContactRange();
     cr.setFrom_column(from_column);
index 8e04048..8321741 100755 (executable)
@@ -737,7 +737,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
         if (evt.isControlDown()
                 && PAEContactMatrix.PAEMATRIX.equals(clicked.getCalcId()))
         {
-          int c = fr - 1;
+          int c = fr;
           ContactRange cr = forCurrentX.getRangeFor(fr, to);
           double cval;
           // TODO: could use GraphLine instead of arbitrary picking
@@ -747,7 +747,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
           // controls feathering - what other elements in row/column
           // should we select
           double thresh = cr.getMean() + (cr.getMax() - cr.getMean()) * .15;
-          while (c > 0)
+          while (c >= 0)
           {
             cval = forCurrentX.getContactAt(c);
             if (// cr.getMin() <= cval &&
@@ -1078,12 +1078,12 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
       ContactGeometry lastXcgeom = new ContactGeometry(forFromX,
               cma.graphHeight);
       ContactGeometry.contactInterval lastXci = lastXcgeom
-              .mapFor(rowIndex[1], rowIndex[1] - deltaY);
+              .mapFor(rowIndex[1], rowIndex[1] + deltaY);
 
       ContactGeometry cXcgeom = new ContactGeometry(forToX,
               cma.graphHeight);
       ContactGeometry.contactInterval cXci = cXcgeom.mapFor(rowIndex[1],
-              rowIndex[1] - deltaY);
+              rowIndex[1] + deltaY);
 
       // mark rectangular region formed by drag
       jalview.bin.Console.trace("Matrix Selection from last(" + fromXc
@@ -1247,7 +1247,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
       {
         row = i;
         res[0] = row;
-        res[1] = height - yPos;
+        res[1] = yPos-lheight;
         break;
       }
     }
@@ -1301,6 +1301,10 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
     // TODO abstract tooltip generator so different implementations can be built
     if (ann.graph == AlignmentAnnotation.CONTACT_MAP)
     {
+      if (rowAndOffset>=ann.graphHeight)
+      {
+        return null;
+      }
       ContactListI clist = av.getContactList(ann, column);
       if (clist != null)
       {
index 8f38d02..0471145 100644 (file)
@@ -109,11 +109,12 @@ public abstract class ContactMapRenderer implements AnnotationRowRendererI
     }
     eRes = Math.min(eRes, aa_annotations.length);
 
-    int x = 0, y2 = y;
+    int x = 0, topY = y;
 
-    g.setColor(shade.no_data);
-
-    g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
+    // uncomment below to render whole area of matrix as pink
+    // g.setColor(shade.no_data);
+    // g.fillRect(x, topY-_aa.height, (eRes - sRes) * charWidth, _aa.graphHeight);
+    
     boolean showGroups = _aa.isShowGroupsForContactMatrix();
     int column;
     int aaMax = aa_annotations.length - 1;
@@ -165,11 +166,11 @@ public abstract class ContactMapRenderer implements AnnotationRowRendererI
       final ContactGeometry cgeom = new ContactGeometry(contacts,
               _aa.graphHeight);
 
-      for (int ht = y2, eht = y2
-              - _aa.graphHeight; ht >= eht; ht -= cgeom.pixels_step)
+      for (int ht = 0, botY = topY
+              - _aa.height; ht < _aa.graphHeight; ht += cgeom.pixels_step)
       {
-        ContactGeometry.contactInterval ci = cgeom.mapFor(y2 - ht,
-                y2 - ht + cgeom.pixels_step);
+        ContactGeometry.contactInterval ci = cgeom.mapFor(ht,
+                ht + cgeom.pixels_step);
         // cstart = (int) Math.floor(((double) y2 - ht) * contacts_per_pixel);
         // cend = (int) Math.min(contact_height,
         // Math.ceil(cstart + contacts_per_pixel * pixels_step));
@@ -216,11 +217,11 @@ public abstract class ContactMapRenderer implements AnnotationRowRendererI
         g.setColor(col);
         if (cgeom.pixels_step > 1)
         {
-          g.fillRect(x * charWidth, ht, charWidth, 1 + cgeom.pixels_step);
+          g.fillRect(x * charWidth, botY+ht, charWidth, 1 + cgeom.pixels_step);
         }
         else
         {
-          g.drawLine(x * charWidth, ht, (x + 1) * charWidth, ht);
+          g.drawLine(x * charWidth, botY+ht, (x + 1) * charWidth, botY+ht);
         }
       }
       x++;
index a8c93cf..33cb9dc 100644 (file)
@@ -2132,7 +2132,7 @@ public abstract class AlignmentViewport
 
         if (aa.graph > 0)
         {
-          aa.height += aa.graphHeight;
+          aa.height += aa.graphHeight+20;
         }
 
         if (aa.height == 0)
index c822ef4..22884f1 100644 (file)
@@ -21,6 +21,21 @@ import jalview.util.MapList;
 import jalview.util.MapUtils;
 import jalview.ws.dbsources.EBIAlfaFold;
 
+/**
+ * routines and class for holding predicted alignment error matrices as produced
+ * by alphafold et al.
+ * 
+ * getContactList(column) returns the vector of predicted alignment errors for
+ * reference position given by column getElementAt(column, i) returns the
+ * predicted superposition error for the ith position when column is used as
+ * reference
+ * 
+ * Many thanks to Ora Schueler Furman for noticing that earlier development
+ * versions did not show the PAE oriented correctly
+ *
+ * @author jprocter
+ *
+ */
 public class PAEContactMatrix extends
         MappableContactMatrix<PAEContactMatrix> implements ContactMatrixI
 {
@@ -129,17 +144,18 @@ public class PAEContactMatrix extends
         Object d = scores.next();
         if (d instanceof Double)
         {
-          elements[row][col++] = ((Double) d).longValue();
+          elements[col][row] = ((Double) d).longValue();
         }
         else
         {
-          elements[row][col++] = (float) ((Long) d).longValue();
+          elements[col][row] = (float) ((Long) d).longValue();
         }
 
-        if (maxscore < elements[row][col - 1])
+        if (maxscore < elements[col][row])
         {
-          maxscore = elements[row][col - 1];
+          maxscore = elements[col][row];
         }
+        col++;
       }
       row++;
       col = 0;
@@ -180,7 +196,7 @@ public class PAEContactMatrix extends
     cols = ((List<Long>) pae_obj.get("residue2")).iterator();
     Iterator<Double> scores = ((List<Double>) pae_obj.get("distance"))
             .iterator();
-    elements = new float[maxrow][maxcol];
+    elements = new float[maxcol][maxrow];
     while (scores.hasNext())
     {
       float escore = scores.next().floatValue();
@@ -194,13 +210,17 @@ public class PAEContactMatrix extends
       {
         maxcol = col;
       }
-      elements[row - 1][col - 1] = escore;
+      elements[col - 1][row-1] = escore;
     }
 
     maxscore = ((Double) MapUtils.getFirst(pae_obj,
             "max_predicted_aligned_error", "max_pae")).floatValue();
   }
 
+  /**
+   * getContactList(column) @returns the vector of predicted alignment errors
+   * for reference position given by column
+   */
   @Override
   public ContactListI getContactList(final int column)
   {
@@ -235,6 +255,10 @@ public class PAEContactMatrix extends
     });
   }
 
+  /**
+   * getElementAt(column, i) @returns the predicted superposition error for the
+   * ith position when column is used as reference
+   */
   @Override
   protected double getElementAt(int _column, int i)
   {
index 37f946b..6518693 100644 (file)
@@ -1563,7 +1563,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase
       {
         paevals[i][j] = ((i - j < 2)
                 || ((i > 1 && i < 5) && (j > 1 && i < 5))) ? 1 : 0f;
-        paevals[j][i] = paevals[i][j];
+        paevals[j][i] = -paevals[i][j];
       }
     }
     PAEContactMatrix dummyMat = new PAEContactMatrix(sq, paevals);
@@ -1573,6 +1573,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase
     float[][] vals = ContactMatrix.fromFloatStringToContacts(content,
             sq.getLength(), sq.getLength());
     assertEquals(vals[3][4], paevals[3][4]);
+    assertEquals(vals[4][3], paevals[4][3]);
     dummyMat.setGroupSet(GroupSet.makeGroups(dummyMat, 0.5f, false));
     Assert.assertNotSame(dummyMat.getNewick(), "");
     AlignmentAnnotation paeCm = sq.addContactList(dummyMat);