2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 import jalview.bin.Cache;
23 import jalview.datamodel.AlignmentAnnotation;
24 import jalview.datamodel.AlignmentI;
25 import jalview.datamodel.AlignmentView;
26 import jalview.datamodel.DBRefEntry;
27 import jalview.datamodel.GraphLine;
28 import jalview.datamodel.SequenceFeature;
29 import jalview.datamodel.SequenceI;
30 import jalview.gui.AlignFrame;
31 import jalview.gui.AlignViewport;
32 import jalview.gui.Desktop;
33 import jalview.gui.TreePanel;
34 import jalview.io.vamsas.DatastoreItem;
35 import jalview.io.vamsas.Rangetype;
37 import java.util.Enumeration;
38 import java.util.HashMap;
39 import java.util.Hashtable;
40 import java.util.IdentityHashMap;
41 import java.util.Vector;
43 import uk.ac.vamsas.client.*;
44 import uk.ac.vamsas.objects.core.*;
49 * org.exolab.castor.util.LocalConfiguration.getInstance().getProperties().setProperty(
50 * "org.exolab.castor.serializer", "org.apache.xml.serialize.XMLSerilazizer"); }
54 public class VamsasAppDatastore
57 * Type used for general jalview generated annotation added to vamsas document
59 public static final String JALVIEW_ANNOTATION_ROW = "JalviewAnnotation";
62 * AlignmentAnnotation property to indicate that values should not be interpolated
64 public static final String DISCRETE_ANNOTATION = "discrete";
66 * continuous property - optional to specify that annotation should be represented
67 * as a continous graph line
69 private static final String CONTINUOUS_ANNOTATION = "continuous";
71 private static final String THRESHOLD = "threshold";
74 Entry provEntry = null;
80 IdentityHashMap jv2vobj;
82 public VamsasAppDatastore(IClientDocument cdoc, Hashtable vobj2jv,
83 IdentityHashMap jv2vobj, Entry provEntry)
86 this.vobj2jv = vobj2jv;
87 this.jv2vobj = jv2vobj;
88 this.provEntry = provEntry;
92 * @return the Vobject bound to Jalview datamodel object
94 protected Vobject getjv2vObj(Object jvobj)
96 if (jv2vobj.containsKey(jvobj))
98 return cdoc.getObject((VorbaId) jv2vobj.get(jvobj));
100 if (Cache.log.isDebugEnabled())
102 Cache.log.debug("Returning null VorbaID binding for jalview object "
111 * @return Jalview datamodel object bound to the vamsas document object
113 protected Object getvObj2jv(uk.ac.vamsas.client.Vobject vobj)
115 VorbaId id = vobj.getVorbaId();
118 id = cdoc.registerObject(vobj);
120 .debug("Registering new object and returning null for getvObj2jv");
123 if (vobj2jv.containsKey(vobj.getVorbaId()))
125 return vobj2jv.get(vobj.getVorbaId());
130 protected void bindjvvobj(Object jvobj, uk.ac.vamsas.client.Vobject vobj)
132 VorbaId id = vobj.getVorbaId();
135 id = cdoc.registerObject(vobj);
136 if (id == null || vobj.getVorbaId() == null
137 || cdoc.getObject(id) != vobj)
139 Cache.log.error("Failed to get id for "
140 + (vobj.isRegisterable() ? "registerable"
141 : "unregisterable") + " object " + vobj);
145 if (vobj2jv.containsKey(vobj.getVorbaId())
146 && !((VorbaId) vobj2jv.get(vobj.getVorbaId())).equals(jvobj))
149 "Warning? Overwriting existing vamsas id binding for "
150 + vobj.getVorbaId(), new Exception(
151 "Overwriting vamsas id binding."));
153 else if (jv2vobj.containsKey(jvobj)
154 && !((VorbaId) jv2vobj.get(jvobj)).equals(vobj.getVorbaId()))
157 "Warning? Overwriting existing jalview object binding for "
158 + jvobj, new Exception(
159 "Overwriting jalview object binding."));
162 * Cache.log.error("Attempt to make conflicting object binding! "+vobj+" id "
163 * +vobj.getVorbaId()+" already bound to "+getvObj2jv(vobj)+" and "+jvobj+"
164 * already bound to "+getjv2vObj(jvobj),new Exception("Excessive call to
167 // we just update the hash's regardless!
168 Cache.log.debug("Binding " + vobj.getVorbaId() + " to " + jvobj);
169 vobj2jv.put(vobj.getVorbaId(), jvobj);
170 // JBPNote - better implementing a hybrid invertible hash.
171 jv2vobj.put(jvobj, vobj.getVorbaId());
175 * put the alignment viewed by AlignViewport into cdoc.
178 * alignViewport to be stored
180 * title for alignment
182 public void storeVAMSAS(AlignViewport av, String aFtitle)
186 jalview.datamodel.AlignmentI jal = av.getAlignment();
188 VAMSAS root = null; // will be resolved based on Dataset Parent.
189 // /////////////////////////////////////////
191 DataSet dataset = null;
192 if (jal.getDataset() == null)
194 Cache.log.warn("Creating new dataset for an alignment.");
195 jal.setDataset(null);
197 dataset = (DataSet) getjv2vObj(jal.getDataset());
200 // it might be that one of the dataset sequences does actually have a
201 // binding, so search for it indirectly.
202 jalview.datamodel.SequenceI[] jdatset = jal.getDataset()
203 .getSequencesArray();
204 for (int i = 0; i < jdatset.length; i++)
206 Vobject vbound = getjv2vObj(jdatset[i]);
209 if (vbound instanceof uk.ac.vamsas.objects.core.Sequence)
213 dataset = (DataSet) vbound.getV_parent();
217 if (dataset != vbound.getV_parent())
220 "IMPLEMENTATION ERROR: Cannot map an alignment of sequences from datasets into the vamsas document.");
221 // This occurs because the dataset for the alignment we are
232 // we create a new dataset on the default vamsas root.
233 root = cdoc.getVamsasRoots()[0]; // default vamsas root for modifying.
234 dataset = new DataSet();
235 root.addDataSet(dataset);
236 bindjvvobj(jal.getDataset(), dataset);
237 dataset.setProvenance(dummyProvenance());
238 dataset.getProvenance().addEntry(provEntry);
243 root = (VAMSAS) dataset.getV_parent();
248 // set new dataset and alignment sequences based on alignment Nucleotide
250 // this *will* break when alignment contains both nucleotide and amino
252 String dict = jal.isNucleotide() ? uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_NA
253 : uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_AA;
254 for (int i = 0; i < jal.getHeight(); i++)
256 SequenceI sq = jal.getSequenceAt(i).getDatasetSequence(); // only insert
260 sequence = (Sequence) getjv2vObj(sq);
261 if (sequence == null)
263 sequence = new Sequence();
264 bindjvvobj(sq, sequence);
265 sq.setVamsasId(sequence.getVorbaId().getId());
266 sequence.setSequence(sq.getSequenceAsString());
267 sequence.setDictionary(dict);
268 sequence.setName(jal.getDataset().getSequenceAt(i).getName());
269 sequence.setStart(jal.getDataset().getSequenceAt(i).getStart());
270 sequence.setEnd(jal.getDataset().getSequenceAt(i).getEnd());
271 sequence.setDescription(jal.getDataset().getSequenceAt(i)
273 dataset.addSequence(sequence);
277 // verify principal attributes. and update any new
278 // features/references.
279 System.out.println("update dataset sequence object.");
281 if (sq.getSequenceFeatures() != null)
283 int sfSize = sq.getSequenceFeatures().length;
285 for (int sf = 0; sf < sfSize; sf++)
287 jalview.datamodel.SequenceFeature feature = (jalview.datamodel.SequenceFeature) sq
288 .getSequenceFeatures()[sf];
290 DataSetAnnotations dsa = (DataSetAnnotations) getjv2vObj(feature);
293 dsa = (DataSetAnnotations) getDSAnnotationFromJalview(
294 new DataSetAnnotations(), feature);
295 if (dsa.getProvenance() == null)
297 dsa.setProvenance(new Provenance());
299 addProvenance(dsa.getProvenance(), "created"); // JBPNote - need
301 dsa.addSeqRef(sequence); // we have just created this annotation
302 // - so safe to use this
303 bindjvvobj(feature, dsa);
304 dataset.addDataSetAnnotations(dsa);
308 // todo: verify and update dataset annotations for sequence
309 System.out.println("update dataset sequence annotations.");
314 if (sq.getDBRef() != null)
316 DBRefEntry[] entries = sq.getDBRef();
317 jalview.datamodel.DBRefEntry dbentry;
318 for (int db = 0; db < entries.length; db++)
320 Rangetype dbr = new jalview.io.vamsas.Dbref(this,
321 dbentry = entries[db], sq, sequence);
326 // dataset.setProvenance(getVamsasProvenance(jal.getDataset().getProvenance()));
327 // ////////////////////////////////////////////
328 if (!av.getAlignment().isAligned())
329 return; // TODO: trees could be written - but for the moment we just skip
331 // ////////////////////////////////////////////
332 // Save the Alignments
334 Alignment alignment = (Alignment) getjv2vObj(av); // this is so we can get
337 if (alignment == null)
339 alignment = new Alignment();
340 bindjvvobj(av, alignment);
341 if (alignment.getProvenance() == null)
343 alignment.setProvenance(new Provenance());
345 addProvenance(alignment.getProvenance(), "added"); // TODO: insert some
348 dataset.addAlignment(alignment);
350 Property title = new Property();
351 title.setName("title");
352 title.setType("string");
353 title.setContent(aFtitle);
354 alignment.addProperty(title);
356 alignment.setGapChar(String.valueOf(av.getGapCharacter()));
357 AlignmentSequence alseq = null;
358 for (int i = 0; i < jal.getHeight(); i++)
360 alseq = new AlignmentSequence();
361 // TODO: VAMSAS: translate lowercase symbols to annotation ?
362 alseq.setSequence(jal.getSequenceAt(i).getSequenceAsString());
363 alseq.setName(jal.getSequenceAt(i).getName());
364 alseq.setStart(jal.getSequenceAt(i).getStart());
365 alseq.setEnd(jal.getSequenceAt(i).getEnd());
366 if (getjv2vObj(jal.getSequenceAt(i).getDatasetSequence()) == null)
369 .warn("Serious. Unbound dataset sequence in alignment: "
370 + jal.getSequenceAt(i).getDatasetSequence());
372 alseq.setRefid(getjv2vObj(jal.getSequenceAt(i)
373 .getDatasetSequence()));
374 alignment.addAlignmentSequence(alseq);
375 bindjvvobj(jal.getSequenceAt(i), alseq);
380 // todo: verify and update mutable alignment props.
381 if (alignment.getModifiable() == null) // TODO: USE VAMSAS LIBRARY
382 // OBJECT LOCK METHODS
384 System.out.println("update alignment in document.");
389 .println("update edited alignment to new alignment in document.");
392 // ////////////////////////////////////////////
393 // SAVE Alignment Sequence Features
394 for (int i = 0, iSize = alignment.getAlignmentSequenceCount(); i < iSize; i++)
396 AlignmentSequence valseq;
397 SequenceI alseq = (SequenceI) getvObj2jv(valseq = alignment
398 .getAlignmentSequence(i));
399 if (alseq != null && alseq.getSequenceFeatures() != null)
402 * We do not put local Alignment Sequence Features into the vamsas
406 * jalview.datamodel.SequenceFeature[] features = alseq
407 * .getSequenceFeatures(); for (int f = 0; f < features.length; f++) {
408 * if (features[f] != null) { AlignmentSequenceAnnotation valseqf = (
409 * AlignmentSequenceAnnotation) getjv2vObj(features[i]); if (valseqf ==
412 * valseqf = (AlignmentSequenceAnnotation) getDSAnnotationFromJalview(
413 * new AlignmentSequenceAnnotation(), features[i]);
414 * valseqf.setGraph(false);
415 * valseqf.addProperty(newProperty("jalview:feature","boolean","true"));
416 * if (valseqf.getProvenance() == null) { valseqf.setProvenance(new
417 * Provenance()); } addProvenance(valseqf.getProvenance(), "created"); //
418 * JBPNote - // need to // update bindjvvobj(features[i], valseqf);
419 * valseq.addAlignmentSequenceAnnotation(valseqf); } }
425 // ////////////////////////////////////////////
427 if (jal.getAlignmentAnnotation() != null)
429 jalview.datamodel.AlignmentAnnotation[] aa = jal
430 .getAlignmentAnnotation();
431 java.util.HashMap AlSeqMaps = new HashMap(); // stores int maps from
432 // alignment columns to
433 // sequence positions.
434 for (int i = 0; i < aa.length; i++)
436 if (aa[i] == null || isJalviewOnly(aa[i]))
440 if (aa[i].sequenceRef != null)
442 // Deal with sequence associated annotation
443 Vobject sref = getjv2vObj(aa[i].sequenceRef);
444 if (sref instanceof uk.ac.vamsas.objects.core.AlignmentSequence)
446 saveAlignmentSequenceAnnotation(AlSeqMaps,
447 (AlignmentSequence) sref, aa[i]);
451 // first find the alignment sequence to associate this with.
452 SequenceI jvalsq = null;
453 Enumeration jval = av.getAlignment().getSequences()
455 while (jval.hasMoreElements())
457 jvalsq = (SequenceI) jval.nextElement();
458 // saveDatasetSequenceAnnotation(AlSeqMaps,(uk.ac.vamsas.objects.core.Sequence)
460 if (jvalsq.getDatasetSequence() == aa[i].sequenceRef)
462 Vobject alsref = getjv2vObj(jvalsq);
463 saveAlignmentSequenceAnnotation(AlSeqMaps,
464 (AlignmentSequence) alsref, aa[i]);
473 // add Alignment Annotation
474 uk.ac.vamsas.objects.core.AlignmentAnnotation an = (uk.ac.vamsas.objects.core.AlignmentAnnotation) getjv2vObj(aa[i]);
477 an = new uk.ac.vamsas.objects.core.AlignmentAnnotation();
478 an.setType(JALVIEW_ANNOTATION_ROW);
479 an.setDescription(aa[i].description);
480 alignment.addAlignmentAnnotation(an);
481 Seg vSeg = new Seg(); // TODO: refactor to have a default
482 // rangeAnnotationType initer/updater that
483 // takes a set of int ranges.
485 vSeg.setInclusive(true);
486 vSeg.setEnd(jal.getWidth());
490 an.setGraph(true); // aa[i].graph);
492 an.setLabel(aa[i].label);
493 an.setProvenance(dummyProvenance());
494 if (aa[i].graph != AlignmentAnnotation.NO_GRAPH)
496 an.setGroup(Integer.toString(aa[i].graphGroup)); // // JBPNote
511 AnnotationElement ae;
513 for (int a = 0; a < aa[i].annotations.length; a++)
515 if ((aa[i] == null) || (aa[i].annotations[a] == null))
520 ae = new AnnotationElement();
521 ae.setDescription(aa[i].annotations[a].description);
522 ae.addGlyph(new Glyph());
523 ae.getGlyph(0).setContent(
524 aa[i].annotations[a].displayCharacter); // assume
531 ae.addValue(aa[i].annotations[a].value);
532 ae.setPosition(a + 1);
533 if (aa[i].annotations[a].secondaryStructure != ' ')
535 Glyph ss = new Glyph();
537 .setDict(uk.ac.vamsas.objects.utils.GlyphDictionary.PROTEIN_SS_3STATE);
540 .valueOf(aa[i].annotations[a].secondaryStructure));
543 an.addAnnotationElement(ae);
547 // an.addProperty(newProperty("jalview:editable", null,
549 // an.setModifiable(""); // TODO: This is not the way the
550 // modifiable flag is supposed to be used.
552 setAnnotationType(an, aa[i]);
554 if (aa[i].graph != jalview.datamodel.AlignmentAnnotation.NO_GRAPH)
557 an.setGroup(Integer.toString(aa[i].graphGroup));
558 if (aa[i].threshold!=null && aa[i].threshold.displayed)
559 an.addProperty(newProperty(THRESHOLD, "float", ""+aa[i].threshold.value));
560 if (aa[i].threshold.label!=null)
561 an.addProperty(newProperty(THRESHOLD+"Name", "string", ""+aa[i].threshold.label));
568 if (an.getModifiable() == null) // TODO: USE VAMSAS LIBRARY OBJECT
571 // verify annotation - update (perhaps)
573 .info("update alignment sequence annotation. not yet implemented.");
577 // verify annotation - update (perhaps)
579 .info("updated alignment sequence annotation added.");
585 // /////////////////////////////////////////////////////
587 // //////////////////////////////////////////////
589 // /////////////////////////////////
590 // FIND ANY ASSOCIATED TREES
591 if (Desktop.desktop != null)
593 javax.swing.JInternalFrame[] frames = Desktop.instance
596 for (int t = 0; t < frames.length; t++)
598 if (frames[t] instanceof TreePanel)
600 TreePanel tp = (TreePanel) frames[t];
602 if (tp.getAlignment() == jal)
604 DatastoreItem vtree = new jalview.io.vamsas.Tree(this, tp,
610 // Store Jalview specific stuff in the Jalview appData
611 // not implemented in the SimpleDoc interface.
616 ex.printStackTrace();
621 private void initRangeAnnotationType(RangeAnnotation an,
622 AlignmentAnnotation alan, int[] gapMap)
624 Seg vSeg = new Seg();
626 vSeg.setInclusive(true);
627 vSeg.setEnd(gapMap.length);
630 // LATER: much of this is verbatim from the alignmentAnnotation
631 // method below. suggests refactoring to make rangeAnnotation the
633 an.setDescription(alan.description);
634 an.setLabel(alan.label);
635 an.setGroup(Integer.toString(alan.graphGroup));
644 AnnotationElement ae;
645 for (int a = 0; a < alan.annotations.length; a++)
647 if (alan.annotations[a] == null)
652 ae = new AnnotationElement();
653 ae.setDescription(alan.annotations[a].description);
654 ae.addGlyph(new Glyph());
655 ae.getGlyph(0).setContent(alan.annotations[a].displayCharacter); // assume
662 if (alan.graph != jalview.datamodel.AlignmentAnnotation.NO_GRAPH)
664 ae.addValue(alan.annotations[a].value);
666 ae.setPosition(gapMap[a] + 1); // position w.r.t. AlignmentSequence
668 if (alan.annotations[a].secondaryStructure != ' ')
670 // we only write an annotation where it really exists.
671 Glyph ss = new Glyph();
673 .setDict(uk.ac.vamsas.objects.utils.GlyphDictionary.PROTEIN_SS_3STATE);
675 .valueOf(alan.annotations[a].secondaryStructure));
678 an.addAnnotationElement(ae);
683 private void saveDatasetSequenceAnnotation(HashMap AlSeqMaps,
684 uk.ac.vamsas.objects.core.Sequence sref, AlignmentAnnotation alan)
688 // objects.core.AlignmentSequence alsref = (uk.ac.vamsas.
689 // objects.core.AlignmentSequence) sref;
690 uk.ac.vamsas.objects.core.DataSetAnnotations an = (uk.ac.vamsas.objects.core.DataSetAnnotations) getjv2vObj(alan);
691 int[] gapMap = getGapMap(AlSeqMaps, alan);
694 an = new uk.ac.vamsas.objects.core.DataSetAnnotations();
695 initRangeAnnotationType(an, alan, gapMap);
697 an.setProvenance(dummyProvenance()); // get provenance as user
698 // created, or jnet, or
700 setAnnotationType(an, alan);
701 an.setGroup(Integer.toString(alan.graphGroup)); // // JBPNote -
709 if (alan.getThreshold()!=null && alan.getThreshold().displayed)
711 an.addProperty(newProperty(THRESHOLD, "float", ""+alan.getThreshold().value));
712 if (alan.getThreshold().label!=null)
713 an.addProperty(newProperty(THRESHOLD+"Name", "string", ""+alan.getThreshold().label));
715 ((DataSet) sref.getV_parent()).addDataSetAnnotations(an);
716 bindjvvobj(alan, an);
720 // update reference sequence Annotation
721 if (an.getModifiable() == null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK
724 // verify existing alignment sequence annotation is up to date
725 System.out.println("update dataset sequence annotation.");
729 // verify existing alignment sequence annotation is up to date
731 .println("make new alignment dataset sequence annotation if modification has happened.");
737 private int[] getGapMap(HashMap AlSeqMaps, AlignmentAnnotation alan)
740 if (AlSeqMaps.containsKey(alan.sequenceRef))
742 gapMap = (int[]) AlSeqMaps.get(alan.sequenceRef);
746 gapMap = new int[alan.sequenceRef.getLength()];
747 // map from alignment position to sequence position.
748 int[] sgapMap = alan.sequenceRef.gapMap();
749 for (int a = 0; a < sgapMap.length; a++)
751 gapMap[sgapMap[a]] = a;
757 private void saveAlignmentSequenceAnnotation(HashMap AlSeqMaps,
758 AlignmentSequence alsref, AlignmentAnnotation alan)
762 // objects.core.AlignmentSequence alsref = (uk.ac.vamsas.
763 // objects.core.AlignmentSequence) sref;
764 uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation an = (uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation) getjv2vObj(alan);
765 int[] gapMap = getGapMap(AlSeqMaps, alan);
768 an = new uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation();
769 initRangeAnnotationType(an, alan, gapMap);
771 * I mean here that we don't actually have a semantic 'type' for the
772 * annotation (this might be - score, intrinsic property, measurement,
773 * something extracted from another program, etc)
775 an.setType(JALVIEW_ANNOTATION_ROW); // TODO: better fix
776 // this rough guess ;)
777 alsref.addAlignmentSequenceAnnotation(an);
778 bindjvvobj(alan, an);
779 // These properties are directly supported by the
780 // AlignmentSequenceAnnotation type.
781 setAnnotationType(an, alan);
782 an.setProvenance(dummyProvenance()); // get provenance as user
783 // created, or jnet, or
788 // update reference sequence Annotation
789 if (an.getModifiable() == null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK
792 // verify existing alignment sequence annotation is up to date
793 System.out.println("update alignment sequence annotation.");
797 // verify existing alignment sequence annotation is up to date
799 .println("make new alignment sequence annotation if modification has happened.");
805 * set vamsas annotation object type from jalview annotation
809 private void setAnnotationType(RangeAnnotation an, AlignmentAnnotation alan)
811 if (an instanceof AlignmentSequenceAnnotation)
813 if (alan.graph != AlignmentAnnotation.NO_GRAPH)
815 ((AlignmentSequenceAnnotation)an).setGraph(true);
818 ((AlignmentSequenceAnnotation)an).setGraph(false);
821 if (an instanceof uk.ac.vamsas.objects.core.AlignmentAnnotation)
823 if (alan.graph != AlignmentAnnotation.NO_GRAPH)
825 ((uk.ac.vamsas.objects.core.AlignmentAnnotation)an).setGraph(true);
828 ((uk.ac.vamsas.objects.core.AlignmentAnnotation)an).setGraph(false);
833 case AlignmentAnnotation.BAR_GRAPH:
834 an.addProperty(newProperty(DISCRETE_ANNOTATION, "boolean","true"));
836 case AlignmentAnnotation.LINE_GRAPH:
837 an.addProperty(newProperty(CONTINUOUS_ANNOTATION, "boolean","true"));
840 // don't add any kind of discrete or continous property info.
844 private Property newProperty(String name, String type, String content)
846 Property vProperty = new Property();
847 vProperty.setName(name);
850 vProperty.setType(type);
854 vProperty.setType("String");
856 vProperty.setContent(content);
861 * correctly create a RangeAnnotation from a jalview sequence feature
864 * (typically DataSetAnnotations or AlignmentSequenceAnnotation)
866 * (the feature to be mapped from)
869 private RangeAnnotation getDSAnnotationFromJalview(RangeAnnotation dsa,
870 SequenceFeature feature)
872 dsa.setType(feature.getType());
873 Seg vSeg = new Seg();
874 vSeg.setStart(feature.getBegin());
875 vSeg.setEnd(feature.getEnd());
876 vSeg.setInclusive(true);
878 dsa.setDescription(feature.getDescription());
879 dsa.setStatus(feature.getStatus());
880 if (feature.links != null && feature.links.size() > 0)
882 for (int i = 0, iSize = feature.links.size(); i < iSize; i++)
884 String link = (String) feature.links.elementAt(i);
885 int sep = link.indexOf('|');
888 Link vLink = new Link();
891 vLink.setContent(link.substring(0, sep - 1));
895 vLink.setContent("");
897 vLink.setHref(link.substring(sep + 1)); // TODO: validate href.
902 dsa.setGroup(feature.getFeatureGroup());
907 * get start<end range of segment, adjusting for inclusivity flag and
911 * @param ensureDirection
912 * when true - always ensure start is less than end.
913 * @return int[] { start, end, direction} where direction==1 for range running
916 private int[] getSegRange(Seg visSeg, boolean ensureDirection)
918 boolean incl = visSeg.getInclusive();
919 // adjust for inclusive flag.
920 int pol = (visSeg.getStart() <= visSeg.getEnd()) ? 1 : -1; // polarity of
922 int start = visSeg.getStart() + (incl ? 0 : pol);
923 int end = visSeg.getEnd() + (incl ? 0 : -pol);
924 if (ensureDirection && pol == -1)
926 // jalview doesn't deal with inverted ranges, yet.
932 { start, end, pol < 0 ? 1 : 0 };
938 * @return true if annotation is not to be stored in document
940 private boolean isJalviewOnly(AlignmentAnnotation annotation)
942 return annotation.label.equals("Quality")
943 || annotation.label.equals("Conservation")
944 || annotation.label.equals("Consensus");
948 * This will return the first AlignFrame viewing AlignViewport av. It will
949 * break if there are more than one AlignFrames viewing a particular av. This
950 * also shouldn't be in the io package.
953 * @return alignFrame for av
955 public AlignFrame getAlignFrameFor(AlignViewport av)
957 if (Desktop.desktop != null)
959 javax.swing.JInternalFrame[] frames = Desktop.instance.getAllFrames();
961 for (int t = 0; t < frames.length; t++)
963 if (frames[t] instanceof AlignFrame)
965 if (((AlignFrame) frames[t]).getViewport() == av)
967 return (AlignFrame) frames[t];
975 public void updateToJalview()
977 VAMSAS _roots[] = cdoc.getVamsasRoots();
979 for (int _root = 0; _root < _roots.length; _root++)
981 VAMSAS root = _roots[_root];
982 boolean newds = false;
983 for (int _ds = 0, _nds = root.getDataSetCount(); _ds < _nds; _ds++)
985 // ///////////////////////////////////
987 DataSet dataset = root.getDataSet(_ds);
988 int i, iSize = dataset.getSequenceCount();
990 jalview.datamodel.Alignment jdataset = (jalview.datamodel.Alignment) getvObj2jv(dataset);
992 if (jdataset == null)
994 Cache.log.debug("Initialising new jalview dataset fields");
996 dsseqs = new Vector();
1000 Cache.log.debug("Update jalview dataset from vamsas.");
1001 jremain = jdataset.getHeight();
1002 dsseqs = jdataset.getSequences();
1005 // TODO: test sequence merging - we preserve existing non vamsas
1006 // sequences but add in any new vamsas ones, and don't yet update any
1007 // sequence attributes
1008 for (i = 0; i < iSize; i++)
1010 Sequence vdseq = dataset.getSequence(i);
1011 jalview.datamodel.SequenceI dsseq = (SequenceI) getvObj2jv(vdseq);
1014 if (!dsseq.getSequenceAsString().equals(vdseq.getSequence()))
1017 "Broken! - mismatch of dataset sequence: and jalview internal dataset sequence.");
1023 dsseq = new jalview.datamodel.Sequence(dataset.getSequence(i)
1024 .getName(), dataset.getSequence(i).getSequence(),
1025 (int) dataset.getSequence(i).getStart(), (int) dataset
1026 .getSequence(i).getEnd());
1027 dsseq.setDescription(dataset.getSequence(i).getDescription());
1028 bindjvvobj(dsseq, dataset.getSequence(i));
1029 dsseq.setVamsasId(dataset.getSequence(i).getVorbaId().getId());
1032 if (vdseq.getDbRefCount() > 0)
1034 DbRef[] dbref = vdseq.getDbRef();
1035 for (int db = 0; db < dbref.length; db++)
1037 new jalview.io.vamsas.Dbref(this, dbref[db], vdseq, dsseq);
1045 SequenceI[] seqs = new SequenceI[dsseqs.size()];
1046 for (i = 0, iSize = dsseqs.size(); i < iSize; i++)
1048 seqs[i] = (SequenceI) dsseqs.elementAt(i);
1049 dsseqs.setElementAt(null, i);
1051 jdataset = new jalview.datamodel.Alignment(seqs);
1052 Cache.log.debug("New vamsas dataset imported into jalview.");
1053 bindjvvobj(jdataset, dataset);
1056 // add any new dataset sequence feature annotations
1057 if (dataset.getDataSetAnnotations() != null)
1059 for (int dsa = 0; dsa < dataset.getDataSetAnnotationsCount(); dsa++)
1061 DataSetAnnotations dseta = dataset.getDataSetAnnotations(dsa);
1062 // TODO: deal with group annotation on datset sequences.
1063 if (dseta.getSeqRefCount() == 1)
1065 SequenceI dsSeq = (SequenceI) getvObj2jv((Vobject) dseta
1066 .getSeqRef(0)); // TODO: deal with group dataset
1070 jalview.bin.Cache.log
1071 .warn("Couldn't resolve jalview sequenceI for dataset object reference "
1072 + ((Vobject) dataset.getDataSetAnnotations(
1073 dsa).getSeqRef(0)).getVorbaId()
1078 if (dseta.getAnnotationElementCount() == 0)
1080 jalview.datamodel.SequenceFeature sf = (jalview.datamodel.SequenceFeature) getvObj2jv(dseta);
1084 .addSequenceFeature(sf = getJalviewSeqFeature(dseta));
1085 bindjvvobj(sf, dseta);
1090 // TODO: deal with alignmentAnnotation style annotation
1091 // appearing on dataset sequences.
1092 // JBPNote: we could just add them to all alignments but
1093 // that may complicate cross references in the jalview
1096 .warn("Ignoring dataset annotation with annotationElements. Not yet supported in jalview.");
1102 if (dataset.getAlignmentCount() > 0)
1104 // LOAD ALIGNMENTS from DATASET
1106 for (int al = 0, nal = dataset.getAlignmentCount(); al < nal; al++)
1108 uk.ac.vamsas.objects.core.Alignment alignment = dataset
1110 AlignViewport av = (AlignViewport) getvObj2jv(alignment);
1111 jalview.datamodel.AlignmentI jal = null;
1114 jal = av.getAlignment();
1116 iSize = alignment.getAlignmentSequenceCount();
1117 boolean newal = (jal == null) ? true : false;
1118 Vector newasAnnots = new Vector();
1119 char gapChar = ' '; // default for new alignments read in from the
1123 dsseqs = jal.getSequences(); // for merge/update
1124 gapChar = jal.getGapCharacter();
1128 dsseqs = new Vector();
1130 char valGapchar = alignment.getGapChar().charAt(0);
1131 for (i = 0; i < iSize; i++)
1133 AlignmentSequence valseq = alignment.getAlignmentSequence(i);
1134 jalview.datamodel.SequenceI alseq = (SequenceI) getvObj2jv(valseq);
1137 // TODO: upperCase/LowerCase situation here ? do we allow it ?
1138 // if (!alseq.getSequence().equals(valseq.getSequence())) {
1139 // throw new Error("Broken! - mismatch of dataset sequence and
1140 // jalview internal dataset sequence.");
1141 if (Cache.log.isDebugEnabled())
1143 Cache.log.debug("Updating apparently edited sequence "
1146 // this might go *horribly* wrong
1147 alseq.setSequence(new String(valseq.getSequence()).replace(
1148 valGapchar, gapChar));
1153 alseq = new jalview.datamodel.Sequence(valseq.getName(),
1154 valseq.getSequence().replace(valGapchar, gapChar),
1155 (int) valseq.getStart(), (int) valseq.getEnd());
1157 Vobject datsetseq = (Vobject) valseq.getRefid();
1158 if (datsetseq != null)
1161 .setDatasetSequence((SequenceI) getvObj2jv(datsetseq)); // exceptions
1163 // AlignemntSequence
1173 .error("Invalid dataset sequence id (null) for alignment sequence "
1174 + valseq.getVorbaId());
1176 bindjvvobj(alseq, valseq);
1177 alseq.setVamsasId(valseq.getVorbaId().getId());
1180 if (valseq.getAlignmentSequenceAnnotationCount() > 0)
1182 AlignmentSequenceAnnotation[] vasannot = valseq
1183 .getAlignmentSequenceAnnotation();
1184 for (int a = 0; a < vasannot.length; a++)
1186 jalview.datamodel.AlignmentAnnotation asa = (jalview.datamodel.AlignmentAnnotation) getvObj2jv(vasannot[a]); // TODO:
1194 int se[] = getBounds(vasannot[a]);
1195 asa = getjAlignmentAnnotation(jal, vasannot[a]);
1196 asa.setSequenceRef(alseq);
1197 asa.createSequenceMapping(alseq, se[0], false); // TODO:
1208 alseq.addAlignmentAnnotation(asa);
1209 bindjvvobj(asa, vasannot[a]);
1210 newasAnnots.add(asa);
1214 // update existing annotation - can do this in place
1215 if (vasannot[a].getModifiable() == null) // TODO: USE
1221 .info("UNIMPLEMENTED: not recovering user modifiable sequence alignment annotation");
1222 // TODO: should at least replace with new one - otherwise
1223 // things will break
1224 // basically do this:
1225 // int se[] = getBounds(vasannot[a]);
1226 // asa.update(getjAlignmentAnnotation(jal, vasannot[a]));
1227 // // update from another annotation object in place.
1228 // asa.createSequenceMapping(alseq, se[0], false);
1237 SequenceI[] seqs = new SequenceI[dsseqs.size()];
1238 for (i = 0, iSize = dsseqs.size(); i < iSize; i++)
1240 seqs[i] = (SequenceI) dsseqs.elementAt(i);
1241 dsseqs.setElementAt(null, i);
1243 jal = new jalview.datamodel.Alignment(seqs);
1244 Cache.log.debug("New vamsas alignment imported into jalview "
1245 + alignment.getVorbaId().getId());
1246 jal.setDataset(jdataset);
1248 if (newasAnnots != null && newasAnnots.size() > 0)
1250 // Add the new sequence annotations in to the alignment.
1251 for (int an = 0, anSize = newasAnnots.size(); an < anSize; an++)
1253 jal.addAnnotation((AlignmentAnnotation) newasAnnots
1255 // TODO: check if anything has to be done - like calling
1256 // adjustForAlignment or something.
1257 newasAnnots.setElementAt(null, an);
1261 // //////////////////////////////////////////
1262 // //LOAD ANNOTATIONS FOR THE ALIGNMENT
1263 // ////////////////////////////////////
1264 if (alignment.getAlignmentAnnotationCount() > 0)
1266 uk.ac.vamsas.objects.core.AlignmentAnnotation[] an = alignment
1267 .getAlignmentAnnotation();
1269 for (int j = 0; j < an.length; j++)
1271 jalview.datamodel.AlignmentAnnotation jan = (jalview.datamodel.AlignmentAnnotation) getvObj2jv(an[j]);
1274 // update or stay the same.
1275 // TODO: should at least replace with a new one - otherwise
1276 // things will break
1277 // basically do this:
1278 // jan.update(getjAlignmentAnnotation(jal, an[a])); // update
1279 // from another annotation object in place.
1282 .debug("update from vamsas alignment annotation to existing jalview alignment annotation.");
1283 if (an[j].getModifiable() == null) // TODO: USE VAMSAS
1284 // LIBRARY OBJECT LOCK
1287 // TODO: user defined annotation is totally mutable... - so
1288 // load it up or throw away if locally edited.
1290 .info("NOT IMPLEMENTED - Recovering user-modifiable annotation - yet...");
1292 // TODO: compare annotation element rows
1293 // TODO: compare props.
1297 jan = getjAlignmentAnnotation(jal, an[j]);
1298 jal.addAnnotation(jan);
1299 bindjvvobj(jan, an[j]);
1303 AlignFrame alignFrame;
1306 Cache.log.debug("New alignframe for alignment "
1307 + alignment.getVorbaId());
1308 // ///////////////////////////////
1309 // construct alignment view
1310 alignFrame = new AlignFrame(jal, AlignFrame.DEFAULT_WIDTH,
1311 AlignFrame.DEFAULT_HEIGHT);
1312 av = alignFrame.getViewport();
1313 String title = alignment.getProvenance().getEntry(
1314 alignment.getProvenance().getEntryCount() - 1)
1316 if (alignment.getPropertyCount() > 0)
1318 for (int p = 0, pe = alignment.getPropertyCount(); p < pe; p++)
1320 if (alignment.getProperty(p).getName().equals(
1323 title = alignment.getProperty(p).getContent();
1327 // TODO: automatically create meaningful title for a vamsas
1328 // alignment using its provenance.
1329 if (Cache.log.isDebugEnabled())
1332 + alignment.getVorbaId() + ")";
1335 jalview.gui.Desktop.addInternalFrame(alignFrame, title
1337 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
1338 bindjvvobj(av, alignment);
1342 // find the alignFrame for jal.
1343 // TODO: fix this so we retrieve the alignFrame handing av
1345 alignFrame = getAlignFrameFor(av);
1348 // /////////////////////////////////////
1349 if (alignment.getTreeCount() > 0)
1352 for (int t = 0; t < alignment.getTreeCount(); t++)
1354 jalview.io.vamsas.Tree vstree = new jalview.io.vamsas.Tree(
1355 this, alignFrame, alignment.getTree(t));
1356 TreePanel tp = null;
1357 if (vstree.isValidTree())
1360 .ShowNewickTree(vstree.getNewickTree(), vstree
1361 .getTitle(), vstree.getInputData(), 600,
1362 500, t * 20 + 50, t * 20 + 50);
1365 bindjvvobj(tp, alignment.getTree(t));
1368 Cache.log.warn("Cannot create tree for tree "+t+" in document ("+alignment.getTree(t).getVorbaId());
1376 // we do sequenceMappings last because they span all datasets in a vamsas
1378 for (int _ds = 0, _nds = root.getDataSetCount(); _ds < _nds; _ds++)
1380 DataSet dataset = root.getDataSet(_ds);
1381 if (dataset.getSequenceMappingCount() > 0)
1383 for (int sm = 0, smCount = dataset.getSequenceMappingCount(); sm < smCount; sm++)
1385 Rangetype seqmap = new jalview.io.vamsas.Sequencemapping(this,
1386 dataset.getSequenceMapping(sm));
1393 // bitfields - should be a template in j1.5
1394 private static int HASSECSTR = 0;
1396 private static int HASVALS = 1;
1398 private static int HASHPHOB = 2;
1400 private static int HASDC = 3;
1402 private static int HASDESCSTR = 4;
1404 private static int HASTWOSTATE = 5; // not used yet.
1407 * parses the AnnotationElements - if they exist - into
1408 * jalview.datamodel.Annotation[] rows Two annotation rows are made if there
1409 * are distinct annotation for both at 'pos' and 'after pos' at any particular
1413 * @return { boolean[static int constants ], int[ae.length] - map to annotated
1414 * object frame, jalview.datamodel.Annotation[],
1415 * jalview.datamodel.Annotation[] (after)}
1417 private Object[] parseRangeAnnotation(
1418 uk.ac.vamsas.objects.core.RangeAnnotation annotation)
1420 // set these attributes by looking in the annotation to decide what kind of
1421 // alignment annotation rows will be made
1422 // TODO: potentially we might make several annotation rows from one vamsas
1423 // alignment annotation. the jv2Vobj binding mechanism
1424 // may not quite cope with this (without binding an array of annotations to
1425 // a vamsas alignment annotation)
1426 // summary flags saying what we found over the set of annotation rows.
1427 boolean[] AeContent = new boolean[]
1428 { false, false, false, false, false };
1429 int[] rangeMap = getMapping(annotation);
1430 jalview.datamodel.Annotation[][] anot = new jalview.datamodel.Annotation[][]
1431 { new jalview.datamodel.Annotation[rangeMap.length],
1432 new jalview.datamodel.Annotation[rangeMap.length] };
1433 boolean mergeable = true; // false if 'after positions cant be placed on
1434 // same annotation row as positions.
1436 if (annotation.getAnnotationElementCount() > 0)
1438 AnnotationElement ae[] = annotation.getAnnotationElement();
1439 for (int aa = 0; aa < ae.length; aa++)
1441 int pos = (int) ae[aa].getPosition() - 1; // pos counts from 1 to
1442 // (|seg.start-seg.end|+1)
1443 if (pos >= 0 && pos < rangeMap.length)
1445 int row = ae[aa].getAfter() ? 1 : 0;
1446 if (anot[row][pos] != null)
1448 // only time this should happen is if the After flag is set.
1449 Cache.log.debug("Ignoring duplicate annotation site at " + pos);
1452 if (anot[1 - row][pos] != null)
1457 if (ae[aa].getDescription() != null)
1459 desc = ae[aa].getDescription();
1460 if (desc.length() > 0)
1462 // have imported valid description string
1463 AeContent[HASDESCSTR] = true;
1466 String dc = null; // ae[aa].getDisplayCharacter()==null ? "dc" :
1467 // ae[aa].getDisplayCharacter();
1468 String ss = null; // ae[aa].getSecondaryStructure()==null ? "ss" :
1469 // ae[aa].getSecondaryStructure();
1470 java.awt.Color colour = null;
1471 if (ae[aa].getGlyphCount() > 0)
1473 Glyph[] glyphs = ae[aa].getGlyph();
1474 for (int g = 0; g < glyphs.length; g++)
1479 uk.ac.vamsas.objects.utils.GlyphDictionary.PROTEIN_SS_3STATE))
1481 ss = glyphs[g].getContent();
1482 AeContent[HASSECSTR] = true;
1487 uk.ac.vamsas.objects.utils.GlyphDictionary.PROTEIN_HD_HYDRO))
1489 Cache.log.debug("ignoring hydrophobicity glyph marker.");
1490 AeContent[HASHPHOB] = true;
1491 char c = (dc = glyphs[g].getContent()).charAt(0);
1492 // dc may get overwritten - but we still set the colour.
1493 colour = new java.awt.Color(c == '+' ? 255 : 0,
1494 c == '.' ? 255 : 0, c == '-' ? 255 : 0);
1497 else if (glyphs[g].getDict().equals(
1498 uk.ac.vamsas.objects.utils.GlyphDictionary.DEFAULT))
1500 dc = glyphs[g].getContent();
1501 AeContent[HASDC] = true;
1505 Cache.log.debug("IMPLEMENTATION TODO: Ignoring unknown glyph type "
1506 + glyphs[g].getDict());
1511 if (ae[aa].getValueCount() > 0)
1513 AeContent[HASVALS] = true;
1514 if (ae[aa].getValueCount() > 1)
1516 Cache.log.warn("ignoring additional "
1517 + (ae[aa].getValueCount() - 1)
1518 + "values in annotation element.");
1520 val = ae[aa].getValue(0);
1524 anot[row][pos] = new jalview.datamodel.Annotation(
1525 (dc != null) ? dc : "", desc, (ss != null) ? ss
1526 .charAt(0) : ' ', val);
1530 anot[row][pos] = new jalview.datamodel.Annotation(
1531 (dc != null) ? dc : "", desc, (ss != null) ? ss
1532 .charAt(0) : ' ', val, colour);
1537 Cache.log.warn("Ignoring out of bound annotation element " + aa
1538 + " in " + annotation.getVorbaId().getId());
1541 // decide on how many annotation rows are needed.
1544 for (int i = 0; i < anot[0].length; i++)
1546 if (anot[1][i] != null)
1548 anot[0][i] = anot[1][i];
1549 anot[0][i].description = anot[0][i].description + " (after)";
1550 AeContent[HASDESCSTR] = true; // we have valid description string
1559 for (int i = 0; i < anot[0].length; i++)
1561 anot[1][i].description = anot[1][i].description + " (after)";
1565 { AeContent, rangeMap, anot[0], anot[1] };
1569 // no annotations to parse. Just return an empty annotationElement[]
1572 { AeContent, rangeMap, anot[0], anot[1] };
1579 * the jalview alignment to which the annotation will be attached
1580 * (ideally - freshly updated from corresponding vamsas alignment)
1582 * @return unbound jalview alignment annotation object.
1584 private jalview.datamodel.AlignmentAnnotation getjAlignmentAnnotation(
1585 jalview.datamodel.AlignmentI jal,
1586 uk.ac.vamsas.objects.core.RangeAnnotation annotation)
1588 if (annotation == null)
1593 // hasSequenceRef=annotation.getClass().equals(uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation.class);
1594 // boolean hasProvenance=hasSequenceRef ||
1595 // (annotation.getClass().equals(uk.ac.vamsas.objects.core.AlignmentAnnotation.class));
1597 * int se[] = getBounds(annotation); if (se==null) se=new int[]
1598 * {0,jal.getWidth()-1};
1600 Object[] parsedRangeAnnotation = parseRangeAnnotation(annotation);
1601 String a_label = annotation.getLabel();
1602 String a_descr = annotation.getDescription();
1605 boolean interp=true; // cleared if annotation is DISCRETE
1606 // set type and other attributes from properties
1607 if (annotation.getPropertyCount() > 0)
1609 // look for special jalview properties
1610 uk.ac.vamsas.objects.core.Property[] props = annotation
1612 for (int p = 0; p < props.length; p++)
1614 if (props[p].getName().equalsIgnoreCase(DISCRETE_ANNOTATION))
1616 type = AlignmentAnnotation.BAR_GRAPH;
1619 (props[p].getName().equalsIgnoreCase(CONTINUOUS_ANNOTATION)) {
1620 type = AlignmentAnnotation.LINE_GRAPH;
1622 (props[p].getName().equalsIgnoreCase(THRESHOLD))
1626 val = new Float(props[p].getContent());
1627 }catch (Exception e)
1629 Cache.log.warn("Failed to parse threshold property");
1634 gl = new GraphLine(val.floatValue(), "", java.awt.Color.black);
1637 gl.value = val.floatValue();
1640 else if (props[p].getName().equalsIgnoreCase(THRESHOLD+"Name"))
1643 gl = new GraphLine(0, "", java.awt.Color.black);
1644 gl.label = props[p].getContent();
1648 jalview.datamodel.AlignmentAnnotation jan = null;
1649 if (a_label == null || a_label.length() == 0)
1651 a_label = annotation.getType();
1652 if (a_label.length() == 0)
1654 a_label = "Unamed annotation";
1657 if (a_descr == null || a_descr.length() == 0)
1659 a_descr = "Annotation of type '" + annotation.getType() + "'";
1661 if (parsedRangeAnnotation == null)
1664 .debug("Inserting empty annotation row elements for a whole-alignment annotation.");
1668 if (parsedRangeAnnotation[3] != null)
1670 Cache.log.warn("Ignoring 'After' annotation row in "
1671 + annotation.getVorbaId());
1673 jalview.datamodel.Annotation[] arow = (jalview.datamodel.Annotation[]) parsedRangeAnnotation[2];
1674 boolean[] has = (boolean[]) parsedRangeAnnotation[0];
1675 // VAMSAS: getGraph is only on derived annotation for alignments - in this
1676 // way its 'odd' - there is already an existing TODO about removing this
1677 // flag as being redundant
1680 * ((annotation.getClass().equals(uk.ac.vamsas.objects.core.AlignmentAnnotation.class) &&
1681 * ((uk.ac.vamsas.objects.core.AlignmentAnnotation)annotation).getGraph()) ||
1682 * (hasSequenceRef=true &&
1683 * ((uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation)annotation).getGraph())) {
1689 type = jalview.datamodel.AlignmentAnnotation.BAR_GRAPH; // default type of value annotation
1692 // no hints - so we ensure HPHOB display is like this.
1693 type = jalview.datamodel.AlignmentAnnotation.BAR_GRAPH;
1696 // make bounds and automatic description strings for jalview user's
1697 // benefit (these shouldn't be written back to vamsas document)
1698 boolean first = true;
1699 float min = 0, max = 1;
1701 for (int i = 0; i < arow.length; i++)
1703 if (arow[i] != null)
1705 if (i - lastval > 1 && interp)
1707 // do some interpolation *between* points
1708 if (arow[lastval] != null)
1710 float interval = arow[i].value - arow[lastval].value;
1711 interval /= i - lastval;
1712 float base = arow[lastval].value;
1713 for (int ip = lastval + 1, np = 0; ip < i; np++, ip++)
1715 arow[ip] = new jalview.datamodel.Annotation("", "", ' ',
1716 interval * np + base);
1717 // NB - Interpolated points don't get a tooltip and
1723 // check range - shouldn't we have a min and max property in the
1724 // annotation object ?
1727 min = max = arow[i].value;
1732 if (arow[i].value < min)
1734 min = arow[i].value;
1736 else if (arow[i].value > max)
1738 max = arow[i].value;
1741 // make tooltip and display char value
1742 if (!has[HASDESCSTR])
1744 arow[i].description = arow[i].value + "";
1750 if (arow[i].description!=null && arow[i].description.length()<3)
1752 // copy over the description as the display char.
1753 arow[i].displayCharacter = new String(arow[i].description);
1757 // mark the position as a point used for the interpolation.
1758 arow[i].displayCharacter = arow[i].value + "";
1763 jan = new jalview.datamodel.AlignmentAnnotation(a_label, a_descr,
1764 arow, min, max, type);
1768 if (annotation.getAnnotationElementCount()==0)
1770 // empty annotation array
1771 // TODO: alignment 'features' compare rangeType spec to alignment width - if it is not complete, then mark regions on the annotation row.
1773 jan = new jalview.datamodel.AlignmentAnnotation(a_label, a_descr,
1775 jan.setThreshold(null);
1777 if (annotation.getLinkCount() > 0)
1779 Cache.log.warn("Ignoring " + annotation.getLinkCount()
1780 + "links added to AlignmentAnnotation.");
1782 if (annotation.getModifiable() == null) // TODO: USE VAMSAS LIBRARY OBJECT
1785 jan.editable = true;
1789 if (annotation.getGroup() != null
1790 && annotation.getGroup().length() > 0)
1792 jan.graphGroup = Integer.parseInt(annotation.getGroup());
1794 } catch (Exception e)
1797 .info("UNIMPLEMENTED : Couldn't parse non-integer group value for setting graphGroup correctly.");
1806 private SequenceFeature getJalviewSeqFeature(RangeAnnotation dseta)
1808 int[] se = getBounds(dseta);
1809 SequenceFeature sf = new jalview.datamodel.SequenceFeature(dseta
1810 .getType(), dseta.getDescription(), dseta.getStatus(), se[0],
1811 se[1], dseta.getGroup());
1812 if (dseta.getLinkCount() > 0)
1814 Link[] links = dseta.getLink();
1815 for (int i = 0; i < links.length; i++)
1817 sf.addLink(links[i].getContent() + "|" + links[i].getHref());
1824 * get real bounds of a RangeType's specification. start and end are an
1825 * inclusive range within which all segments and positions lie. TODO: refactor
1829 * @return int[] { start, end}
1831 private int[] getBounds(RangeType dseta)
1836 if (dseta.getSegCount() > 0 && dseta.getPosCount() > 0)
1839 "Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!");
1841 if (dseta.getSegCount() > 0)
1843 se = getSegRange(dseta.getSeg(0), true);
1844 for (int s = 1, sSize = dseta.getSegCount(); s < sSize; s++)
1846 int nse[] = getSegRange(dseta.getSeg(s), true);
1857 if (dseta.getPosCount() > 0)
1859 // could do a polarity for pos range too. and pass back indication of
1861 int pos = dseta.getPos(0).getI();
1864 for (int p = 0, pSize = dseta.getPosCount(); p < pSize; p++)
1866 pos = dseta.getPos(p).getI();
1883 * map from a rangeType's internal frame to the referenced object's coordinate
1887 * @return int [] { ref(pos)...} for all pos in rangeType's frame.
1889 private int[] getMapping(RangeType dseta)
1891 Vector posList = new Vector();
1895 if (dseta.getSegCount() > 0 && dseta.getPosCount() > 0)
1898 "Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!");
1900 if (dseta.getSegCount() > 0)
1902 for (int s = 0, sSize = dseta.getSegCount(); s < sSize; s++)
1904 se = getSegRange(dseta.getSeg(s), false);
1905 int se_end = se[1 - se[2]] + (se[2] == 0 ? 1 : -1);
1906 for (int p = se[se[2]]; p != se_end; p += se[2] == 0 ? 1 : -1)
1908 posList.add(new Integer(p));
1912 else if (dseta.getPosCount() > 0)
1914 int pos = dseta.getPos(0).getI();
1916 for (int p = 0, pSize = dseta.getPosCount(); p < pSize; p++)
1918 pos = dseta.getPos(p).getI();
1919 posList.add(new Integer(pos));
1923 if (posList != null && posList.size() > 0)
1925 int[] range = new int[posList.size()];
1926 for (int i = 0; i < range.length; i++)
1928 range[i] = ((Integer) posList.elementAt(i)).intValue();
1939 * where the from range is the local mapped range, and the to range
1940 * is the 'mapped' range in the MapRangeType
1947 private jalview.util.MapList parsemapType(MapType maprange, int localu,
1950 jalview.util.MapList ml = null;
1951 int[] localRange = getMapping(maprange.getLocal());
1952 int[] mappedRange = getMapping(maprange.getMapped());
1953 long lu = maprange.getLocal().hasUnit() ? maprange.getLocal().getUnit()
1955 long mu = maprange.getMapped().hasUnit() ? maprange.getMapped()
1956 .getUnit() : mappedu;
1957 ml = new jalview.util.MapList(localRange, mappedRange, (int) lu,
1963 * initialise a range type object from a set of start/end inclusive intervals
1968 private void initRangeType(RangeType mrt, int[] range)
1970 for (int i = 0; i < range.length; i += 2)
1972 Seg vSeg = new Seg();
1973 vSeg.setStart(range[i]);
1974 vSeg.setEnd(range[i + 1]);
1980 * initialise a MapType object from a MapList object.
1986 private void initMapType(MapType maprange, jalview.util.MapList ml,
1989 maprange.setLocal(new Local());
1990 maprange.setMapped(new Mapped());
1991 initRangeType(maprange.getLocal(), ml.getFromRanges());
1992 initRangeType(maprange.getMapped(), ml.getToRanges());
1995 maprange.getLocal().setUnit(ml.getFromRatio());
1996 maprange.getLocal().setUnit(ml.getToRatio());
2001 * not needed now. Provenance getVamsasProvenance(jalview.datamodel.Provenance
2002 * jprov) { jalview.datamodel.ProvenanceEntry[] entries = null; // TODO: fix
2003 * App and Action here. Provenance prov = new Provenance();
2004 * org.exolab.castor.types.Date date = new org.exolab.castor.types.Date( new
2005 * java.util.Date()); Entry provEntry;
2007 * if (jprov != null) { entries = jprov.getEntries(); for (int i = 0; i <
2008 * entries.length; i++) { provEntry = new Entry(); try { date = new
2009 * org.exolab.castor.types.Date(entries[i].getDate()); } catch (Exception ex) {
2010 * ex.printStackTrace();
2012 * date = new org.exolab.castor.types.Date(entries[i].getDate()); }
2013 * provEntry.setDate(date); provEntry.setUser(entries[i].getUser());
2014 * provEntry.setAction(entries[i].getAction()); prov.addEntry(provEntry); } }
2015 * else { provEntry = new Entry(); provEntry.setDate(date);
2016 * provEntry.setUser(System.getProperty("user.name")); // TODO: ext string
2017 * provEntry.setApp("JVAPP"); // TODO: ext string provEntry.setAction(action);
2018 * prov.addEntry(provEntry); }
2022 jalview.datamodel.Provenance getJalviewProvenance(Provenance prov)
2024 // TODO: fix App and Action entries and check use of provenance in jalview.
2025 jalview.datamodel.Provenance jprov = new jalview.datamodel.Provenance();
2026 for (int i = 0; i < prov.getEntryCount(); i++)
2028 jprov.addEntry(prov.getEntry(i).getUser(), prov.getEntry(i)
2029 .getAction(), prov.getEntry(i).getDate(), prov.getEntry(i)
2038 * @return default initial provenance list for a Jalview created vamsas
2041 Provenance dummyProvenance()
2043 return dummyProvenance(null);
2046 Entry dummyPEntry(String action)
2048 Entry entry = new Entry();
2049 entry.setApp(this.provEntry.getApp());
2052 entry.setAction(action);
2056 entry.setAction("created.");
2058 entry.setDate(new java.util.Date());
2059 entry.setUser(this.provEntry.getUser());
2063 Provenance dummyProvenance(String action)
2065 Provenance prov = new Provenance();
2066 prov.addEntry(dummyPEntry(action));
2070 void addProvenance(Provenance p, String action)
2072 p.addEntry(dummyPEntry(action));
2075 public Entry getProvEntry()
2080 public IClientDocument getClientDocument()
2085 public IdentityHashMap getJvObjectBinding()
2090 public Hashtable getVamsasObjectBinding()
2095 public void storeSequenceMappings(AlignViewport viewport, String title)
2098 AlignViewport av = viewport;
2101 jalview.datamodel.AlignmentI jal = av.getAlignment();
2102 // /////////////////////////////////////////
2104 DataSet dataset = null;
2105 if (jal.getDataset() == null)
2107 Cache.log.warn("Creating new dataset for an alignment.");
2108 jal.setDataset(null);
2110 dataset = (DataSet) getjv2vObj(jal.getDataset());
2111 // Store any sequence mappings.
2112 if (av.getAlignment().getCodonFrames() != null
2113 && av.getAlignment().getCodonFrames().length > 0)
2115 jalview.datamodel.AlignedCodonFrame[] cframes = av.getAlignment()
2117 for (int cf = 0; cf < cframes.length; cf++)
2119 if (cframes[cf].getdnaSeqs().length > 0)
2121 jalview.datamodel.SequenceI[] dmps = cframes[cf].getdnaSeqs();
2122 jalview.datamodel.Mapping[] mps = cframes[cf].getProtMappings();
2123 for (int smp = 0; smp < mps.length; smp++)
2125 uk.ac.vamsas.objects.core.SequenceType mfrom = (SequenceType) getjv2vObj(dmps[smp]);
2128 new jalview.io.vamsas.Sequencemapping(this, mps[smp],
2134 .warn("NO Vamsas Binding for local sequence! NOT CREATING MAPPING FOR "
2137 + mps[smp].getTo().getName());
2143 } catch (Exception e)
2145 throw new Exception("Couldn't store sequence mappings for " + title,