From: James Procter Date: Tue, 16 Jan 2024 17:28:04 +0000 (+0000) Subject: JAL-4366 JAL-728 simple hack to use 3di matrix when gecos-3di is enabled X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=bc1a3842b31a35a7794f4afec4911ad421c7c3e4;p=jalview.git JAL-4366 JAL-728 simple hack to use 3di matrix when gecos-3di is enabled --- diff --git a/src/jalview/analysis/Conservation.java b/src/jalview/analysis/Conservation.java index 5bb0b09..fdb397f 100755 --- a/src/jalview/analysis/Conservation.java +++ b/src/jalview/analysis/Conservation.java @@ -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 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 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); diff --git a/src/jalview/analysis/scoremodels/ScoreModels.java b/src/jalview/analysis/scoremodels/ScoreModels.java index 3def8c3..95e114e 100644 --- a/src/jalview/analysis/scoremodels/ScoreModels.java +++ b/src/jalview/analysis/scoremodels/ScoreModels.java @@ -181,4 +181,9 @@ public class ScoreModels { return PAM250; } + public ScoreMatrix getFOLDSEEK3DI() + { + return FOLDSEEK3DI; + } + } diff --git a/src/jalview/api/AlignViewportI.java b/src/jalview/api/AlignViewportI.java index 0cfd03d..cde9e1a 100644 --- a/src/jalview/api/AlignViewportI.java +++ b/src/jalview/api/AlignViewportI.java @@ -567,4 +567,6 @@ public interface AlignViewportI extends ViewStyleI Iterator getViewAsVisibleContigs(boolean selectedRegionOnly); ContactMatrixI getContactMatrix(AlignmentAnnotation alignmentAnnotation); + + boolean is3di(); } diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 3e1bc63..0150e62 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -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(); diff --git a/src/jalview/workers/ConservationThread.java b/src/jalview/workers/ConservationThread.java index 54b0191..0afa711 100644 --- a/src/jalview/workers/ConservationThread.java +++ b/src/jalview/workers/ConservationThread.java @@ -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.