- /*
- * Add to the sequence (sets copyAnn.datasetSequence), unless the
- * original annotation is already on the sequence.
- */
- if (!seq.hasAnnotation(ann))
- {
- seq.addAlignmentAnnotation(copyAnn);
- }
- // adjust for gaps
- copyAnn.adjustForAlignment();
- // add to the alignment and set visible
- alignment.addAnnotation(copyAnn);
- copyAnn.visible = true;
+ /**
+ * Make a copy of a reference annotation {@code ann} and add it to an
+ * alignment sequence {@code seq} in {@code alignment}, optionally limited to
+ * the extent of {@code selectionGroup}
+ *
+ * @param alignment
+ * @param seq
+ * @param ann
+ * @param selectionGroup
+ * - may be null
+ * @return annotation added to {@code seq and {@code alignment}
+ */
+ public static AlignmentAnnotation addReferenceAnnotationTo(
+ final AlignmentI alignment, final SequenceI seq,
+ final AlignmentAnnotation ann, final SequenceGroup selectionGroup)
+ {
+ AlignmentAnnotation copyAnn = new AlignmentAnnotation(ann);
+ int startRes = 0;
+ int endRes = ann.annotations.length;
+ if (selectionGroup != null)
+ {
+ startRes = -1 + Math.min(seq.getEnd(), Math.max(seq.getStart(),
+ seq.findPosition(selectionGroup.getStartRes())));
+ endRes = -1 + Math.min(seq.getEnd(),
+ seq.findPosition(selectionGroup.getEndRes()));
+
+ }
+ copyAnn.restrict(startRes, endRes + 0);
+
+ /*
+ * Add to the sequence (sets copyAnn.datasetSequence), unless the
+ * original annotation is already on the sequence.
+ */
+ if (!seq.hasAnnotation(ann))
+ {
+ ContactMatrixI cm = seq.getDatasetSequence().getContactMatrixFor(ann);
+ if (cm != null)
+ {
+ seq.addContactListFor(copyAnn, cm);