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.getSequenceSetId()); // this is so we can get
337 if (alignment == null)
339 alignment = new Alignment();
340 bindjvvobj(av.getSequenceSetId(), 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=findViewport(alignment);
1112 jalview.datamodel.AlignmentI jal = null;
1115 jal = av.getAlignment();
1117 iSize = alignment.getAlignmentSequenceCount();
1118 boolean newal = (jal == null) ? true : false;
1119 Vector newasAnnots = new Vector();
1120 char gapChar = ' '; // default for new alignments read in from the
1124 dsseqs = jal.getSequences(); // for merge/update
1125 gapChar = jal.getGapCharacter();
1129 dsseqs = new Vector();
1131 char valGapchar = alignment.getGapChar().charAt(0);
1132 for (i = 0; i < iSize; i++)
1134 AlignmentSequence valseq = alignment.getAlignmentSequence(i);
1135 jalview.datamodel.SequenceI alseq = (SequenceI) getvObj2jv(valseq);
1138 // TODO: upperCase/LowerCase situation here ? do we allow it ?
1139 // if (!alseq.getSequence().equals(valseq.getSequence())) {
1140 // throw new Error("Broken! - mismatch of dataset sequence and
1141 // jalview internal dataset sequence.");
1142 if (Cache.log.isDebugEnabled())
1144 Cache.log.debug("Updating apparently edited sequence "
1147 // this might go *horribly* wrong
1148 alseq.setSequence(new String(valseq.getSequence()).replace(
1149 valGapchar, gapChar));
1154 alseq = new jalview.datamodel.Sequence(valseq.getName(),
1155 valseq.getSequence().replace(valGapchar, gapChar),
1156 (int) valseq.getStart(), (int) valseq.getEnd());
1158 Vobject datsetseq = (Vobject) valseq.getRefid();
1159 if (datsetseq != null)
1162 .setDatasetSequence((SequenceI) getvObj2jv(datsetseq)); // exceptions
1164 // AlignemntSequence
1174 .error("Invalid dataset sequence id (null) for alignment sequence "
1175 + valseq.getVorbaId());
1177 bindjvvobj(alseq, valseq);
1178 alseq.setVamsasId(valseq.getVorbaId().getId());
1181 if (valseq.getAlignmentSequenceAnnotationCount() > 0)
1183 AlignmentSequenceAnnotation[] vasannot = valseq
1184 .getAlignmentSequenceAnnotation();
1185 for (int a = 0; a < vasannot.length; a++)
1187 jalview.datamodel.AlignmentAnnotation asa = (jalview.datamodel.AlignmentAnnotation) getvObj2jv(vasannot[a]); // TODO:
1195 int se[] = getBounds(vasannot[a]);
1196 asa = getjAlignmentAnnotation(jal, vasannot[a]);
1197 asa.setSequenceRef(alseq);
1198 asa.createSequenceMapping(alseq, se[0], false); // TODO:
1209 alseq.addAlignmentAnnotation(asa);
1210 bindjvvobj(asa, vasannot[a]);
1211 newasAnnots.add(asa);
1215 // update existing annotation - can do this in place
1216 if (vasannot[a].getModifiable() == null) // TODO: USE
1222 .info("UNIMPLEMENTED: not recovering user modifiable sequence alignment annotation");
1223 // TODO: should at least replace with new one - otherwise
1224 // things will break
1225 // basically do this:
1226 // int se[] = getBounds(vasannot[a]);
1227 // asa.update(getjAlignmentAnnotation(jal, vasannot[a]));
1228 // // update from another annotation object in place.
1229 // asa.createSequenceMapping(alseq, se[0], false);
1238 SequenceI[] seqs = new SequenceI[dsseqs.size()];
1239 for (i = 0, iSize = dsseqs.size(); i < iSize; i++)
1241 seqs[i] = (SequenceI) dsseqs.elementAt(i);
1242 dsseqs.setElementAt(null, i);
1244 jal = new jalview.datamodel.Alignment(seqs);
1245 Cache.log.debug("New vamsas alignment imported into jalview "
1246 + alignment.getVorbaId().getId());
1247 jal.setDataset(jdataset);
1249 if (newasAnnots != null && newasAnnots.size() > 0)
1251 // Add the new sequence annotations in to the alignment.
1252 for (int an = 0, anSize = newasAnnots.size(); an < anSize; an++)
1254 jal.addAnnotation((AlignmentAnnotation) newasAnnots
1256 // TODO: check if anything has to be done - like calling
1257 // adjustForAlignment or something.
1258 newasAnnots.setElementAt(null, an);
1262 // //////////////////////////////////////////
1263 // //LOAD ANNOTATIONS FOR THE ALIGNMENT
1264 // ////////////////////////////////////
1265 if (alignment.getAlignmentAnnotationCount() > 0)
1267 uk.ac.vamsas.objects.core.AlignmentAnnotation[] an = alignment
1268 .getAlignmentAnnotation();
1270 for (int j = 0; j < an.length; j++)
1272 jalview.datamodel.AlignmentAnnotation jan = (jalview.datamodel.AlignmentAnnotation) getvObj2jv(an[j]);
1275 // update or stay the same.
1276 // TODO: should at least replace with a new one - otherwise
1277 // things will break
1278 // basically do this:
1279 // jan.update(getjAlignmentAnnotation(jal, an[a])); // update
1280 // from another annotation object in place.
1283 .debug("update from vamsas alignment annotation to existing jalview alignment annotation.");
1284 if (an[j].getModifiable() == null) // TODO: USE VAMSAS
1285 // LIBRARY OBJECT LOCK
1288 // TODO: user defined annotation is totally mutable... - so
1289 // load it up or throw away if locally edited.
1291 .info("NOT IMPLEMENTED - Recovering user-modifiable annotation - yet...");
1293 // TODO: compare annotation element rows
1294 // TODO: compare props.
1298 jan = getjAlignmentAnnotation(jal, an[j]);
1299 jal.addAnnotation(jan);
1300 bindjvvobj(jan, an[j]);
1304 AlignFrame alignFrame;
1307 Cache.log.debug("New alignframe for alignment "
1308 + alignment.getVorbaId());
1309 // ///////////////////////////////
1310 // construct alignment view
1311 alignFrame = new AlignFrame(jal, AlignFrame.DEFAULT_WIDTH,
1312 AlignFrame.DEFAULT_HEIGHT);
1313 av = alignFrame.getViewport();
1314 String title = alignment.getProvenance().getEntry(
1315 alignment.getProvenance().getEntryCount() - 1)
1317 if (alignment.getPropertyCount() > 0)
1319 for (int p = 0, pe = alignment.getPropertyCount(); p < pe; p++)
1321 if (alignment.getProperty(p).getName().equals(
1324 title = alignment.getProperty(p).getContent();
1328 // TODO: automatically create meaningful title for a vamsas
1329 // alignment using its provenance.
1330 if (Cache.log.isDebugEnabled())
1333 + alignment.getVorbaId() + ")";
1336 jalview.gui.Desktop.addInternalFrame(alignFrame, title
1338 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
1339 bindjvvobj(av.getSequenceSetId(), alignment);
1343 // find the alignFrame for jal.
1344 // TODO: fix this so we retrieve the alignFrame handing av
1346 alignFrame = getAlignFrameFor(av);
1349 // /////////////////////////////////////
1350 if (alignment.getTreeCount() > 0)
1353 for (int t = 0; t < alignment.getTreeCount(); t++)
1355 jalview.io.vamsas.Tree vstree = new jalview.io.vamsas.Tree(
1356 this, alignFrame, alignment.getTree(t));
1357 TreePanel tp = null;
1358 if (vstree.isValidTree())
1361 .ShowNewickTree(vstree.getNewickTree(), vstree
1362 .getTitle(), vstree.getInputData(), 600,
1363 500, t * 20 + 50, t * 20 + 50);
1368 bindjvvobj(tp, alignment.getTree(t));
1371 vstree.UpdateSequenceTreeMap(tp);
1372 } catch (RuntimeException e)
1374 Cache.log.warn("update of labels failed.",e);
1379 Cache.log.warn("Cannot create tree for tree "+t+" in document ("+alignment.getTree(t).getVorbaId());
1387 // we do sequenceMappings last because they span all datasets in a vamsas
1389 for (int _ds = 0, _nds = root.getDataSetCount(); _ds < _nds; _ds++)
1391 DataSet dataset = root.getDataSet(_ds);
1392 if (dataset.getSequenceMappingCount() > 0)
1394 for (int sm = 0, smCount = dataset.getSequenceMappingCount(); sm < smCount; sm++)
1396 Rangetype seqmap = new jalview.io.vamsas.Sequencemapping(this,
1397 dataset.getSequenceMapping(sm));
1404 public AlignViewport findViewport(Alignment alignment)
1406 AlignViewport av=null;
1407 AlignViewport[] avs = findViewportForSequenceSetId((String)getvObj2jv(alignment));
1415 private AlignViewport[] findViewportForSequenceSetId(String sequenceSetId)
1417 Vector viewp = new Vector();
1418 if (Desktop.desktop != null)
1420 javax.swing.JInternalFrame[] frames = Desktop.instance.getAllFrames();
1422 for (int t = 0; t < frames.length; t++)
1424 if (frames[t] instanceof AlignFrame)
1426 if (((AlignFrame) frames[t]).getViewport().getSequenceSetId().equals(sequenceSetId))
1428 viewp.addElement(((AlignFrame) frames[t]).getViewport());
1434 AlignViewport[] vp = new AlignViewport[viewp.size()];
1442 // bitfields - should be a template in j1.5
1443 private static int HASSECSTR = 0;
1445 private static int HASVALS = 1;
1447 private static int HASHPHOB = 2;
1449 private static int HASDC = 3;
1451 private static int HASDESCSTR = 4;
1453 private static int HASTWOSTATE = 5; // not used yet.
1456 * parses the AnnotationElements - if they exist - into
1457 * jalview.datamodel.Annotation[] rows Two annotation rows are made if there
1458 * are distinct annotation for both at 'pos' and 'after pos' at any particular
1462 * @return { boolean[static int constants ], int[ae.length] - map to annotated
1463 * object frame, jalview.datamodel.Annotation[],
1464 * jalview.datamodel.Annotation[] (after)}
1466 private Object[] parseRangeAnnotation(
1467 uk.ac.vamsas.objects.core.RangeAnnotation annotation)
1469 // set these attributes by looking in the annotation to decide what kind of
1470 // alignment annotation rows will be made
1471 // TODO: potentially we might make several annotation rows from one vamsas
1472 // alignment annotation. the jv2Vobj binding mechanism
1473 // may not quite cope with this (without binding an array of annotations to
1474 // a vamsas alignment annotation)
1475 // summary flags saying what we found over the set of annotation rows.
1476 boolean[] AeContent = new boolean[]
1477 { false, false, false, false, false };
1478 int[] rangeMap = getMapping(annotation);
1479 jalview.datamodel.Annotation[][] anot = new jalview.datamodel.Annotation[][]
1480 { new jalview.datamodel.Annotation[rangeMap.length],
1481 new jalview.datamodel.Annotation[rangeMap.length] };
1482 boolean mergeable = true; // false if 'after positions cant be placed on
1483 // same annotation row as positions.
1485 if (annotation.getAnnotationElementCount() > 0)
1487 AnnotationElement ae[] = annotation.getAnnotationElement();
1488 for (int aa = 0; aa < ae.length; aa++)
1490 int pos = (int) ae[aa].getPosition() - 1; // pos counts from 1 to
1491 // (|seg.start-seg.end|+1)
1492 if (pos >= 0 && pos < rangeMap.length)
1494 int row = ae[aa].getAfter() ? 1 : 0;
1495 if (anot[row][pos] != null)
1497 // only time this should happen is if the After flag is set.
1498 Cache.log.debug("Ignoring duplicate annotation site at " + pos);
1501 if (anot[1 - row][pos] != null)
1506 if (ae[aa].getDescription() != null)
1508 desc = ae[aa].getDescription();
1509 if (desc.length() > 0)
1511 // have imported valid description string
1512 AeContent[HASDESCSTR] = true;
1515 String dc = null; // ae[aa].getDisplayCharacter()==null ? "dc" :
1516 // ae[aa].getDisplayCharacter();
1517 String ss = null; // ae[aa].getSecondaryStructure()==null ? "ss" :
1518 // ae[aa].getSecondaryStructure();
1519 java.awt.Color colour = null;
1520 if (ae[aa].getGlyphCount() > 0)
1522 Glyph[] glyphs = ae[aa].getGlyph();
1523 for (int g = 0; g < glyphs.length; g++)
1528 uk.ac.vamsas.objects.utils.GlyphDictionary.PROTEIN_SS_3STATE))
1530 ss = glyphs[g].getContent();
1531 AeContent[HASSECSTR] = true;
1536 uk.ac.vamsas.objects.utils.GlyphDictionary.PROTEIN_HD_HYDRO))
1538 Cache.log.debug("ignoring hydrophobicity glyph marker.");
1539 AeContent[HASHPHOB] = true;
1540 char c = (dc = glyphs[g].getContent()).charAt(0);
1541 // dc may get overwritten - but we still set the colour.
1542 colour = new java.awt.Color(c == '+' ? 255 : 0,
1543 c == '.' ? 255 : 0, c == '-' ? 255 : 0);
1546 else if (glyphs[g].getDict().equals(
1547 uk.ac.vamsas.objects.utils.GlyphDictionary.DEFAULT))
1549 dc = glyphs[g].getContent();
1550 AeContent[HASDC] = true;
1554 Cache.log.debug("IMPLEMENTATION TODO: Ignoring unknown glyph type "
1555 + glyphs[g].getDict());
1560 if (ae[aa].getValueCount() > 0)
1562 AeContent[HASVALS] = true;
1563 if (ae[aa].getValueCount() > 1)
1565 Cache.log.warn("ignoring additional "
1566 + (ae[aa].getValueCount() - 1)
1567 + "values in annotation element.");
1569 val = ae[aa].getValue(0);
1573 anot[row][pos] = new jalview.datamodel.Annotation(
1574 (dc != null) ? dc : "", desc, (ss != null) ? ss
1575 .charAt(0) : ' ', val);
1579 anot[row][pos] = new jalview.datamodel.Annotation(
1580 (dc != null) ? dc : "", desc, (ss != null) ? ss
1581 .charAt(0) : ' ', val, colour);
1586 Cache.log.warn("Ignoring out of bound annotation element " + aa
1587 + " in " + annotation.getVorbaId().getId());
1590 // decide on how many annotation rows are needed.
1593 for (int i = 0; i < anot[0].length; i++)
1595 if (anot[1][i] != null)
1597 anot[0][i] = anot[1][i];
1598 anot[0][i].description = anot[0][i].description + " (after)";
1599 AeContent[HASDESCSTR] = true; // we have valid description string
1608 for (int i = 0; i < anot[0].length; i++)
1610 anot[1][i].description = anot[1][i].description + " (after)";
1614 { AeContent, rangeMap, anot[0], anot[1] };
1618 // no annotations to parse. Just return an empty annotationElement[]
1621 { AeContent, rangeMap, anot[0], anot[1] };
1628 * the jalview alignment to which the annotation will be attached
1629 * (ideally - freshly updated from corresponding vamsas alignment)
1631 * @return unbound jalview alignment annotation object.
1633 private jalview.datamodel.AlignmentAnnotation getjAlignmentAnnotation(
1634 jalview.datamodel.AlignmentI jal,
1635 uk.ac.vamsas.objects.core.RangeAnnotation annotation)
1637 if (annotation == null)
1642 // hasSequenceRef=annotation.getClass().equals(uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation.class);
1643 // boolean hasProvenance=hasSequenceRef ||
1644 // (annotation.getClass().equals(uk.ac.vamsas.objects.core.AlignmentAnnotation.class));
1646 * int se[] = getBounds(annotation); if (se==null) se=new int[]
1647 * {0,jal.getWidth()-1};
1649 Object[] parsedRangeAnnotation = parseRangeAnnotation(annotation);
1650 String a_label = annotation.getLabel();
1651 String a_descr = annotation.getDescription();
1654 boolean interp=true; // cleared if annotation is DISCRETE
1655 // set type and other attributes from properties
1656 if (annotation.getPropertyCount() > 0)
1658 // look for special jalview properties
1659 uk.ac.vamsas.objects.core.Property[] props = annotation
1661 for (int p = 0; p < props.length; p++)
1663 if (props[p].getName().equalsIgnoreCase(DISCRETE_ANNOTATION))
1665 type = AlignmentAnnotation.BAR_GRAPH;
1668 (props[p].getName().equalsIgnoreCase(CONTINUOUS_ANNOTATION)) {
1669 type = AlignmentAnnotation.LINE_GRAPH;
1671 (props[p].getName().equalsIgnoreCase(THRESHOLD))
1675 val = new Float(props[p].getContent());
1676 }catch (Exception e)
1678 Cache.log.warn("Failed to parse threshold property");
1683 gl = new GraphLine(val.floatValue(), "", java.awt.Color.black);
1686 gl.value = val.floatValue();
1689 else if (props[p].getName().equalsIgnoreCase(THRESHOLD+"Name"))
1692 gl = new GraphLine(0, "", java.awt.Color.black);
1693 gl.label = props[p].getContent();
1697 jalview.datamodel.AlignmentAnnotation jan = null;
1698 if (a_label == null || a_label.length() == 0)
1700 a_label = annotation.getType();
1701 if (a_label.length() == 0)
1703 a_label = "Unamed annotation";
1706 if (a_descr == null || a_descr.length() == 0)
1708 a_descr = "Annotation of type '" + annotation.getType() + "'";
1710 if (parsedRangeAnnotation == null)
1713 .debug("Inserting empty annotation row elements for a whole-alignment annotation.");
1717 if (parsedRangeAnnotation[3] != null)
1719 Cache.log.warn("Ignoring 'After' annotation row in "
1720 + annotation.getVorbaId());
1722 jalview.datamodel.Annotation[] arow = (jalview.datamodel.Annotation[]) parsedRangeAnnotation[2];
1723 boolean[] has = (boolean[]) parsedRangeAnnotation[0];
1724 // VAMSAS: getGraph is only on derived annotation for alignments - in this
1725 // way its 'odd' - there is already an existing TODO about removing this
1726 // flag as being redundant
1729 * ((annotation.getClass().equals(uk.ac.vamsas.objects.core.AlignmentAnnotation.class) &&
1730 * ((uk.ac.vamsas.objects.core.AlignmentAnnotation)annotation).getGraph()) ||
1731 * (hasSequenceRef=true &&
1732 * ((uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation)annotation).getGraph())) {
1738 type = jalview.datamodel.AlignmentAnnotation.BAR_GRAPH; // default type of value annotation
1741 // no hints - so we ensure HPHOB display is like this.
1742 type = jalview.datamodel.AlignmentAnnotation.BAR_GRAPH;
1745 // make bounds and automatic description strings for jalview user's
1746 // benefit (these shouldn't be written back to vamsas document)
1747 boolean first = true;
1748 float min = 0, max = 1;
1750 for (int i = 0; i < arow.length; i++)
1752 if (arow[i] != null)
1754 if (i - lastval > 1 && interp)
1756 // do some interpolation *between* points
1757 if (arow[lastval] != null)
1759 float interval = arow[i].value - arow[lastval].value;
1760 interval /= i - lastval;
1761 float base = arow[lastval].value;
1762 for (int ip = lastval + 1, np = 0; ip < i; np++, ip++)
1764 arow[ip] = new jalview.datamodel.Annotation("", "", ' ',
1765 interval * np + base);
1766 // NB - Interpolated points don't get a tooltip and
1772 // check range - shouldn't we have a min and max property in the
1773 // annotation object ?
1776 min = max = arow[i].value;
1781 if (arow[i].value < min)
1783 min = arow[i].value;
1785 else if (arow[i].value > max)
1787 max = arow[i].value;
1790 // make tooltip and display char value
1791 if (!has[HASDESCSTR])
1793 arow[i].description = arow[i].value + "";
1799 if (arow[i].description!=null && arow[i].description.length()<3)
1801 // copy over the description as the display char.
1802 arow[i].displayCharacter = new String(arow[i].description);
1806 // mark the position as a point used for the interpolation.
1807 arow[i].displayCharacter = arow[i].value + "";
1812 jan = new jalview.datamodel.AlignmentAnnotation(a_label, a_descr,
1813 arow, min, max, type);
1817 if (annotation.getAnnotationElementCount()==0)
1819 // empty annotation array
1820 // TODO: alignment 'features' compare rangeType spec to alignment width - if it is not complete, then mark regions on the annotation row.
1822 jan = new jalview.datamodel.AlignmentAnnotation(a_label, a_descr,
1824 jan.setThreshold(null);
1826 if (annotation.getLinkCount() > 0)
1828 Cache.log.warn("Ignoring " + annotation.getLinkCount()
1829 + "links added to AlignmentAnnotation.");
1831 if (annotation.getModifiable() == null) // TODO: USE VAMSAS LIBRARY OBJECT
1834 jan.editable = true;
1838 if (annotation.getGroup() != null
1839 && annotation.getGroup().length() > 0)
1841 jan.graphGroup = Integer.parseInt(annotation.getGroup());
1843 } catch (Exception e)
1846 .info("UNIMPLEMENTED : Couldn't parse non-integer group value for setting graphGroup correctly.");
1855 private SequenceFeature getJalviewSeqFeature(RangeAnnotation dseta)
1857 int[] se = getBounds(dseta);
1858 SequenceFeature sf = new jalview.datamodel.SequenceFeature(dseta
1859 .getType(), dseta.getDescription(), dseta.getStatus(), se[0],
1860 se[1], dseta.getGroup());
1861 if (dseta.getLinkCount() > 0)
1863 Link[] links = dseta.getLink();
1864 for (int i = 0; i < links.length; i++)
1866 sf.addLink(links[i].getContent() + "|" + links[i].getHref());
1873 * get real bounds of a RangeType's specification. start and end are an
1874 * inclusive range within which all segments and positions lie. TODO: refactor
1878 * @return int[] { start, end}
1880 private int[] getBounds(RangeType dseta)
1885 if (dseta.getSegCount() > 0 && dseta.getPosCount() > 0)
1888 "Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!");
1890 if (dseta.getSegCount() > 0)
1892 se = getSegRange(dseta.getSeg(0), true);
1893 for (int s = 1, sSize = dseta.getSegCount(); s < sSize; s++)
1895 int nse[] = getSegRange(dseta.getSeg(s), true);
1906 if (dseta.getPosCount() > 0)
1908 // could do a polarity for pos range too. and pass back indication of
1910 int pos = dseta.getPos(0).getI();
1913 for (int p = 0, pSize = dseta.getPosCount(); p < pSize; p++)
1915 pos = dseta.getPos(p).getI();
1932 * map from a rangeType's internal frame to the referenced object's coordinate
1936 * @return int [] { ref(pos)...} for all pos in rangeType's frame.
1938 private int[] getMapping(RangeType dseta)
1940 Vector posList = new Vector();
1944 if (dseta.getSegCount() > 0 && dseta.getPosCount() > 0)
1947 "Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!");
1949 if (dseta.getSegCount() > 0)
1951 for (int s = 0, sSize = dseta.getSegCount(); s < sSize; s++)
1953 se = getSegRange(dseta.getSeg(s), false);
1954 int se_end = se[1 - se[2]] + (se[2] == 0 ? 1 : -1);
1955 for (int p = se[se[2]]; p != se_end; p += se[2] == 0 ? 1 : -1)
1957 posList.add(new Integer(p));
1961 else if (dseta.getPosCount() > 0)
1963 int pos = dseta.getPos(0).getI();
1965 for (int p = 0, pSize = dseta.getPosCount(); p < pSize; p++)
1967 pos = dseta.getPos(p).getI();
1968 posList.add(new Integer(pos));
1972 if (posList != null && posList.size() > 0)
1974 int[] range = new int[posList.size()];
1975 for (int i = 0; i < range.length; i++)
1977 range[i] = ((Integer) posList.elementAt(i)).intValue();
1988 * where the from range is the local mapped range, and the to range
1989 * is the 'mapped' range in the MapRangeType
1996 private jalview.util.MapList parsemapType(MapType maprange, int localu,
1999 jalview.util.MapList ml = null;
2000 int[] localRange = getMapping(maprange.getLocal());
2001 int[] mappedRange = getMapping(maprange.getMapped());
2002 long lu = maprange.getLocal().hasUnit() ? maprange.getLocal().getUnit()
2004 long mu = maprange.getMapped().hasUnit() ? maprange.getMapped()
2005 .getUnit() : mappedu;
2006 ml = new jalview.util.MapList(localRange, mappedRange, (int) lu,
2012 * initialise a range type object from a set of start/end inclusive intervals
2017 private void initRangeType(RangeType mrt, int[] range)
2019 for (int i = 0; i < range.length; i += 2)
2021 Seg vSeg = new Seg();
2022 vSeg.setStart(range[i]);
2023 vSeg.setEnd(range[i + 1]);
2029 * initialise a MapType object from a MapList object.
2035 private void initMapType(MapType maprange, jalview.util.MapList ml,
2038 maprange.setLocal(new Local());
2039 maprange.setMapped(new Mapped());
2040 initRangeType(maprange.getLocal(), ml.getFromRanges());
2041 initRangeType(maprange.getMapped(), ml.getToRanges());
2044 maprange.getLocal().setUnit(ml.getFromRatio());
2045 maprange.getLocal().setUnit(ml.getToRatio());
2050 * not needed now. Provenance getVamsasProvenance(jalview.datamodel.Provenance
2051 * jprov) { jalview.datamodel.ProvenanceEntry[] entries = null; // TODO: fix
2052 * App and Action here. Provenance prov = new Provenance();
2053 * org.exolab.castor.types.Date date = new org.exolab.castor.types.Date( new
2054 * java.util.Date()); Entry provEntry;
2056 * if (jprov != null) { entries = jprov.getEntries(); for (int i = 0; i <
2057 * entries.length; i++) { provEntry = new Entry(); try { date = new
2058 * org.exolab.castor.types.Date(entries[i].getDate()); } catch (Exception ex) {
2059 * ex.printStackTrace();
2061 * date = new org.exolab.castor.types.Date(entries[i].getDate()); }
2062 * provEntry.setDate(date); provEntry.setUser(entries[i].getUser());
2063 * provEntry.setAction(entries[i].getAction()); prov.addEntry(provEntry); } }
2064 * else { provEntry = new Entry(); provEntry.setDate(date);
2065 * provEntry.setUser(System.getProperty("user.name")); // TODO: ext string
2066 * provEntry.setApp("JVAPP"); // TODO: ext string provEntry.setAction(action);
2067 * prov.addEntry(provEntry); }
2071 jalview.datamodel.Provenance getJalviewProvenance(Provenance prov)
2073 // TODO: fix App and Action entries and check use of provenance in jalview.
2074 jalview.datamodel.Provenance jprov = new jalview.datamodel.Provenance();
2075 for (int i = 0; i < prov.getEntryCount(); i++)
2077 jprov.addEntry(prov.getEntry(i).getUser(), prov.getEntry(i)
2078 .getAction(), prov.getEntry(i).getDate(), prov.getEntry(i)
2087 * @return default initial provenance list for a Jalview created vamsas
2090 Provenance dummyProvenance()
2092 return dummyProvenance(null);
2095 Entry dummyPEntry(String action)
2097 Entry entry = new Entry();
2098 entry.setApp(this.provEntry.getApp());
2101 entry.setAction(action);
2105 entry.setAction("created.");
2107 entry.setDate(new java.util.Date());
2108 entry.setUser(this.provEntry.getUser());
2112 Provenance dummyProvenance(String action)
2114 Provenance prov = new Provenance();
2115 prov.addEntry(dummyPEntry(action));
2119 void addProvenance(Provenance p, String action)
2121 p.addEntry(dummyPEntry(action));
2124 public Entry getProvEntry()
2129 public IClientDocument getClientDocument()
2134 public IdentityHashMap getJvObjectBinding()
2139 public Hashtable getVamsasObjectBinding()
2144 public void storeSequenceMappings(AlignViewport viewport, String title)
2147 AlignViewport av = viewport;
2150 jalview.datamodel.AlignmentI jal = av.getAlignment();
2151 // /////////////////////////////////////////
2153 DataSet dataset = null;
2154 if (jal.getDataset() == null)
2156 Cache.log.warn("Creating new dataset for an alignment.");
2157 jal.setDataset(null);
2159 dataset = (DataSet) getjv2vObj(jal.getDataset());
2160 // Store any sequence mappings.
2161 if (av.getAlignment().getCodonFrames() != null
2162 && av.getAlignment().getCodonFrames().length > 0)
2164 jalview.datamodel.AlignedCodonFrame[] cframes = av.getAlignment()
2166 for (int cf = 0; cf < cframes.length; cf++)
2168 if (cframes[cf].getdnaSeqs().length > 0)
2170 jalview.datamodel.SequenceI[] dmps = cframes[cf].getdnaSeqs();
2171 jalview.datamodel.Mapping[] mps = cframes[cf].getProtMappings();
2172 for (int smp = 0; smp < mps.length; smp++)
2174 uk.ac.vamsas.objects.core.SequenceType mfrom = (SequenceType) getjv2vObj(dmps[smp]);
2177 new jalview.io.vamsas.Sequencemapping(this, mps[smp],
2183 .warn("NO Vamsas Binding for local sequence! NOT CREATING MAPPING FOR "
2184 + dmps[smp].getDisplayId(true)
2186 + mps[smp].getTo().getName());
2192 } catch (Exception e)
2194 throw new Exception("Couldn't store sequence mappings for " + title,