From 0ebcd487f08f9873987d9a32edce7df47aa27927 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Tue, 31 May 2016 17:32:08 +0100 Subject: [PATCH] JAL-2023 adjustments to mappings added for split frame to avoid duplication and ensure saved in project --- src/jalview/analysis/AlignmentUtils.java | 20 ++++++++++++++++++++ src/jalview/datamodel/Alignment.java | 17 +++++++++++++++++ src/jalview/datamodel/AlignmentI.java | 8 ++++++++ src/jalview/gui/AlignFrame.java | 18 ++++++++++++++++-- 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index fba023f..081f446 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -2114,6 +2114,26 @@ public class AlignmentUtils { AlignmentI copy = new Alignment(new Alignment(seqs)); + /* + * add mappings between sequences to the new alignment + */ + AlignedCodonFrame mappings = new AlignedCodonFrame(); + copy.addCodonFrame(mappings); + for (int i = 0; i < copy.getHeight(); i++) + { + SequenceI from = seqs[i]; + SequenceI to = copy.getSequenceAt(i); + if (to.getDatasetSequence() != null) + { + to = to.getDatasetSequence(); + } + int start = from.getStart(); + int end = from.getEnd(); + MapList map = new MapList(new int[] { start, end }, new int[] { + start, end }, 1, 1); + mappings.addMap(to, from, map); + } + SequenceIdMatcher matcher = new SequenceIdMatcher(seqs); if (xrefs != null) { diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index a9b0d53..f14539b 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -30,6 +30,7 @@ import java.util.Collections; import java.util.Enumeration; import java.util.HashSet; import java.util.Hashtable; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -1287,6 +1288,22 @@ public class Alignment implements AlignmentI } } + /** + * adds a set of mappings (while ignoring any duplicates) + */ + @Override + public void addCodonFrames(Iterable codons) + { + if (codons != null) + { + Iterator it = codons.iterator(); + while (it.hasNext()) + { + addCodonFrame(it.next()); + } + } + } + /* * (non-Javadoc) * diff --git a/src/jalview/datamodel/AlignmentI.java b/src/jalview/datamodel/AlignmentI.java index 76d1a48..4ae8ba2 100755 --- a/src/jalview/datamodel/AlignmentI.java +++ b/src/jalview/datamodel/AlignmentI.java @@ -363,6 +363,14 @@ public interface AlignmentI extends AnnotatedCollectionI void addCodonFrame(AlignedCodonFrame codons); /** + * add a set of aligned codons mappings for this alignment, apart from any + * duplicates which are ignored + * + * @param codons + */ + void addCodonFrames(Iterable codons); + + /** * remove a particular codon frame reference from this alignment * * @param codons diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index d9d5f27..d548695 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -4679,6 +4679,17 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return showp; } + /** + * Finds and displays cross-references for the selected sequences (protein + * products for nucleotide sequences, dna coding sequences for peptides). + * + * @param sel + * the sequences to show cross-references for + * @param dna + * true if from a nucleotide alignment (so showing proteins) + * @param source + * the database to show cross-references for + */ protected void showProductsFor(final SequenceI[] sel, final boolean dna, final String source) { @@ -4749,7 +4760,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, System.err.println("Failed to make CDS alignment"); } al.getCodonFrames().clear(); - al.getCodonFrames().addAll(copyAlignment.getCodonFrames()); + al.addCodonFrames(copyAlignment.getCodonFrames()); + al.addCodonFrames(cf); /* * pending getting Embl transcripts to 'align', @@ -4767,7 +4779,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { copyAlignment = AlignmentUtils.makeCopyAlignment( sequenceSelection, xrefs.getSequencesArray()); - copyAlignment.getCodonFrames().addAll(cf); + copyAlignment.addCodonFrames(cf); + al.addCodonFrames(copyAlignment.getCodonFrames()); + al.addCodonFrames(cf); } copyAlignment.setGapCharacter(AlignFrame.this.viewport .getGapCharacter()); -- 1.7.10.2