From: gmungoc Date: Mon, 4 Jul 2016 14:21:49 +0000 (+0100) Subject: JAL-2110 use shared alignment dataset when copying alignment for split X-Git-Tag: Release_2_10_0~140^2~5^2~23 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=f931c557266d95b3f4ab5b64bd108123c90e85ab JAL-2110 use shared alignment dataset when copying alignment for split frame --- diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index 9150d62..033f7e5 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -2211,32 +2211,15 @@ public class AlignmentUtils * * @param seqs * @param xrefs + * @param dataset + * alignment dataset shared by the new copy * @return */ public static AlignmentI makeCopyAlignment(SequenceI[] seqs, - SequenceI[] xrefs) + SequenceI[] xrefs, AlignmentI dataset) { 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); - } + copy.setDataset(dataset); SequenceIdMatcher matcher = new SequenceIdMatcher(seqs); if (xrefs != null) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index b310ab9..15b1fb4 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -4787,8 +4787,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } else { + /* + * copy peptide sequences, and add in any alternate products + * of their located coding xrefs + */ copyAlignment = AlignmentUtils.makeCopyAlignment( - sequenceSelection, xrefs.getSequencesArray()); + sequenceSelection, xrefs.getSequencesArray(), dataset); } copyAlignment.setGapCharacter(AlignFrame.this.viewport .getGapCharacter()); diff --git a/test/jalview/analysis/AlignmentUtilsTests.java b/test/jalview/analysis/AlignmentUtilsTests.java index d704ec6..9394385 100644 --- a/test/jalview/analysis/AlignmentUtilsTests.java +++ b/test/jalview/analysis/AlignmentUtilsTests.java @@ -1015,13 +1015,19 @@ public class AlignmentUtilsTests .contains(cds.getSequenceAt(1).getDatasetSequence())); /* - * Verify mappings from CDS to peptide, cDNA to CDS, and cDNA to peptide - * the mappings are on the shared alignment dataset + * verify cds has dbref with mapping to protein and vice versa */ - List cdsMappings = cds.getDataset().getCodonFrames(); + DBRefEntry[] cdsDbrefs = cds.getSequenceAt(0).getDBRefs(); + // assertNotNull(cdsDbrefs); + // assertEquals(1, cdsDbrefs.length); + // assertNotNull(cdsDbrefs[0].getMap()); + /* + * Verify mappings from CDS to peptide, cDNA to CDS, and cDNA to peptide + * the mappings are on the shared alignment dataset * 6 mappings, 2*(DNA->CDS), 2*(DNA->Pep), 2*(CDS->Pep) */ + List cdsMappings = cds.getDataset().getCodonFrames(); assertEquals(6, cdsMappings.size()); /* diff --git a/test/jalview/datamodel/SequenceTest.java b/test/jalview/datamodel/SequenceTest.java index 5c5c5c3..eb32e5d 100644 --- a/test/jalview/datamodel/SequenceTest.java +++ b/test/jalview/datamodel/SequenceTest.java @@ -78,7 +78,18 @@ public class SequenceTest // change sequence, should trigger an update of cached result sq.setSequence("ASDFASDFADSF"); assertTrue(sq.isProtein()); + + /* + * in situ change of sequence doesn't change hashcode :-O + * (sequence should not expose internal implementation) + */ + for (int i = 0; i < sq.getSequence().length; i++) + { + sq.getSequence()[i] = "acgtu".charAt(i % 5); + } + assertTrue(sq.isProtein()); // but it isn't } + @Test(groups = { "Functional" }) public void testGetAnnotation() {