JAL-4366 JAL-728 simple hack to use 3di matrix when gecos-3di is enabled
[jalview.git] / src / jalview / analysis / Conservation.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);