From 3b37db6ed63140990a6cf5a7d36875b94e90a5df Mon Sep 17 00:00:00 2001 From: jprocter Date: Thu, 9 Dec 2010 15:33:08 +0000 Subject: [PATCH] refactored and added methods for getting richer AlignmentView object (JAL-716) --- src/jalview/appletgui/AlignViewport.java | 115 +++++------------------------ src/jalview/gui/AlignViewport.java | 116 +++++------------------------- 2 files changed, 35 insertions(+), 196 deletions(-) diff --git a/src/jalview/appletgui/AlignViewport.java b/src/jalview/appletgui/AlignViewport.java index 6d6a3e6..62c313f 100755 --- a/src/jalview/appletgui/AlignViewport.java +++ b/src/jalview/appletgui/AlignViewport.java @@ -1218,90 +1218,7 @@ public class AlignViewport public jalview.datamodel.CigarArray getViewAsCigars( boolean selectedRegionOnly) { - CigarArray selection = null; - SequenceI[] seqs = null; - int i, iSize; - int start = 0, end = 0; - if (selectedRegionOnly && selectionGroup != null) - { - iSize = selectionGroup.getSize(); - seqs = selectionGroup.getSequencesInOrder(alignment); - start = selectionGroup.getStartRes(); - end = selectionGroup.getEndRes(); // inclusive for start and end in - // SeqCigar constructor - } - else - { - iSize = alignment.getHeight(); - seqs = alignment.getSequencesArray(); - end = alignment.getWidth() - 1; - } - SeqCigar[] selseqs = new SeqCigar[iSize]; - for (i = 0; i < iSize; i++) - { - selseqs[i] = new SeqCigar(seqs[i], start, end); - } - selection = new CigarArray(selseqs); - // now construct the CigarArray operations - if (hasHiddenColumns) - { - Vector regions = colSel.getHiddenColumns(); - int[] region; - int hideStart, hideEnd; - int last = start; - for (int j = 0; last < end & j < regions.size(); j++) - { - region = (int[]) regions.elementAt(j); - hideStart = region[0]; - hideEnd = region[1]; - // edit hidden regions to selection range - if (hideStart < last) - { - if (hideEnd > last) - { - hideStart = last; - } - else - { - continue; - } - } - - if (hideStart > end) - { - break; - } - - if (hideEnd > end) - { - hideEnd = end; - } - - if (hideStart > hideEnd) - { - break; - } - /** - * form operations... - */ - if (last < hideStart) - { - selection.addOperation(CigarArray.M, hideStart - last); - } - selection.addOperation(CigarArray.D, 1 + hideEnd - hideStart); - last = hideEnd + 1; - } - // Final match if necessary. - if (last < end) - { - selection.addOperation(CigarArray.M, end - last + 1); - } - } - else - { - selection.addOperation(CigarArray.M, end - start + 1); - } - return selection; + return new jalview.datamodel.CigarArray(alignment, (hasHiddenColumns ? colSel : null), (selectedRegionOnly ? selectionGroup : null)); } /** @@ -1313,22 +1230,24 @@ public class AlignViewport * @return AlignmentView */ jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly) + { + return getAlignmentView(selectedOnly, false); + } + + /** + * return a compact representation of the current alignment selection to pass + * to an analysis function + * + * @param selectedOnly + * boolean true to just return the selected view + * @param markGroups + * boolean true to annotate the alignment view with groups on the alignment (and intersecting with selected region if selectedOnly is true) + * @return AlignmentView + */ + public jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly, boolean markGroups) { - // JBPNote: - // this is here because the AlignmentView constructor modifies the - // CigarArray - // object. Refactoring of Cigar and alignment view representation should - // be done to remove redundancy. - CigarArray aligview = getViewAsCigars(selectedOnly); - if (aligview != null) - { - return new AlignmentView(aligview, - (selectedOnly && selectionGroup != null) ? selectionGroup - .getStartRes() : 0); - } - return null; + return new AlignmentView(alignment, colSel, selectionGroup, hasHiddenColumns, selectedOnly, markGroups); } - /** * This method returns the visible alignment as text, as seen on the GUI, ie * if columns are hidden they will not be returned in the result. Use this for diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index ef7d35c..033b3bc 100755 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -1565,90 +1565,7 @@ public class AlignViewport implements SelectionSource public jalview.datamodel.CigarArray getViewAsCigars( boolean selectedRegionOnly) { - CigarArray selection = null; - SequenceI[] seqs = null; - int i, iSize; - int start = 0, end = 0; - if (selectedRegionOnly && selectionGroup != null) - { - iSize = selectionGroup.getSize(); - seqs = selectionGroup.getSequencesInOrder(alignment); - start = selectionGroup.getStartRes(); - end = selectionGroup.getEndRes(); // inclusive for start and end in - // SeqCigar constructor - } - else - { - iSize = alignment.getHeight(); - seqs = alignment.getSequencesArray(); - end = alignment.getWidth() - 1; - } - SeqCigar[] selseqs = new SeqCigar[iSize]; - for (i = 0; i < iSize; i++) - { - selseqs[i] = new SeqCigar(seqs[i], start, end); - } - selection = new CigarArray(selseqs); - // now construct the CigarArray operations - if (hasHiddenColumns) - { - Vector regions = colSel.getHiddenColumns(); - int[] region; - int hideStart, hideEnd; - int last = start; - for (int j = 0; last < end & j < regions.size(); j++) - { - region = (int[]) regions.elementAt(j); - hideStart = region[0]; - hideEnd = region[1]; - // edit hidden regions to selection range - if (hideStart < last) - { - if (hideEnd > last) - { - hideStart = last; - } - else - { - continue; - } - } - - if (hideStart > end) - { - break; - } - - if (hideEnd > end) - { - hideEnd = end; - } - - if (hideStart > hideEnd) - { - break; - } - /** - * form operations... - */ - if (last < hideStart) - { - selection.addOperation(CigarArray.M, hideStart - last); - } - selection.addOperation(CigarArray.D, 1 + hideEnd - hideStart); - last = hideEnd + 1; - } - // Final match if necessary. - if (last < end) - { - selection.addOperation(CigarArray.M, end - last + 1); - } - } - else - { - selection.addOperation(CigarArray.M, end - start + 1); - } - return selection; + return new jalview.datamodel.CigarArray(alignment, (hasHiddenColumns ? colSel : null), (selectedRegionOnly ? selectionGroup : null)); } /** @@ -1659,21 +1576,24 @@ public class AlignViewport implements SelectionSource * boolean true to just return the selected view * @return AlignmentView */ - jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly) + public jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly) { - // JBPNote: - // this is here because the AlignmentView constructor modifies the - // CigarArray - // object. Refactoring of Cigar and alignment view representation should - // be done to remove redundancy. - CigarArray aligview = getViewAsCigars(selectedOnly); - if (aligview != null) - { - return new AlignmentView(aligview, - (selectedOnly && selectionGroup != null) ? selectionGroup - .getStartRes() : 0); - } - return null; + return getAlignmentView(selectedOnly, false); + } + + /** + * return a compact representation of the current alignment selection to pass + * to an analysis function + * + * @param selectedOnly + * boolean true to just return the selected view + * @param markGroups + * boolean true to annotate the alignment view with groups on the alignment (and intersecting with selected region if selectedOnly is true) + * @return AlignmentView + */ + public jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly, boolean markGroups) + { + return new AlignmentView(alignment, colSel, selectionGroup, hasHiddenColumns, selectedOnly, markGroups); } /** -- 1.7.10.2