JAL-34 fix up comparison annotation so it gets shown and scaled properly
[jalview.git] / src / jalview / workers / AlignmentComparisonThread.java
index dfdbb87..8ec1683 100644 (file)
@@ -25,6 +25,7 @@ import jalview.analysis.Conservation;
 import jalview.analysis.scoremodels.ScoreModels;
 import jalview.api.AlignViewportI;
 import jalview.api.AlignmentViewPanel;
+import jalview.bin.Console;
 import jalview.datamodel.AlignedCodonFrame;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
@@ -51,11 +52,13 @@ public class AlignmentComparisonThread extends AlignCalcWorker
           AlignmentViewPanel alignPanel)
   {
     super(alignViewport, alignPanel);
+    comparisonAnnot = alignViewport.getComparisonAnnotation();
   }
 
-  Annotation[] correspondence = new Annotation[] {};
+  Annotation[] correspondence = new Annotation[1];
   AlignmentAnnotation comparisonAnnot=null;
   int alWidth;
+  private int maxCor=1;
 
   @Override
   public void run()
@@ -97,7 +100,7 @@ public class AlignmentComparisonThread extends AlignCalcWorker
 
         return;
       }
-      comparisonAnnot = alignViewport.getAlignment().findOrCreateAnnotation("Comparison", "CORRESPONDENCE", true, null, null);
+      
       comparisonAnnot.annotations=correspondence;
       ourAnnot.add(comparisonAnnot);
       ourAnnots = ourAnnot;
@@ -105,8 +108,9 @@ public class AlignmentComparisonThread extends AlignCalcWorker
       try
       {
         computeColumnCorrespondence(alignViewport, codingComplement);
-      } catch (IndexOutOfBoundsException x)
+      } catch (Throwable x)
       {
+        Console.error("Unexpected error computing similarity of alignments",x);
         // probable race condition. just finish and return without any fuss.
         calcMan.workerComplete(this);
         return;
@@ -151,13 +155,16 @@ public class AlignmentComparisonThread extends AlignCalcWorker
 
     int colEnd = alignViewport.getAlignment().getWidth();
     Annotation[] colCorrsp = new Annotation[colEnd];
+    maxCor=0;
     for (int col = 0; col < colEnd; col++)
     {
       int[] theirWidth = MappingUtils.findMappedColumns(col, ourMappings,
               us, them, alignViewport.getGapCharacter());
+      int wid =theirWidth != null ? Math.abs(theirWidth[1] - theirWidth[0])
+              : 0;
       colCorrsp[col] = new Annotation(
-              theirWidth != null ? Math.abs(theirWidth[1] - theirWidth[0])
-                      : 0);
+              wid);
+      maxCor = Math.max(maxCor, wid);
     }
     correspondence=colCorrsp;
   }
@@ -167,7 +174,9 @@ public class AlignmentComparisonThread extends AlignCalcWorker
     if (b || !calcMan.isWorking(this) && correspondence!=null)
     {
       comparisonAnnot.annotations = correspondence;
+      comparisonAnnot.graphMax=(float)maxCor;
       comparisonAnnot.validateRangeAndDisplay();
+      ap.paintAlignment(false, false);
     }
   }