+ List<AlignmentAnnotation> ourAnnot = running.getAnnotation(),
+ newAnnots = new ArrayList<>();
+ //
+ // update graphGroup for all annotation
+ //
+ /**
+ * find a graphGroup greater than any existing ones this could be a method
+ * provided by alignment Alignment.getNewGraphGroup() - returns next
+ * unused graph group
+ */
+ int graphGroup = 1;
+ if (alignViewport.getAlignment().getAlignmentAnnotation() != null)
+ {
+ for (AlignmentAnnotation ala : alignViewport.getAlignment()
+ .getAlignmentAnnotation())
+ {
+ if (ala.graphGroup > graphGroup)
+ {
+ graphGroup = ala.graphGroup;
+ }
+ }
+ }
+ /**
+ * update graphGroup in the annotation rows returned from service
+ */
+ // TODO: look at sequence annotation rows and update graph groups in the
+ // case of reference annotation.
+ for (AlignmentAnnotation ala : ourAnnot)
+ {
+ if (ala.graphGroup > 0)
+ {
+ ala.graphGroup += graphGroup;
+ }
+ SequenceI aseq = null;
+
+ /**
+ * transfer sequence refs and adjust gapmap
+ */
+ if (ala.sequenceRef != null)
+ {
+ SequenceI seq = running.getSeqNames()
+ .get(ala.sequenceRef.getName());
+ aseq = seq;
+ while (seq.getDatasetSequence() != null)
+ {
+ seq = seq.getDatasetSequence();
+ }
+ }
+ Annotation[] resAnnot = ala.annotations,
+ gappedAnnot = new Annotation[Math.max(
+ alignViewport.getAlignment().getWidth(),
+ gapMap.length)];
+ for (int p = 0, ap = start; ap < gappedAnnot.length; ap++)
+ {
+ if (gapMap != null && gapMap.length > ap && !gapMap[ap])
+ {
+ gappedAnnot[ap] = new Annotation("", "", ' ', Float.NaN);
+ }
+ else if (p < resAnnot.length)
+ {
+ gappedAnnot[ap] = resAnnot[p++];
+ }
+ }
+ ala.sequenceRef = aseq;
+ ala.annotations = gappedAnnot;
+ AlignmentAnnotation newAnnot = getAlignViewport().getAlignment()
+ .updateFromOrCopyAnnotation(ala);
+ if (aseq != null)
+ {
+
+ aseq.addAlignmentAnnotation(newAnnot);
+ newAnnot.adjustForAlignment();
+
+ AlignmentAnnotationUtils.replaceAnnotationOnAlignmentWith(
+ newAnnot, newAnnot.label, newAnnot.getCalcId());
+ }
+ newAnnots.add(newAnnot);
+
+ }
+ for (SequenceI sq : running.getSeqs())
+ {
+ if (!sq.getFeatures().hasFeatures()
+ && (sq.getDBRefs() == null || sq.getDBRefs().length == 0))
+ {
+ continue;
+ }
+ running.setTransferSequenceFeatures(true);
+ SequenceI seq = running.getSeqNames().get(sq.getName());
+ SequenceI dseq;
+ ContiguousI seqRange = seq.findPositions(start, end);
+
+ while ((dseq = seq).getDatasetSequence() != null)
+ {
+ seq = seq.getDatasetSequence();
+ }
+ List<ContiguousI> sourceRange = new ArrayList();
+ if (gapMap != null && gapMap.length >= end)
+ {
+ int lastcol = start, col = start;
+ do
+ {
+ if (col == end || !gapMap[col])
+ {
+ if (lastcol <= (col - 1))
+ {
+ seqRange = seq.findPositions(lastcol, col);
+ sourceRange.add(seqRange);
+ }
+ lastcol = col + 1;
+ }
+ } while (++col <= end);
+ }
+ else
+ {
+ sourceRange.add(seq.findPositions(start, end));
+ }
+ int i = 0;
+ int source_startend[] = new int[sourceRange.size() * 2];
+
+ for (ContiguousI range : sourceRange)
+ {
+ source_startend[i++] = range.getBegin();
+ source_startend[i++] = range.getEnd();
+ }
+ Mapping mp = new Mapping(
+ new MapList(source_startend, new int[]
+ { seq.getStart(), seq.getEnd() }, 1, 1));
+ dseq.transferAnnotation(sq, mp);
+
+ }
+ updateOurAnnots(newAnnots);