JAL-4366 JAL-728 simple hack to use 3di matrix when gecos-3di is enabled
authorJames Procter <j.procter@dundee.ac.uk>
Tue, 16 Jan 2024 17:28:04 +0000 (17:28 +0000)
committerJames Procter <j.procter@dundee.ac.uk>
Tue, 16 Jan 2024 17:28:04 +0000 (17:28 +0000)
src/jalview/analysis/Conservation.java
src/jalview/analysis/scoremodels/ScoreModels.java
src/jalview/api/AlignViewportI.java
src/jalview/viewmodel/AlignmentViewport.java
src/jalview/workers/ConservationThread.java

index 5bb0b09..fdb397f 100755 (executable)
@@ -24,6 +24,7 @@ import java.util.Locale;
 
 import jalview.analysis.scoremodels.ScoreMatrix;
 import jalview.analysis.scoremodels.ScoreModels;
+import jalview.api.analysis.ScoreModelI;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.Annotation;
 import jalview.datamodel.ResidueCount;
@@ -562,7 +563,32 @@ public class Conservation
   // From Alignment.java in jalview118
   public void findQuality()
   {
-    findQuality(0, maxLength - 1, ScoreModels.getInstance().getBlosum62());
+    findQuality(0, maxLength - 1, getQualitySubstMat());
+  }
+
+  public ScoreMatrix getQualitySubstMat()
+  {
+    return sm;
+  }
+
+  /**
+   * default for quality calc is BLOSUM
+   */
+  private ScoreMatrix sm = ScoreModels.getInstance().getBlosum62();
+
+  /**
+   * set the matrix used for calculating quality scores
+   * 
+   * @param scoreMatrix
+   *          - must be a valid score matrix able to evaluate all amino acid
+   *          substitutions
+   */
+  public void setQualitySubstMat(ScoreMatrix scoreMatrix)
+  {
+    if (scoreMatrix != null && scoreMatrix.isProtein())
+    {
+      sm = scoreMatrix;
+    }
   }
 
   /**
@@ -844,7 +870,40 @@ public class Conservation
           List<SequenceI> seqs, int start, int end, boolean positiveOnly,
           int maxPercentGaps, boolean calcQuality)
   {
+    return calculateConservation(name, seqs, start, end, positiveOnly,
+            maxPercentGaps, calcQuality, null);
+  }
+
+  /**
+   * construct and call the calculation methods on a new Conservation object
+   * 
+   * @param name
+   *          - name of conservation
+   * @param seqs
+   * @param start
+   *          first column in calculation window
+   * @param end
+   *          last column in calculation window
+   * @param positiveOnly
+   *          calculate positive (true) or positive and negative (false)
+   *          conservation
+   * @param maxPercentGaps
+   *          percentage of gaps tolerated in column
+   * @param calcQuality
+   *          flag indicating if alignment quality should be calculated
+   * @param scoreMatrix
+   *          - null or peptide score matrix used for quality calculation
+   * @return Conservation object ready for use in visualization
+   */
+  public static Conservation calculateConservation(String name,
+          List<SequenceI> seqs, int start, int end, boolean positiveOnly,
+          int maxPercentGaps, boolean calcQuality, ScoreMatrix scoreMatrix)
+  {
     Conservation cons = new Conservation(name, seqs, start, end);
+    if (scoreMatrix != null)
+    {
+      cons.setQualitySubstMat(scoreMatrix);
+    }
     cons.calculate();
     cons.verdict(positiveOnly, maxPercentGaps);
 
index 3def8c3..95e114e 100644 (file)
@@ -181,4 +181,9 @@ public class ScoreModels
   {
     return PAM250;
   }
+  public ScoreMatrix getFOLDSEEK3DI()
+  {
+    return FOLDSEEK3DI;
+  }
+  
 }
index 0cfd03d..cde9e1a 100644 (file)
@@ -567,4 +567,6 @@ public interface AlignViewportI extends ViewStyleI
   Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly);
 
   ContactMatrixI getContactMatrix(AlignmentAnnotation alignmentAnnotation);
+
+  boolean is3di();
 }
index 3e1bc63..0150e62 100644 (file)
@@ -2309,6 +2309,14 @@ public abstract class AlignmentViewport
   }
 
   @Override
+  public boolean is3di()
+  {
+    return getAlignment() == null ? false
+            : !isNucleotide() && getGlobalColourScheme() != null
+                    && "3Di-gecos".equalsIgnoreCase(
+                            getGlobalColourScheme().getSchemeName());
+  }
+  @Override
   public boolean isNucleotide()
   {
     return getAlignment() == null ? false : getAlignment().isNucleotide();
index 54b0191..0afa711 100644 (file)
@@ -21,6 +21,7 @@
 package jalview.workers;
 
 import jalview.analysis.Conservation;
+import jalview.analysis.scoremodels.ScoreModels;
 import jalview.api.AlignViewportI;
 import jalview.api.AlignmentViewPanel;
 import jalview.datamodel.AlignmentAnnotation;
@@ -95,9 +96,10 @@ public class ConservationThread extends AlignCalcWorker
       }
       try
       {
+        // TODO - TDI is there a conservation measure ?
         cons = Conservation.calculateConservation("All",
                 alignment.getSequences(), 0, alWidth - 1, false,
-                ConsPercGaps, quality != null);
+                ConsPercGaps, quality != null, alignViewport.is3di() ? ScoreModels.getInstance().getFOLDSEEK3DI():ScoreModels.getInstance().getDefaultModel(true));
       } catch (IndexOutOfBoundsException x)
       {
         // probable race condition. just finish and return without any fuss.