From 6ad5371a97b278e6fe208610b3547566052c9318 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 7 Mar 2016 12:54:19 +0000 Subject: [PATCH] JAL-2023 fix for CDS shared dataset, robust load of split frame project --- src/jalview/analysis/AlignmentUtils.java | 24 ++++++++++++---- src/jalview/gui/AlignFrame.java | 12 ++++++-- src/jalview/gui/Jalview2XML.java | 11 ++++---- test/jalview/analysis/AlignmentUtilsTests.java | 35 ++++++++++++++++++++---- 4 files changed, 64 insertions(+), 18 deletions(-) diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index f2262fb..332c649 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -1302,7 +1302,9 @@ public class AlignmentUtils /** * Constructs an alignment consisting of the mapped exon regions in the given - * nucleotide sequences, and updates mappings to match. + * nucleotide sequences, and updates mappings to match. The new alignment's + * sequences are added to the parent alignment's dataset, and both alignments + * share the same dataset. * * @param dna * aligned dna sequences @@ -1312,7 +1314,7 @@ public class AlignmentUtils * sequences (or null if no exons are found) */ public static AlignmentI makeExonAlignment(SequenceI[] dna, - Set mappings) + Set mappings, AlignmentI al) { Set newMappings = new LinkedHashSet(); List exonSequences = new ArrayList(); @@ -1334,9 +1336,21 @@ public class AlignmentUtils } } } - AlignmentI al = new Alignment( + AlignmentI cds = new Alignment( exonSequences.toArray(new SequenceI[exonSequences.size()])); - al.setDataset(null); + + /* + * add new sequences to the shared dataset, set it on the new alignment + */ + List dsseqs = al.getDataset().getSequences(); + for (SequenceI seq : cds.getSequences()) + { + if (!dsseqs.contains(seq.getDatasetSequence())) + { + dsseqs.add(seq.getDatasetSequence()); + } + } + cds.setDataset(al.getDataset()); /* * Replace the old mappings with the new ones @@ -1344,7 +1358,7 @@ public class AlignmentUtils mappings.clear(); mappings.addAll(newMappings); - return al; + return cds; } /** diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 63e6787..56cf231 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -845,6 +845,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * operation that affects the data in the current view (selection changed, * etc) to update the menus to reflect the new state. */ + @Override public void setMenusForViewport() { setMenusFromViewport(viewport); @@ -1401,6 +1402,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, alignPanel.makeEPS(f); } + @Override public void createSVG(File f) { alignPanel.makeSVG(f); @@ -1574,6 +1576,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } } + @Override public void addHistoryItem(CommandI command) { if (command.getSize() > 0) @@ -3497,6 +3500,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param cs * DOCUMENT ME! */ + @Override public void changeColour(ColourSchemeI cs) { // TODO: pull up to controller method @@ -4752,8 +4756,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, try { // update our local dataset reference - Alignment ds = AlignFrame.this.getViewport().getAlignment() - .getDataset(); + AlignmentI alignment = AlignFrame.this.getViewport() + .getAlignment(); + Alignment ds = alignment.getDataset(); Alignment prods = CrossRef .findXrefSequences(sel, dna, source, ds); if (prods != null) @@ -4806,7 +4811,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (dna) { copyAlignment = AlignmentUtils.makeExonAlignment( - sequenceSelection, cf); + sequenceSelection, cf, alignment); al.getCodonFrames().clear(); al.getCodonFrames().addAll(cf); final StructureSelectionManager ssm = StructureSelectionManager @@ -5755,6 +5760,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.firePropertyChange("alignment", null, al); } + @Override public void setShowSeqFeatures(boolean b) { showSeqFeatures.setSelected(b); diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index 6fea041..ce8d2dd 100644 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -163,7 +163,7 @@ public class Jalview2XML */ Map seqRefIds = null; - Vector frefedSequence = null; + Vector frefedSequence = null; boolean raiseGUI = true; // whether errors are raised in dialog boxes or not @@ -258,7 +258,7 @@ public class Jalview2XML int r = 0, rSize = frefedSequence.size(); while (r < rSize) { - Object[] ref = (Object[]) frefedSequence.elementAt(r); + Object[] ref = frefedSequence.elementAt(r); if (ref != null) { String sref = (String) ref[0]; @@ -2178,6 +2178,7 @@ public class Jalview2XML { SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { setLoadingFinishedForNewStructureViewers(); @@ -2252,7 +2253,7 @@ public class Jalview2XML } if (frefedSequence == null) { - frefedSequence = new Vector(); + frefedSequence = new Vector(); } AlignFrame af = null, _af = null; @@ -2848,7 +2849,7 @@ public class Jalview2XML { mapping = addMapping(maps[m].getMapping()); } - if (dnaseq != null) + if (dnaseq != null && mapping.getTo() != null) { cf.addMap(dnaseq, mapping.getTo(), mapping.getMap()); } @@ -5088,7 +5089,7 @@ public class Jalview2XML } if (this.frefedSequence == null) { - frefedSequence = new Vector(); + frefedSequence = new Vector(); } viewportsAdded.clear(); diff --git a/test/jalview/analysis/AlignmentUtilsTests.java b/test/jalview/analysis/AlignmentUtilsTests.java index b13f991..febe991 100644 --- a/test/jalview/analysis/AlignmentUtilsTests.java +++ b/test/jalview/analysis/AlignmentUtilsTests.java @@ -1026,11 +1026,23 @@ public class AlignmentUtilsTests acf.addMap(dna2.getDatasetSequence(), pep2.getDatasetSequence(), map); mappings.add(acf); + AlignmentI dna = new Alignment(new SequenceI[] { dna1, dna2 }); + dna.setDataset(null); AlignmentI exons = AlignmentUtils.makeExonAlignment(new SequenceI[] { - dna1, dna2 }, mappings); - assertEquals(2, exons.getSequences().size()); - assertEquals("GGGTTT", exons.getSequenceAt(0).getSequenceAsString()); - assertEquals("GGGTTTCCC", exons.getSequenceAt(1).getSequenceAsString()); + dna1, dna2 }, mappings, dna); + List exonSeqs = exons.getSequences(); + assertEquals(2, exonSeqs.size()); + assertEquals("GGGTTT", exonSeqs.get(0).getSequenceAsString()); + assertEquals("GGGTTTCCC", exonSeqs.get(1).getSequenceAsString()); + + /* + * verify shared, extended alignment dataset + */ + assertSame(dna.getDataset(), exons.getDataset()); + assertTrue(dna.getDataset().getSequences() + .contains(exonSeqs.get(0).getDatasetSequence())); + assertTrue(dna.getDataset().getSequences() + .contains(exonSeqs.get(1).getDatasetSequence())); /* * Verify updated mappings @@ -1183,8 +1195,10 @@ public class AlignmentUtilsTests * Create the Exon alignment; also replaces the dna-to-protein mappings with * exon-to-protein and exon-to-dna mappings */ + AlignmentI dna = new Alignment(new SequenceI[] { dna1 }); + dna.setDataset(null); AlignmentI exal = AlignmentUtils.makeExonAlignment( - new SequenceI[] { dna1 }, mappings); + new SequenceI[] { dna1 }, mappings, dna); /* * Verify we have 3 exon sequences, mapped to pep1/2/3 respectively @@ -1192,6 +1206,17 @@ public class AlignmentUtilsTests List exons = exal.getSequences(); assertEquals(3, exons.size()); + /* + * verify shared, extended alignment dataset + */ + assertSame(dna.getDataset(), exal.getDataset()); + assertTrue(dna.getDataset().getSequences() + .contains(exons.get(0).getDatasetSequence())); + assertTrue(dna.getDataset().getSequences() + .contains(exons.get(1).getDatasetSequence())); + assertTrue(dna.getDataset().getSequences() + .contains(exons.get(2).getDatasetSequence())); + SequenceI exon = exons.get(0); assertEquals("GGGTTT", exon.getSequenceAsString()); assertEquals("dna1|A12345", exon.getName()); -- 1.7.10.2