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 Hashtable alignRDHash;
84 public VamsasAppDatastore(IClientDocument cdoc, Hashtable vobj2jv,
85 IdentityHashMap jv2vobj, Entry provEntry, Hashtable alignRDHash)
88 this.vobj2jv = vobj2jv;
89 this.jv2vobj = jv2vobj;
90 this.provEntry = provEntry;
91 this.alignRDHash = alignRDHash;
95 * @return the Vobject bound to Jalview datamodel object
97 protected Vobject getjv2vObj(Object jvobj)
99 if (jv2vobj.containsKey(jvobj))
101 return cdoc.getObject((VorbaId) jv2vobj.get(jvobj));
103 if (Cache.log.isDebugEnabled())
105 Cache.log.debug("Returning null VorbaID binding for jalview object "
114 * @return Jalview datamodel object bound to the vamsas document object
116 protected Object getvObj2jv(uk.ac.vamsas.client.Vobject vobj)
118 VorbaId id = vobj.getVorbaId();
121 id = cdoc.registerObject(vobj);
123 .debug("Registering new object and returning null for getvObj2jv");
126 if (vobj2jv.containsKey(vobj.getVorbaId()))
128 return vobj2jv.get(vobj.getVorbaId());
133 protected void bindjvvobj(Object jvobj, uk.ac.vamsas.client.Vobject vobj)
135 VorbaId id = vobj.getVorbaId();
138 id = cdoc.registerObject(vobj);
139 if (id == null || vobj.getVorbaId() == null
140 || cdoc.getObject(id) != vobj)
142 Cache.log.error("Failed to get id for "
143 + (vobj.isRegisterable() ? "registerable"
144 : "unregisterable") + " object " + vobj);
148 if (vobj2jv.containsKey(vobj.getVorbaId())
149 && !((VorbaId) vobj2jv.get(vobj.getVorbaId())).equals(jvobj))
152 "Warning? Overwriting existing vamsas id binding for "
153 + vobj.getVorbaId(), new Exception(
154 "Overwriting vamsas id binding."));
156 else if (jv2vobj.containsKey(jvobj)
157 && !((VorbaId) jv2vobj.get(jvobj)).equals(vobj.getVorbaId()))
160 "Warning? Overwriting existing jalview object binding for "
161 + jvobj, new Exception(
162 "Overwriting jalview object binding."));
165 * Cache.log.error("Attempt to make conflicting object binding! "+vobj+" id "
166 * +vobj.getVorbaId()+" already bound to "+getvObj2jv(vobj)+" and "+jvobj+"
167 * already bound to "+getjv2vObj(jvobj),new Exception("Excessive call to
170 // we just update the hash's regardless!
171 Cache.log.debug("Binding " + vobj.getVorbaId() + " to " + jvobj);
172 vobj2jv.put(vobj.getVorbaId(), jvobj);
173 // JBPNote - better implementing a hybrid invertible hash.
174 jv2vobj.put(jvobj, vobj.getVorbaId());
178 * put the alignment viewed by AlignViewport into cdoc.
181 * alignViewport to be stored
183 * title for alignment
185 public void storeVAMSAS(AlignViewport av, String aFtitle)
189 jalview.datamodel.AlignmentI jal = av.getAlignment();
191 VAMSAS root = null; // will be resolved based on Dataset Parent.
192 // /////////////////////////////////////////
194 DataSet dataset = null;
195 if (jal.getDataset() == null)
197 Cache.log.warn("Creating new dataset for an alignment.");
198 jal.setDataset(null);
200 dataset = (DataSet) getjv2vObj(jal.getDataset());
203 // it might be that one of the dataset sequences does actually have a
204 // binding, so search for it indirectly.
205 jalview.datamodel.SequenceI[] jdatset = jal.getDataset()
206 .getSequencesArray();
207 for (int i = 0; i < jdatset.length; i++)
209 Vobject vbound = getjv2vObj(jdatset[i]);
212 if (vbound instanceof uk.ac.vamsas.objects.core.Sequence)
216 dataset = (DataSet) vbound.getV_parent();
220 if (dataset != vbound.getV_parent())
223 "IMPLEMENTATION ERROR: Cannot map an alignment of sequences from datasets into the vamsas document.");
224 // This occurs because the dataset for the alignment we are
235 // we create a new dataset on the default vamsas root.
236 root = cdoc.getVamsasRoots()[0]; // default vamsas root for modifying.
237 dataset = new DataSet();
238 root.addDataSet(dataset);
239 bindjvvobj(jal.getDataset(), dataset);
240 dataset.setProvenance(dummyProvenance());
241 // dataset.getProvenance().addEntry(provEntry);
246 root = (VAMSAS) dataset.getV_parent();
251 // set new dataset and alignment sequences based on alignment Nucleotide
253 // this *will* break when alignment contains both nucleotide and amino
255 String dict = jal.isNucleotide() ? uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_NA
256 : uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_AA;
257 Vector dssmods = new Vector();
258 for (int i = 0; i < jal.getHeight(); i++)
260 SequenceI sq = jal.getSequenceAt(i).getDatasetSequence(); // only insert
264 sequence = (Sequence) getjv2vObj(sq);
265 if (sequence == null)
267 sequence = new Sequence();
268 bindjvvobj(sq, sequence);
269 sq.setVamsasId(sequence.getVorbaId().getId());
270 sequence.setSequence(sq.getSequenceAsString());
271 sequence.setDictionary(dict);
272 sequence.setName(sq.getName());
273 sequence.setStart(sq.getStart());
274 sequence.setEnd(sq.getEnd());
275 sequence.setDescription(sq.getDescription());
276 dataset.addSequence(sequence);
277 dssmods.addElement(dssmods);
281 boolean dsmod = false;
282 // verify and update principal attributes.
283 if (sq.getDescription()!=null && (sequence.getDescription()==null || !sequence.getDescription().equals(sq.getDescription())))
285 sequence.setDescription(sq.getDescription());
288 if (sequence.getSequence()==null || !sequence.getSequence().equals(sq.getSequenceAsString()))
290 if (sequence.getStart()!=sq.getStart() || sequence.getEnd()!=sq.getEnd())
292 // update modified sequence.
293 sequence.setSequence(sq.getSequenceAsString());
294 sequence.setStart(sq.getStart());
295 sequence.setEnd(sq.getEnd());
299 if (!dict.equals(sequence.getDictionary()))
301 sequence.setDictionary(dict);
304 if (!sequence.getName().equals(sq.getName()))
306 sequence.setName(sq.getName());
311 dssmods.addElement(sequence);
314 // add or update any new features/references on dataset sequence
315 if (sq.getSequenceFeatures() != null)
317 int sfSize = sq.getSequenceFeatures().length;
319 for (int sf = 0; sf < sfSize; sf++)
321 // TODO: update/modifiable synchronizer
322 jalview.datamodel.SequenceFeature feature = (jalview.datamodel.SequenceFeature) sq
323 .getSequenceFeatures()[sf];
325 DataSetAnnotations dsa = (DataSetAnnotations) getjv2vObj(feature);
328 dsa = (DataSetAnnotations) getDSAnnotationFromJalview(
329 new DataSetAnnotations(), feature);
330 if (dsa.getProvenance() == null)
332 dsa.setProvenance(new Provenance());
334 addProvenance(dsa.getProvenance(), "created"); // JBPNote - need
336 dsa.addSeqRef(sequence); // we have just created this annotation
337 // - so safe to use this
338 bindjvvobj(feature, dsa);
339 dataset.addDataSetAnnotations(dsa);
343 // todo: verify and update dataset annotations for sequence
344 System.out.println("update dataset sequence annotations.");
349 if (sq.getDBRef() != null)
351 DBRefEntry[] entries = sq.getDBRef();
352 jalview.datamodel.DBRefEntry dbentry;
353 for (int db = 0; db < entries.length; db++)
355 Rangetype dbr = new jalview.io.vamsas.Dbref(this,
356 dbentry = entries[db], sq, sequence);
361 if (dssmods.size()>0)
365 Entry pentry = this.addProvenance(dataset.getProvenance(), "updated sequences");
366 // pentry.addInput(vInput); could write in which sequences were modified.
367 dssmods.removeAllElements();
370 // dataset.setProvenance(getVamsasProvenance(jal.getDataset().getProvenance()));
371 // ////////////////////////////////////////////
372 if (!av.getAlignment().isAligned())
373 return; // TODO: trees could be written - but for the moment we just skip
374 // ////////////////////////////////////////////
375 // Save the Alignments
377 Alignment alignment = (Alignment) getjv2vObj(av.getSequenceSetId()); // this is so we can get
380 if (alignment == null)
382 alignment = new Alignment();
383 bindjvvobj(av.getSequenceSetId(), alignment);
384 if (alignment.getProvenance() == null)
386 alignment.setProvenance(new Provenance());
388 addProvenance(alignment.getProvenance(), "added"); // TODO: insert some
391 dataset.addAlignment(alignment);
393 Property title = new Property();
394 title.setName("title");
395 title.setType("string");
396 title.setContent(aFtitle);
397 alignment.addProperty(title);
399 alignment.setGapChar(String.valueOf(av.getGapCharacter()));
400 for (int i = 0; i < jal.getHeight(); i++)
402 syncToAlignmentSequence(jal.getSequenceAt(i), alignment);
404 alignRDHash.put(av.getSequenceSetId(),av.getUndoRedoHash());
408 boolean alismod = av.isUndoRedoHashModified((long[]) alignRDHash.get(av.getSequenceSetId()));
409 // todo: verify and update mutable alignment props.
410 // TODO: Use isLocked methods
411 if (alignment.getModifiable() == null || alignment.getModifiable().length()==0)
413 boolean modified = false;
414 for (int i = 0; i < jal.getHeight(); i++)
416 modified |= syncToAlignmentSequence(jal.getSequenceAt(i), alignment);
423 addProvenance(alignment.getProvenance(), "Edited"); // TODO: insert something sensible here again
427 addProvenance(alignment.getProvenance(), "Attributes Edited"); // TODO: insert something sensible here again
430 System.out.println("update alignment in document.");
435 .println("update edited alignment to new alignment in document.");
438 // ////////////////////////////////////////////
439 // SAVE Alignment Sequence Features
440 for (int i = 0, iSize = alignment.getAlignmentSequenceCount(); i < iSize; i++)
442 AlignmentSequence valseq;
443 SequenceI alseq = (SequenceI) getvObj2jv(valseq = alignment
444 .getAlignmentSequence(i));
445 if (alseq != null && alseq.getSequenceFeatures() != null)
448 * We do not put local Alignment Sequence Features into the vamsas
452 * jalview.datamodel.SequenceFeature[] features = alseq
453 * .getSequenceFeatures(); for (int f = 0; f < features.length; f++) {
454 * if (features[f] != null) { AlignmentSequenceAnnotation valseqf = (
455 * AlignmentSequenceAnnotation) getjv2vObj(features[i]); if (valseqf ==
458 * valseqf = (AlignmentSequenceAnnotation) getDSAnnotationFromJalview(
459 * new AlignmentSequenceAnnotation(), features[i]);
460 * valseqf.setGraph(false);
461 * valseqf.addProperty(newProperty("jalview:feature","boolean","true"));
462 * if (valseqf.getProvenance() == null) { valseqf.setProvenance(new
463 * Provenance()); } addProvenance(valseqf.getProvenance(), "created"); //
464 * JBPNote - // need to // update bindjvvobj(features[i], valseqf);
465 * valseq.addAlignmentSequenceAnnotation(valseqf); } }
471 // ////////////////////////////////////////////
473 if (jal.getAlignmentAnnotation() != null)
475 jalview.datamodel.AlignmentAnnotation[] aa = jal
476 .getAlignmentAnnotation();
477 java.util.HashMap AlSeqMaps = new HashMap(); // stores int maps from
478 // alignment columns to
479 // sequence positions.
480 for (int i = 0; i < aa.length; i++)
482 if (aa[i] == null || isJalviewOnly(aa[i]))
486 if (aa[i].sequenceRef != null)
488 // Deal with sequence associated annotation
489 Vobject sref = getjv2vObj(aa[i].sequenceRef);
490 if (sref instanceof uk.ac.vamsas.objects.core.AlignmentSequence)
492 saveAlignmentSequenceAnnotation(AlSeqMaps,
493 (AlignmentSequence) sref, aa[i]);
497 // first find the alignment sequence to associate this with.
498 SequenceI jvalsq = null;
499 Enumeration jval = av.getAlignment().getSequences()
501 while (jval.hasMoreElements())
503 jvalsq = (SequenceI) jval.nextElement();
504 // saveDatasetSequenceAnnotation(AlSeqMaps,(uk.ac.vamsas.objects.core.Sequence)
506 if (jvalsq.getDatasetSequence() == aa[i].sequenceRef)
508 Vobject alsref = getjv2vObj(jvalsq);
509 saveAlignmentSequenceAnnotation(AlSeqMaps,
510 (AlignmentSequence) alsref, aa[i]);
519 // add Alignment Annotation
520 uk.ac.vamsas.objects.core.AlignmentAnnotation an = (uk.ac.vamsas.objects.core.AlignmentAnnotation) getjv2vObj(aa[i]);
523 an = new uk.ac.vamsas.objects.core.AlignmentAnnotation();
524 an.setType(JALVIEW_ANNOTATION_ROW);
525 an.setDescription(aa[i].description);
526 alignment.addAlignmentAnnotation(an);
527 Seg vSeg = new Seg(); // TODO: refactor to have a default
528 // rangeAnnotationType initer/updater that
529 // takes a set of int ranges.
531 vSeg.setInclusive(true);
532 vSeg.setEnd(jal.getWidth());
536 an.setGraph(true); // aa[i].graph);
538 an.setLabel(aa[i].label);
539 an.setProvenance(dummyProvenance());
540 if (aa[i].graph != AlignmentAnnotation.NO_GRAPH)
542 an.setGroup(Integer.toString(aa[i].graphGroup)); // // JBPNote
557 AnnotationElement ae;
559 for (int a = 0; a < aa[i].annotations.length; a++)
561 if ((aa[i] == null) || (aa[i].annotations[a] == null))
566 ae = new AnnotationElement();
567 ae.setDescription(aa[i].annotations[a].description);
568 ae.addGlyph(new Glyph());
569 ae.getGlyph(0).setContent(
570 aa[i].annotations[a].displayCharacter); // assume
577 ae.addValue(aa[i].annotations[a].value);
578 ae.setPosition(a + 1);
579 if (aa[i].annotations[a].secondaryStructure != ' ')
581 Glyph ss = new Glyph();
583 .setDict(uk.ac.vamsas.objects.utils.GlyphDictionary.PROTEIN_SS_3STATE);
586 .valueOf(aa[i].annotations[a].secondaryStructure));
589 an.addAnnotationElement(ae);
593 // an.addProperty(newProperty("jalview:editable", null,
595 // an.setModifiable(""); // TODO: This is not the way the
596 // modifiable flag is supposed to be used.
598 setAnnotationType(an, aa[i]);
600 if (aa[i].graph != jalview.datamodel.AlignmentAnnotation.NO_GRAPH)
603 an.setGroup(Integer.toString(aa[i].graphGroup));
604 if (aa[i].threshold!=null && aa[i].threshold.displayed)
605 an.addProperty(newProperty(THRESHOLD, "float", ""+aa[i].threshold.value));
606 if (aa[i].threshold.label!=null)
607 an.addProperty(newProperty(THRESHOLD+"Name", "string", ""+aa[i].threshold.label));
614 if (an.getModifiable() == null) // TODO: USE VAMSAS LIBRARY OBJECT
617 // verify annotation - update (perhaps)
619 .info("update alignment sequence annotation. not yet implemented.");
623 // verify annotation - update (perhaps)
625 .info("updated alignment sequence annotation added.");
631 // /////////////////////////////////////////////////////
633 // //////////////////////////////////////////////
635 // /////////////////////////////////
636 // FIND ANY ASSOCIATED TREES
637 if (Desktop.desktop != null)
639 javax.swing.JInternalFrame[] frames = Desktop.instance
642 for (int t = 0; t < frames.length; t++)
644 if (frames[t] instanceof TreePanel)
646 TreePanel tp = (TreePanel) frames[t];
648 if (tp.getAlignment() == jal)
650 DatastoreItem vtree = new jalview.io.vamsas.Tree(this, tp,
656 // Store Jalview specific stuff in the Jalview appData
657 // not implemented in the SimpleDoc interface.
662 ex.printStackTrace();
667 * sync a jalview alignment seuqence into a vamsas alignment
668 * assumes all lock transformation/bindings have been sorted out before hand.
669 * creates/syncs the vamsas alignment sequence for jvalsq and adds it to the alignment if necessary.
671 private boolean syncToAlignmentSequence(SequenceI jvalsq,
674 boolean modal = false;
675 // todo: islocked method here
676 boolean up2doc=false;
677 AlignmentSequence alseq = (AlignmentSequence) getjv2vObj(jvalsq);
680 alseq = new AlignmentSequence();
683 // boolean locked = (alignment.getModifiable()==null || alignment.getModifiable().length()>0);
684 // TODO: VAMSAS: translate lowercase symbols to annotation ?
685 if (up2doc || !alseq.getSequence().equals(jvalsq.getSequenceAsString()))
687 alseq.setSequence(jvalsq.getSequenceAsString());
688 alseq.setStart(jvalsq.getStart());
689 alseq.setEnd(jvalsq.getEnd());
692 if (up2doc || !alseq.getName().equals(jvalsq.getName()))
695 alseq.setName(jvalsq.getName());
697 if (jvalsq.getDescription()!=null && (alseq.getDescription()==null || !jvalsq.getDescription().equals(alseq.getDescription())))
700 alseq.setDescription(jvalsq.getDescription());
702 if (getjv2vObj(jvalsq.getDatasetSequence()) == null)
705 .warn("Serious Implementation error - Unbound dataset sequence in alignment: "
706 + jvalsq.getDatasetSequence());
708 alseq.setRefid(getjv2vObj(jvalsq
709 .getDatasetSequence()));
713 alignment.addAlignmentSequence(alseq);
714 bindjvvobj(jvalsq, alseq);
716 return up2doc || modal;
719 * locally sync a jalview alignment seuqence from a vamsas alignment
720 * assumes all lock transformation/bindings have been sorted out before hand.
721 * creates/syncs the jvalsq from the alignment sequence
723 private boolean syncFromAlignmentSequence(AlignmentSequence valseq, char valGapchar, char gapChar, Vector dsseqs)
726 boolean modal = false;
727 // todo: islocked method here
728 boolean upFromdoc=false;
729 jalview.datamodel.SequenceI alseq = (SequenceI) getvObj2jv(valseq);
737 // boolean locked = (alignment.getModifiable()==null || alignment.getModifiable().length()>0);
738 // TODO: VAMSAS: translate lowercase symbols to annotation ?
739 if (upFromdoc || !valseq.getSequence().equals(alseq.getSequenceAsString()))
741 // this might go *horribly* wrong
742 alseq.setSequence(new String(valseq.getSequence()).replace(
743 valGapchar, gapChar));
744 alseq.setStart((int) valseq.getStart());
745 alseq.setEnd((int) valseq.getEnd());
748 if (!valseq.getName().equals(alseq.getName()))
751 alseq.setName(valseq.getName());
753 if (alseq.getDescription()==null
754 || (valseq.getDescription()==null
755 || alseq.getDescription().equals(valseq.getDescription())))
757 alseq.setDescription(valseq.getDescription());
760 if (modal && Cache.log.isDebugEnabled())
762 Cache.log.debug("Updating apparently edited sequence "
768 alseq = new jalview.datamodel.Sequence(valseq.getName(),
769 valseq.getSequence().replace(valGapchar, gapChar),
770 (int) valseq.getStart(), (int) valseq.getEnd());
772 Vobject datsetseq = (Vobject) valseq.getRefid();
773 if (datsetseq != null)
776 .setDatasetSequence((SequenceI) getvObj2jv(datsetseq)); // exceptions
788 .error("Invalid dataset sequence id (null) for alignment sequence "
789 + valseq.getVorbaId());
791 bindjvvobj(alseq, valseq);
792 alseq.setVamsasId(valseq.getVorbaId().getId());
795 Vobject datsetseq = (Vobject) valseq.getRefid();
796 if (datsetseq != null)
798 if (datsetseq != alseq.getDatasetSequence())
803 .setDatasetSequence((SequenceI) getvObj2jv(datsetseq)); // exceptions
805 return upFromdoc || modal;
808 private void initRangeAnnotationType(RangeAnnotation an,
809 AlignmentAnnotation alan, int[] gapMap)
811 Seg vSeg = new Seg();
813 vSeg.setInclusive(true);
814 vSeg.setEnd(gapMap.length);
817 // LATER: much of this is verbatim from the alignmentAnnotation
818 // method below. suggests refactoring to make rangeAnnotation the
820 an.setDescription(alan.description);
821 an.setLabel(alan.label);
822 an.setGroup(Integer.toString(alan.graphGroup));
831 AnnotationElement ae;
832 for (int a = 0; a < alan.annotations.length; a++)
834 if (alan.annotations[a] == null)
839 ae = new AnnotationElement();
840 ae.setDescription(alan.annotations[a].description);
841 ae.addGlyph(new Glyph());
842 ae.getGlyph(0).setContent(alan.annotations[a].displayCharacter); // assume
849 if (alan.graph != jalview.datamodel.AlignmentAnnotation.NO_GRAPH)
851 ae.addValue(alan.annotations[a].value);
853 ae.setPosition(gapMap[a] + 1); // position w.r.t. AlignmentSequence
855 if (alan.annotations[a].secondaryStructure != ' ')
857 // we only write an annotation where it really exists.
858 Glyph ss = new Glyph();
860 .setDict(uk.ac.vamsas.objects.utils.GlyphDictionary.PROTEIN_SS_3STATE);
862 .valueOf(alan.annotations[a].secondaryStructure));
865 an.addAnnotationElement(ae);
870 private void saveDatasetSequenceAnnotation(HashMap AlSeqMaps,
871 uk.ac.vamsas.objects.core.Sequence sref, AlignmentAnnotation alan)
875 // objects.core.AlignmentSequence alsref = (uk.ac.vamsas.
876 // objects.core.AlignmentSequence) sref;
877 uk.ac.vamsas.objects.core.DataSetAnnotations an = (uk.ac.vamsas.objects.core.DataSetAnnotations) getjv2vObj(alan);
878 int[] gapMap = getGapMap(AlSeqMaps, alan);
881 an = new uk.ac.vamsas.objects.core.DataSetAnnotations();
882 initRangeAnnotationType(an, alan, gapMap);
884 an.setProvenance(dummyProvenance()); // get provenance as user
885 // created, or jnet, or
887 setAnnotationType(an, alan);
888 an.setGroup(Integer.toString(alan.graphGroup)); // // JBPNote -
896 if (alan.getThreshold()!=null && alan.getThreshold().displayed)
898 an.addProperty(newProperty(THRESHOLD, "float", ""+alan.getThreshold().value));
899 if (alan.getThreshold().label!=null)
900 an.addProperty(newProperty(THRESHOLD+"Name", "string", ""+alan.getThreshold().label));
902 ((DataSet) sref.getV_parent()).addDataSetAnnotations(an);
903 bindjvvobj(alan, an);
907 // update reference sequence Annotation
908 if (an.getModifiable() == null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK
911 // verify existing alignment sequence annotation is up to date
912 System.out.println("update dataset sequence annotation.");
916 // verify existing alignment sequence annotation is up to date
918 .println("make new alignment dataset sequence annotation if modification has happened.");
924 private int[] getGapMap(HashMap AlSeqMaps, AlignmentAnnotation alan)
927 if (AlSeqMaps.containsKey(alan.sequenceRef))
929 gapMap = (int[]) AlSeqMaps.get(alan.sequenceRef);
933 gapMap = new int[alan.sequenceRef.getLength()];
934 // map from alignment position to sequence position.
935 int[] sgapMap = alan.sequenceRef.gapMap();
936 for (int a = 0; a < sgapMap.length; a++)
938 gapMap[sgapMap[a]] = a;
944 private void saveAlignmentSequenceAnnotation(HashMap AlSeqMaps,
945 AlignmentSequence alsref, AlignmentAnnotation alan)
949 // objects.core.AlignmentSequence alsref = (uk.ac.vamsas.
950 // objects.core.AlignmentSequence) sref;
951 uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation an = (uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation) getjv2vObj(alan);
952 int[] gapMap = getGapMap(AlSeqMaps, alan);
955 an = new uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation();
956 initRangeAnnotationType(an, alan, gapMap);
958 * I mean here that we don't actually have a semantic 'type' for the
959 * annotation (this might be - score, intrinsic property, measurement,
960 * something extracted from another program, etc)
962 an.setType(JALVIEW_ANNOTATION_ROW); // TODO: better fix
963 // this rough guess ;)
964 alsref.addAlignmentSequenceAnnotation(an);
965 bindjvvobj(alan, an);
966 // These properties are directly supported by the
967 // AlignmentSequenceAnnotation type.
968 setAnnotationType(an, alan);
969 an.setProvenance(dummyProvenance()); // get provenance as user
970 // created, or jnet, or
975 // update reference sequence Annotation
976 if (an.getModifiable() == null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK
979 // verify existing alignment sequence annotation is up to date
980 System.out.println("update alignment sequence annotation.");
984 // verify existing alignment sequence annotation is up to date
986 .println("make new alignment sequence annotation if modification has happened.");
992 * set vamsas annotation object type from jalview annotation
996 private void setAnnotationType(RangeAnnotation an, AlignmentAnnotation alan)
998 if (an instanceof AlignmentSequenceAnnotation)
1000 if (alan.graph != AlignmentAnnotation.NO_GRAPH)
1002 ((AlignmentSequenceAnnotation)an).setGraph(true);
1005 ((AlignmentSequenceAnnotation)an).setGraph(false);
1008 if (an instanceof uk.ac.vamsas.objects.core.AlignmentAnnotation)
1010 if (alan.graph != AlignmentAnnotation.NO_GRAPH)
1012 ((uk.ac.vamsas.objects.core.AlignmentAnnotation)an).setGraph(true);
1015 ((uk.ac.vamsas.objects.core.AlignmentAnnotation)an).setGraph(false);
1020 case AlignmentAnnotation.BAR_GRAPH:
1021 an.addProperty(newProperty(DISCRETE_ANNOTATION, "boolean","true"));
1023 case AlignmentAnnotation.LINE_GRAPH:
1024 an.addProperty(newProperty(CONTINUOUS_ANNOTATION, "boolean","true"));
1027 // don't add any kind of discrete or continous property info.
1031 private Property newProperty(String name, String type, String content)
1033 Property vProperty = new Property();
1034 vProperty.setName(name);
1037 vProperty.setType(type);
1041 vProperty.setType("String");
1043 vProperty.setContent(content);
1048 * correctly create a RangeAnnotation from a jalview sequence feature
1051 * (typically DataSetAnnotations or AlignmentSequenceAnnotation)
1053 * (the feature to be mapped from)
1056 private RangeAnnotation getDSAnnotationFromJalview(RangeAnnotation dsa,
1057 SequenceFeature feature)
1059 dsa.setType(feature.getType());
1060 Seg vSeg = new Seg();
1061 vSeg.setStart(feature.getBegin());
1062 vSeg.setEnd(feature.getEnd());
1063 vSeg.setInclusive(true);
1065 dsa.setDescription(feature.getDescription());
1066 dsa.setStatus(feature.getStatus());
1067 if (feature.links != null && feature.links.size() > 0)
1069 for (int i = 0, iSize = feature.links.size(); i < iSize; i++)
1071 String link = (String) feature.links.elementAt(i);
1072 int sep = link.indexOf('|');
1075 Link vLink = new Link();
1078 vLink.setContent(link.substring(0, sep - 1));
1082 vLink.setContent("");
1084 vLink.setHref(link.substring(sep + 1)); // TODO: validate href.
1089 dsa.setGroup(feature.getFeatureGroup());
1094 * get start<end range of segment, adjusting for inclusivity flag and
1098 * @param ensureDirection
1099 * when true - always ensure start is less than end.
1100 * @return int[] { start, end, direction} where direction==1 for range running
1101 * from end to start.
1103 private int[] getSegRange(Seg visSeg, boolean ensureDirection)
1105 boolean incl = visSeg.getInclusive();
1106 // adjust for inclusive flag.
1107 int pol = (visSeg.getStart() <= visSeg.getEnd()) ? 1 : -1; // polarity of
1109 int start = visSeg.getStart() + (incl ? 0 : pol);
1110 int end = visSeg.getEnd() + (incl ? 0 : -pol);
1111 if (ensureDirection && pol == -1)
1113 // jalview doesn't deal with inverted ranges, yet.
1119 { start, end, pol < 0 ? 1 : 0 };
1125 * @return true if annotation is not to be stored in document
1127 private boolean isJalviewOnly(AlignmentAnnotation annotation)
1129 return annotation.label.equals("Quality")
1130 || annotation.label.equals("Conservation")
1131 || annotation.label.equals("Consensus");
1135 * This will return the first AlignFrame viewing AlignViewport av. It will
1136 * break if there are more than one AlignFrames viewing a particular av. This
1137 * also shouldn't be in the io package.
1140 * @return alignFrame for av
1142 public AlignFrame getAlignFrameFor(AlignViewport av)
1144 if (Desktop.desktop != null)
1146 javax.swing.JInternalFrame[] frames = Desktop.instance.getAllFrames();
1148 for (int t = 0; t < frames.length; t++)
1150 if (frames[t] instanceof AlignFrame)
1152 if (((AlignFrame) frames[t]).getViewport() == av)
1154 return (AlignFrame) frames[t];
1162 public void updateToJalview()
1164 VAMSAS _roots[] = cdoc.getVamsasRoots();
1166 for (int _root = 0; _root < _roots.length; _root++)
1168 VAMSAS root = _roots[_root];
1169 boolean newds = false;
1170 for (int _ds = 0, _nds = root.getDataSetCount(); _ds < _nds; _ds++)
1172 // ///////////////////////////////////
1174 DataSet dataset = root.getDataSet(_ds);
1175 int i, iSize = dataset.getSequenceCount();
1177 jalview.datamodel.Alignment jdataset = (jalview.datamodel.Alignment) getvObj2jv(dataset);
1179 if (jdataset == null)
1181 Cache.log.debug("Initialising new jalview dataset fields");
1183 dsseqs = new Vector();
1187 Cache.log.debug("Update jalview dataset from vamsas.");
1188 jremain = jdataset.getHeight();
1189 dsseqs = jdataset.getSequences();
1192 // TODO: test sequence merging - we preserve existing non vamsas
1193 // sequences but add in any new vamsas ones, and don't yet update any
1194 // sequence attributes
1195 for (i = 0; i < iSize; i++)
1197 Sequence vdseq = dataset.getSequence(i);
1198 jalview.datamodel.SequenceI dsseq = (SequenceI) getvObj2jv(vdseq);
1201 if (!dsseq.getSequenceAsString().equals(vdseq.getSequence()))
1204 "Broken! - mismatch of dataset sequence: and jalview internal dataset sequence.");
1210 dsseq = new jalview.datamodel.Sequence(dataset.getSequence(i)
1211 .getName(), dataset.getSequence(i).getSequence(),
1212 (int) dataset.getSequence(i).getStart(), (int) dataset
1213 .getSequence(i).getEnd());
1214 dsseq.setDescription(dataset.getSequence(i).getDescription());
1215 bindjvvobj(dsseq, dataset.getSequence(i));
1216 dsseq.setVamsasId(dataset.getSequence(i).getVorbaId().getId());
1219 if (vdseq.getDbRefCount() > 0)
1221 DbRef[] dbref = vdseq.getDbRef();
1222 for (int db = 0; db < dbref.length; db++)
1224 new jalview.io.vamsas.Dbref(this, dbref[db], vdseq, dsseq);
1227 dsseq.updatePDBIds();
1233 SequenceI[] seqs = new SequenceI[dsseqs.size()];
1234 for (i = 0, iSize = dsseqs.size(); i < iSize; i++)
1236 seqs[i] = (SequenceI) dsseqs.elementAt(i);
1237 dsseqs.setElementAt(null, i);
1239 jdataset = new jalview.datamodel.Alignment(seqs);
1240 Cache.log.debug("New vamsas dataset imported into jalview.");
1241 bindjvvobj(jdataset, dataset);
1244 // add any new dataset sequence feature annotations
1245 if (dataset.getDataSetAnnotations() != null)
1247 for (int dsa = 0; dsa < dataset.getDataSetAnnotationsCount(); dsa++)
1249 DataSetAnnotations dseta = dataset.getDataSetAnnotations(dsa);
1250 // TODO: deal with group annotation on datset sequences.
1251 if (dseta.getSeqRefCount() == 1)
1253 SequenceI dsSeq = (SequenceI) getvObj2jv((Vobject) dseta
1254 .getSeqRef(0)); // TODO: deal with group dataset
1258 jalview.bin.Cache.log
1259 .warn("Couldn't resolve jalview sequenceI for dataset object reference "
1260 + ((Vobject) dataset.getDataSetAnnotations(
1261 dsa).getSeqRef(0)).getVorbaId()
1266 if (dseta.getAnnotationElementCount() == 0)
1268 jalview.datamodel.SequenceFeature sf = (jalview.datamodel.SequenceFeature) getvObj2jv(dseta);
1272 .addSequenceFeature(sf = getJalviewSeqFeature(dseta));
1273 bindjvvobj(sf, dseta);
1278 // TODO: deal with alignmentAnnotation style annotation
1279 // appearing on dataset sequences.
1280 // JBPNote: we could just add them to all alignments but
1281 // that may complicate cross references in the jalview
1284 .warn("Ignoring dataset annotation with annotationElements. Not yet supported in jalview.");
1290 if (dataset.getAlignmentCount() > 0)
1292 // LOAD ALIGNMENTS from DATASET
1294 for (int al = 0, nal = dataset.getAlignmentCount(); al < nal; al++)
1296 uk.ac.vamsas.objects.core.Alignment alignment = dataset
1298 AlignViewport av=findViewport(alignment);
1300 jalview.datamodel.AlignmentI jal = null;
1303 jal = av.getAlignment();
1305 iSize = alignment.getAlignmentSequenceCount();
1306 boolean newal = (jal == null) ? true : false;
1307 boolean refreshal = false;
1308 Vector newasAnnots = new Vector();
1309 char gapChar = ' '; // default for new alignments read in from the
1313 dsseqs = jal.getSequences(); // for merge/update
1314 gapChar = jal.getGapCharacter();
1318 dsseqs = new Vector();
1320 char valGapchar = alignment.getGapChar().charAt(0);
1321 for (i = 0; i < iSize; i++)
1323 AlignmentSequence valseq = alignment.getAlignmentSequence(i);
1324 jalview.datamodel.Sequence alseq = (jalview.datamodel.Sequence) getvObj2jv(valseq);
1325 if (syncFromAlignmentSequence(valseq, valGapchar, gapChar, dsseqs) && alseq!=null)
1328 // updated to sequence from the document
1332 if (valseq.getAlignmentSequenceAnnotationCount() > 0)
1334 AlignmentSequenceAnnotation[] vasannot = valseq
1335 .getAlignmentSequenceAnnotation();
1336 for (int a = 0; a < vasannot.length; a++)
1338 jalview.datamodel.AlignmentAnnotation asa = (jalview.datamodel.AlignmentAnnotation) getvObj2jv(vasannot[a]); // TODO:
1346 int se[] = getBounds(vasannot[a]);
1347 asa = getjAlignmentAnnotation(jal, vasannot[a]);
1348 asa.setSequenceRef(alseq);
1349 asa.createSequenceMapping(alseq, se[0], false); // TODO:
1360 alseq.addAlignmentAnnotation(asa);
1361 bindjvvobj(asa, vasannot[a]);
1362 newasAnnots.add(asa);
1366 // update existing annotation - can do this in place
1367 if (vasannot[a].getModifiable() == null) // TODO: USE
1373 .info("UNIMPLEMENTED: not recovering user modifiable sequence alignment annotation");
1374 // TODO: should at least replace with new one - otherwise
1375 // things will break
1376 // basically do this:
1377 // int se[] = getBounds(vasannot[a]);
1378 // asa.update(getjAlignmentAnnotation(jal, vasannot[a]));
1379 // // update from another annotation object in place.
1380 // asa.createSequenceMapping(alseq, se[0], false);
1389 SequenceI[] seqs = new SequenceI[dsseqs.size()];
1390 for (i = 0, iSize = dsseqs.size(); i < iSize; i++)
1392 seqs[i] = (SequenceI) dsseqs.elementAt(i);
1393 dsseqs.setElementAt(null, i);
1395 jal = new jalview.datamodel.Alignment(seqs);
1396 Cache.log.debug("New vamsas alignment imported into jalview "
1397 + alignment.getVorbaId().getId());
1398 jal.setDataset(jdataset);
1400 if (newasAnnots != null && newasAnnots.size() > 0)
1402 // Add the new sequence annotations in to the alignment.
1403 for (int an = 0, anSize = newasAnnots.size(); an < anSize; an++)
1405 jal.addAnnotation((AlignmentAnnotation) newasAnnots
1407 // TODO: check if anything has to be done - like calling
1408 // adjustForAlignment or something.
1409 newasAnnots.setElementAt(null, an);
1413 // //////////////////////////////////////////
1414 // //LOAD ANNOTATIONS FOR THE ALIGNMENT
1415 // ////////////////////////////////////
1416 if (alignment.getAlignmentAnnotationCount() > 0)
1418 uk.ac.vamsas.objects.core.AlignmentAnnotation[] an = alignment
1419 .getAlignmentAnnotation();
1421 for (int j = 0; j < an.length; j++)
1423 jalview.datamodel.AlignmentAnnotation jan = (jalview.datamodel.AlignmentAnnotation) getvObj2jv(an[j]);
1426 // update or stay the same.
1427 // TODO: should at least replace with a new one - otherwise
1428 // things will break
1429 // basically do this:
1430 // jan.update(getjAlignmentAnnotation(jal, an[a])); // update
1431 // from another annotation object in place.
1434 .debug("update from vamsas alignment annotation to existing jalview alignment annotation.");
1435 if (an[j].getModifiable() == null) // TODO: USE VAMSAS
1436 // LIBRARY OBJECT LOCK
1439 // TODO: user defined annotation is totally mutable... - so
1440 // load it up or throw away if locally edited.
1442 .info("NOT IMPLEMENTED - Recovering user-modifiable annotation - yet...");
1444 // TODO: compare annotation element rows
1445 // TODO: compare props.
1449 jan = getjAlignmentAnnotation(jal, an[j]);
1450 jal.addAnnotation(jan);
1451 bindjvvobj(jan, an[j]);
1455 AlignFrame alignFrame;
1458 Cache.log.debug("New alignframe for alignment "
1459 + alignment.getVorbaId());
1460 // ///////////////////////////////
1461 // construct alignment view
1462 alignFrame = new AlignFrame(jal, AlignFrame.DEFAULT_WIDTH,
1463 AlignFrame.DEFAULT_HEIGHT);
1464 av = alignFrame.getViewport();
1465 String title = alignment.getProvenance().getEntry(
1466 alignment.getProvenance().getEntryCount() - 1)
1468 if (alignment.getPropertyCount() > 0)
1470 for (int p = 0, pe = alignment.getPropertyCount(); p < pe; p++)
1472 if (alignment.getProperty(p).getName().equals(
1475 title = alignment.getProperty(p).getContent();
1479 // TODO: automatically create meaningful title for a vamsas
1480 // alignment using its provenance.
1481 if (Cache.log.isDebugEnabled())
1484 + alignment.getVorbaId() + ")";
1487 jalview.gui.Desktop.addInternalFrame(alignFrame, title
1489 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
1490 bindjvvobj(av.getSequenceSetId(), alignment);
1494 // find the alignFrame for jal.
1495 // TODO: fix this so we retrieve the alignFrame handing av
1497 alignFrame = getAlignFrameFor(av);
1500 av.alignmentChanged(alignFrame.alignPanel);
1504 // /////////////////////////////////////
1505 if (alignment.getTreeCount() > 0)
1508 for (int t = 0; t < alignment.getTreeCount(); t++)
1510 jalview.io.vamsas.Tree vstree = new jalview.io.vamsas.Tree(
1511 this, alignFrame, alignment.getTree(t));
1512 TreePanel tp = null;
1513 if (vstree.isValidTree())
1516 .ShowNewickTree(vstree.getNewickTree(), vstree
1517 .getTitle(), vstree.getInputData(), 600,
1518 500, t * 20 + 50, t * 20 + 50);
1523 bindjvvobj(tp, alignment.getTree(t));
1526 vstree.UpdateSequenceTreeMap(tp);
1527 } catch (RuntimeException e)
1529 Cache.log.warn("update of labels failed.",e);
1534 Cache.log.warn("Cannot create tree for tree "+t+" in document ("+alignment.getTree(t).getVorbaId());
1542 // we do sequenceMappings last because they span all datasets in a vamsas
1544 for (int _ds = 0, _nds = root.getDataSetCount(); _ds < _nds; _ds++)
1546 DataSet dataset = root.getDataSet(_ds);
1547 if (dataset.getSequenceMappingCount() > 0)
1549 for (int sm = 0, smCount = dataset.getSequenceMappingCount(); sm < smCount; sm++)
1551 Rangetype seqmap = new jalview.io.vamsas.Sequencemapping(this,
1552 dataset.getSequenceMapping(sm));
1559 public AlignViewport findViewport(Alignment alignment)
1561 AlignViewport av=null;
1562 AlignViewport[] avs = findViewportForSequenceSetId((String)getvObj2jv(alignment));
1570 private AlignViewport[] findViewportForSequenceSetId(String sequenceSetId)
1572 Vector viewp = new Vector();
1573 if (Desktop.desktop != null)
1575 javax.swing.JInternalFrame[] frames = Desktop.instance.getAllFrames();
1577 for (int t = 0; t < frames.length; t++)
1579 if (frames[t] instanceof AlignFrame)
1581 if (((AlignFrame) frames[t]).getViewport().getSequenceSetId().equals(sequenceSetId))
1583 viewp.addElement(((AlignFrame) frames[t]).getViewport());
1589 AlignViewport[] vp = new AlignViewport[viewp.size()];
1597 // bitfields - should be a template in j1.5
1598 private static int HASSECSTR = 0;
1600 private static int HASVALS = 1;
1602 private static int HASHPHOB = 2;
1604 private static int HASDC = 3;
1606 private static int HASDESCSTR = 4;
1608 private static int HASTWOSTATE = 5; // not used yet.
1611 * parses the AnnotationElements - if they exist - into
1612 * jalview.datamodel.Annotation[] rows Two annotation rows are made if there
1613 * are distinct annotation for both at 'pos' and 'after pos' at any particular
1617 * @return { boolean[static int constants ], int[ae.length] - map to annotated
1618 * object frame, jalview.datamodel.Annotation[],
1619 * jalview.datamodel.Annotation[] (after)}
1621 private Object[] parseRangeAnnotation(
1622 uk.ac.vamsas.objects.core.RangeAnnotation annotation)
1624 // set these attributes by looking in the annotation to decide what kind of
1625 // alignment annotation rows will be made
1626 // TODO: potentially we might make several annotation rows from one vamsas
1627 // alignment annotation. the jv2Vobj binding mechanism
1628 // may not quite cope with this (without binding an array of annotations to
1629 // a vamsas alignment annotation)
1630 // summary flags saying what we found over the set of annotation rows.
1631 boolean[] AeContent = new boolean[]
1632 { false, false, false, false, false };
1633 int[] rangeMap = getMapping(annotation);
1634 jalview.datamodel.Annotation[][] anot = new jalview.datamodel.Annotation[][]
1635 { new jalview.datamodel.Annotation[rangeMap.length],
1636 new jalview.datamodel.Annotation[rangeMap.length] };
1637 boolean mergeable = true; // false if 'after positions cant be placed on
1638 // same annotation row as positions.
1640 if (annotation.getAnnotationElementCount() > 0)
1642 AnnotationElement ae[] = annotation.getAnnotationElement();
1643 for (int aa = 0; aa < ae.length; aa++)
1645 int pos = (int) ae[aa].getPosition() - 1; // pos counts from 1 to
1646 // (|seg.start-seg.end|+1)
1647 if (pos >= 0 && pos < rangeMap.length)
1649 int row = ae[aa].getAfter() ? 1 : 0;
1650 if (anot[row][pos] != null)
1652 // only time this should happen is if the After flag is set.
1653 Cache.log.debug("Ignoring duplicate annotation site at " + pos);
1656 if (anot[1 - row][pos] != null)
1661 if (ae[aa].getDescription() != null)
1663 desc = ae[aa].getDescription();
1664 if (desc.length() > 0)
1666 // have imported valid description string
1667 AeContent[HASDESCSTR] = true;
1670 String dc = null; // ae[aa].getDisplayCharacter()==null ? "dc" :
1671 // ae[aa].getDisplayCharacter();
1672 String ss = null; // ae[aa].getSecondaryStructure()==null ? "ss" :
1673 // ae[aa].getSecondaryStructure();
1674 java.awt.Color colour = null;
1675 if (ae[aa].getGlyphCount() > 0)
1677 Glyph[] glyphs = ae[aa].getGlyph();
1678 for (int g = 0; g < glyphs.length; g++)
1683 uk.ac.vamsas.objects.utils.GlyphDictionary.PROTEIN_SS_3STATE))
1685 ss = glyphs[g].getContent();
1686 AeContent[HASSECSTR] = true;
1691 uk.ac.vamsas.objects.utils.GlyphDictionary.PROTEIN_HD_HYDRO))
1693 Cache.log.debug("ignoring hydrophobicity glyph marker.");
1694 AeContent[HASHPHOB] = true;
1695 char c = (dc = glyphs[g].getContent()).charAt(0);
1696 // dc may get overwritten - but we still set the colour.
1697 colour = new java.awt.Color(c == '+' ? 255 : 0,
1698 c == '.' ? 255 : 0, c == '-' ? 255 : 0);
1701 else if (glyphs[g].getDict().equals(
1702 uk.ac.vamsas.objects.utils.GlyphDictionary.DEFAULT))
1704 dc = glyphs[g].getContent();
1705 AeContent[HASDC] = true;
1709 Cache.log.debug("IMPLEMENTATION TODO: Ignoring unknown glyph type "
1710 + glyphs[g].getDict());
1715 if (ae[aa].getValueCount() > 0)
1717 AeContent[HASVALS] = true;
1718 if (ae[aa].getValueCount() > 1)
1720 Cache.log.warn("ignoring additional "
1721 + (ae[aa].getValueCount() - 1)
1722 + "values in annotation element.");
1724 val = ae[aa].getValue(0);
1728 anot[row][pos] = new jalview.datamodel.Annotation(
1729 (dc != null) ? dc : "", desc, (ss != null) ? ss
1730 .charAt(0) : ' ', val);
1734 anot[row][pos] = new jalview.datamodel.Annotation(
1735 (dc != null) ? dc : "", desc, (ss != null) ? ss
1736 .charAt(0) : ' ', val, colour);
1741 Cache.log.warn("Ignoring out of bound annotation element " + aa
1742 + " in " + annotation.getVorbaId().getId());
1745 // decide on how many annotation rows are needed.
1748 for (int i = 0; i < anot[0].length; i++)
1750 if (anot[1][i] != null)
1752 anot[0][i] = anot[1][i];
1753 anot[0][i].description = anot[0][i].description + " (after)";
1754 AeContent[HASDESCSTR] = true; // we have valid description string
1763 for (int i = 0; i < anot[0].length; i++)
1765 anot[1][i].description = anot[1][i].description + " (after)";
1769 { AeContent, rangeMap, anot[0], anot[1] };
1773 // no annotations to parse. Just return an empty annotationElement[]
1776 { AeContent, rangeMap, anot[0], anot[1] };
1783 * the jalview alignment to which the annotation will be attached
1784 * (ideally - freshly updated from corresponding vamsas alignment)
1786 * @return unbound jalview alignment annotation object.
1788 private jalview.datamodel.AlignmentAnnotation getjAlignmentAnnotation(
1789 jalview.datamodel.AlignmentI jal,
1790 uk.ac.vamsas.objects.core.RangeAnnotation annotation)
1792 if (annotation == null)
1797 // hasSequenceRef=annotation.getClass().equals(uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation.class);
1798 // boolean hasProvenance=hasSequenceRef ||
1799 // (annotation.getClass().equals(uk.ac.vamsas.objects.core.AlignmentAnnotation.class));
1801 * int se[] = getBounds(annotation); if (se==null) se=new int[]
1802 * {0,jal.getWidth()-1};
1804 Object[] parsedRangeAnnotation = parseRangeAnnotation(annotation);
1805 String a_label = annotation.getLabel();
1806 String a_descr = annotation.getDescription();
1809 boolean interp=true; // cleared if annotation is DISCRETE
1810 // set type and other attributes from properties
1811 if (annotation.getPropertyCount() > 0)
1813 // look for special jalview properties
1814 uk.ac.vamsas.objects.core.Property[] props = annotation
1816 for (int p = 0; p < props.length; p++)
1818 if (props[p].getName().equalsIgnoreCase(DISCRETE_ANNOTATION))
1820 type = AlignmentAnnotation.BAR_GRAPH;
1823 (props[p].getName().equalsIgnoreCase(CONTINUOUS_ANNOTATION)) {
1824 type = AlignmentAnnotation.LINE_GRAPH;
1826 (props[p].getName().equalsIgnoreCase(THRESHOLD))
1830 val = new Float(props[p].getContent());
1831 }catch (Exception e)
1833 Cache.log.warn("Failed to parse threshold property");
1838 gl = new GraphLine(val.floatValue(), "", java.awt.Color.black);
1841 gl.value = val.floatValue();
1844 else if (props[p].getName().equalsIgnoreCase(THRESHOLD+"Name"))
1847 gl = new GraphLine(0, "", java.awt.Color.black);
1848 gl.label = props[p].getContent();
1852 jalview.datamodel.AlignmentAnnotation jan = null;
1853 if (a_label == null || a_label.length() == 0)
1855 a_label = annotation.getType();
1856 if (a_label.length() == 0)
1858 a_label = "Unamed annotation";
1861 if (a_descr == null || a_descr.length() == 0)
1863 a_descr = "Annotation of type '" + annotation.getType() + "'";
1865 if (parsedRangeAnnotation == null)
1868 .debug("Inserting empty annotation row elements for a whole-alignment annotation.");
1872 if (parsedRangeAnnotation[3] != null)
1874 Cache.log.warn("Ignoring 'After' annotation row in "
1875 + annotation.getVorbaId());
1877 jalview.datamodel.Annotation[] arow = (jalview.datamodel.Annotation[]) parsedRangeAnnotation[2];
1878 boolean[] has = (boolean[]) parsedRangeAnnotation[0];
1879 // VAMSAS: getGraph is only on derived annotation for alignments - in this
1880 // way its 'odd' - there is already an existing TODO about removing this
1881 // flag as being redundant
1884 * ((annotation.getClass().equals(uk.ac.vamsas.objects.core.AlignmentAnnotation.class) &&
1885 * ((uk.ac.vamsas.objects.core.AlignmentAnnotation)annotation).getGraph()) ||
1886 * (hasSequenceRef=true &&
1887 * ((uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation)annotation).getGraph())) {
1893 type = jalview.datamodel.AlignmentAnnotation.BAR_GRAPH; // default type of value annotation
1896 // no hints - so we ensure HPHOB display is like this.
1897 type = jalview.datamodel.AlignmentAnnotation.BAR_GRAPH;
1900 // make bounds and automatic description strings for jalview user's
1901 // benefit (these shouldn't be written back to vamsas document)
1902 boolean first = true;
1903 float min = 0, max = 1;
1905 for (int i = 0; i < arow.length; i++)
1907 if (arow[i] != null)
1909 if (i - lastval > 1 && interp)
1911 // do some interpolation *between* points
1912 if (arow[lastval] != null)
1914 float interval = arow[i].value - arow[lastval].value;
1915 interval /= i - lastval;
1916 float base = arow[lastval].value;
1917 for (int ip = lastval + 1, np = 0; ip < i; np++, ip++)
1919 arow[ip] = new jalview.datamodel.Annotation("", "", ' ',
1920 interval * np + base);
1921 // NB - Interpolated points don't get a tooltip and
1927 // check range - shouldn't we have a min and max property in the
1928 // annotation object ?
1931 min = max = arow[i].value;
1936 if (arow[i].value < min)
1938 min = arow[i].value;
1940 else if (arow[i].value > max)
1942 max = arow[i].value;
1945 // make tooltip and display char value
1946 if (!has[HASDESCSTR])
1948 arow[i].description = arow[i].value + "";
1954 if (arow[i].description!=null && arow[i].description.length()<3)
1956 // copy over the description as the display char.
1957 arow[i].displayCharacter = new String(arow[i].description);
1961 // mark the position as a point used for the interpolation.
1962 arow[i].displayCharacter = arow[i].value + "";
1967 jan = new jalview.datamodel.AlignmentAnnotation(a_label, a_descr,
1968 arow, min, max, type);
1972 if (annotation.getAnnotationElementCount()==0)
1974 // empty annotation array
1975 // TODO: alignment 'features' compare rangeType spec to alignment width - if it is not complete, then mark regions on the annotation row.
1977 jan = new jalview.datamodel.AlignmentAnnotation(a_label, a_descr,
1979 jan.setThreshold(null);
1981 if (annotation.getLinkCount() > 0)
1983 Cache.log.warn("Ignoring " + annotation.getLinkCount()
1984 + "links added to AlignmentAnnotation.");
1986 if (annotation.getModifiable() == null || annotation.getModifiable().length()==0) // TODO: USE VAMSAS LIBRARY OBJECT
1989 jan.editable = true;
1993 if (annotation.getGroup() != null
1994 && annotation.getGroup().length() > 0)
1996 jan.graphGroup = Integer.parseInt(annotation.getGroup()); // TODO: group similarly named annotation together ?
1998 } catch (Exception e)
2001 .info("UNIMPLEMENTED : Couldn't parse non-integer group value for setting graphGroup correctly.");
2010 private SequenceFeature getJalviewSeqFeature(RangeAnnotation dseta)
2012 int[] se = getBounds(dseta);
2013 SequenceFeature sf = new jalview.datamodel.SequenceFeature(dseta
2014 .getType(), dseta.getDescription(), dseta.getStatus(), se[0],
2015 se[1], dseta.getGroup());
2016 if (dseta.getLinkCount() > 0)
2018 Link[] links = dseta.getLink();
2019 for (int i = 0; i < links.length; i++)
2021 sf.addLink(links[i].getContent() + "|" + links[i].getHref());
2028 * get real bounds of a RangeType's specification. start and end are an
2029 * inclusive range within which all segments and positions lie. TODO: refactor
2033 * @return int[] { start, end}
2035 private int[] getBounds(RangeType dseta)
2040 if (dseta.getSegCount() > 0 && dseta.getPosCount() > 0)
2043 "Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!");
2045 if (dseta.getSegCount() > 0)
2047 se = getSegRange(dseta.getSeg(0), true);
2048 for (int s = 1, sSize = dseta.getSegCount(); s < sSize; s++)
2050 int nse[] = getSegRange(dseta.getSeg(s), true);
2061 if (dseta.getPosCount() > 0)
2063 // could do a polarity for pos range too. and pass back indication of
2065 int pos = dseta.getPos(0).getI();
2068 for (int p = 0, pSize = dseta.getPosCount(); p < pSize; p++)
2070 pos = dseta.getPos(p).getI();
2087 * map from a rangeType's internal frame to the referenced object's coordinate
2091 * @return int [] { ref(pos)...} for all pos in rangeType's frame.
2093 private int[] getMapping(RangeType dseta)
2095 Vector posList = new Vector();
2099 if (dseta.getSegCount() > 0 && dseta.getPosCount() > 0)
2102 "Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!");
2104 if (dseta.getSegCount() > 0)
2106 for (int s = 0, sSize = dseta.getSegCount(); s < sSize; s++)
2108 se = getSegRange(dseta.getSeg(s), false);
2109 int se_end = se[1 - se[2]] + (se[2] == 0 ? 1 : -1);
2110 for (int p = se[se[2]]; p != se_end; p += se[2] == 0 ? 1 : -1)
2112 posList.add(new Integer(p));
2116 else if (dseta.getPosCount() > 0)
2118 int pos = dseta.getPos(0).getI();
2120 for (int p = 0, pSize = dseta.getPosCount(); p < pSize; p++)
2122 pos = dseta.getPos(p).getI();
2123 posList.add(new Integer(pos));
2127 if (posList != null && posList.size() > 0)
2129 int[] range = new int[posList.size()];
2130 for (int i = 0; i < range.length; i++)
2132 range[i] = ((Integer) posList.elementAt(i)).intValue();
2143 * where the from range is the local mapped range, and the to range
2144 * is the 'mapped' range in the MapRangeType
2151 private jalview.util.MapList parsemapType(MapType maprange, int localu,
2154 jalview.util.MapList ml = null;
2155 int[] localRange = getMapping(maprange.getLocal());
2156 int[] mappedRange = getMapping(maprange.getMapped());
2157 long lu = maprange.getLocal().hasUnit() ? maprange.getLocal().getUnit()
2159 long mu = maprange.getMapped().hasUnit() ? maprange.getMapped()
2160 .getUnit() : mappedu;
2161 ml = new jalview.util.MapList(localRange, mappedRange, (int) lu,
2167 * initialise a range type object from a set of start/end inclusive intervals
2172 private void initRangeType(RangeType mrt, int[] range)
2174 for (int i = 0; i < range.length; i += 2)
2176 Seg vSeg = new Seg();
2177 vSeg.setStart(range[i]);
2178 vSeg.setEnd(range[i + 1]);
2184 * initialise a MapType object from a MapList object.
2190 private void initMapType(MapType maprange, jalview.util.MapList ml,
2193 maprange.setLocal(new Local());
2194 maprange.setMapped(new Mapped());
2195 initRangeType(maprange.getLocal(), ml.getFromRanges());
2196 initRangeType(maprange.getMapped(), ml.getToRanges());
2199 maprange.getLocal().setUnit(ml.getFromRatio());
2200 maprange.getLocal().setUnit(ml.getToRatio());
2205 * not needed now. Provenance getVamsasProvenance(jalview.datamodel.Provenance
2206 * jprov) { jalview.datamodel.ProvenanceEntry[] entries = null; // TODO: fix
2207 * App and Action here. Provenance prov = new Provenance();
2208 * org.exolab.castor.types.Date date = new org.exolab.castor.types.Date( new
2209 * java.util.Date()); Entry provEntry;
2211 * if (jprov != null) { entries = jprov.getEntries(); for (int i = 0; i <
2212 * entries.length; i++) { provEntry = new Entry(); try { date = new
2213 * org.exolab.castor.types.Date(entries[i].getDate()); } catch (Exception ex) {
2214 * ex.printStackTrace();
2216 * date = new org.exolab.castor.types.Date(entries[i].getDate()); }
2217 * provEntry.setDate(date); provEntry.setUser(entries[i].getUser());
2218 * provEntry.setAction(entries[i].getAction()); prov.addEntry(provEntry); } }
2219 * else { provEntry = new Entry(); provEntry.setDate(date);
2220 * provEntry.setUser(System.getProperty("user.name")); // TODO: ext string
2221 * provEntry.setApp("JVAPP"); // TODO: ext string provEntry.setAction(action);
2222 * prov.addEntry(provEntry); }
2226 jalview.datamodel.Provenance getJalviewProvenance(Provenance prov)
2228 // TODO: fix App and Action entries and check use of provenance in jalview.
2229 jalview.datamodel.Provenance jprov = new jalview.datamodel.Provenance();
2230 for (int i = 0; i < prov.getEntryCount(); i++)
2232 jprov.addEntry(prov.getEntry(i).getUser(), prov.getEntry(i)
2233 .getAction(), prov.getEntry(i).getDate(), prov.getEntry(i)
2242 * @return default initial provenance list for a Jalview created vamsas
2245 Provenance dummyProvenance()
2247 return dummyProvenance(null);
2250 Entry dummyPEntry(String action)
2252 Entry entry = new Entry();
2253 entry.setApp(this.provEntry.getApp());
2256 entry.setAction(action);
2260 entry.setAction("created.");
2262 entry.setDate(new java.util.Date());
2263 entry.setUser(this.provEntry.getUser());
2267 Provenance dummyProvenance(String action)
2269 Provenance prov = new Provenance();
2270 prov.addEntry(dummyPEntry(action));
2274 Entry addProvenance(Provenance p, String action)
2276 Entry dentry = dummyPEntry(action);
2281 public Entry getProvEntry()
2286 public IClientDocument getClientDocument()
2291 public IdentityHashMap getJvObjectBinding()
2296 public Hashtable getVamsasObjectBinding()
2301 public void storeSequenceMappings(AlignViewport viewport, String title)
2304 AlignViewport av = viewport;
2307 jalview.datamodel.AlignmentI jal = av.getAlignment();
2308 // /////////////////////////////////////////
2310 DataSet dataset = null;
2311 if (jal.getDataset() == null)
2313 Cache.log.warn("Creating new dataset for an alignment.");
2314 jal.setDataset(null);
2316 dataset = (DataSet) getjv2vObj(jal.getDataset());
2317 // Store any sequence mappings.
2318 if (av.getAlignment().getCodonFrames() != null
2319 && av.getAlignment().getCodonFrames().length > 0)
2321 jalview.datamodel.AlignedCodonFrame[] cframes = av.getAlignment()
2323 for (int cf = 0; cf < cframes.length; cf++)
2325 if (cframes[cf].getdnaSeqs().length > 0)
2327 jalview.datamodel.SequenceI[] dmps = cframes[cf].getdnaSeqs();
2328 jalview.datamodel.Mapping[] mps = cframes[cf].getProtMappings();
2329 for (int smp = 0; smp < mps.length; smp++)
2331 uk.ac.vamsas.objects.core.SequenceType mfrom = (SequenceType) getjv2vObj(dmps[smp]);
2334 new jalview.io.vamsas.Sequencemapping(this, mps[smp],
2340 .warn("NO Vamsas Binding for local sequence! NOT CREATING MAPPING FOR "
2341 + dmps[smp].getDisplayId(true)
2343 + mps[smp].getTo().getName());
2349 } catch (Exception e)
2351 throw new Exception("Couldn't store sequence mappings for " + title,