From 6e8e0af46a13c3a314754245ff27273f7a11eb18 Mon Sep 17 00:00:00 2001 From: MorellThomas Date: Thu, 23 May 2024 14:50:03 +0200 Subject: [PATCH] Fix PaSiMap taking scoreModels input and allow AlignSeq/PairwiseAlignPanel to take a ScoreMatrix --- src/jalview/analysis/AlignSeq.java | 33 ++----------------------------- src/jalview/analysis/PaSiMap.java | 20 +++++++++++++++---- src/jalview/gui/CalculationChooser.java | 11 ++++++++++- src/jalview/gui/PairwiseAlignPanel.java | 7 +++++++ 4 files changed, 35 insertions(+), 36 deletions(-) diff --git a/src/jalview/analysis/AlignSeq.java b/src/jalview/analysis/AlignSeq.java index 22cffb1..ae8638d 100755 --- a/src/jalview/analysis/AlignSeq.java +++ b/src/jalview/analysis/AlignSeq.java @@ -1466,37 +1466,8 @@ public class AlignSeq this.alignmentScore = (score <= minScore) ? Float.NaN : score; } - public void clear() + public void setScoreMatrix(ScoreMatrix sm) { - score = null; - alignmentScore = 0f; - E = null; - F = null; - traceback = null; // todo is this actually used? - seq1 = null; - seq2 = null; - s1 = null; - s2 = null; - s1str = null; - s2str = null; - maxi = 0; - maxj = 0; - aseq1 = null; - aseq2 = null; - astr1 = ""; - astr2 = ""; - indelfreeAstr1 = ""; - indelfreeAstr2 = ""; - seq1start = 0; - seq1end = 0; - seq2start = 0; - seq2end = 0; - count = 0; - maxscore = 0f; - meanScore = 0f; //needed for PaSiMap - hypotheticMaxScore = 0; // needed for PaSiMap - prev = 0; - StringBuffer output = new StringBuffer(); - String type = null; // AlignSeq.PEP or AlignSeq.DNA + this.scoreMatrix = sm; } } diff --git a/src/jalview/analysis/PaSiMap.java b/src/jalview/analysis/PaSiMap.java index 86888ee..fd20465 100755 --- a/src/jalview/analysis/PaSiMap.java +++ b/src/jalview/analysis/PaSiMap.java @@ -22,6 +22,8 @@ package jalview.analysis; import jalview.api.analysis.ScoreModelI; import jalview.api.analysis.SimilarityParamsI; +import jalview.analysis.scoremodels.ScoreMatrix; +import jalview.analysis.scoremodels.ScoreModels; import jalview.bin.Console; import jalview.datamodel.Point; import jalview.datamodel.SequenceI; @@ -45,7 +47,7 @@ public class PaSiMap implements Runnable */ final private AlignmentViewport seqs; - final private ScoreModelI scoreModel; + final private ScoreMatrix scoreMatrix; final private byte dim = 8; @@ -73,7 +75,17 @@ public class PaSiMap implements Runnable public PaSiMap(AlignmentViewport sequences, ScoreModelI sm, PairwiseAlignPanel pap) { this.seqs = sequences; - this.scoreModel = sm; + + //convert ScoreModel name into score matrix, use default if not Blosum or Pam + if (sm.getName().equals("BLOSUM62")) + { + this.scoreMatrix = ScoreModels.getInstance().getBlosum62(); + } else if (sm.getName().equals("PAM250")) { + this.scoreMatrix = ScoreModels.getInstance().getPam250(); + } else { + this.scoreMatrix = null; + } + this.alignment = pap; } @@ -163,7 +175,7 @@ public class PaSiMap implements Runnable public String getDetails() { StringBuilder sb = new StringBuilder(1024); - sb.append("PaSiMap calculation using ").append(scoreModel.getName()) + sb.append("PaSiMap calculation using ").append(scoreMatrix.getName()) .append(" sequence similarity matrix\n========\n\n"); PrintStream ps = wrapOutputBuffer(sb); @@ -203,7 +215,7 @@ public class PaSiMap implements Runnable try { //alignment = new PairwiseAlignPanel(seqs, true, 100, 5); - alignment.calculate(); + alignment.calculate(scoreMatrix); float[][] scores = alignment.getAlignmentScores(); //bigger index first -- eg scores[14][13] SequenceI[] iseqs = alignment.getInputSequences(); Connectivity.getConnectivity(iseqs, scores, dim); diff --git a/src/jalview/gui/CalculationChooser.java b/src/jalview/gui/CalculationChooser.java index 3b7ca81..0053547 100644 --- a/src/jalview/gui/CalculationChooser.java +++ b/src/jalview/gui/CalculationChooser.java @@ -601,13 +601,22 @@ public class CalculationChooser extends JPanel ScoreModels scoreModels = ScoreModels.getInstance(); for (ScoreModelI sm : scoreModels.getModels()) { - if ((!nucleotide && sm.isProtein() || nucleotide && sm.isDNA() + if (!forPasimap && (!nucleotide && sm.isProtein() || nucleotide && sm.isDNA() || sm.isSecondaryStructure() && ssPresent)) { filtered.add(sm); } } + + /* + * make PaSiMap only use Blosum62 and Pam250 + */ + if (forPasimap && !nucleotide && !forPca) + { + filtered.add(scoreModels.getBlosum62()); + filtered.add(scoreModels.getPam250()); + } /* * special case: add BLOSUM62 as last option for nucleotide PCA, diff --git a/src/jalview/gui/PairwiseAlignPanel.java b/src/jalview/gui/PairwiseAlignPanel.java index 6800b0c..65f1c6d 100755 --- a/src/jalview/gui/PairwiseAlignPanel.java +++ b/src/jalview/gui/PairwiseAlignPanel.java @@ -21,6 +21,7 @@ package jalview.gui; import jalview.analysis.AlignSeq; +import jalview.analysis.scoremodels.ScoreMatrix; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentView; import jalview.datamodel.SequenceGroup; @@ -115,6 +116,10 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel public void calculate() { + calculate(null); + } + public void calculate (ScoreMatrix sm) + { StringBuilder sb = new StringBuilder(1024); @@ -176,6 +181,8 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel { AlignSeq as = new AlignSeq(seqs[i], seqStrings[i], seqs[j], seqStrings[j], type, GAP_OPEN_COST, GAP_EXTEND_COST); + if (sm != null) + as.setScoreMatrix(sm); if (as.s1str.length() == 0 || as.s2str.length() == 0) { -- 1.7.10.2