From: James Procter Date: Sat, 16 Dec 2023 08:43:06 +0000 (+0000) Subject: JAL-789 pairwise alignment via calculations dialog, allowing score model to be changed X-Git-Tag: Release_2_11_4_0~31^2~4 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=fe86192e63ce740b92eec50deb6305c19a58325f;p=jalview.git JAL-789 pairwise alignment via calculations dialog, allowing score model to be changed merged in with feature/JAL-4159_pasimap --- diff --git a/src/jalview/analysis/AlignSeq.java b/src/jalview/analysis/AlignSeq.java index 1abbda7..757c8d1 100755 --- a/src/jalview/analysis/AlignSeq.java +++ b/src/jalview/analysis/AlignSeq.java @@ -24,6 +24,7 @@ import jalview.analysis.scoremodels.PIDModel; import jalview.analysis.scoremodels.ScoreMatrix; import jalview.analysis.scoremodels.ScoreModels; import jalview.analysis.scoremodels.SimilarityParams; +import jalview.api.analysis.SimilarityParamsI; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.Mapping; @@ -1500,6 +1501,8 @@ public class AlignSeq public void setScoreMatrix(ScoreMatrix sm) { - this.scoreMatrix = sm; + if (sm != null) { + scoreMatrix = sm; + } } } diff --git a/src/jalview/gui/CalculationChooser.java b/src/jalview/gui/CalculationChooser.java index c9737a1..bf67a44 100644 --- a/src/jalview/gui/CalculationChooser.java +++ b/src/jalview/gui/CalculationChooser.java @@ -63,6 +63,7 @@ import javax.swing.event.InternalFrameEvent; import jalview.analysis.AlignmentUtils; import jalview.analysis.TreeBuilder; +import jalview.analysis.scoremodels.ScoreMatrix; import jalview.analysis.scoremodels.ScoreModels; import jalview.analysis.scoremodels.SimilarityParams; import jalview.api.analysis.ScoreModelI; @@ -87,6 +88,9 @@ public class CalculationChooser extends JPanel private static final Font VERDANA_11PT = new Font("Verdana", 0, 11); + + private static final int MIN_PAIRWISE_SELECTION = 2; + private static final int MIN_TREE_SELECTION = 3; private static final int MIN_PCA_SELECTION = 4; @@ -113,6 +117,8 @@ public class CalculationChooser extends JPanel AlignFrame af; + JRadioButton pairwise; + JRadioButton pca; JRadioButton pasimap; @@ -209,6 +215,9 @@ public class CalculationChooser extends JPanel averageDistance = new JRadioButton( MessageManager.getString("label.tree_calc_av")); averageDistance.setOpaque(false); + + pairwise = new JRadioButton(MessageManager.getString("label.pairwise_alignment")); + pairwise.setOpaque(false); JPanel calcChoicePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); calcChoicePanel.setOpaque(false); @@ -242,12 +251,14 @@ public class CalculationChooser extends JPanel treePanel.add(averageDistance); calcChoicePanel.add(treePanel); + calcChoicePanel.add(pairwise,FlowLayout.CENTER); ButtonGroup calcTypes = new ButtonGroup(); calcTypes.add(pca); calcTypes.add(pasimap); calcTypes.add(neighbourJoining); calcTypes.add(averageDistance); + calcTypes.add(pairwise); ActionListener calcChanged = new ActionListener() { @@ -266,7 +277,7 @@ public class CalculationChooser extends JPanel //to do ssSourceDropdown = buildSSSourcesOptionsList(); ssSourceDropdown.setVisible(false); // Initially hide the dropdown - + pairwise.addActionListener(calcChanged); /* * score models drop-down - with added tooltips! */ @@ -394,8 +405,10 @@ public class CalculationChooser extends JPanel MIN_TREE_SELECTION); boolean checkAverageDistance = checkEnabled(averageDistance, size, MIN_TREE_SELECTION); + boolean checkPairwise = checkEnabled(pairwise, size, + MIN_PAIRWISE_SELECTION); - if (checkPca || checkPasimap || checkNeighbourJoining || checkAverageDistance) + if (checkPca || checkPasimap || checkPca || checkNeighbourJoining || checkAverageDistance || checkPairwise) { calculate.setToolTipText(null); calculate.setEnabled(true); @@ -651,6 +664,7 @@ public class CalculationChooser extends JPanel { boolean doPCA = pca.isSelected(); boolean doPaSiMap = pasimap.isSelected(); + boolean doPairwise= pairwise.isSelected(); String modelName = modelNames.getSelectedItem() == null ? "" : modelNames.getSelectedItem().toString(); String ssSource = ""; Object selectedItem = ssSourceDropdown.getSelectedItem(); @@ -663,22 +677,35 @@ public class CalculationChooser extends JPanel params.setSecondaryStructureSource(ssSource); } - if (doPCA && !doPaSiMap) + if (doPCA) { openPcaPanel(modelName, params); - } - else if (doPaSiMap && !doPCA) - { - openPasimapPanel(modelName, params); - } - else - { - openTreePanel(modelName, params); - } + } else if (doPaSiMap) { + openPasimapPanel(modelName, params); + } else if (doPairwise) { + openPairwisePanel(modelName, params); + } else { + openTreePanel(modelName, params); + } closeFrame(); } + private void openPairwisePanel(String modelName, SimilarityParamsI params) + { + ScoreModelI sm = ScoreModels.getInstance().getScoreModel(modelName, af.alignPanel); + if (sm==null || !(sm instanceof ScoreMatrix)) + { + return; + } + JInternalFrame frame = new JInternalFrame(); + frame.setFrameIcon(null); + frame.setContentPane(new PairwiseAlignPanel(af.getViewport(),(ScoreMatrix)sm)); + Desktop.addInternalFrame(frame, + MessageManager.getString("action.pairwise_alignment"), 600, + 500); + } + /** * Open a new Tree panel on the desktop * diff --git a/src/jalview/gui/PaSiMapPanel.java b/src/jalview/gui/PaSiMapPanel.java index 4a2d19d..3bf731d 100644 --- a/src/jalview/gui/PaSiMapPanel.java +++ b/src/jalview/gui/PaSiMapPanel.java @@ -212,7 +212,7 @@ public class PaSiMapPanel extends GPaSiMapPanel } PairwiseAlignPanel pap = new PairwiseAlignPanel(av, selGroup, true, - GAP_OPEN_COST, GAP_EXTEND_COST, false); + GAP_OPEN_COST, GAP_EXTEND_COST, false, null); System.out.println(pap != null); setPairwiseAlignPanel(pap); getPasimapModel().calculate(pap); diff --git a/src/jalview/gui/PairwiseAlignPanel.java b/src/jalview/gui/PairwiseAlignPanel.java index 8b59197..e8b130e 100755 --- a/src/jalview/gui/PairwiseAlignPanel.java +++ b/src/jalview/gui/PairwiseAlignPanel.java @@ -22,6 +22,8 @@ package jalview.gui; import jalview.analysis.AlignSeq; import jalview.analysis.scoremodels.ScoreMatrix; +import jalview.api.analysis.ScoreModelI; +import jalview.api.analysis.SimilarityParamsI; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentView; import jalview.datamodel.SequenceGroup; @@ -86,20 +88,34 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel * Creates a new PairwiseAlignPanel object. * * @param viewport - * DOCUMENT ME! + * contains selected sequences to align * @param endGaps ~ toggle gaps and the beginning and end of sequences */ public PairwiseAlignPanel(AlignmentViewport viewport) { - this(viewport, null, false, 120, 20, true); // default penalties used in AlignSeq + this(viewport, null, false, 120, 20, true, null); // default penalties used in AlignSeq + } + public PairwiseAlignPanel(AlignmentViewport viewport, ScoreMatrix params) + { + this(viewport, null, false, 120, 20, true,params); // default penalties used in AlignSeq } public PairwiseAlignPanel(AlignmentViewport viewport, boolean endGaps, int gapOpenCost, int gapExtendCost) { - this(viewport, null, endGaps, gapOpenCost, gapExtendCost, true); + this(viewport, null, endGaps, gapOpenCost, gapExtendCost, true, null); } + /** + * Create a new pairwise alignpanel with specified parameters and score model, and optionally start the calculation + * @param viewport + * @param selection + * @param endGaps + * @param gapOpenCost + * @param gapExtendCost + * @param run + * @param scoreMatrix + */ public PairwiseAlignPanel(AlignmentViewport viewport, SequenceGroup selection, boolean endGaps, - int gapOpenCost, int gapExtendCost, boolean run) + int gapOpenCost, int gapExtendCost, boolean run, ScoreMatrix scoreMatrix) { super(); this.av = viewport; @@ -108,9 +124,11 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel this.endGaps = endGaps; this.selection = selection; this.total = MiscMath.combinations(av.getAlignment().getHeight(), 2); - - if (run) - calculate(); + + if (run) { + calculate(scoreMatrix); + } + System.out.println("Creating pap"); } @@ -178,10 +196,12 @@ 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) + if (sm != null) { + as.setScoreMatrix(sm); + } + + if (as.s1str.length() == 0 || as.s2str.length() == 0) { continue; }