import jalview.analysis.SecStrConsensus.SimpleBP;
import jalview.analysis.WUSSParseException;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
this.calcId = annotation.calcId;
if (annotation.properties != null)
{
- properties = new HashMap<String, String>();
+ properties = new HashMap<>();
for (Map.Entry<String, String> val : annotation.properties.entrySet())
{
properties.put(val.getKey(), val.getValue());
if (annotation.sequenceMapping != null)
{
Integer p = null;
- sequenceMapping = new HashMap<Integer, Annotation>();
+ sequenceMapping = new HashMap<>();
Iterator<Integer> pos = annotation.sequenceMapping.keySet()
.iterator();
while (pos.hasNext())
int epos = sequenceRef.findPosition(endRes);
if (sequenceMapping != null)
{
- Map<Integer, Annotation> newmapping = new HashMap<Integer, Annotation>();
+ Map<Integer, Annotation> newmapping = new HashMap<>();
Iterator<Integer> e = sequenceMapping.keySet().iterator();
while (e.hasNext())
{
{
return;
}
- sequenceMapping = new HashMap<Integer, Annotation>();
+ sequenceMapping = new HashMap<>();
int seqPos;
{
return;
}
- hidden.makeVisibleAnnotation(this);
+ makeVisibleAnnotation(hidden);
}
public void setPadGaps(boolean padgaps, char gapchar)
/**
* properties associated with the calcId
*/
- protected Map<String, String> properties = new HashMap<String, String>();
+ protected Map<String, String> properties = new HashMap<>();
/**
* base colour for line graphs. If null, will be set automatically by
: false;
// TODO build a better annotation element map and get rid of annotations[]
- Map<Integer, Annotation> mapForsq = new HashMap<Integer, Annotation>();
+ Map<Integer, Annotation> mapForsq = new HashMap<>();
if (sequenceMapping != null)
{
if (sp2sq != null)
if (mapping != null)
{
Map<Integer, Annotation> old = sequenceMapping;
- Map<Integer, Annotation> remap = new HashMap<Integer, Annotation>();
+ Map<Integer, Annotation> remap = new HashMap<>();
int index = -1;
for (int mp[] : mapping.values())
{
{
if (properties == null)
{
- properties = new HashMap<String, String>();
+ properties = new HashMap<>();
}
properties.put(property, value);
}
{
return graphMin < graphMax;
}
+
+ /**
+ * delete any columns in alignmentAnnotation that are hidden (including
+ * sequence associated annotation).
+ *
+ * @param hiddenColumns
+ * the set of hidden columns
+ */
+ public void makeVisibleAnnotation(HiddenColumns hiddenColumns)
+ {
+ if (annotations != null)
+ {
+ makeVisibleAnnotation(0, annotations.length, hiddenColumns);
+ }
+ }
+
+ /**
+ * 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 hiddenColumns
+ * the set of hidden columns
+ */
+ public void makeVisibleAnnotation(int start, int end,
+ HiddenColumns hiddenColumns)
+ {
+ if (annotations != null)
+ {
+ if (hiddenColumns.hasHiddenColumns())
+ {
+ removeHiddenAnnotation(start, end, hiddenColumns);
+ }
+ else
+ {
+ restrict(start, end);
+ }
+ }
+ }
+
+ /**
+ * The actual implementation of deleting hidden annotation columns
+ *
+ * @param start
+ * remove any annotation to the right of this column
+ * @param end
+ * remove any annotation to the left of this column
+ * @param hiddenColumns
+ * the set of hidden columns
+ */
+ private void removeHiddenAnnotation(int start, int end,
+ HiddenColumns hiddenColumns)
+ {
+ // mangle the alignmentAnnotation annotation array
+ ArrayList<Annotation[]> annels = new ArrayList<>();
+ Annotation[] els = null;
+
+ int w = 0;
+
+ Iterator<int[]> blocks = hiddenColumns.getVisContigsIterator(start,
+ end + 1, false);
+
+ int copylength;
+ int annotationLength;
+ while (blocks.hasNext())
+ {
+ int[] block = blocks.next();
+ annotationLength = block[1] - block[0] + 1;
+
+ if (blocks.hasNext())
+ {
+ // copy just the visible segment of the annotation row
+ copylength = annotationLength;
+ }
+ else
+ {
+ if (annotationLength + block[0] <= annotations.length)
+ {
+ // copy just the visible segment of the annotation row
+ copylength = annotationLength;
+ }
+ else
+ {
+ // copy to the end of the annotation row
+ copylength = annotations.length - block[0];
+ }
+ }
+
+ els = new Annotation[annotationLength];
+ annels.add(els);
+ System.arraycopy(annotations, block[0], els, 0, copylength);
+ w += annotationLength;
+ }
+
+ if (w != 0)
+ {
+ annotations = new Annotation[w];
+
+ w = 0;
+ for (Annotation[] chnk : annels)
+ {
+ System.arraycopy(chnk, 0, annotations, w, chnk.length);
+ w += chnk.length;
+ }
+ }
+ }
+
}
}
}
- /**
- * delete any columns in alignmentAnnotation that are hidden (including
- * sequence associated annotation).
- *
- * @param alignmentAnnotation
- */
- public void makeVisibleAnnotation(AlignmentAnnotation alignmentAnnotation)
- {
- if (alignmentAnnotation != null
- && alignmentAnnotation.annotations != null)
- {
- makeVisibleAnnotation(0, alignmentAnnotation.annotations.length,
- 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)
- {
- try
- {
- LOCK.readLock().lock();
-
- int startFrom = start;
- int endAt = end;
-
- if (alignmentAnnotation != null
- && alignmentAnnotation.annotations != null)
- {
- if (!hiddenColumns.isEmpty())
- {
- removeHiddenAnnotation(startFrom, endAt, alignmentAnnotation);
- }
- else
- {
- alignmentAnnotation.restrict(startFrom, endAt);
- }
- }
- } finally
- {
- LOCK.readLock().unlock();
- }
- }
-
- private void removeHiddenAnnotation(int start, int end,
- AlignmentAnnotation alignmentAnnotation)
- {
- // mangle the alignmentAnnotation annotation array
- ArrayList<Annotation[]> annels = new ArrayList<>();
- Annotation[] els = null;
-
- int w = 0;
-
- Iterator<int[]> blocks = new VisibleContigsIterator(start, end + 1,
- hiddenColumns);
-
- int copylength;
- int annotationLength;
- while (blocks.hasNext())
- {
- int[] block = blocks.next();
- annotationLength = block[1] - block[0] + 1;
-
- if (blocks.hasNext())
- {
- // copy just the visible segment of the annotation row
- copylength = annotationLength;
- }
- else
- {
- if (annotationLength + block[0] <= alignmentAnnotation.annotations.length)
- {
- // copy just the visible segment of the annotation row
- copylength = annotationLength;
- }
- else
- {
- // copy to the end of the annotation row
- copylength = alignmentAnnotation.annotations.length - block[0];
- }
- }
-
- els = new Annotation[annotationLength];
- annels.add(els);
- System.arraycopy(alignmentAnnotation.annotations, block[0], els, 0,
- copylength);
- w += annotationLength;
- }
-
- if (w != 0)
- {
- alignmentAnnotation.annotations = new Annotation[w];
-
- w = 0;
- for (Annotation[] chnk : annels)
- {
- System.arraycopy(chnk, 0, alignmentAnnotation.annotations, w,
- chnk.length);
- w += chnk.length;
- }
- }
- }
/**
*
AlignmentAnnotation na = new AlignmentAnnotation(ala[i]);
if (selgp != null)
{
- hidden.makeVisibleAnnotation(selgp.getStartRes(),
- selgp.getEndRes(), na);
+ na.makeVisibleAnnotation(selgp.getStartRes(), selgp.getEndRes(),
+ hidden);
}
else
{
- hidden.makeVisibleAnnotation(na);
+ na.makeVisibleAnnotation(hidden);
}
alv.addAnnotation(na);
}
AlignmentAnnotation clone = new AlignmentAnnotation(annot);
if (selectedOnly && selectionGroup != null)
{
- alignment.getHiddenColumns().makeVisibleAnnotation(
+ clone.makeVisibleAnnotation(
selectionGroup.getStartRes(), selectionGroup.getEndRes(),
- clone);
+ alignment.getHiddenColumns());
}
else
{
- alignment.getHiddenColumns().makeVisibleAnnotation(clone);
+ clone.makeVisibleAnnotation(alignment.getHiddenColumns());
}
ala.add(clone);
}
*/
package jalview.datamodel;
+import static org.testng.Assert.assertNull;
import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNull;
import jalview.analysis.AlignSeq;
import jalview.gui.JvOptionPane;
Assert.assertTrue(ann.isQuantitative(),
"Mixed 'E' annotation set should be quantitative.");
}
+
+ @Test(groups = "Functional")
+ public void testMakeVisibleAnnotation()
+ {
+ HiddenColumns h = new HiddenColumns();
+ Annotation[] anns = new Annotation[] { null, null, new Annotation(1),
+ new Annotation(2), new Annotation(3), null, null, new Annotation(4),
+ new Annotation(5), new Annotation(6), new Annotation(7),
+ new Annotation(8) };
+ AlignmentAnnotation ann = new AlignmentAnnotation("an", "some an",
+ anns);
+
+ // null annotations
+ AlignmentAnnotation emptyann = new AlignmentAnnotation("an", "some ann",
+ null);
+ emptyann.makeVisibleAnnotation(h);
+ assertNull(emptyann.annotations);
+
+ emptyann.makeVisibleAnnotation(3, 4, h);
+ assertNull(emptyann.annotations);
+
+ // without bounds, does everything
+ ann.makeVisibleAnnotation(h);
+ assertEquals(12, ann.annotations.length);
+ assertNull(ann.annotations[0]);
+ assertNull(ann.annotations[1]);
+ assertEquals(1.0f, ann.annotations[2].value);
+ assertEquals(2.0f, ann.annotations[3].value);
+ assertEquals(3.0f, ann.annotations[4].value);
+ assertNull(ann.annotations[5]);
+ assertNull(ann.annotations[6]);
+ assertEquals(4.0f, ann.annotations[7].value);
+ assertEquals(5.0f, ann.annotations[8].value);
+ assertEquals(6.0f, ann.annotations[9].value);
+ assertEquals(7.0f, ann.annotations[10].value);
+ assertEquals(8.0f, ann.annotations[11].value);
+
+ // without hidden cols, just truncates
+ ann.makeVisibleAnnotation(3, 5, h);
+ assertEquals(3, ann.annotations.length);
+ assertEquals(2.0f, ann.annotations[0].value);
+ assertEquals(3.0f, ann.annotations[1].value);
+ assertNull(ann.annotations[2]);
+
+ anns = new Annotation[] { null, null, new Annotation(1),
+ new Annotation(2), new Annotation(3), null, null, new Annotation(4),
+ new Annotation(5), new Annotation(6), new Annotation(7),
+ new Annotation(8) };
+ ann = new AlignmentAnnotation("an", "some an", anns);
+ h.hideColumns(4, 7);
+ ann.makeVisibleAnnotation(1, 9, h);
+ assertEquals(5, ann.annotations.length);
+ assertNull(ann.annotations[0]);
+ assertEquals(1.0f, ann.annotations[1].value);
+ assertEquals(2.0f, ann.annotations[2].value);
+ assertEquals(5.0f, ann.annotations[3].value);
+ assertEquals(6.0f, ann.annotations[4].value);
+
+ anns = new Annotation[] { null, null, new Annotation(1),
+ new Annotation(2), new Annotation(3), null, null, new Annotation(4),
+ new Annotation(5), new Annotation(6), new Annotation(7),
+ new Annotation(8) };
+ ann = new AlignmentAnnotation("an", "some an", anns);
+ h.hideColumns(1, 2);
+ ann.makeVisibleAnnotation(1, 9, h);
+ assertEquals(3, ann.annotations.length);
+ assertEquals(2.0f, ann.annotations[0].value);
+ assertEquals(5.0f, ann.annotations[1].value);
+ assertEquals(6.0f, ann.annotations[2].value);
+
+ anns = new Annotation[] { null, null, new Annotation(1),
+ new Annotation(2), new Annotation(3), null, null, new Annotation(4),
+ new Annotation(5), new Annotation(6), new Annotation(7),
+ new Annotation(8), new Annotation(9), new Annotation(10),
+ new Annotation(11), new Annotation(12), new Annotation(13),
+ new Annotation(14), new Annotation(15) };
+ ann = new AlignmentAnnotation("an", "some an", anns);
+ h = new HiddenColumns();
+ h.hideColumns(5, 18);
+ h.hideColumns(20, 21);
+ ann.makeVisibleAnnotation(1, 21, h);
+ assertEquals(5, ann.annotations.length);
+ assertEquals(1.0f, ann.annotations[1].value);
+ assertEquals(2.0f, ann.annotations[2].value);
+ assertEquals(3.0f, ann.annotations[3].value);
+ assertNull(ann.annotations[0]);
+ assertNull(ann.annotations[4]);
+ }
}
}
@Test(groups = "Functional")
- public void testMakeVisibleAnnotation()
- {
- HiddenColumns h = new HiddenColumns();
- Annotation[] anns = new Annotation[] { null, null, new Annotation(1),
- new Annotation(2), new Annotation(3), null, null, new Annotation(4),
- new Annotation(5), new Annotation(6), new Annotation(7),
- new Annotation(8) };
- AlignmentAnnotation ann = new AlignmentAnnotation("an", "some an",
- anns);
-
- // null annotation
- AlignmentAnnotation nullann = null;
- h.makeVisibleAnnotation(nullann);
- assertNull(nullann);
-
- h.makeVisibleAnnotation(1, 2, nullann);
- assertNull(nullann);
-
- // null annotations
- AlignmentAnnotation emptyann = new AlignmentAnnotation("an", "some ann", null);
- h.makeVisibleAnnotation(emptyann);
- assertNull(emptyann.annotations);
-
- h.makeVisibleAnnotation(3, 4, emptyann);
- assertNull(emptyann.annotations);
-
- // without bounds, does everything
- h.makeVisibleAnnotation(ann);
- assertEquals(12, ann.annotations.length);
- assertNull(ann.annotations[0]);
- assertNull(ann.annotations[1]);
- assertEquals(1.0f, ann.annotations[2].value);
- assertEquals(2.0f, ann.annotations[3].value);
- assertEquals(3.0f, ann.annotations[4].value);
- assertNull(ann.annotations[5]);
- assertNull(ann.annotations[6]);
- assertEquals(4.0f, ann.annotations[7].value);
- assertEquals(5.0f, ann.annotations[8].value);
- assertEquals(6.0f, ann.annotations[9].value);
- assertEquals(7.0f, ann.annotations[10].value);
- assertEquals(8.0f, ann.annotations[11].value);
-
- // without hidden cols, just truncates
- h.makeVisibleAnnotation(3, 5, ann);
- assertEquals(3, ann.annotations.length);
- assertEquals(2.0f, ann.annotations[0].value);
- assertEquals(3.0f, ann.annotations[1].value);
- assertNull(ann.annotations[2]);
-
- anns = new Annotation[] { null, null, new Annotation(1),
- new Annotation(2), new Annotation(3), null, null, new Annotation(4),
- new Annotation(5), new Annotation(6), new Annotation(7),
- new Annotation(8) };
- ann = new AlignmentAnnotation("an", "some an", anns);
- h.hideColumns(4, 7);
- h.makeVisibleAnnotation(1, 9, ann);
- assertEquals(5, ann.annotations.length);
- assertNull(ann.annotations[0]);
- assertEquals(1.0f, ann.annotations[1].value);
- assertEquals(2.0f, ann.annotations[2].value);
- assertEquals(5.0f, ann.annotations[3].value);
- assertEquals(6.0f, ann.annotations[4].value);
-
- anns = new Annotation[] { null, null, new Annotation(1),
- new Annotation(2), new Annotation(3), null, null, new Annotation(4),
- new Annotation(5), new Annotation(6), new Annotation(7),
- new Annotation(8) };
- ann = new AlignmentAnnotation("an", "some an", anns);
- h.hideColumns(1, 2);
- h.makeVisibleAnnotation(1, 9, ann);
- assertEquals(3, ann.annotations.length);
- assertEquals(2.0f, ann.annotations[0].value);
- assertEquals(5.0f, ann.annotations[1].value);
- assertEquals(6.0f, ann.annotations[2].value);
-
- anns = new Annotation[] { null, null, new Annotation(1),
- new Annotation(2), new Annotation(3), null, null, new Annotation(4),
- new Annotation(5), new Annotation(6), new Annotation(7),
- new Annotation(8), new Annotation(9), new Annotation(10),
- new Annotation(11), new Annotation(12), new Annotation(13),
- new Annotation(14), new Annotation(15) };
- ann = new AlignmentAnnotation("an", "some an", anns);
- h = new HiddenColumns();
- h.hideColumns(5, 18);
- h.hideColumns(20, 21);
- h.makeVisibleAnnotation(1, 21, ann);
- assertEquals(5, ann.annotations.length);
- assertEquals(1.0f, ann.annotations[1].value);
- assertEquals(2.0f, ann.annotations[2].value);
- assertEquals(3.0f, ann.annotations[3].value);
- assertNull(ann.annotations[0]);
- assertNull(ann.annotations[4]);
- }
-
- @Test(groups = "Functional")
public void testSubtractVisibleColumns()
{
HiddenColumns h = new HiddenColumns();