+ else
+ {
+ Cache.log
+ .error("Invalid dataset sequence id (null) for alignment sequence "
+ + valseq.getVorbaId());
+ }
+ bindjvvobj(alseq, valseq);
+ alseq.setVamsasId(valseq.getVorbaId().getId());
+ dsseqs.add(alseq);
+ }
+ Vobject datsetseq = (Vobject) valseq.getRefid();
+ if (datsetseq != null)
+ {
+ if (datsetseq != alseq.getDatasetSequence())
+ {
+ modal = true;
+ }
+ alseq.setDatasetSequence((SequenceI) getvObj2jv(datsetseq)); // exceptions
+ }
+ return upFromdoc || modal;
+ }
+
+ private void initRangeAnnotationType(RangeAnnotation an,
+ AlignmentAnnotation alan, int[] gapMap)
+ {
+ Seg vSeg = new Seg();
+ vSeg.setStart(1);
+ vSeg.setInclusive(true);
+ vSeg.setEnd(gapMap.length);
+ an.addSeg(vSeg);
+
+ // LATER: much of this is verbatim from the alignmentAnnotation
+ // method below. suggests refactoring to make rangeAnnotation the
+ // base class
+ an.setDescription(alan.description);
+ an.setLabel(alan.label);
+ an.setGroup(Integer.toString(alan.graphGroup));
+ // // JBPNote -
+ // originally we
+ // were going to
+ // store
+ // graphGroup in
+ // the Jalview
+ // specific
+ // bits.
+ AnnotationElement ae;
+ for (int a = 0; a < alan.annotations.length; a++)
+ {
+ if (alan.annotations[a] == null)
+ {
+ continue;
+ }
+
+ ae = new AnnotationElement();
+ ae.setDescription(alan.annotations[a].description);
+ ae.addGlyph(new Glyph());
+ ae.getGlyph(0).setContent(alan.annotations[a].displayCharacter); // assume
+ // jax-b
+ // takes
+ // care
+ // of
+ // utf8
+ // translation
+ if (alan.graph != jalview.datamodel.AlignmentAnnotation.NO_GRAPH)
+ {
+ ae.addValue(alan.annotations[a].value);
+ }
+ ae.setPosition(gapMap[a] + 1); // position w.r.t. AlignmentSequence
+ // symbols
+ if (alan.annotations[a].secondaryStructure != ' ')
+ {
+ // we only write an annotation where it really exists.
+ Glyph ss = new Glyph();
+ ss.setDict(uk.ac.vamsas.objects.utils.GlyphDictionary.PROTEIN_SS_3STATE);
+ ss.setContent(String
+ .valueOf(alan.annotations[a].secondaryStructure));
+ ae.addGlyph(ss);
+ }
+ an.addAnnotationElement(ae);
+ }
+
+ }
+
+ private void saveDatasetSequenceAnnotation(HashMap AlSeqMaps,
+ uk.ac.vamsas.objects.core.Sequence sref, AlignmentAnnotation alan)
+ {
+ // {
+ // uk.ac.vamsas.
+ // objects.core.AlignmentSequence alsref = (uk.ac.vamsas.
+ // objects.core.AlignmentSequence) sref;
+ uk.ac.vamsas.objects.core.DataSetAnnotations an = (uk.ac.vamsas.objects.core.DataSetAnnotations) getjv2vObj(alan);
+ int[] gapMap = getGapMap(AlSeqMaps, alan);
+ if (an == null)
+ {
+ an = new uk.ac.vamsas.objects.core.DataSetAnnotations();
+ initRangeAnnotationType(an, alan, gapMap);
+
+ an.setProvenance(dummyProvenance()); // get provenance as user
+ // created, or jnet, or
+ // something else.
+ setAnnotationType(an, alan);
+ an.setGroup(Integer.toString(alan.graphGroup)); // // JBPNote -
+ // originally we
+ // were going to
+ // store
+ // graphGroup in
+ // the Jalview
+ // specific
+ // bits.
+ if (alan.getThreshold() != null && alan.getThreshold().displayed)
+ {
+ an.addProperty(Properties.newProperty(THRESHOLD,
+ Properties.FLOATTYPE, "" + alan.getThreshold().value));
+ if (alan.getThreshold().label != null)
+ an.addProperty(Properties.newProperty(THRESHOLD + "Name",
+ Properties.STRINGTYPE, "" + alan.getThreshold().label));
+ }
+ ((DataSet) sref.getV_parent()).addDataSetAnnotations(an);
+ bindjvvobj(alan, an);
+ }
+ else
+ {
+ // update reference sequence Annotation
+ if (an.getModifiable() == null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK
+ // METHODS)
+ {
+ // verify existing alignment sequence annotation is up to date
+ System.out.println("update dataset sequence annotation.");
+ }
+ else
+ {
+ // verify existing alignment sequence annotation is up to date
+ System.out
+ .println("make new alignment dataset sequence annotation if modification has happened.");
+ }
+ }
+
+ }
+
+ private int[] getGapMap(HashMap AlSeqMaps, AlignmentAnnotation alan)
+ {
+ int[] gapMap;
+ if (AlSeqMaps.containsKey(alan.sequenceRef))
+ {
+ gapMap = (int[]) AlSeqMaps.get(alan.sequenceRef);
+ }
+ else
+ {
+ gapMap = new int[alan.sequenceRef.getLength()];
+ // map from alignment position to sequence position.
+ int[] sgapMap = alan.sequenceRef.gapMap();
+ for (int a = 0; a < sgapMap.length; a++)
+ {
+ gapMap[sgapMap[a]] = a;
+ }
+ }
+ return gapMap;
+ }
+
+ private void saveAlignmentSequenceAnnotation(HashMap AlSeqMaps,
+ AlignmentSequence alsref, AlignmentAnnotation alan)
+ {
+ // {
+ // uk.ac.vamsas.
+ // objects.core.AlignmentSequence alsref = (uk.ac.vamsas.
+ // objects.core.AlignmentSequence) sref;
+ uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation an = (uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation) getjv2vObj(alan);
+ int[] gapMap = getGapMap(AlSeqMaps, alan);
+ if (an == null)
+ {
+ an = new uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation();
+ initRangeAnnotationType(an, alan, gapMap);
+ /**
+ * I mean here that we don't actually have a semantic 'type' for the
+ * annotation (this might be - score, intrinsic property, measurement,
+ * something extracted from another program, etc)
+ */
+ an.setType(JALVIEW_ANNOTATION_ROW); // TODO: better fix
+ // this rough guess ;)
+ alsref.addAlignmentSequenceAnnotation(an);
+ bindjvvobj(alan, an);
+ // These properties are directly supported by the
+ // AlignmentSequenceAnnotation type.
+ setAnnotationType(an, alan);
+ an.setProvenance(dummyProvenance()); // get provenance as user
+ // created, or jnet, or
+ // something else.
+ }
+ else
+ {
+ // update reference sequence Annotation
+ if (an.getModifiable() == null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK
+ // METHODS)
+ {
+ // verify existing alignment sequence annotation is up to date
+ System.out.println("update alignment sequence annotation.");
+ }
+ else
+ {
+ // verify existing alignment sequence annotation is up to date
+ System.out
+ .println("make new alignment sequence annotation if modification has happened.");
+ }
+ }
+ }
+
+ /**
+ * set vamsas annotation object type from jalview annotation
+ *
+ * @param an
+ * @param alan
+ */
+ private void setAnnotationType(RangeAnnotation an,
+ AlignmentAnnotation alan)
+ {
+ if (an instanceof AlignmentSequenceAnnotation)
+ {
+ if (alan.graph != AlignmentAnnotation.NO_GRAPH)
+ {
+ ((AlignmentSequenceAnnotation) an).setGraph(true);
+ }
+ else
+ {
+ ((AlignmentSequenceAnnotation) an).setGraph(false);
+ }
+ }
+ if (an instanceof uk.ac.vamsas.objects.core.AlignmentAnnotation)
+ {
+ if (alan.graph != AlignmentAnnotation.NO_GRAPH)
+ {
+ ((uk.ac.vamsas.objects.core.AlignmentAnnotation) an).setGraph(true);
+ }
+ else
+ {
+ ((uk.ac.vamsas.objects.core.AlignmentAnnotation) an)
+ .setGraph(false);
+ }
+ }
+ switch (alan.graph)
+ {
+ case AlignmentAnnotation.BAR_GRAPH:
+ an.addProperty(Properties.newProperty(DISCRETE_ANNOTATION,
+ Properties.BOOLEANTYPE, "true"));
+ break;
+ case AlignmentAnnotation.LINE_GRAPH:
+ an.addProperty(Properties.newProperty(CONTINUOUS_ANNOTATION,
+ Properties.BOOLEANTYPE, "true"));
+ break;
+ default:
+ // don't add any kind of discrete or continous property info.