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 // ////////////////////////////////////////////
329 // ////////////////////////////////////////////
330 // Save the Alignments
332 Alignment alignment = (Alignment) getjv2vObj(av); // this is so we can get
335 if (alignment == null)
337 alignment = new Alignment();
338 bindjvvobj(av, alignment);
339 if (alignment.getProvenance() == null)
341 alignment.setProvenance(new Provenance());
343 addProvenance(alignment.getProvenance(), "added"); // TODO: insert some
346 dataset.addAlignment(alignment);
348 Property title = new Property();
349 title.setName("title");
350 title.setType("string");
351 title.setContent(aFtitle);
352 alignment.addProperty(title);
354 alignment.setGapChar(String.valueOf(av.getGapCharacter()));
355 AlignmentSequence alseq = null;
356 for (int i = 0; i < jal.getHeight(); i++)
358 alseq = new AlignmentSequence();
359 // TODO: VAMSAS: translate lowercase symbols to annotation ?
360 alseq.setSequence(jal.getSequenceAt(i).getSequenceAsString());
361 alseq.setName(jal.getSequenceAt(i).getName());
362 alseq.setStart(jal.getSequenceAt(i).getStart());
363 alseq.setEnd(jal.getSequenceAt(i).getEnd());
364 if (getjv2vObj(jal.getSequenceAt(i).getDatasetSequence()) == null)
367 .warn("Serious. Unbound dataset sequence in alignment: "
368 + jal.getSequenceAt(i).getDatasetSequence());
370 alseq.setRefid(getjv2vObj(jal.getSequenceAt(i)
371 .getDatasetSequence()));
372 alignment.addAlignmentSequence(alseq);
373 bindjvvobj(jal.getSequenceAt(i), alseq);
378 // todo: verify and update mutable alignment props.
379 if (alignment.getModifiable() == null) // TODO: USE VAMSAS LIBRARY
380 // OBJECT LOCK METHODS
382 System.out.println("update alignment in document.");
387 .println("update edited alignment to new alignment in document.");
390 // ////////////////////////////////////////////
391 // SAVE Alignment Sequence Features
392 for (int i = 0, iSize = alignment.getAlignmentSequenceCount(); i < iSize; i++)
394 AlignmentSequence valseq;
395 SequenceI alseq = (SequenceI) getvObj2jv(valseq = alignment
396 .getAlignmentSequence(i));
397 if (alseq != null && alseq.getSequenceFeatures() != null)
400 * We do not put local Alignment Sequence Features into the vamsas
404 * jalview.datamodel.SequenceFeature[] features = alseq
405 * .getSequenceFeatures(); for (int f = 0; f < features.length; f++) {
406 * if (features[f] != null) { AlignmentSequenceAnnotation valseqf = (
407 * AlignmentSequenceAnnotation) getjv2vObj(features[i]); if (valseqf ==
410 * valseqf = (AlignmentSequenceAnnotation) getDSAnnotationFromJalview(
411 * new AlignmentSequenceAnnotation(), features[i]);
412 * valseqf.setGraph(false);
413 * valseqf.addProperty(newProperty("jalview:feature","boolean","true"));
414 * if (valseqf.getProvenance() == null) { valseqf.setProvenance(new
415 * Provenance()); } addProvenance(valseqf.getProvenance(), "created"); //
416 * JBPNote - // need to // update bindjvvobj(features[i], valseqf);
417 * valseq.addAlignmentSequenceAnnotation(valseqf); } }
423 // ////////////////////////////////////////////
425 if (jal.getAlignmentAnnotation() != null)
427 jalview.datamodel.AlignmentAnnotation[] aa = jal
428 .getAlignmentAnnotation();
429 java.util.HashMap AlSeqMaps = new HashMap(); // stores int maps from
430 // alignment columns to
431 // sequence positions.
432 for (int i = 0; i < aa.length; i++)
434 if (aa[i] == null || isJalviewOnly(aa[i]))
438 if (aa[i].sequenceRef != null)
440 // Deal with sequence associated annotation
441 Vobject sref = getjv2vObj(aa[i].sequenceRef);
442 if (sref instanceof uk.ac.vamsas.objects.core.AlignmentSequence)
444 saveAlignmentSequenceAnnotation(AlSeqMaps,
445 (AlignmentSequence) sref, aa[i]);
449 // first find the alignment sequence to associate this with.
450 SequenceI jvalsq = null;
451 Enumeration jval = av.getAlignment().getSequences()
453 while (jval.hasMoreElements())
455 jvalsq = (SequenceI) jval.nextElement();
456 // saveDatasetSequenceAnnotation(AlSeqMaps,(uk.ac.vamsas.objects.core.Sequence)
458 if (jvalsq.getDatasetSequence() == aa[i].sequenceRef)
460 Vobject alsref = getjv2vObj(jvalsq);
461 saveAlignmentSequenceAnnotation(AlSeqMaps,
462 (AlignmentSequence) alsref, aa[i]);
471 // add Alignment Annotation
472 uk.ac.vamsas.objects.core.AlignmentAnnotation an = (uk.ac.vamsas.objects.core.AlignmentAnnotation) getjv2vObj(aa[i]);
475 an = new uk.ac.vamsas.objects.core.AlignmentAnnotation();
476 an.setType(JALVIEW_ANNOTATION_ROW);
477 an.setDescription(aa[i].description);
478 alignment.addAlignmentAnnotation(an);
479 Seg vSeg = new Seg(); // TODO: refactor to have a default
480 // rangeAnnotationType initer/updater that
481 // takes a set of int ranges.
483 vSeg.setInclusive(true);
484 vSeg.setEnd(jal.getWidth());
488 an.setGraph(true); // aa[i].graph);
490 an.setLabel(aa[i].label);
491 an.setProvenance(dummyProvenance());
492 if (aa[i].graph != AlignmentAnnotation.NO_GRAPH)
494 an.setGroup(Integer.toString(aa[i].graphGroup)); // // JBPNote
509 AnnotationElement ae;
511 for (int a = 0; a < aa[i].annotations.length; a++)
513 if ((aa[i] == null) || (aa[i].annotations[a] == null))
518 ae = new AnnotationElement();
519 ae.setDescription(aa[i].annotations[a].description);
520 ae.addGlyph(new Glyph());
521 ae.getGlyph(0).setContent(
522 aa[i].annotations[a].displayCharacter); // assume
529 ae.addValue(aa[i].annotations[a].value);
530 ae.setPosition(a + 1);
531 if (aa[i].annotations[a].secondaryStructure != ' ')
533 Glyph ss = new Glyph();
535 .setDict(uk.ac.vamsas.objects.utils.GlyphDictionary.PROTEIN_SS_3STATE);
538 .valueOf(aa[i].annotations[a].secondaryStructure));
541 an.addAnnotationElement(ae);
545 // an.addProperty(newProperty("jalview:editable", null,
547 // an.setModifiable(""); // TODO: This is not the way the
548 // modifiable flag is supposed to be used.
550 setAnnotationType(an, aa[i]);
552 if (aa[i].graph != jalview.datamodel.AlignmentAnnotation.NO_GRAPH)
555 an.setGroup(Integer.toString(aa[i].graphGroup));
556 if (aa[i].threshold!=null && aa[i].threshold.displayed)
557 an.addProperty(newProperty(THRESHOLD, "float", ""+aa[i].threshold.value));
558 if (aa[i].threshold.label!=null)
559 an.addProperty(newProperty(THRESHOLD+"Name", "string", ""+aa[i].threshold.label));
566 if (an.getModifiable() == null) // TODO: USE VAMSAS LIBRARY OBJECT
569 // verify annotation - update (perhaps)
571 .info("update alignment sequence annotation. not yet implemented.");
575 // verify annotation - update (perhaps)
577 .info("updated alignment sequence annotation added.");
583 // /////////////////////////////////////////////////////
585 // //////////////////////////////////////////////
587 // /////////////////////////////////
588 // FIND ANY ASSOCIATED TREES
589 if (Desktop.desktop != null)
591 javax.swing.JInternalFrame[] frames = Desktop.instance
594 for (int t = 0; t < frames.length; t++)
596 if (frames[t] instanceof TreePanel)
598 TreePanel tp = (TreePanel) frames[t];
600 if (tp.getAlignment() == jal)
602 DatastoreItem vtree = new jalview.io.vamsas.Tree(this, tp,
608 // Store Jalview specific stuff in the Jalview appData
609 // not implemented in the SimpleDoc interface.
614 ex.printStackTrace();
619 private void initRangeAnnotationType(RangeAnnotation an,
620 AlignmentAnnotation alan, int[] gapMap)
622 Seg vSeg = new Seg();
624 vSeg.setInclusive(true);
625 vSeg.setEnd(gapMap.length);
628 // LATER: much of this is verbatim from the alignmentAnnotation
629 // method below. suggests refactoring to make rangeAnnotation the
631 an.setDescription(alan.description);
632 an.setLabel(alan.label);
633 an.setGroup(Integer.toString(alan.graphGroup));
642 AnnotationElement ae;
643 for (int a = 0; a < alan.annotations.length; a++)
645 if (alan.annotations[a] == null)
650 ae = new AnnotationElement();
651 ae.setDescription(alan.annotations[a].description);
652 ae.addGlyph(new Glyph());
653 ae.getGlyph(0).setContent(alan.annotations[a].displayCharacter); // assume
660 if (alan.graph != jalview.datamodel.AlignmentAnnotation.NO_GRAPH)
662 ae.addValue(alan.annotations[a].value);
664 ae.setPosition(gapMap[a] + 1); // position w.r.t. AlignmentSequence
666 if (alan.annotations[a].secondaryStructure != ' ')
668 // we only write an annotation where it really exists.
669 Glyph ss = new Glyph();
671 .setDict(uk.ac.vamsas.objects.utils.GlyphDictionary.PROTEIN_SS_3STATE);
673 .valueOf(alan.annotations[a].secondaryStructure));
676 an.addAnnotationElement(ae);
681 private void saveDatasetSequenceAnnotation(HashMap AlSeqMaps,
682 uk.ac.vamsas.objects.core.Sequence sref, AlignmentAnnotation alan)
686 // objects.core.AlignmentSequence alsref = (uk.ac.vamsas.
687 // objects.core.AlignmentSequence) sref;
688 uk.ac.vamsas.objects.core.DataSetAnnotations an = (uk.ac.vamsas.objects.core.DataSetAnnotations) getjv2vObj(alan);
689 int[] gapMap = getGapMap(AlSeqMaps, alan);
692 an = new uk.ac.vamsas.objects.core.DataSetAnnotations();
693 initRangeAnnotationType(an, alan, gapMap);
695 an.setProvenance(dummyProvenance()); // get provenance as user
696 // created, or jnet, or
698 setAnnotationType(an, alan);
699 an.setGroup(Integer.toString(alan.graphGroup)); // // JBPNote -
707 if (alan.getThreshold()!=null && alan.getThreshold().displayed)
709 an.addProperty(newProperty(THRESHOLD, "float", ""+alan.getThreshold().value));
710 if (alan.getThreshold().label!=null)
711 an.addProperty(newProperty(THRESHOLD+"Name", "string", ""+alan.getThreshold().label));
713 ((DataSet) sref.getV_parent()).addDataSetAnnotations(an);
714 bindjvvobj(alan, an);
718 // update reference sequence Annotation
719 if (an.getModifiable() == null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK
722 // verify existing alignment sequence annotation is up to date
723 System.out.println("update dataset sequence annotation.");
727 // verify existing alignment sequence annotation is up to date
729 .println("make new alignment dataset sequence annotation if modification has happened.");
735 private int[] getGapMap(HashMap AlSeqMaps, AlignmentAnnotation alan)
738 if (AlSeqMaps.containsKey(alan.sequenceRef))
740 gapMap = (int[]) AlSeqMaps.get(alan.sequenceRef);
744 gapMap = new int[alan.sequenceRef.getLength()];
745 // map from alignment position to sequence position.
746 int[] sgapMap = alan.sequenceRef.gapMap();
747 for (int a = 0; a < sgapMap.length; a++)
749 gapMap[sgapMap[a]] = a;
755 private void saveAlignmentSequenceAnnotation(HashMap AlSeqMaps,
756 AlignmentSequence alsref, AlignmentAnnotation alan)
760 // objects.core.AlignmentSequence alsref = (uk.ac.vamsas.
761 // objects.core.AlignmentSequence) sref;
762 uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation an = (uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation) getjv2vObj(alan);
763 int[] gapMap = getGapMap(AlSeqMaps, alan);
766 an = new uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation();
767 initRangeAnnotationType(an, alan, gapMap);
769 * I mean here that we don't actually have a semantic 'type' for the
770 * annotation (this might be - score, intrinsic property, measurement,
771 * something extracted from another program, etc)
773 an.setType(JALVIEW_ANNOTATION_ROW); // TODO: better fix
774 // this rough guess ;)
775 alsref.addAlignmentSequenceAnnotation(an);
776 bindjvvobj(alan, an);
777 // These properties are directly supported by the
778 // AlignmentSequenceAnnotation type.
779 setAnnotationType(an, alan);
780 an.setProvenance(dummyProvenance()); // get provenance as user
781 // created, or jnet, or
786 // update reference sequence Annotation
787 if (an.getModifiable() == null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK
790 // verify existing alignment sequence annotation is up to date
791 System.out.println("update alignment sequence annotation.");
795 // verify existing alignment sequence annotation is up to date
797 .println("make new alignment sequence annotation if modification has happened.");
803 * set vamsas annotation object type from jalview annotation
807 private void setAnnotationType(RangeAnnotation an, AlignmentAnnotation alan)
809 if (an instanceof AlignmentSequenceAnnotation)
811 if (alan.graph != AlignmentAnnotation.NO_GRAPH)
813 ((AlignmentSequenceAnnotation)an).setGraph(true);
816 ((AlignmentSequenceAnnotation)an).setGraph(false);
819 if (an instanceof uk.ac.vamsas.objects.core.AlignmentAnnotation)
821 if (alan.graph != AlignmentAnnotation.NO_GRAPH)
823 ((uk.ac.vamsas.objects.core.AlignmentAnnotation)an).setGraph(true);
826 ((uk.ac.vamsas.objects.core.AlignmentAnnotation)an).setGraph(false);
831 case AlignmentAnnotation.BAR_GRAPH:
832 an.addProperty(newProperty(DISCRETE_ANNOTATION, "boolean","true"));
834 case AlignmentAnnotation.LINE_GRAPH:
835 an.addProperty(newProperty(CONTINUOUS_ANNOTATION, "boolean","true"));
838 // don't add any kind of discrete or continous property info.
842 private Property newProperty(String name, String type, String content)
844 Property vProperty = new Property();
845 vProperty.setName(name);
848 vProperty.setType(type);
852 vProperty.setType("String");
854 vProperty.setContent(content);
859 * correctly create a RangeAnnotation from a jalview sequence feature
862 * (typically DataSetAnnotations or AlignmentSequenceAnnotation)
864 * (the feature to be mapped from)
867 private RangeAnnotation getDSAnnotationFromJalview(RangeAnnotation dsa,
868 SequenceFeature feature)
870 dsa.setType(feature.getType());
871 Seg vSeg = new Seg();
872 vSeg.setStart(feature.getBegin());
873 vSeg.setEnd(feature.getEnd());
874 vSeg.setInclusive(true);
876 dsa.setDescription(feature.getDescription());
877 dsa.setStatus(feature.getStatus());
878 if (feature.links != null && feature.links.size() > 0)
880 for (int i = 0, iSize = feature.links.size(); i < iSize; i++)
882 String link = (String) feature.links.elementAt(i);
883 int sep = link.indexOf('|');
886 Link vLink = new Link();
889 vLink.setContent(link.substring(0, sep - 1));
893 vLink.setContent("");
895 vLink.setHref(link.substring(sep + 1)); // TODO: validate href.
900 dsa.setGroup(feature.getFeatureGroup());
905 * get start<end range of segment, adjusting for inclusivity flag and
909 * @param ensureDirection
910 * when true - always ensure start is less than end.
911 * @return int[] { start, end, direction} where direction==1 for range running
914 private int[] getSegRange(Seg visSeg, boolean ensureDirection)
916 boolean incl = visSeg.getInclusive();
917 // adjust for inclusive flag.
918 int pol = (visSeg.getStart() <= visSeg.getEnd()) ? 1 : -1; // polarity of
920 int start = visSeg.getStart() + (incl ? 0 : pol);
921 int end = visSeg.getEnd() + (incl ? 0 : -pol);
922 if (ensureDirection && pol == -1)
924 // jalview doesn't deal with inverted ranges, yet.
930 { start, end, pol < 0 ? 1 : 0 };
936 * @return true if annotation is not to be stored in document
938 private boolean isJalviewOnly(AlignmentAnnotation annotation)
940 return annotation.label.equals("Quality")
941 || annotation.label.equals("Conservation")
942 || annotation.label.equals("Consensus");
946 * This will return the first AlignFrame viewing AlignViewport av. It will
947 * break if there are more than one AlignFrames viewing a particular av. This
948 * also shouldn't be in the io package.
951 * @return alignFrame for av
953 public AlignFrame getAlignFrameFor(AlignViewport av)
955 if (Desktop.desktop != null)
957 javax.swing.JInternalFrame[] frames = Desktop.instance.getAllFrames();
959 for (int t = 0; t < frames.length; t++)
961 if (frames[t] instanceof AlignFrame)
963 if (((AlignFrame) frames[t]).getViewport() == av)
965 return (AlignFrame) frames[t];
973 public void updateToJalview()
975 VAMSAS _roots[] = cdoc.getVamsasRoots();
977 for (int _root = 0; _root < _roots.length; _root++)
979 VAMSAS root = _roots[_root];
980 boolean newds = false;
981 for (int _ds = 0, _nds = root.getDataSetCount(); _ds < _nds; _ds++)
983 // ///////////////////////////////////
985 DataSet dataset = root.getDataSet(_ds);
986 int i, iSize = dataset.getSequenceCount();
988 jalview.datamodel.Alignment jdataset = (jalview.datamodel.Alignment) getvObj2jv(dataset);
990 if (jdataset == null)
992 Cache.log.debug("Initialising new jalview dataset fields");
994 dsseqs = new Vector();
998 Cache.log.debug("Update jalview dataset from vamsas.");
999 jremain = jdataset.getHeight();
1000 dsseqs = jdataset.getSequences();
1003 // TODO: test sequence merging - we preserve existing non vamsas
1004 // sequences but add in any new vamsas ones, and don't yet update any
1005 // sequence attributes
1006 for (i = 0; i < iSize; i++)
1008 Sequence vdseq = dataset.getSequence(i);
1009 jalview.datamodel.SequenceI dsseq = (SequenceI) getvObj2jv(vdseq);
1012 if (!dsseq.getSequenceAsString().equals(vdseq.getSequence()))
1015 "Broken! - mismatch of dataset sequence: and jalview internal dataset sequence.");
1021 dsseq = new jalview.datamodel.Sequence(dataset.getSequence(i)
1022 .getName(), dataset.getSequence(i).getSequence(),
1023 (int) dataset.getSequence(i).getStart(), (int) dataset
1024 .getSequence(i).getEnd());
1025 dsseq.setDescription(dataset.getSequence(i).getDescription());
1026 bindjvvobj(dsseq, dataset.getSequence(i));
1027 dsseq.setVamsasId(dataset.getSequence(i).getVorbaId().getId());
1030 if (vdseq.getDbRefCount() > 0)
1032 DbRef[] dbref = vdseq.getDbRef();
1033 for (int db = 0; db < dbref.length; db++)
1035 new jalview.io.vamsas.Dbref(this, dbref[db], vdseq, dsseq);
1043 SequenceI[] seqs = new SequenceI[dsseqs.size()];
1044 for (i = 0, iSize = dsseqs.size(); i < iSize; i++)
1046 seqs[i] = (SequenceI) dsseqs.elementAt(i);
1047 dsseqs.setElementAt(null, i);
1049 jdataset = new jalview.datamodel.Alignment(seqs);
1050 Cache.log.debug("New vamsas dataset imported into jalview.");
1051 bindjvvobj(jdataset, dataset);
1054 // add any new dataset sequence feature annotations
1055 if (dataset.getDataSetAnnotations() != null)
1057 for (int dsa = 0; dsa < dataset.getDataSetAnnotationsCount(); dsa++)
1059 DataSetAnnotations dseta = dataset.getDataSetAnnotations(dsa);
1060 // TODO: deal with group annotation on datset sequences.
1061 if (dseta.getSeqRefCount() == 1)
1063 SequenceI dsSeq = (SequenceI) getvObj2jv((Vobject) dseta
1064 .getSeqRef(0)); // TODO: deal with group dataset
1068 jalview.bin.Cache.log
1069 .warn("Couldn't resolve jalview sequenceI for dataset object reference "
1070 + ((Vobject) dataset.getDataSetAnnotations(
1071 dsa).getSeqRef(0)).getVorbaId()
1076 if (dseta.getAnnotationElementCount() == 0)
1078 jalview.datamodel.SequenceFeature sf = (jalview.datamodel.SequenceFeature) getvObj2jv(dseta);
1082 .addSequenceFeature(sf = getJalviewSeqFeature(dseta));
1083 bindjvvobj(sf, dseta);
1088 // TODO: deal with alignmentAnnotation style annotation
1089 // appearing on dataset sequences.
1090 // JBPNote: we could just add them to all alignments but
1091 // that may complicate cross references in the jalview
1094 .warn("Ignoring dataset annotation with annotationElements. Not yet supported in jalview.");
1100 if (dataset.getAlignmentCount() > 0)
1102 // LOAD ALIGNMENTS from DATASET
1104 for (int al = 0, nal = dataset.getAlignmentCount(); al < nal; al++)
1106 uk.ac.vamsas.objects.core.Alignment alignment = dataset
1108 AlignViewport av = (AlignViewport) getvObj2jv(alignment);
1109 jalview.datamodel.AlignmentI jal = null;
1112 jal = av.getAlignment();
1114 iSize = alignment.getAlignmentSequenceCount();
1115 boolean newal = (jal == null) ? true : false;
1116 Vector newasAnnots = new Vector();
1117 char gapChar = ' '; // default for new alignments read in from the
1121 dsseqs = jal.getSequences(); // for merge/update
1122 gapChar = jal.getGapCharacter();
1126 dsseqs = new Vector();
1128 char valGapchar = alignment.getGapChar().charAt(0);
1129 for (i = 0; i < iSize; i++)
1131 AlignmentSequence valseq = alignment.getAlignmentSequence(i);
1132 jalview.datamodel.SequenceI alseq = (SequenceI) getvObj2jv(valseq);
1135 // TODO: upperCase/LowerCase situation here ? do we allow it ?
1136 // if (!alseq.getSequence().equals(valseq.getSequence())) {
1137 // throw new Error("Broken! - mismatch of dataset sequence and
1138 // jalview internal dataset sequence.");
1139 if (Cache.log.isDebugEnabled())
1141 Cache.log.debug("Updating apparently edited sequence "
1144 // this might go *horribly* wrong
1145 alseq.setSequence(new String(valseq.getSequence()).replace(
1146 valGapchar, gapChar));
1151 alseq = new jalview.datamodel.Sequence(valseq.getName(),
1152 valseq.getSequence().replace(valGapchar, gapChar),
1153 (int) valseq.getStart(), (int) valseq.getEnd());
1155 Vobject datsetseq = (Vobject) valseq.getRefid();
1156 if (datsetseq != null)
1159 .setDatasetSequence((SequenceI) getvObj2jv(datsetseq)); // exceptions
1161 // AlignemntSequence
1171 .error("Invalid dataset sequence id (null) for alignment sequence "
1172 + valseq.getVorbaId());
1174 bindjvvobj(alseq, valseq);
1175 alseq.setVamsasId(valseq.getVorbaId().getId());
1178 if (valseq.getAlignmentSequenceAnnotationCount() > 0)
1180 AlignmentSequenceAnnotation[] vasannot = valseq
1181 .getAlignmentSequenceAnnotation();
1182 for (int a = 0; a < vasannot.length; a++)
1184 jalview.datamodel.AlignmentAnnotation asa = (jalview.datamodel.AlignmentAnnotation) getvObj2jv(vasannot[a]); // TODO:
1192 int se[] = getBounds(vasannot[a]);
1193 asa = getjAlignmentAnnotation(jal, vasannot[a]);
1194 asa.setSequenceRef(alseq);
1195 asa.createSequenceMapping(alseq, se[0], false); // TODO:
1206 alseq.addAlignmentAnnotation(asa);
1207 bindjvvobj(asa, vasannot[a]);
1208 newasAnnots.add(asa);
1212 // update existing annotation - can do this in place
1213 if (vasannot[a].getModifiable() == null) // TODO: USE
1219 .info("UNIMPLEMENTED: not recovering user modifiable sequence alignment annotation");
1220 // TODO: should at least replace with new one - otherwise
1221 // things will break
1222 // basically do this:
1223 // int se[] = getBounds(vasannot[a]);
1224 // asa.update(getjAlignmentAnnotation(jal, vasannot[a]));
1225 // // update from another annotation object in place.
1226 // asa.createSequenceMapping(alseq, se[0], false);
1235 SequenceI[] seqs = new SequenceI[dsseqs.size()];
1236 for (i = 0, iSize = dsseqs.size(); i < iSize; i++)
1238 seqs[i] = (SequenceI) dsseqs.elementAt(i);
1239 dsseqs.setElementAt(null, i);
1241 jal = new jalview.datamodel.Alignment(seqs);
1242 Cache.log.debug("New vamsas alignment imported into jalview "
1243 + alignment.getVorbaId().getId());
1244 jal.setDataset(jdataset);
1246 if (newasAnnots != null && newasAnnots.size() > 0)
1248 // Add the new sequence annotations in to the alignment.
1249 for (int an = 0, anSize = newasAnnots.size(); an < anSize; an++)
1251 jal.addAnnotation((AlignmentAnnotation) newasAnnots
1253 // TODO: check if anything has to be done - like calling
1254 // adjustForAlignment or something.
1255 newasAnnots.setElementAt(null, an);
1259 // //////////////////////////////////////////
1260 // //LOAD ANNOTATIONS FOR THE ALIGNMENT
1261 // ////////////////////////////////////
1262 if (alignment.getAlignmentAnnotationCount() > 0)
1264 uk.ac.vamsas.objects.core.AlignmentAnnotation[] an = alignment
1265 .getAlignmentAnnotation();
1267 for (int j = 0; j < an.length; j++)
1269 jalview.datamodel.AlignmentAnnotation jan = (jalview.datamodel.AlignmentAnnotation) getvObj2jv(an[j]);
1272 // update or stay the same.
1273 // TODO: should at least replace with a new one - otherwise
1274 // things will break
1275 // basically do this:
1276 // jan.update(getjAlignmentAnnotation(jal, an[a])); // update
1277 // from another annotation object in place.
1280 .debug("update from vamsas alignment annotation to existing jalview alignment annotation.");
1281 if (an[j].getModifiable() == null) // TODO: USE VAMSAS
1282 // LIBRARY OBJECT LOCK
1285 // TODO: user defined annotation is totally mutable... - so
1286 // load it up or throw away if locally edited.
1288 .info("NOT IMPLEMENTED - Recovering user-modifiable annotation - yet...");
1290 // TODO: compare annotation element rows
1291 // TODO: compare props.
1295 jan = getjAlignmentAnnotation(jal, an[j]);
1296 jal.addAnnotation(jan);
1297 bindjvvobj(jan, an[j]);
1301 AlignFrame alignFrame;
1304 Cache.log.debug("New alignframe for alignment "
1305 + alignment.getVorbaId());
1306 // ///////////////////////////////
1307 // construct alignment view
1308 alignFrame = new AlignFrame(jal, AlignFrame.DEFAULT_WIDTH,
1309 AlignFrame.DEFAULT_HEIGHT);
1310 av = alignFrame.getViewport();
1311 String title = alignment.getProvenance().getEntry(
1312 alignment.getProvenance().getEntryCount() - 1)
1314 if (alignment.getPropertyCount() > 0)
1316 for (int p = 0, pe = alignment.getPropertyCount(); p < pe; p++)
1318 if (alignment.getProperty(p).getName().equals(
1321 title = alignment.getProperty(p).getContent();
1325 // TODO: automatically create meaningful title for a vamsas
1326 // alignment using its provenance.
1327 if (Cache.log.isDebugEnabled())
1330 + alignment.getVorbaId() + ")";
1333 jalview.gui.Desktop.addInternalFrame(alignFrame, title
1335 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
1336 bindjvvobj(av, alignment);
1340 // find the alignFrame for jal.
1341 // TODO: fix this so we retrieve the alignFrame handing av
1343 alignFrame = getAlignFrameFor(av);
1346 // /////////////////////////////////////
1347 if (alignment.getTreeCount() > 0)
1350 for (int t = 0; t < alignment.getTreeCount(); t++)
1352 jalview.io.vamsas.Tree vstree = new jalview.io.vamsas.Tree(
1353 this, alignFrame, alignment.getTree(t));
1354 TreePanel tp = alignFrame
1355 .ShowNewickTree(vstree.getNewickTree(), vstree
1356 .getTitle(), vstree.getInputData(), 600,
1357 500, t * 20 + 50, t * 20 + 50);
1359 bindjvvobj(tp, alignment.getTree(t));
1362 Cache.log.warn("Cannot create tree for tree "+t+" in document ("+alignment.getTree(t).getVorbaId());
1370 // we do sequenceMappings last because they span all datasets in a vamsas
1372 for (int _ds = 0, _nds = root.getDataSetCount(); _ds < _nds; _ds++)
1374 DataSet dataset = root.getDataSet(_ds);
1375 if (dataset.getSequenceMappingCount() > 0)
1377 for (int sm = 0, smCount = dataset.getSequenceMappingCount(); sm < smCount; sm++)
1379 Rangetype seqmap = new jalview.io.vamsas.Sequencemapping(this,
1380 dataset.getSequenceMapping(sm));
1387 // bitfields - should be a template in j1.5
1388 private static int HASSECSTR = 0;
1390 private static int HASVALS = 1;
1392 private static int HASHPHOB = 2;
1394 private static int HASDC = 3;
1396 private static int HASDESCSTR = 4;
1398 private static int HASTWOSTATE = 5; // not used yet.
1401 * parses the AnnotationElements - if they exist - into
1402 * jalview.datamodel.Annotation[] rows Two annotation rows are made if there
1403 * are distinct annotation for both at 'pos' and 'after pos' at any particular
1407 * @return { boolean[static int constants ], int[ae.length] - map to annotated
1408 * object frame, jalview.datamodel.Annotation[],
1409 * jalview.datamodel.Annotation[] (after)}
1411 private Object[] parseRangeAnnotation(
1412 uk.ac.vamsas.objects.core.RangeAnnotation annotation)
1414 // set these attributes by looking in the annotation to decide what kind of
1415 // alignment annotation rows will be made
1416 // TODO: potentially we might make several annotation rows from one vamsas
1417 // alignment annotation. the jv2Vobj binding mechanism
1418 // may not quite cope with this (without binding an array of annotations to
1419 // a vamsas alignment annotation)
1420 // summary flags saying what we found over the set of annotation rows.
1421 boolean[] AeContent = new boolean[]
1422 { false, false, false, false, false };
1423 int[] rangeMap = getMapping(annotation);
1424 jalview.datamodel.Annotation[][] anot = new jalview.datamodel.Annotation[][]
1425 { new jalview.datamodel.Annotation[rangeMap.length],
1426 new jalview.datamodel.Annotation[rangeMap.length] };
1427 boolean mergeable = true; // false if 'after positions cant be placed on
1428 // same annotation row as positions.
1430 if (annotation.getAnnotationElementCount() > 0)
1432 AnnotationElement ae[] = annotation.getAnnotationElement();
1433 for (int aa = 0; aa < ae.length; aa++)
1435 int pos = (int) ae[aa].getPosition() - 1; // pos counts from 1 to
1436 // (|seg.start-seg.end|+1)
1437 if (pos >= 0 && pos < rangeMap.length)
1439 int row = ae[aa].getAfter() ? 1 : 0;
1440 if (anot[row][pos] != null)
1442 // only time this should happen is if the After flag is set.
1443 Cache.log.debug("Ignoring duplicate annotation site at " + pos);
1446 if (anot[1 - row][pos] != null)
1451 if (ae[aa].getDescription() != null)
1453 desc = ae[aa].getDescription();
1454 if (desc.length() > 0)
1456 // have imported valid description string
1457 AeContent[HASDESCSTR] = true;
1460 String dc = null; // ae[aa].getDisplayCharacter()==null ? "dc" :
1461 // ae[aa].getDisplayCharacter();
1462 String ss = null; // ae[aa].getSecondaryStructure()==null ? "ss" :
1463 // ae[aa].getSecondaryStructure();
1464 java.awt.Color colour = null;
1465 if (ae[aa].getGlyphCount() > 0)
1467 Glyph[] glyphs = ae[aa].getGlyph();
1468 for (int g = 0; g < glyphs.length; g++)
1473 uk.ac.vamsas.objects.utils.GlyphDictionary.PROTEIN_SS_3STATE))
1475 ss = glyphs[g].getContent();
1476 AeContent[HASSECSTR] = true;
1481 uk.ac.vamsas.objects.utils.GlyphDictionary.PROTEIN_HD_HYDRO))
1483 Cache.log.debug("ignoring hydrophobicity glyph marker.");
1484 AeContent[HASHPHOB] = true;
1485 char c = (dc = glyphs[g].getContent()).charAt(0);
1486 // dc may get overwritten - but we still set the colour.
1487 colour = new java.awt.Color(c == '+' ? 255 : 0,
1488 c == '.' ? 255 : 0, c == '-' ? 255 : 0);
1491 else if (glyphs[g].getDict().equals(
1492 uk.ac.vamsas.objects.utils.GlyphDictionary.DEFAULT))
1494 dc = glyphs[g].getContent();
1495 AeContent[HASDC] = true;
1499 Cache.log.debug("IMPLEMENTATION TODO: Ignoring unknown glyph type "
1500 + glyphs[g].getDict());
1505 if (ae[aa].getValueCount() > 0)
1507 AeContent[HASVALS] = true;
1508 if (ae[aa].getValueCount() > 1)
1510 Cache.log.warn("ignoring additional "
1511 + (ae[aa].getValueCount() - 1)
1512 + "values in annotation element.");
1514 val = ae[aa].getValue(0);
1518 anot[row][pos] = new jalview.datamodel.Annotation(
1519 (dc != null) ? dc : "", desc, (ss != null) ? ss
1520 .charAt(0) : ' ', val);
1524 anot[row][pos] = new jalview.datamodel.Annotation(
1525 (dc != null) ? dc : "", desc, (ss != null) ? ss
1526 .charAt(0) : ' ', val, colour);
1531 Cache.log.warn("Ignoring out of bound annotation element " + aa
1532 + " in " + annotation.getVorbaId().getId());
1535 // decide on how many annotation rows are needed.
1538 for (int i = 0; i < anot[0].length; i++)
1540 if (anot[1][i] != null)
1542 anot[0][i] = anot[1][i];
1543 anot[0][i].description = anot[0][i].description + " (after)";
1544 AeContent[HASDESCSTR] = true; // we have valid description string
1553 for (int i = 0; i < anot[0].length; i++)
1555 anot[1][i].description = anot[1][i].description + " (after)";
1559 { AeContent, rangeMap, anot[0], anot[1] };
1563 // no annotations to parse. Just return an empty annotationElement[]
1566 { AeContent, rangeMap, anot[0], anot[1] };
1573 * the jalview alignment to which the annotation will be attached
1574 * (ideally - freshly updated from corresponding vamsas alignment)
1576 * @return unbound jalview alignment annotation object.
1578 private jalview.datamodel.AlignmentAnnotation getjAlignmentAnnotation(
1579 jalview.datamodel.AlignmentI jal,
1580 uk.ac.vamsas.objects.core.RangeAnnotation annotation)
1582 if (annotation == null)
1587 // hasSequenceRef=annotation.getClass().equals(uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation.class);
1588 // boolean hasProvenance=hasSequenceRef ||
1589 // (annotation.getClass().equals(uk.ac.vamsas.objects.core.AlignmentAnnotation.class));
1591 * int se[] = getBounds(annotation); if (se==null) se=new int[]
1592 * {0,jal.getWidth()-1};
1594 Object[] parsedRangeAnnotation = parseRangeAnnotation(annotation);
1595 String a_label = annotation.getLabel();
1596 String a_descr = annotation.getDescription();
1599 boolean interp=true; // cleared if annotation is DISCRETE
1600 // set type and other attributes from properties
1601 if (annotation.getPropertyCount() > 0)
1603 // look for special jalview properties
1604 uk.ac.vamsas.objects.core.Property[] props = annotation
1606 for (int p = 0; p < props.length; p++)
1608 if (props[p].getName().equalsIgnoreCase(DISCRETE_ANNOTATION))
1610 type = AlignmentAnnotation.BAR_GRAPH;
1613 (props[p].getName().equalsIgnoreCase(CONTINUOUS_ANNOTATION)) {
1614 type = AlignmentAnnotation.LINE_GRAPH;
1616 (props[p].getName().equalsIgnoreCase(THRESHOLD))
1620 val = new Float(props[p].getContent());
1621 }catch (Exception e)
1623 Cache.log.warn("Failed to parse threshold property");
1628 gl = new GraphLine(val.floatValue(), "", java.awt.Color.black);
1631 gl.value = val.floatValue();
1634 else if (props[p].getName().equalsIgnoreCase(THRESHOLD+"Name"))
1637 gl = new GraphLine(0, "", java.awt.Color.black);
1638 gl.label = props[p].getContent();
1642 jalview.datamodel.AlignmentAnnotation jan = null;
1643 if (a_label == null || a_label.length() == 0)
1645 a_label = annotation.getType();
1646 if (a_label.length() == 0)
1648 a_label = "Unamed annotation";
1651 if (a_descr == null || a_descr.length() == 0)
1653 a_descr = "Annotation of type '" + annotation.getType() + "'";
1655 if (parsedRangeAnnotation == null)
1658 .debug("Inserting empty annotation row elements for a whole-alignment annotation.");
1662 if (parsedRangeAnnotation[3] != null)
1664 Cache.log.warn("Ignoring 'After' annotation row in "
1665 + annotation.getVorbaId());
1667 jalview.datamodel.Annotation[] arow = (jalview.datamodel.Annotation[]) parsedRangeAnnotation[2];
1668 boolean[] has = (boolean[]) parsedRangeAnnotation[0];
1669 // VAMSAS: getGraph is only on derived annotation for alignments - in this
1670 // way its 'odd' - there is already an existing TODO about removing this
1671 // flag as being redundant
1674 * ((annotation.getClass().equals(uk.ac.vamsas.objects.core.AlignmentAnnotation.class) &&
1675 * ((uk.ac.vamsas.objects.core.AlignmentAnnotation)annotation).getGraph()) ||
1676 * (hasSequenceRef=true &&
1677 * ((uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation)annotation).getGraph())) {
1683 type = jalview.datamodel.AlignmentAnnotation.BAR_GRAPH; // default type of value annotation
1686 // no hints - so we ensure HPHOB display is like this.
1687 type = jalview.datamodel.AlignmentAnnotation.BAR_GRAPH;
1690 // make bounds and automatic description strings for jalview user's
1691 // benefit (these shouldn't be written back to vamsas document)
1692 boolean first = true;
1693 float min = 0, max = 1;
1695 for (int i = 0; i < arow.length; i++)
1697 if (arow[i] != null)
1699 if (i - lastval > 1 && interp)
1701 // do some interpolation *between* points
1702 if (arow[lastval] != null)
1704 float interval = arow[i].value - arow[lastval].value;
1705 interval /= i - lastval;
1706 float base = arow[lastval].value;
1707 for (int ip = lastval + 1, np = 0; ip < i; np++, ip++)
1709 arow[ip] = new jalview.datamodel.Annotation("", "", ' ',
1710 interval * np + base);
1711 // NB - Interpolated points don't get a tooltip and
1717 // check range - shouldn't we have a min and max property in the
1718 // annotation object ?
1721 min = max = arow[i].value;
1726 if (arow[i].value < min)
1728 min = arow[i].value;
1730 else if (arow[i].value > max)
1732 max = arow[i].value;
1735 // make tooltip and display char value
1736 if (!has[HASDESCSTR])
1738 arow[i].description = arow[i].value + "";
1744 if (arow[i].description!=null && arow[i].description.length()<3)
1746 // copy over the description as the display char.
1747 arow[i].displayCharacter = new String(arow[i].description);
1751 // mark the position as a point used for the interpolation.
1752 arow[i].displayCharacter = arow[i].value + "";
1757 jan = new jalview.datamodel.AlignmentAnnotation(a_label, a_descr,
1758 arow, min, max, type);
1762 jan = new jalview.datamodel.AlignmentAnnotation(a_label, a_descr,
1764 jan.setThreshold(null);
1766 if (annotation.getLinkCount() > 0)
1768 Cache.log.warn("Ignoring " + annotation.getLinkCount()
1769 + "links added to AlignmentAnnotation.");
1771 if (annotation.getModifiable() == null) // TODO: USE VAMSAS LIBRARY OBJECT
1774 jan.editable = true;
1778 if (annotation.getGroup() != null
1779 && annotation.getGroup().length() > 0)
1781 jan.graphGroup = Integer.parseInt(annotation.getGroup());
1783 } catch (Exception e)
1786 .info("UNIMPLEMENTED : Couldn't parse non-integer group value for setting graphGroup correctly.");
1795 private SequenceFeature getJalviewSeqFeature(RangeAnnotation dseta)
1797 int[] se = getBounds(dseta);
1798 SequenceFeature sf = new jalview.datamodel.SequenceFeature(dseta
1799 .getType(), dseta.getDescription(), dseta.getStatus(), se[0],
1800 se[1], dseta.getGroup());
1801 if (dseta.getLinkCount() > 0)
1803 Link[] links = dseta.getLink();
1804 for (int i = 0; i < links.length; i++)
1806 sf.addLink(links[i].getContent() + "|" + links[i].getHref());
1813 * get real bounds of a RangeType's specification. start and end are an
1814 * inclusive range within which all segments and positions lie. TODO: refactor
1818 * @return int[] { start, end}
1820 private int[] getBounds(RangeType dseta)
1825 if (dseta.getSegCount() > 0 && dseta.getPosCount() > 0)
1828 "Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!");
1830 if (dseta.getSegCount() > 0)
1832 se = getSegRange(dseta.getSeg(0), true);
1833 for (int s = 1, sSize = dseta.getSegCount(); s < sSize; s++)
1835 int nse[] = getSegRange(dseta.getSeg(s), true);
1846 if (dseta.getPosCount() > 0)
1848 // could do a polarity for pos range too. and pass back indication of
1850 int pos = dseta.getPos(0).getI();
1853 for (int p = 0, pSize = dseta.getPosCount(); p < pSize; p++)
1855 pos = dseta.getPos(p).getI();
1872 * map from a rangeType's internal frame to the referenced object's coordinate
1876 * @return int [] { ref(pos)...} for all pos in rangeType's frame.
1878 private int[] getMapping(RangeType dseta)
1880 Vector posList = new Vector();
1884 if (dseta.getSegCount() > 0 && dseta.getPosCount() > 0)
1887 "Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!");
1889 if (dseta.getSegCount() > 0)
1891 for (int s = 0, sSize = dseta.getSegCount(); s < sSize; s++)
1893 se = getSegRange(dseta.getSeg(s), false);
1894 int se_end = se[1 - se[2]] + (se[2] == 0 ? 1 : -1);
1895 for (int p = se[se[2]]; p != se_end; p += se[2] == 0 ? 1 : -1)
1897 posList.add(new Integer(p));
1901 else if (dseta.getPosCount() > 0)
1903 int pos = dseta.getPos(0).getI();
1905 for (int p = 0, pSize = dseta.getPosCount(); p < pSize; p++)
1907 pos = dseta.getPos(p).getI();
1908 posList.add(new Integer(pos));
1912 if (posList != null && posList.size() > 0)
1914 int[] range = new int[posList.size()];
1915 for (int i = 0; i < range.length; i++)
1917 range[i] = ((Integer) posList.elementAt(i)).intValue();
1928 * where the from range is the local mapped range, and the to range
1929 * is the 'mapped' range in the MapRangeType
1936 private jalview.util.MapList parsemapType(MapType maprange, int localu,
1939 jalview.util.MapList ml = null;
1940 int[] localRange = getMapping(maprange.getLocal());
1941 int[] mappedRange = getMapping(maprange.getMapped());
1942 long lu = maprange.getLocal().hasUnit() ? maprange.getLocal().getUnit()
1944 long mu = maprange.getMapped().hasUnit() ? maprange.getMapped()
1945 .getUnit() : mappedu;
1946 ml = new jalview.util.MapList(localRange, mappedRange, (int) lu,
1952 * initialise a range type object from a set of start/end inclusive intervals
1957 private void initRangeType(RangeType mrt, int[] range)
1959 for (int i = 0; i < range.length; i += 2)
1961 Seg vSeg = new Seg();
1962 vSeg.setStart(range[i]);
1963 vSeg.setEnd(range[i + 1]);
1969 * initialise a MapType object from a MapList object.
1975 private void initMapType(MapType maprange, jalview.util.MapList ml,
1978 maprange.setLocal(new Local());
1979 maprange.setMapped(new Mapped());
1980 initRangeType(maprange.getLocal(), ml.getFromRanges());
1981 initRangeType(maprange.getMapped(), ml.getToRanges());
1984 maprange.getLocal().setUnit(ml.getFromRatio());
1985 maprange.getLocal().setUnit(ml.getToRatio());
1990 * not needed now. Provenance getVamsasProvenance(jalview.datamodel.Provenance
1991 * jprov) { jalview.datamodel.ProvenanceEntry[] entries = null; // TODO: fix
1992 * App and Action here. Provenance prov = new Provenance();
1993 * org.exolab.castor.types.Date date = new org.exolab.castor.types.Date( new
1994 * java.util.Date()); Entry provEntry;
1996 * if (jprov != null) { entries = jprov.getEntries(); for (int i = 0; i <
1997 * entries.length; i++) { provEntry = new Entry(); try { date = new
1998 * org.exolab.castor.types.Date(entries[i].getDate()); } catch (Exception ex) {
1999 * ex.printStackTrace();
2001 * date = new org.exolab.castor.types.Date(entries[i].getDate()); }
2002 * provEntry.setDate(date); provEntry.setUser(entries[i].getUser());
2003 * provEntry.setAction(entries[i].getAction()); prov.addEntry(provEntry); } }
2004 * else { provEntry = new Entry(); provEntry.setDate(date);
2005 * provEntry.setUser(System.getProperty("user.name")); // TODO: ext string
2006 * provEntry.setApp("JVAPP"); // TODO: ext string provEntry.setAction(action);
2007 * prov.addEntry(provEntry); }
2011 jalview.datamodel.Provenance getJalviewProvenance(Provenance prov)
2013 // TODO: fix App and Action entries and check use of provenance in jalview.
2014 jalview.datamodel.Provenance jprov = new jalview.datamodel.Provenance();
2015 for (int i = 0; i < prov.getEntryCount(); i++)
2017 jprov.addEntry(prov.getEntry(i).getUser(), prov.getEntry(i)
2018 .getAction(), prov.getEntry(i).getDate(), prov.getEntry(i)
2027 * @return default initial provenance list for a Jalview created vamsas
2030 Provenance dummyProvenance()
2032 return dummyProvenance(null);
2035 Entry dummyPEntry(String action)
2037 Entry entry = new Entry();
2038 entry.setApp(this.provEntry.getApp());
2041 entry.setAction(action);
2045 entry.setAction("created.");
2047 entry.setDate(new java.util.Date());
2048 entry.setUser(this.provEntry.getUser());
2052 Provenance dummyProvenance(String action)
2054 Provenance prov = new Provenance();
2055 prov.addEntry(dummyPEntry(action));
2059 void addProvenance(Provenance p, String action)
2061 p.addEntry(dummyPEntry(action));
2064 public Entry getProvEntry()
2069 public IClientDocument getClientDocument()
2074 public IdentityHashMap getJvObjectBinding()
2079 public Hashtable getVamsasObjectBinding()
2084 public void storeSequenceMappings(AlignViewport viewport, String title)
2087 AlignViewport av = viewport;
2090 jalview.datamodel.AlignmentI jal = av.getAlignment();
2091 // /////////////////////////////////////////
2093 DataSet dataset = null;
2094 if (jal.getDataset() == null)
2096 Cache.log.warn("Creating new dataset for an alignment.");
2097 jal.setDataset(null);
2099 dataset = (DataSet) getjv2vObj(jal.getDataset());
2100 // Store any sequence mappings.
2101 if (av.getAlignment().getCodonFrames() != null
2102 && av.getAlignment().getCodonFrames().length > 0)
2104 jalview.datamodel.AlignedCodonFrame[] cframes = av.getAlignment()
2106 for (int cf = 0; cf < cframes.length; cf++)
2108 if (cframes[cf].getdnaSeqs().length > 0)
2110 jalview.datamodel.SequenceI[] dmps = cframes[cf].getdnaSeqs();
2111 jalview.datamodel.Mapping[] mps = cframes[cf].getProtMappings();
2112 for (int smp = 0; smp < mps.length; smp++)
2114 uk.ac.vamsas.objects.core.SequenceType mfrom = (SequenceType) getjv2vObj(dmps[smp]);
2117 new jalview.io.vamsas.Sequencemapping(this, mps[smp],
2123 .warn("NO Vamsas Binding for local sequence! NOT CREATING MAPPING FOR "
2126 + mps[smp].getTo().getName());
2132 } catch (Exception e)
2134 throw new Exception("Couldn't store sequence mappings for " + title,