From bd306b69256571ae575562d3079c842fa3be43f5 Mon Sep 17 00:00:00 2001 From: Mateusz Warowny Date: Tue, 17 Oct 2023 14:24:33 +0200 Subject: [PATCH] JAL-1601 Create alignment copying method in AlignmentUtils --- src/jalview/analysis/AlignmentUtils.java | 23 ++++++++++++++++++++++ src/jalview/ws2/gui/SearchServiceGuiHandler.java | 15 ++------------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index 6ac59ba..efe5228 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -48,6 +48,7 @@ import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.DBRefEntry; import jalview.datamodel.GeneLociI; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.IncompleteCodonException; import jalview.datamodel.Mapping; import jalview.datamodel.Sequence; @@ -2768,4 +2769,26 @@ public class AlignmentUtils } return true; } + + /** + * Creates a deep copy of an alignment along with a dataset alignment, + * alignment annotations, representative sequence and hidden columns. + */ + public static AlignmentI deepCopyAlignment(AlignmentI alignment) + { + var alnCpy = new Alignment(alignment); + alnCpy.setGapCharacter(alignment.getGapCharacter()); + alnCpy.setDataset(alignment.getDataset()); + for (AlignmentAnnotation annotation : alignment.getAlignmentAnnotation()) + alnCpy.addAnnotation(new AlignmentAnnotation(annotation)); + if (alignment.hasSeqrep()) + { + int idx = alignment.findIndex(alignment.getSeqrep()); + if (idx >= 0) + alnCpy.setSeqrep(alnCpy.getSequenceAt(idx)); + } + if (alignment.getHiddenColumns() != null) + alnCpy.setHiddenColumns(new HiddenColumns(alignment.getHiddenColumns())); + return alnCpy; + } } diff --git a/src/jalview/ws2/gui/SearchServiceGuiHandler.java b/src/jalview/ws2/gui/SearchServiceGuiHandler.java index e66315f..6c7ee13 100644 --- a/src/jalview/ws2/gui/SearchServiceGuiHandler.java +++ b/src/jalview/ws2/gui/SearchServiceGuiHandler.java @@ -4,6 +4,7 @@ import java.util.List; import javax.swing.SwingUtilities; +import jalview.analysis.AlignmentUtils; import jalview.bin.Console; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; @@ -138,19 +139,7 @@ class SearchServiceGuiHandler implements TaskEventListener } infoPanel.showResultsNewFrame.addActionListener(evt -> { // copy alignment for each frame to have its own instance - var alnCpy = new Alignment(result); - alnCpy.setGapCharacter(result.getGapCharacter()); - alnCpy.setDataset(result.getDataset()); - for (AlignmentAnnotation annotation : result.getAlignmentAnnotation()) - alnCpy.addAnnotation(new AlignmentAnnotation(annotation)); - if (result.hasSeqrep()) - { - int idx = result.findIndex(result.getSeqrep()); - if (idx >= 0) - alnCpy.setSeqrep(alnCpy.getSequenceAt(idx)); - } - if (result.getHiddenColumns() != null) - alnCpy.setHiddenColumns(new HiddenColumns(result.getHiddenColumns())); + var alnCpy = AlignmentUtils.deepCopyAlignment(result); displayResultsNewFrame(alnCpy); }); SwingUtilities.invokeLater(infoPanel::setResultsReady); -- 1.7.10.2