From 9b3219d225131af5a165553f206ebf8da304ee23 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 30 Nov 2015 09:33:36 +0000 Subject: [PATCH] JAL-653 (experimental) 'realise' dummy sequences in add alignment --- src/jalview/gui/AlignViewport.java | 103 +++++++++++++++++++++++++++++------- 1 file changed, 84 insertions(+), 19 deletions(-) diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 92c6355..5944b80 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -482,6 +482,7 @@ public class AlignViewport extends AlignmentViewport implements * * @return DOCUMENT ME! */ + @Override public char getGapCharacter() { return getAlignment().getGapCharacter(); @@ -506,6 +507,7 @@ public class AlignViewport extends AlignmentViewport implements * * @return DOCUMENT ME! */ + @Override public ColumnSelection getColumnSelection() { return colSel; @@ -617,6 +619,7 @@ public class AlignViewport extends AlignmentViewport implements /** * Send the current selection to be broadcast to any selection listeners. */ + @Override public void sendSelection() { jalview.structure.StructureSelectionManager @@ -736,6 +739,7 @@ public class AlignViewport extends AlignmentViewport implements return seqvectors.toArray(new SequenceI[seqvectors.size()][]); } + @Override public boolean isNormaliseSequenceLogo() { return normaliseSequenceLogo; @@ -750,6 +754,7 @@ public class AlignViewport extends AlignmentViewport implements * * @return true if alignment characters should be displayed */ + @Override public boolean isValidCharWidth() { return validCharWidth; @@ -825,10 +830,10 @@ public class AlignViewport extends AlignmentViewport implements * may give the user the option to open a new frame, or split panel, with cDNA * and protein linked. * - * @param al + * @param toAdd * @param title */ - public void addAlignment(AlignmentI al, String title) + public void addAlignment(AlignmentI toAdd, String title) { // TODO: promote to AlignViewportI? applet CutAndPasteTransfer is different @@ -841,25 +846,37 @@ public class AlignViewport extends AlignmentViewport implements // TODO: create undo object for this JAL-1101 /* - * If any cDNA/protein mappings can be made between the alignments, offer to - * open a linked alignment with split frame option. + * Ensure datasets are created for the new alignment as + * mappings operate on dataset sequences + */ + toAdd.setDataset(null); + + /* + * Check if any added sequence could be the object of a mapping or + * cross-reference; if so, make the mapping explicit + */ + realiseMappings(getAlignment(), toAdd); + + /* + * If any cDNA/protein mappings exist or can be made between the alignments, + * offer to open a split frame with linked alignments */ if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true)) { - if (al.getDataset() == null) - { - // need to create ds seqs - for (SequenceI sq : al.getSequences()) - { - if (sq.getDatasetSequence() == null) - { - sq.createDatasetSequence(); - } - } - } - if (AlignmentUtils.isMappable(al, getAlignment())) + // if (toAdd.getDataset() == null) + // { + // // need to create ds seqs + // for (SequenceI sq : toAdd.getSequences()) + // { + // if (sq.getDatasetSequence() == null) + // { + // sq.createDatasetSequence(); + // } + // } + // } + if (AlignmentUtils.isMappable(toAdd, getAlignment())) { - if (openLinkedAlignment(al, title)) + if (openLinkedAlignment(toAdd, title)) { return; } @@ -872,9 +889,9 @@ public class AlignViewport extends AlignmentViewport implements // TODO: JAL-407 regardless of above - identical sequences (based on ID and // provenance) should share the same dataset sequence - for (int i = 0; i < al.getHeight(); i++) + for (int i = 0; i < toAdd.getHeight(); i++) { - getAlignment().addSequence(al.getSequenceAt(i)); + getAlignment().addSequence(toAdd.getSequenceAt(i)); } setEndSeq(getAlignment().getHeight()); @@ -882,6 +899,54 @@ public class AlignViewport extends AlignmentViewport implements } /** + * Check if any added sequence could be the object of a mapping or + * cross-reference; if so, make the mapping explicit. Returns the count of + * mappings updated. + * + * @param al + * @param toAdd + */ + protected int realiseMappings(AlignmentI al, AlignmentI toAdd) + { + // TODO this is proof of concept + // we might want to give the user some choice here + int count = 0; + for (SequenceI seq : toAdd.getSequences()) + { + count += realiseMappingsTo(al, seq); + } + return count; + } + + /** + * If the alignment holds any mappings to a dummy (placeholder) sequence that + * matches the given sequence, then update the mapping to point to the + * sequence. Returns the number of mappings updated. + * + * @param al + * @param seq + * @return + */ + protected int realiseMappingsTo(AlignmentI al, SequenceI seq) + { + int count = 0; + Set mappings = al.getDataset().getCodonFrames(); + // TODO are mappings on alignment or alignment dataset?!? + for (AlignedCodonFrame mapping : mappings) + { + /* + * TODO could just go straight to realiseWith() here unless we want + * to give the user some choice before going ahead + */ + if (mapping.isRealisableWith(seq)) + { + count += mapping.realiseWith(seq); + } + } + return count; + } + + /** * Show a dialog with the option to open and link (cDNA <-> protein) as a new * alignment, either as a standalone alignment or in a split frame. Returns * true if the new alignment was opened, false if not, because the user -- 1.7.10.2