+ * Copy constructor
+ * creates a new independent annotation row with the same associated sequenceRef
+ * @param annotation
+ */
+ public AlignmentAnnotation(AlignmentAnnotation annotation)
+ {
+ this.label = new String(annotation.label);
+ if (annotation.description != null)
+ this.description = new String(annotation.description);
+ this.graphMin = annotation.graphMin;
+ this.graphMax = annotation.graphMax;
+ this.graph = annotation.graph;
+ this.graphHeight = annotation.graphHeight;
+ this.graphGroup = annotation.graphGroup;
+ this.editable = annotation.editable;
+ this.autoCalculated = annotation.autoCalculated;
+ this.hasIcons = annotation.hasIcons;
+ this.hasText = annotation.hasText;
+ this.height = annotation.height;
+ this.label = annotation.label;
+ this.padGaps = annotation.padGaps;
+ this.visible = annotation.visible;
+ if (this.hasScore = annotation.hasScore)
+ {
+ this.score = annotation.score;
+ }
+ if (threshold!=null) {
+ threshold = new GraphLine(annotation.threshold);
+ }
+ if (annotation.annotations!=null) {
+ Annotation[] ann = annotation.annotations;
+ this.annotations = new Annotation[ann.length];
+ for (int i=0; i<ann.length; i++) {
+ annotations[i] = new Annotation(ann[i]);
+ };
+ if (annotation.sequenceRef!=null) {
+ this.sequenceRef = annotation.sequenceRef;
+ if (annotation.sequenceMapping!=null)
+ {
+ Integer p=null;
+ sequenceMapping = new Hashtable();
+ Enumeration pos=annotation.sequenceMapping.keys();
+ while (pos.hasMoreElements()) {
+ // could optimise this!
+ p = (Integer) pos.nextElement();
+ Annotation a = (Annotation) annotation.sequenceMapping.get(p);
+ if (a==null)
+ {
+ continue;
+ }
+ for (int i=0; i<ann.length; i++)
+ {
+ if (ann[i]==a)
+ {
+ sequenceMapping.put(p, annotations[i]);
+ }
+ }
+ }
+ } else {
+ this.sequenceMapping = null;
+ }
+ }
+ }
+ validateRangeAndDisplay(); // construct hashcodes, etc.
+ }
+
+ /**
+ * clip the annotation to the columns given by startRes and endRes (inclusive)
+ * and prune any existing sequenceMapping to just those columns.
+ * @param startRes
+ * @param endRes
+ */
+ public void restrict(int startRes, int endRes)
+ {
+ if (annotations==null)
+ return;
+ Annotation[] temp = new Annotation[endRes-startRes+1];
+ if (startRes<annotations.length)
+ {
+ System.arraycopy(annotations, startRes, temp, 0, Math.min(endRes, annotations.length-1)-startRes+1);
+ }
+ if (sequenceRef!=null) {
+ // Clip the mapping, if it exists.
+ int spos = sequenceRef.findPosition(startRes);
+ int epos = sequenceRef.findPosition(endRes);
+ if (sequenceMapping!=null)
+ {
+ Hashtable newmapping = new Hashtable();
+ Enumeration e = sequenceMapping.keys();
+ while (e.hasMoreElements())
+ {
+ Integer pos = (Integer) e.nextElement();
+ if (pos.intValue()>=spos && pos.intValue()<=epos)
+ {
+ newmapping.put(pos, sequenceMapping.get(pos));
+ }
+ }
+ sequenceMapping.clear();
+ sequenceMapping = newmapping;
+ }
+ }
+ annotations=temp;
+ }
+ /**
+ * set the annotation row to be at least length Annotations
+ * @param length minimum number of columns required in the annotation row
+ * @return false if the annotation row is greater than length
+ */
+ public boolean padAnnotation(int length) {
+ if (annotations==null)
+ {
+ return true; // annotation row is correct - null == not visible and undefined length
+ }
+ if (annotations.length<length)
+ {
+ Annotation[] na = new Annotation[length];
+ System.arraycopy(annotations, 0, na, 0, annotations.length);
+ annotations = na;
+ return true;
+ }
+ return annotations.length>length;
+
+ }
+
+ /**