From 693451006944585e867137a70866d9dd40f421f2 Mon Sep 17 00:00:00 2001 From: jprocter Date: Tue, 2 Oct 2007 15:48:40 +0000 Subject: [PATCH] javadoc and operator for editing AlignmentAnnotation to remove hidden columns --- src/jalview/datamodel/ColumnSelection.java | 95 ++++++++++++++++++++++++++-- 1 file changed, 88 insertions(+), 7 deletions(-) diff --git a/src/jalview/datamodel/ColumnSelection.java b/src/jalview/datamodel/ColumnSelection.java index 4904495..73b7899 100644 --- a/src/jalview/datamodel/ColumnSelection.java +++ b/src/jalview/datamodel/ColumnSelection.java @@ -108,11 +108,11 @@ public class ColumnSelection } /** - * DOCUMENT ME! + * Column number at position i in selection * - * @param i DOCUMENT ME! + * @param i index into selected columns * - * @return DOCUMENT ME! + * @return column number in alignment */ public int columnAt(int i) { @@ -130,9 +130,9 @@ public class ColumnSelection } /** - * DOCUMENT ME! + * rightmost selected column * - * @return DOCUMENT ME! + * @return rightmost column in alignment that is selected */ public int getMax() { @@ -150,9 +150,9 @@ public class ColumnSelection } /** - * DOCUMENT ME! + * Leftmost column in selection * - * @return DOCUMENT ME! + * @return column index of leftmost column in selection */ public int getMin() { @@ -900,4 +900,85 @@ public class ColumnSelection start, end - 1}; } } + + /** + * delete any columns in alignmentAnnotation that are hidden (including sequence associated annotation). + * @param alignmentAnnotation + */ + public void makeVisibleAnnotation(AlignmentAnnotation alignmentAnnotation) + { + makeVisibleAnnotation(-1,-1,alignmentAnnotation); + } + /** + * delete any columns in alignmentAnnotation that are hidden (including sequence associated annotation). + * @param start remove any annotation to the right of this column + * @param end remove any annotation to the left of this column + * @param alignmentAnnotation the annotation to operate on + */ + public void makeVisibleAnnotation(int start, int end, AlignmentAnnotation alignmentAnnotation) + { + if (alignmentAnnotation.annotations==null) + { + return; + } + if (start==end && end==-1) + { + start = 0; + end = alignmentAnnotation.annotations.length; + } + if (hiddenColumns != null && hiddenColumns.size() > 0) + { + // then mangle the alignmentAnnotation annotation array + Vector annels = new Vector(); + Annotation[] els = null; + Vector regions = getHiddenColumns(); + int blockStart = start, blockEnd = end; + int[] region; + int hideStart, hideEnd,w=0; + + for (int j = 0; j < regions.size(); j++) + { + region = (int[]) regions.elementAt(j); + hideStart = region[0]; + hideEnd = region[1]; + + if (hideStart < start) + { + continue; + } + + blockStart = Math.min(blockStart, hideEnd + 1); + blockEnd = Math.min(blockEnd, hideStart); + + if (blockStart > blockEnd) + { + break; + } + + annels.addElement(els = new Annotation[blockEnd-blockStart]); + System.arraycopy(alignmentAnnotation.annotations, blockStart, els, 0, els.length); + w+=els.length; + blockStart = hideEnd + 1; + blockEnd = end; + } + + if (end > blockStart) + { + annels.addElement(els = new Annotation[end-blockStart]); + System.arraycopy(alignmentAnnotation.annotations, blockStart, els, 0, els.length); + w+=els.length; + } + if (w==0) + return; + Enumeration e = annels.elements(); + alignmentAnnotation.annotations = new Annotation[w]; + w=0; + while (e.hasMoreElements()) + { + Annotation[] chnk = (Annotation[]) e.nextElement(); + System.arraycopy(chnk, 0, alignmentAnnotation.annotations, w, chnk.length); + w+=chnk.length; + } + } + } } -- 1.7.10.2