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.SequenceFeature;
28 import jalview.datamodel.SequenceI;
29 import jalview.gui.AlignFrame;
30 import jalview.gui.AlignViewport;
31 import jalview.gui.Desktop;
32 import jalview.gui.TreePanel;
33 import jalview.io.vamsas.DatastoreItem;
35 import java.util.Enumeration;
36 import java.util.HashMap;
37 import java.util.Hashtable;
38 import java.util.IdentityHashMap;
39 import java.util.Vector;
41 import uk.ac.vamsas.client.*;
42 import uk.ac.vamsas.objects.core.*;
47 * org.exolab.castor.util.LocalConfiguration.getInstance().getProperties().setProperty(
48 * "org.exolab.castor.serializer", "org.apache.xml.serialize.XMLSerilazizer"); }
52 public class VamsasAppDatastore
54 public static final String JALVIEW_ANNOTATION_ROW = "jalview:AnnotationRow";
56 public static final String JALVIEW_GRAPH_TYPE = "jalview:graphType";
58 Entry provEntry = null;
64 IdentityHashMap jv2vobj;
66 public VamsasAppDatastore(IClientDocument cdoc, Hashtable vobj2jv,
67 IdentityHashMap jv2vobj, Entry provEntry)
70 this.vobj2jv = vobj2jv;
71 this.jv2vobj = jv2vobj;
72 this.provEntry = provEntry;
75 * @return the Vobject bound to Jalview datamodel object
77 protected Vobject getjv2vObj(Object jvobj)
79 if (jv2vobj.containsKey(jvobj))
81 return cdoc.getObject( (VorbaId) jv2vobj.get(jvobj));
83 if (Cache.log.isDebugEnabled())
85 Cache.log.debug("Returning null VorbaID binding for jalview object "+jvobj);
93 * @return Jalview datamodel object bound to the vamsas document object
95 protected Object getvObj2jv(uk.ac.vamsas.client.Vobject vobj)
97 VorbaId id = vobj.getVorbaId();
100 id = cdoc.registerObject(vobj);
102 .debug("Registering new object and returning null for getvObj2jv");
105 if (vobj2jv.containsKey(vobj.getVorbaId()))
107 return vobj2jv.get(vobj.getVorbaId());
112 protected void bindjvvobj(Object jvobj, uk.ac.vamsas.client.Vobject vobj)
114 VorbaId id = vobj.getVorbaId();
117 id = cdoc.registerObject(vobj);
118 if (id == null || vobj.getVorbaId() == null || cdoc.getObject(id)!=vobj)
120 Cache.log.error("Failed to get id for " +
121 (vobj.isRegisterable() ? "registerable" :
122 "unregisterable") + " object " + vobj);
126 if (vobj2jv.containsKey(vobj.getVorbaId()) &&
127 ! ( (VorbaId) vobj2jv.get(vobj.getVorbaId())).equals(jvobj))
129 Cache.log.debug("Warning? Overwriting existing vamsas id binding for " +
131 new Exception("Overwriting vamsas id binding."));
133 else if (jv2vobj.containsKey(jvobj) &&
134 ! ( (VorbaId) jv2vobj.get(jvobj)).equals(vobj.getVorbaId()))
137 "Warning? Overwriting existing jalview object binding for " + jvobj,
138 new Exception("Overwriting jalview object binding."));
140 /* Cache.log.error("Attempt to make conflicting object binding! "+vobj+" id " +vobj.getVorbaId()+" already bound to "+getvObj2jv(vobj)+" and "+jvobj+" already bound to "+getjv2vObj(jvobj),new Exception("Excessive call to bindjvvobj"));
142 // we just update the hash's regardless!
143 Cache.log.debug("Binding "+vobj.getVorbaId()+" to "+jvobj);
144 vobj2jv.put(vobj.getVorbaId(), jvobj);
145 // JBPNote - better implementing a hybrid invertible hash.
146 jv2vobj.put(jvobj, vobj.getVorbaId());
150 * put the alignment viewed by AlignViewport into cdoc.
152 * @param av alignViewport to be stored
153 * @param aFtitle title for alignment
155 public void storeVAMSAS(AlignViewport av, String aFtitle)
159 jalview.datamodel.AlignmentI jal = av.getAlignment();
161 VAMSAS root = null; // will be resolved based on Dataset Parent.
162 // /////////////////////////////////////////
164 DataSet dataset = null;
165 if (jal.getDataset() == null)
167 Cache.log.warn("Creating new dataset for an alignment.");
168 jal.setDataset(null);
170 dataset = (DataSet) getjv2vObj(jal.getDataset());
173 // it might be that one of the dataset sequences does actually have a binding, so search for it indirectly.
174 jalview.datamodel.SequenceI[] jdatset = jal.getDataset().getSequencesArray();
175 for (int i=0; i<jdatset.length; i++)
177 Vobject vbound = getjv2vObj(jdatset[i]);
180 if (vbound instanceof uk.ac.vamsas.objects.core.Sequence)
184 dataset = (DataSet) vbound.getV_parent();
186 if (dataset!=vbound.getV_parent())
188 throw new Error("IMPLEMENTATION ERROR: Cannot map an alignment of sequences from datasets into the vamsas document.");
189 // This occurs because the dataset for the alignment we are trying to
197 if (dataset == null) {
198 // we create a new dataset on the default vamsas root.
199 root = cdoc.getVamsasRoots()[0]; // default vamsas root for modifying.
200 dataset = new DataSet();
201 root.addDataSet(dataset);
202 bindjvvobj(jal.getDataset(), dataset);
203 dataset.setProvenance(dummyProvenance());
204 dataset.getProvenance().addEntry(provEntry);
209 root = (VAMSAS) dataset.getV_parent();
214 // set new dataset and alignment sequences based on alignment Nucleotide
216 // this *will* break when alignment contains both nucleotide and amino
218 String dict = jal.isNucleotide() ?
219 uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_NA
220 : uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_AA;
221 for (int i = 0; i < jal.getHeight(); i++)
223 SequenceI sq = jal.getSequenceAt(i).getDatasetSequence(); // only insert
227 sequence = (Sequence) getjv2vObj(sq);
228 if (sequence == null)
230 sequence = new Sequence();
231 bindjvvobj(sq, sequence);
232 sq.setVamsasId(sequence.getVorbaId().getId());
233 sequence.setSequence(sq.getSequenceAsString());
234 sequence.setDictionary(dict);
235 sequence.setName(jal.getDataset().getSequenceAt(i).getName());
236 sequence.setStart(jal.getDataset().getSequenceAt(i).getStart());
237 sequence.setEnd(jal.getDataset().getSequenceAt(i).getEnd());
238 dataset.addSequence(sequence);
242 // verify principal attributes. and update any new
243 // features/references.
244 System.out.println("update dataset sequence object.");
246 if (sq.getSequenceFeatures() != null)
248 int sfSize = sq.getSequenceFeatures().length;
250 for (int sf = 0; sf < sfSize; sf++)
252 jalview.datamodel.SequenceFeature feature = (jalview.datamodel.
254 .getSequenceFeatures()[sf];
256 DataSetAnnotations dsa = (DataSetAnnotations) getjv2vObj(feature);
259 dsa = (DataSetAnnotations) getDSAnnotationFromJalview(
260 new DataSetAnnotations(), feature);
261 if (dsa.getProvenance() == null)
263 dsa.setProvenance(new Provenance());
265 addProvenance(dsa.getProvenance(), "created"); // JBPNote - need
267 dsa.addSeqRef(sequence); // we have just created this annotation - so safe to use this
268 bindjvvobj(feature, dsa);
269 dataset.addDataSetAnnotations(dsa);
273 // todo: verify and update dataset annotations for sequence
274 System.out.println("update dataset sequence annotations.");
279 if (sq.getDBRef() != null)
281 DBRefEntry[] entries = sq.getDBRef();
282 jalview.datamodel.DBRefEntry dbentry;
283 for (int db = 0; db < entries.length; db++)
285 dbentry = entries[db];
286 dbref = (DbRef) getjv2vObj(dbentry);
290 bindjvvobj(dbentry, dbref);
291 dbref.setAccessionId(dbentry.getAccessionId());
292 dbref.setSource(dbentry.getSource());
293 dbref.setVersion(dbentry.getVersion());
295 * TODO: Maps are not yet supported by Jalview. Map vMap = new
296 * Map(); vMap.set dbref.addMap(vMap);
298 sequence.addDbRef(dbref);
302 // TODO: verify and update dbrefs in vamsas document
303 // there will be trouble when a dataset sequence is modified to
304 // contain more residues than were originally referenced - we must
305 // then make a number of dataset sequence entries
307 .println("update dataset sequence database references.");
313 // dataset.setProvenance(getVamsasProvenance(jal.getDataset().getProvenance()));
314 // ////////////////////////////////////////////
316 // ////////////////////////////////////////////
317 // Save the Alignments
319 Alignment alignment = (Alignment) getjv2vObj(av); // this is so we can get the alignviewport back
320 if (alignment == null)
322 alignment = new Alignment();
323 bindjvvobj(av, alignment);
324 if (alignment.getProvenance() == null)
326 alignment.setProvenance(new Provenance());
328 addProvenance(alignment.getProvenance(), "added"); // TODO: insert some
331 dataset.addAlignment(alignment);
333 Property title = new Property();
334 title.setName("jalview:AlTitle");
335 title.setType("string");
336 title.setContent(aFtitle);
337 alignment.addProperty(title);
339 alignment.setGapChar(String.valueOf(av.getGapCharacter()));
340 AlignmentSequence alseq = null;
341 for (int i = 0; i < jal.getHeight(); i++)
343 alseq = new AlignmentSequence();
344 // TODO: VAMSAS: translate lowercase symbols to annotation ?
345 alseq.setSequence(jal.getSequenceAt(i).getSequenceAsString());
346 alseq.setName(jal.getSequenceAt(i).getName());
347 alseq.setStart(jal.getSequenceAt(i).getStart());
348 alseq.setEnd(jal.getSequenceAt(i).getEnd());
349 if (getjv2vObj(jal.getSequenceAt(i).getDatasetSequence())==null)
351 Cache.log.warn("Serious. Unbound dataset sequence in alignment: "+jal.getSequenceAt(i).getDatasetSequence());
353 alseq.setRefid(getjv2vObj(jal.getSequenceAt(i).getDatasetSequence()));
354 alignment.addAlignmentSequence(alseq);
355 bindjvvobj(jal.getSequenceAt(i), alseq);
360 // todo: verify and update mutable alignment props.
361 if (alignment.getModifiable()==null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK METHODS
363 System.out.println("update alignment in document.");
368 .println("update edited alignment to new alignment in document.");
371 // ////////////////////////////////////////////
372 // SAVE Alignment Sequence Features
373 for (int i = 0, iSize = alignment.getAlignmentSequenceCount(); i < iSize;
376 AlignmentSequence valseq;
377 SequenceI alseq = (SequenceI) getvObj2jv(valseq = alignment
378 .getAlignmentSequence(i));
379 if (alseq != null && alseq.getSequenceFeatures() != null)
381 jalview.datamodel.SequenceFeature[] features = alseq
382 .getSequenceFeatures();
383 for (int f = 0; f < features.length; f++)
385 if (features[f] != null)
387 AlignmentSequenceAnnotation valseqf = (
388 AlignmentSequenceAnnotation) getjv2vObj(features[i]);
392 valseqf = (AlignmentSequenceAnnotation)
393 getDSAnnotationFromJalview(
394 new AlignmentSequenceAnnotation(), features[i]);
395 if (valseqf.getProvenance() == null)
397 valseqf.setProvenance(new Provenance());
399 addProvenance(valseqf.getProvenance(), "created"); // JBPNote -
402 bindjvvobj(features[i], valseqf);
403 valseq.addAlignmentSequenceAnnotation(valseqf);
411 // ////////////////////////////////////////////
413 if (jal.getAlignmentAnnotation() != null)
415 jalview.datamodel.AlignmentAnnotation[] aa = jal
416 .getAlignmentAnnotation();
417 java.util.HashMap AlSeqMaps = new HashMap(); // stores int maps from
418 // alignment columns to
419 // sequence positions.
420 for (int i = 0; i < aa.length; i++)
422 if (aa[i] == null || isJalviewOnly(aa[i]))
426 if (aa[i].sequenceRef != null)
428 // Deal with sequence associated annotation
429 Vobject sref = getjv2vObj(aa[i].sequenceRef);
430 if (sref instanceof uk.ac.vamsas.objects.core.AlignmentSequence)
432 saveAlignmentSequenceAnnotation(AlSeqMaps, (AlignmentSequence) sref, aa[i]);
435 // first find the alignment sequence to associate this with.
436 SequenceI jvalsq=null;
437 Enumeration jval = av.getAlignment().getSequences().elements();
438 while (jval.hasMoreElements())
440 jvalsq = (SequenceI) jval.nextElement();
441 //saveDatasetSequenceAnnotation(AlSeqMaps,(uk.ac.vamsas.objects.core.Sequence) sref, aa[i]);
442 if (jvalsq.getDatasetSequence() == aa[i].sequenceRef)
444 Vobject alsref = getjv2vObj(jvalsq);
445 saveAlignmentSequenceAnnotation(AlSeqMaps, (AlignmentSequence) alsref, aa[i]);
453 // add Alignment Annotation
454 uk.ac.vamsas.objects.core.AlignmentAnnotation an = (uk.ac.vamsas.
455 objects.core.AlignmentAnnotation) getjv2vObj(aa[i]);
458 an = new uk.ac.vamsas.objects.core.AlignmentAnnotation();
459 an.setType(JALVIEW_ANNOTATION_ROW);
460 an.setDescription(aa[i].description);
461 alignment.addAlignmentAnnotation(an);
462 Seg vSeg = new Seg(); // TODO: refactor to have a default rangeAnnotationType initer/updater that takes a set of int ranges.
464 vSeg.setInclusive(true);
465 vSeg.setEnd(jal.getWidth());
469 an.setGraph(true); // aa[i].graph);
471 an.setLabel(aa[i].label);
472 an.setProvenance(dummyProvenance());
473 if (aa[i].graph != AlignmentAnnotation.NO_GRAPH)
475 an.setGroup(Integer.toString(aa[i].graphGroup)); // // JBPNote -
489 AnnotationElement ae;
491 for (int a = 0; a < aa[i].annotations.length; a++)
493 if ( (aa[i] == null) || (aa[i].annotations[a] == null))
498 ae = new AnnotationElement();
499 ae.setDescription(aa[i].annotations[a].description);
500 ae.addGlyph(new Glyph());
502 .setContent(aa[i].annotations[a].displayCharacter); // assume
509 ae.addValue(aa[i].annotations[a].value);
510 ae.setPosition(a + 1);
511 if (aa[i].annotations[a].secondaryStructure != ' ')
513 Glyph ss = new Glyph();
515 .setDict(uk.ac.vamsas.objects.utils.GlyphDictionary.
518 .valueOf(aa[i].annotations[a].
519 secondaryStructure));
522 an.addAnnotationElement(ae);
526 //an.addProperty(newProperty("jalview:editable", null, "true"));
527 // an.setModifiable(""); // TODO: This is not the way the modifiable flag is supposed to be used.
529 if (aa[i].graph != jalview.datamodel.AlignmentAnnotation.NO_GRAPH)
532 an.setGroup(Integer.toString(aa[i].graphGroup));
533 an.addProperty(newProperty(JALVIEW_GRAPH_TYPE, null,
535 jalview.datamodel.AlignmentAnnotation.
536 BAR_GRAPH) ? "BAR_GRAPH" :
540 vProperty=new Property();
541 vProperty.setName("jalview:graphThreshhold");
542 vProperty.setContent(aa[i].threshold);
549 if (an.getModifiable()==null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK METHODS)
551 // verify annotation - update (perhaps)
553 "update alignment sequence annotation. not yet implemented.");
557 // verify annotation - update (perhaps)
558 Cache.log.info("updated alignment sequence annotation added.");
564 // /////////////////////////////////////////////////////
566 // //////////////////////////////////////////////
568 // /////////////////////////////////
569 // FIND ANY ASSOCIATED TREES
570 if (Desktop.desktop != null)
572 javax.swing.JInternalFrame[] frames = Desktop.instance.getAllFrames();
574 for (int t = 0; t < frames.length; t++)
576 if (frames[t] instanceof TreePanel)
578 TreePanel tp = (TreePanel) frames[t];
580 if (tp.getAlignment() == jal)
582 DatastoreItem vtree = new jalview.io.vamsas.Tree(this, tp, jal, alignment);
587 // Store Jalview specific stuff in the Jalview appData
588 // not implemented in the SimpleDoc interface.
593 ex.printStackTrace();
597 private void initRangeAnnotationType(RangeAnnotation an, AlignmentAnnotation alan, int[] gapMap)
599 Seg vSeg = new Seg();
601 vSeg.setInclusive(true);
602 vSeg.setEnd(gapMap.length);
605 // LATER: much of this is verbatim from the alignmentAnnotation
606 // method below. suggests refactoring to make rangeAnnotation the
608 an.setDescription(alan.description);
609 an.setLabel(alan.label);
610 an.setGroup(Integer.toString(alan.graphGroup));
619 AnnotationElement ae;
620 for (int a = 0; a < alan.annotations.length; a++)
622 if (alan.annotations[a] == null)
627 ae = new AnnotationElement();
628 ae.setDescription(alan.annotations[a].description);
629 ae.addGlyph(new Glyph());
631 .setContent(alan.annotations[a].displayCharacter); // assume
639 jalview.datamodel.AlignmentAnnotation.NO_GRAPH)
641 ae.addValue(alan.annotations[a].value);
643 ae.setPosition(gapMap[a] + 1); // position w.r.t. AlignmentSequence
645 if (alan.annotations[a].secondaryStructure != ' ')
647 // we only write an annotation where it really exists.
648 Glyph ss = new Glyph();
650 .setDict(uk.ac.vamsas.objects.utils.GlyphDictionary.
653 .valueOf(alan.annotations[a].
654 secondaryStructure));
657 an.addAnnotationElement(ae);
661 private void saveDatasetSequenceAnnotation(HashMap AlSeqMaps, uk.ac.vamsas.objects.core.Sequence sref, AlignmentAnnotation alan)
665 // objects.core.AlignmentSequence alsref = (uk.ac.vamsas.
666 // objects.core.AlignmentSequence) sref;
667 uk.ac.vamsas.objects.core.DataSetAnnotations an = (uk.ac.
668 vamsas.objects.core.DataSetAnnotations) getjv2vObj(alan);
669 int[] gapMap = getGapMap(AlSeqMaps, alan);
672 an = new uk.ac.vamsas.objects.core.DataSetAnnotations();
673 initRangeAnnotationType(an, alan, gapMap);
674 an.setProvenance(dummyProvenance()); // get provenance as user
675 // created, or jnet, or
677 an.setType("jalview:SecondaryStructurePrediction"); // TODO: better fix this rough guess ;)
678 // The properties below don't fit into the DataSet Sequence Annotation as it currently is defined.
681 an.addProperty(newProperty("jalview:displayAsGraph", "boolean", "true"));
683 an.setGroup(Integer.toString(alan.graphGroup)); // // JBPNote -
691 ((DataSet) sref.getV_parent()).addDataSetAnnotations(an);
692 bindjvvobj(alan, an);
696 // update reference sequence Annotation
697 if (an.getModifiable()==null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK METHODS)
699 // verify existing alignment sequence annotation is up to date
700 System.out.println("update dataset sequence annotation.");
704 // verify existing alignment sequence annotation is up to date
707 "make new alignment dataset sequence annotation if modification has happened.");
712 private int[] getGapMap(HashMap AlSeqMaps, AlignmentAnnotation alan)
715 if (AlSeqMaps.containsKey(alan.sequenceRef))
717 gapMap = (int[]) AlSeqMaps.get(alan.sequenceRef);
721 gapMap = new int[alan.sequenceRef.getLength()];
722 // map from alignment position to sequence position.
723 int[] sgapMap = alan.sequenceRef.gapMap();
724 for (int a = 0; a < sgapMap.length; a++)
726 gapMap[sgapMap[a]] = a;
732 private void saveAlignmentSequenceAnnotation(HashMap AlSeqMaps, AlignmentSequence alsref, AlignmentAnnotation alan)
736 // objects.core.AlignmentSequence alsref = (uk.ac.vamsas.
737 // objects.core.AlignmentSequence) sref;
738 uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation an = (uk.ac.
739 vamsas.objects.core.AlignmentSequenceAnnotation) getjv2vObj(alan);
740 int[] gapMap = getGapMap(AlSeqMaps, alan);
743 an = new uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation();
744 initRangeAnnotationType(an, alan, gapMap);
746 * I mean here that we don't actually have a semantic 'type' for the annotation (this might be - score, intrinsic property, measurement, something extracted from another program, etc)
748 an.setType("jalview:SecondaryStructurePrediction"); // TODO: better fix this rough guess ;)
749 alsref.addAlignmentSequenceAnnotation(an);
750 bindjvvobj(alan, an);
751 // These properties are directly supported by the AlignmentSequenceAnnotation type.
752 if (alan.graph != AlignmentAnnotation.NO_GRAPH)
755 an.addProperty(newProperty(JALVIEW_GRAPH_TYPE, "integer", ""+alan.graph));
761 an.setProvenance(dummyProvenance()); // get provenance as user
762 // created, or jnet, or
767 // update reference sequence Annotation
768 if (an.getModifiable()==null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK METHODS)
770 // verify existing alignment sequence annotation is up to date
771 System.out.println("update alignment sequence annotation.");
775 // verify existing alignment sequence annotation is up to date
778 "make new alignment sequence annotation if modification has happened.");
782 private Property newProperty(String name, String type, String content)
784 Property vProperty = new Property();
785 vProperty.setName(name);
788 vProperty.setType(type);
792 vProperty.setType("String");
794 vProperty.setContent(content);
799 * correctly create a RangeAnnotation from a jalview sequence feature
802 * (typically DataSetAnnotations or AlignmentSequenceAnnotation)
804 * (the feature to be mapped from)
807 private RangeAnnotation getDSAnnotationFromJalview(RangeAnnotation dsa,
808 SequenceFeature feature)
810 dsa.setType(feature.getType());
811 Seg vSeg = new Seg();
812 vSeg.setStart(feature.getBegin());
813 vSeg.setEnd(feature.getEnd());
814 vSeg.setInclusive(true);
816 dsa.setDescription(feature.getDescription());
817 dsa.setStatus(feature.getStatus());
818 if (feature.links != null && feature.links.size() > 0)
820 for (int i = 0, iSize = feature.links.size(); i < iSize; i++)
822 String link = (String) feature.links.elementAt(i);
823 int sep = link.indexOf('|');
826 Link vLink = new Link();
829 vLink.setContent(link.substring(0, sep - 1));
833 vLink.setContent("");
835 vLink.setHref(link.substring(sep + 1)); // TODO: validate href.
840 dsa.setGroup(feature.getFeatureGroup());
847 * @return Object[] { AlignmentView, AlignmentI - reference alignment for
850 private Object[] recoverInputData(Provenance tp)
852 for (int pe = 0; pe < tp.getEntryCount(); pe++)
854 if (tp.getEntry(pe).getInputCount() > 0)
856 if (tp.getEntry(pe).getInputCount() > 1)
858 Cache.log.warn("Ignoring additional input spec in provenance entry "
859 + tp.getEntry(pe).toString());
861 // LATER: deal sensibly with multiple inputs
862 Input vInput = tp.getEntry(pe).getInput(0);
863 // LATER: deal sensibly with multiple object specification for input
864 if (vInput.getObjRef().length==1 && vInput.getObjRef(0) instanceof uk.ac.vamsas.objects.core.Alignment)
866 // recover an AlignmentView for the input data
867 AlignViewport javport = (AlignViewport) getvObj2jv( (uk.ac.vamsas.
868 client.Vobject) vInput
870 jalview.datamodel.AlignmentI jal = javport.getAlignment();
871 jalview.datamodel.CigarArray view = javport.getAlignment().
872 getCompactAlignment();
873 int from = 1, to = jal.getWidth();
874 int offset = 0; // deleteRange modifies its frame of reference
875 for (int r = 0, s = vInput.getSegCount(); r < s; r++)
877 Seg visSeg = vInput.getSeg(r);
878 int se[] = getSegRange(visSeg, true); // jalview doesn't do bidirection alignments yet.
881 Cache.log.warn("Ignoring invalid segment in InputData spec.");
887 view.deleteRange(offset + from - 1, offset + se[0] - 2);
888 offset -= se[0] - from;
895 view.deleteRange(offset + from - 1, offset + to - 1); // final deletion - TODO: check off by
900 new AlignmentView(view), jal};
904 Cache.log.debug("Returning null for input data recovery from provenance.");
909 * get start<end range of segment, adjusting for inclusivity flag and
913 * @param ensureDirection when true - always ensure start is less than end.
914 * @return int[] { start, end, direction} where direction==1 for range running from end to start.
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.
933 start, end, pol < 0 ? 1 : 0};
939 * @return true if annotation is not to be stored in document
941 private boolean isJalviewOnly(AlignmentAnnotation annotation)
943 return annotation.label.equals("Quality")
944 || annotation.label.equals("Conservation")
945 || annotation.label.equals("Consensus");
949 * This will return the first AlignFrame viewing AlignViewport av.
950 * It will break if there are more than one AlignFrames viewing a particular av.
951 * This 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)
993 if (jdataset == null)
995 Cache.log.debug("Initialising new jalview dataset fields");
997 dsseqs = new Vector();
1001 Cache.log.debug("Update jalview dataset from vamsas.");
1002 jremain = jdataset.getHeight();
1003 dsseqs = jdataset.getSequences();
1006 // TODO: test sequence merging - we preserve existing non vamsas
1007 // sequences but add in any new vamsas ones, and don't yet update any
1008 // sequence attributes
1009 for (i = 0; i < iSize; i++)
1011 Sequence vdseq = dataset.getSequence(i);
1012 jalview.datamodel.SequenceI dsseq = (SequenceI) getvObj2jv(vdseq);
1015 if (!dsseq.getSequenceAsString().equals(vdseq.getSequence()))
1018 "Broken! - mismatch of dataset sequence: and jalview internal dataset sequence.");
1024 dsseq = new jalview.datamodel.Sequence(
1025 dataset.getSequence(i).getName(),
1026 dataset.getSequence(i).getSequence(),
1027 (int)dataset.getSequence(i).getStart(),
1028 (int)dataset.getSequence(i).getEnd());
1029 dsseq.setDescription(dataset.getSequence(i).getDescription());
1030 bindjvvobj(dsseq, dataset.getSequence(i));
1031 dsseq.setVamsasId(dataset.getSequence(i).getVorbaId().getId());
1034 if (vdseq.getDbRefCount() > 0)
1036 DbRef[] dbref = vdseq.getDbRef();
1037 for (int db = 0; db < dbref.length; db++)
1039 jalview.datamodel.DBRefEntry dbr = (jalview.datamodel.DBRefEntry)
1040 getvObj2jv(dbref[db]);
1044 dsseq.addDBRef(dbr = new jalview.datamodel.DBRefEntry
1046 dbref[db].getSource().toString(),
1047 dbref[db].getVersion().toString(),
1048 dbref[db].getAccessionId().toString()));
1049 bindjvvobj(dbr, dbref[db]);
1057 SequenceI[] seqs = new SequenceI[dsseqs.size()];
1058 for (i = 0, iSize = dsseqs.size(); i < iSize; i++)
1060 seqs[i] = (SequenceI) dsseqs.elementAt(i);
1061 dsseqs.setElementAt(null, i);
1063 jdataset = new jalview.datamodel.Alignment(seqs);
1064 Cache.log.debug("New vamsas dataset imported into jalview.");
1065 bindjvvobj(jdataset, dataset);
1068 // add any new dataset sequence feature annotations
1069 if (dataset.getDataSetAnnotations() != null)
1071 for (int dsa = 0; dsa < dataset.getDataSetAnnotationsCount(); dsa++)
1073 DataSetAnnotations dseta = dataset.getDataSetAnnotations(dsa);
1074 // TODO: deal with group annotation on datset sequences.
1075 if (dseta.getSeqRefCount()==1)
1077 SequenceI dsSeq = (SequenceI) getvObj2jv( (Vobject) dseta.getSeqRef(0)); // TODO: deal with group dataset annotations
1080 jalview.bin.Cache.log.warn(
1081 "Couldn't resolve jalview sequenceI for dataset object reference " +
1082 ( (Vobject) dataset.getDataSetAnnotations(dsa).getSeqRef(0)).
1083 getVorbaId().getId());
1087 if (dseta.getAnnotationElementCount() == 0)
1089 jalview.datamodel.SequenceFeature sf = (jalview.datamodel.
1090 SequenceFeature) getvObj2jv(dseta);
1093 dsSeq.addSequenceFeature(sf = getJalviewSeqFeature(dseta));
1094 bindjvvobj(sf, dseta);
1099 // TODO: deal with alignmentAnnotation style annotation
1100 // appearing on dataset sequences.
1101 // JBPNote: we could just add them to all alignments but
1102 // that may complicate cross references in the jalview
1104 Cache.log.warn("Ignoring dataset annotation with annotationElements. Not yet supported in jalview.");
1111 if (dataset.getAlignmentCount() > 0)
1113 // LOAD ALIGNMENTS from DATASET
1115 for (int al = 0, nal = dataset.getAlignmentCount(); al < nal; al++)
1117 uk.ac.vamsas.objects.core.Alignment alignment = dataset.getAlignment(
1119 AlignViewport av = (AlignViewport) getvObj2jv(alignment);
1120 jalview.datamodel.AlignmentI jal = null;
1123 jal = av.getAlignment();
1125 iSize = alignment.getAlignmentSequenceCount();
1126 boolean newal = (jal == null) ? true : false;
1127 Vector newasAnnots = new Vector();
1128 char gapChar = ' '; // default for new alignments read in from the document
1131 dsseqs = jal.getSequences(); // for merge/update
1132 gapChar = jal.getGapCharacter();
1136 dsseqs = new Vector();
1138 char valGapchar = alignment.getGapChar().charAt(0);
1139 for (i = 0; i < iSize; i++)
1141 AlignmentSequence valseq = alignment.getAlignmentSequence(i);
1142 jalview.datamodel.SequenceI alseq = (SequenceI) getvObj2jv(valseq);
1145 //TODO: upperCase/LowerCase situation here ? do we allow it ?
1146 //if (!alseq.getSequence().equals(valseq.getSequence())) {
1147 // throw new Error("Broken! - mismatch of dataset sequence and jalview internal dataset sequence.");
1148 if (Cache.log.isDebugEnabled())
1150 Cache.log.debug("Updating apparently edited sequence " +
1153 // this might go *horribly* wrong
1154 alseq.setSequence(new String(valseq.getSequence()).replace(
1155 valGapchar, gapChar));
1160 alseq = new jalview.datamodel.Sequence(
1162 valseq.getSequence().replace(valGapchar, gapChar),
1163 (int)valseq.getStart(),
1164 (int)valseq.getEnd());
1166 Vobject datsetseq = (Vobject) valseq.getRefid();
1167 if (datsetseq != null)
1169 alseq.setDatasetSequence( (SequenceI) getvObj2jv(datsetseq)); // exceptions if AlignemntSequence reference isn't a simple SequenceI
1174 "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.
1188 datamodel.AlignmentAnnotation) getvObj2jv(vasannot[a]); // TODO: 1:many jalview alignment sequence annotations
1191 int se[] = getBounds(vasannot[a]);
1192 asa = getjAlignmentAnnotation(jal, vasannot[a]);
1193 asa.sequenceRef = alseq;
1194 asa.createSequenceMapping(alseq, alseq.getStart() + se[0], false); // TODO: verify that positions in alseqAnnotation correspond to ungapped residue positions.
1195 bindjvvobj(asa, vasannot[a]);
1196 newasAnnots.add(asa);
1200 // update existing annotation - can do this in place
1201 if (vasannot[a].getModifiable()==null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK METHODS)
1204 "UNIMPLEMENTED: not recovering user modifiable sequence alignment annotation");
1205 // TODO: should at least replace with new one - otherwise things will break
1206 // basically do this:
1207 // int se[] = getBounds(vasannot[a]);
1208 // asa.update(getjAlignmentAnnotation(jal, vasannot[a])); // update from another annotation object in place.
1209 // asa.createSequenceMapping(alseq, se[0], false);
1218 SequenceI[] seqs = new SequenceI[dsseqs.size()];
1219 for (i = 0, iSize = dsseqs.size(); i < iSize; i++)
1221 seqs[i] = (SequenceI) dsseqs.elementAt(i);
1222 dsseqs.setElementAt(null, i);
1224 jal = new jalview.datamodel.Alignment(seqs);
1225 Cache.log.debug("New vamsas alignment imported into jalview " +
1226 alignment.getVorbaId().getId());
1227 jal.setDataset(jdataset);
1229 if (newasAnnots != null && newasAnnots.size() > 0)
1231 // Add the new sequence annotations in to the alignment.
1232 for (int an = 0, anSize = newasAnnots.size(); an < anSize; an++)
1234 jal.addAnnotation( (AlignmentAnnotation) newasAnnots.elementAt(
1236 // TODO: check if anything has to be done - like calling adjustForAlignment or something.
1237 newasAnnots.setElementAt(null, an);
1241 // //////////////////////////////////////////
1242 // //LOAD ANNOTATIONS FOR THE ALIGNMENT
1243 // ////////////////////////////////////
1244 if (alignment.getAlignmentAnnotationCount() > 0)
1246 uk.ac.vamsas.objects.core.AlignmentAnnotation[] an = alignment.
1247 getAlignmentAnnotation();
1249 for (int j = 0; j < an.length; j++)
1251 jalview.datamodel.AlignmentAnnotation jan = (jalview.datamodel.
1252 AlignmentAnnotation) getvObj2jv(an[j]);
1255 // update or stay the same.
1256 // TODO: should at least replace with a new one - otherwise things will break
1257 // basically do this:
1258 // jan.update(getjAlignmentAnnotation(jal, an[a])); // update from another annotation object in place.
1260 Cache.log.debug("update from vamsas alignment annotation to existing jalview alignment annotation.");
1261 if (an[j].getModifiable()==null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK METHODS)
1263 // TODO: user defined annotation is totally mutable... - so load it up or throw away if locally edited.
1265 "NOT IMPLEMENTED - Recovering user-modifiable annotation - yet...");
1267 // TODO: compare annotation element rows
1268 // TODO: compare props.
1272 jan = getjAlignmentAnnotation(jal, an[j]);
1273 jal.addAnnotation(jan);
1274 bindjvvobj(jan, an[j]);
1278 AlignFrame alignFrame;
1281 Cache.log.debug("New alignframe for alignment " +
1282 alignment.getVorbaId());
1283 // ///////////////////////////////
1284 // construct alignment view
1285 alignFrame = new AlignFrame(jal, AlignFrame.DEFAULT_WIDTH,
1286 AlignFrame.DEFAULT_HEIGHT);
1287 av = alignFrame.getViewport();
1288 String title = alignment.getProvenance().getEntry(alignment.
1289 getProvenance().getEntryCount() - 1).getAction();
1290 if (alignment.getPropertyCount() > 0)
1292 for (int p = 0, pe = alignment.getPropertyCount(); p < pe; p++)
1294 if (alignment.getProperty(p).getName().equals(
1297 title = alignment.getProperty(p).getContent();
1301 // TODO: automatically create meaningful title for a vamsas alignment using its provenance.
1302 jalview.gui.Desktop.addInternalFrame(alignFrame,
1303 title + "(" + alignment.getVorbaId() + ")",
1304 AlignFrame.DEFAULT_WIDTH,
1305 AlignFrame.DEFAULT_HEIGHT);
1306 bindjvvobj(av, alignment);
1310 // find the alignFrame for jal.
1311 // TODO: fix this so we retrieve the alignFrame handing av *directly*
1312 alignFrame = getAlignFrameFor(av);
1315 // /////////////////////////////////////
1316 if (alignment.getTreeCount() > 0)
1319 for (int t = 0; t < alignment.getTreeCount(); t++)
1321 Tree tree = alignment.getTree(t);
1322 TreePanel tp = (TreePanel) getvObj2jv(tree);
1326 "Update from vamsas document to alignment associated tree not implemented yet.");
1331 Object[] idata = this.recoverInputData(tree.getProvenance());
1334 AlignmentView inputData = null;
1335 if (idata != null && idata[0] != null)
1337 inputData = (AlignmentView) idata[0];
1339 tp = alignFrame.ShowNewickTree(
1340 new jalview.io.NewickFile(tree.getNewick(0).getContent()),
1341 tree.getNewick(0).getTitle() + " (" + tree.getVorbaId() +
1344 t * 20 + 50, t * 20 + 50);
1345 bindjvvobj(tp, tree);
1349 Cache.log.warn("Problems parsing treefile '" +
1350 tree.getNewick(0).getContent() + "'", e);
1362 // bitfields - should be a template in j1.5
1363 private static int HASSECSTR = 0;
1364 private static int HASVALS = 1;
1365 private static int HASHPHOB = 2;
1366 private static int HASDC = 3;
1367 private static int HASDESCSTR = 4;
1368 private static int HASTWOSTATE = 5; // not used yet.
1370 * parses the AnnotationElements - if they exist - into jalview.datamodel.Annotation[] rows
1371 * Two annotation rows are made if there are distinct annotation for both at 'pos' and 'after pos' at any particular site.
1373 * @return { boolean[static int constants ], int[ae.length] - map to annotated object frame, jalview.datamodel.Annotation[], jalview.datamodel.Annotation[] (after)}
1375 private Object[] parseRangeAnnotation(uk.ac.vamsas.objects.core.RangeAnnotation
1378 // set these attributes by looking in the annotation to decide what kind of alignment annotation rows will be made
1379 // TODO: potentially we might make several annotation rows from one vamsas alignment annotation. the jv2Vobj binding mechanism
1380 // may not quite cope with this (without binding an array of annotations to a vamsas alignment annotation)
1381 // summary flags saying what we found over the set of annotation rows.
1382 boolean[] AeContent = new boolean[]
1384 false, false, false, false, false};
1385 int[] rangeMap = getMapping(annotation);
1386 jalview.datamodel.Annotation[][] anot = new jalview.datamodel.Annotation[][]
1388 new jalview.datamodel.Annotation[rangeMap.length],
1389 new jalview.datamodel.Annotation[rangeMap.length]
1391 boolean mergeable = true; //false if 'after positions cant be placed on same annotation row as positions.
1393 if (annotation.getAnnotationElementCount() > 0)
1395 AnnotationElement ae[] = annotation.getAnnotationElement();
1396 for (int aa = 0; aa < ae.length; aa++)
1398 int pos = (int) ae[aa].getPosition() - 1; // pos counts from 1 to (|seg.start-seg.end|+1)
1399 if (pos >= 0 && pos < rangeMap.length)
1401 int row = ae[aa].getAfter() ? 1 : 0;
1402 if (anot[row][pos] != null)
1404 // only time this should happen is if the After flag is set.
1405 Cache.log.debug("Ignoring duplicate annotation site at " + pos);
1408 if (anot[1 - row][pos] != null)
1413 if (ae[aa].getDescription() != null)
1415 desc = ae[aa].getDescription();
1416 if (desc.length() > 0)
1418 // have imported valid description string
1419 AeContent[HASDESCSTR] = true;
1422 String dc = null; //ae[aa].getDisplayCharacter()==null ? "dc" : ae[aa].getDisplayCharacter();
1423 String ss = null; //ae[aa].getSecondaryStructure()==null ? "ss" : ae[aa].getSecondaryStructure();
1424 java.awt.Color colour = null;
1425 if (ae[aa].getGlyphCount() > 0)
1427 Glyph[] glyphs = ae[aa].getGlyph();
1428 for (int g = 0; g < glyphs.length; g++)
1430 if (glyphs[g].getDict().equals(uk.ac.vamsas.objects.utils.
1431 GlyphDictionary.PROTEIN_SS_3STATE))
1433 ss = glyphs[g].getContent();
1434 AeContent[HASSECSTR] = true;
1436 else if (glyphs[g].getDict().equals(uk.ac.vamsas.objects.utils.
1440 Cache.log.debug("ignoring hydrophobicity glyph marker.");
1441 AeContent[HASHPHOB] = true;
1442 char c = (dc = glyphs[g].getContent()).charAt(0);
1443 // dc may get overwritten - but we still set the colour.
1444 colour = new java.awt.Color(c == '+' ? 255 : 0,
1446 c == '-' ? 255 : 0);
1449 else if (glyphs[g].getDict().equals(uk.ac.vamsas.objects.utils.
1450 GlyphDictionary.DEFAULT))
1452 dc = glyphs[g].getContent();
1453 AeContent[HASDC] = true;
1457 Cache.log.debug("Ignoring unknown glyph type " +
1458 glyphs[g].getDict());
1463 if (ae[aa].getValueCount() > 0)
1465 AeContent[HASVALS] = true;
1466 if (ae[aa].getValueCount() > 1)
1468 Cache.log.warn("ignoring additional " +
1469 (ae[aa].getValueCount() - 1) +
1470 "values in annotation element.");
1472 val = ae[aa].getValue(0);
1476 anot[row][pos] = new jalview.datamodel.Annotation( (dc != null) ?
1477 dc : "", desc, (ss != null) ? ss.charAt(0) : ' ', val);
1481 anot[row][pos] = new jalview.datamodel.Annotation( (dc != null) ?
1482 dc : "", desc, (ss != null) ? ss.charAt(0) : ' ', val, colour);
1487 Cache.log.warn("Ignoring out of bound annotation element " + aa +
1488 " in " + annotation.getVorbaId().getId());
1491 // decide on how many annotation rows are needed.
1494 for (int i = 0; i < anot[0].length; i++)
1496 if (anot[1][i] != null)
1498 anot[0][i] = anot[1][i];
1499 anot[0][i].description = anot[0][i].description + " (after)";
1500 AeContent[HASDESCSTR] = true; // we have valid description string data
1508 for (int i = 0; i < anot[0].length; i++)
1510 anot[1][i].description = anot[1][i].description + " (after)";
1515 AeContent, rangeMap, anot[0], anot[1]};
1519 // no annotations to parse. Just return an empty annotationElement[] array.
1522 AeContent, rangeMap, anot[0], anot[1]};
1528 * @param jal the jalview alignment to which the annotation will be attached (ideally - freshly updated from corresponding vamsas alignment)
1530 * @return unbound jalview alignment annotation object.
1532 private jalview.datamodel.AlignmentAnnotation getjAlignmentAnnotation(jalview.
1533 datamodel.AlignmentI jal,
1534 uk.ac.vamsas.objects.core.RangeAnnotation annotation)
1536 jalview.datamodel.AlignmentAnnotation jan = null;
1537 if (annotation == null)
1541 // boolean hasSequenceRef=annotation.getClass().equals(uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation.class);
1542 //boolean hasProvenance=hasSequenceRef || (annotation.getClass().equals(uk.ac.vamsas.objects.core.AlignmentAnnotation.class));
1543 /*int se[] = getBounds(annotation);
1545 se=new int[] {0,jal.getWidth()-1};
1547 Object[] parsedRangeAnnotation = parseRangeAnnotation(annotation);
1548 String a_label = annotation.getLabel();
1549 String a_descr = annotation.getDescription();
1550 if (a_label == null || a_label.length() == 0)
1552 a_label = annotation.getType();
1553 if (a_label.length() == 0)
1555 a_label = "Unamed annotation";
1558 if (a_descr == null || a_descr.length() == 0)
1560 a_descr = "Annotation of type '" + annotation.getType() + "'";
1562 if (parsedRangeAnnotation == null)
1565 "Inserting empty annotation row elements for a whole-alignment annotation.");
1569 if (parsedRangeAnnotation[3] != null)
1571 Cache.log.warn("Ignoring 'After' annotation row in " +
1572 annotation.getVorbaId());
1574 jalview.datamodel.Annotation[] arow = (jalview.datamodel.Annotation[])
1575 parsedRangeAnnotation[2];
1576 boolean[] has = (boolean[]) parsedRangeAnnotation[0];
1577 // VAMSAS: getGraph is only on derived annotation for alignments - in this way its 'odd' - there is already an existing TODO about removing this flag as being redundant
1578 /*if ((annotation.getClass().equals(uk.ac.vamsas.objects.core.AlignmentAnnotation.class) && ((uk.ac.vamsas.objects.core.AlignmentAnnotation)annotation).getGraph())
1579 || (hasSequenceRef=true && ((uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation)annotation).getGraph())) {
1583 // make bounds and automatic description strings for jalview user's benefit (these shouldn't be written back to vamsas document)
1584 boolean first = true;
1585 float min = 0, max = 1;
1587 for (int i = 0; i < arow.length; i++)
1589 if (arow[i] != null)
1591 if (i - lastval > 1)
1593 // do some interpolation *between* points
1594 if (arow[lastval] != null)
1596 float interval = arow[i].value - arow[lastval].value;
1597 interval /= i - lastval;
1598 float base = arow[lastval].value;
1599 for (int ip = lastval + 1, np = 0; ip < i; np++, ip++)
1601 arow[ip] = new jalview.datamodel.Annotation("", "", ' ',
1602 interval * np + base);
1603 // NB - Interpolated points don't get a tooltip and description.
1608 // check range - shouldn't we have a min and max property in the annotation object ?
1611 min = max = arow[i].value;
1616 if (arow[i].value < min)
1618 min = arow[i].value;
1620 else if (arow[i].value > max)
1622 max = arow[i].value;
1625 // make tooltip and display char value
1626 if (!has[HASDESCSTR])
1628 arow[i].description = arow[i].value + "";
1632 arow[i].displayCharacter = arow[i].value + "";
1636 int type = jalview.datamodel.AlignmentAnnotation.LINE_GRAPH;
1639 type = jalview.datamodel.AlignmentAnnotation.BAR_GRAPH;
1641 jan = new jalview.datamodel.AlignmentAnnotation(a_label, a_descr, arow,
1646 jan = new jalview.datamodel.AlignmentAnnotation(a_label, a_descr, arow);
1647 jan.setThreshold(null);
1649 if (annotation.getLinkCount() > 0)
1651 Cache.log.warn("Ignoring " + annotation.getLinkCount() +
1652 "links added to AlignmentAnnotation.");
1654 if (annotation.getModifiable()==null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK METHODS)
1656 jan.editable = true;
1659 if (annotation.getPropertyCount() > 0)
1661 // look for special jalview properties
1662 uk.ac.vamsas.objects.core.Property[] props = annotation.getProperty();
1663 for (int p = 0; p < props.length; p++)
1665 if (props[p].getName().equalsIgnoreCase(JALVIEW_GRAPH_TYPE))
1669 // probably a jalview annotation graph so recover the visualization hints.
1670 jan.graph = jalview.datamodel.AlignmentAnnotation.
1671 getGraphValueFromString(props[p].getContent());
1676 "Invalid graph type value in jalview:graphType property.");
1680 if (annotation.getGroup() != null &&
1681 annotation.getGroup().length() > 0)
1683 jan.graphGroup = Integer.parseInt(annotation.getGroup());
1688 Cache.log.info("UNIMPLEMENTED : Couldn't parse non-integer group value for setting graphGroup correctly.");
1701 private SequenceFeature getJalviewSeqFeature(RangeAnnotation dseta)
1703 int[] se = getBounds(dseta);
1704 SequenceFeature sf = new jalview.datamodel.SequenceFeature(dseta.getType(),
1705 dseta.getDescription(), dseta.getStatus(), se[0], se[1], dseta
1707 if (dseta.getLinkCount() > 0)
1709 Link[] links = dseta.getLink();
1710 for (int i = 0; i < links.length; i++)
1712 sf.addLink(links[i].getContent() + "|" + links[i].getHref());
1719 * get real bounds of a RangeType's specification. start and end are an
1720 * inclusive range within which all segments and positions lie.
1721 * TODO: refactor to vamsas utils
1723 * @return int[] { start, end}
1725 private int[] getBounds(RangeType dseta)
1730 if (dseta.getSegCount() > 0 && dseta.getPosCount() > 0)
1732 throw new Error("Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!");
1734 if (dseta.getSegCount() > 0)
1736 se = getSegRange(dseta.getSeg(0), true);
1737 for (int s = 1, sSize = dseta.getSegCount(); s < sSize; s++)
1739 int nse[] = getSegRange(dseta.getSeg(s), true);
1750 if (dseta.getPosCount() > 0)
1752 // could do a polarity for pos range too. and pass back indication of discontinuities.
1753 int pos = dseta.getPos(0).getI();
1757 for (int p = 0, pSize = dseta.getPosCount(); p < pSize; p++)
1759 pos = dseta.getPos(p).getI();
1776 * map from a rangeType's internal frame to the referenced object's coordinate frame.
1778 * @return int [] { ref(pos)...} for all pos in rangeType's frame.
1780 private int[] getMapping(RangeType dseta)
1782 Vector posList = new Vector();
1786 if (dseta.getSegCount() > 0 && dseta.getPosCount() > 0)
1788 throw new Error("Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!");
1790 if (dseta.getSegCount() > 0)
1792 for (int s = 0, sSize = dseta.getSegCount(); s < sSize; s++)
1794 se = getSegRange(dseta.getSeg(s), false);
1795 int se_end = se[1 - se[2]] + (se[2] == 0 ? 1 : -1);
1796 for (int p = se[se[2]]; p != se_end; p += se[2] == 0 ? 1 : -1)
1798 posList.add(new Integer(p));
1802 else if (dseta.getPosCount() > 0)
1804 int pos = dseta.getPos(0).getI();
1806 for (int p = 0, pSize = dseta.getPosCount(); p < pSize; p++)
1808 pos = dseta.getPos(p).getI();
1809 posList.add(new Integer(pos));
1813 if (posList != null && posList.size() > 0)
1815 int[] range = new int[posList.size()];
1816 for (int i = 0; i < range.length; i++)
1818 range[i] = ( (Integer) posList.elementAt(i)).intValue();
1827 * Provenance getVamsasProvenance(jalview.datamodel.Provenance jprov) {
1828 jalview.datamodel.ProvenanceEntry[] entries = null;
1829 // TODO: fix App and Action here.
1830 Provenance prov = new Provenance();
1831 org.exolab.castor.types.Date date = new org.exolab.castor.types.Date(
1832 new java.util.Date());
1837 entries = jprov.getEntries();
1838 for (int i = 0; i < entries.length; i++)
1840 provEntry = new Entry();
1843 date = new org.exolab.castor.types.Date(entries[i].getDate());
1844 } catch (Exception ex)
1846 ex.printStackTrace();
1848 date = new org.exolab.castor.types.Date(entries[i].getDate());
1850 provEntry.setDate(date);
1851 provEntry.setUser(entries[i].getUser());
1852 provEntry.setAction(entries[i].getAction());
1853 prov.addEntry(provEntry);
1858 provEntry = new Entry();
1859 provEntry.setDate(date);
1860 provEntry.setUser(System.getProperty("user.name")); // TODO: ext string
1861 provEntry.setApp("JVAPP"); // TODO: ext string
1862 provEntry.setAction(action);
1863 prov.addEntry(provEntry);
1869 jalview.datamodel.Provenance getJalviewProvenance(Provenance prov)
1871 // TODO: fix App and Action entries and check use of provenance in jalview.
1872 jalview.datamodel.Provenance jprov = new jalview.datamodel.Provenance();
1873 for (int i = 0; i < prov.getEntryCount(); i++)
1875 jprov.addEntry(prov.getEntry(i).getUser(), prov.getEntry(i).getAction(),
1876 prov.getEntry(i).getDate(),
1877 prov.getEntry(i).getId());
1885 * @return default initial provenance list for a Jalview created vamsas
1888 Provenance dummyProvenance()
1890 return dummyProvenance(null);
1893 Entry dummyPEntry(String action)
1895 Entry entry = new Entry();
1896 entry.setApp(this.provEntry.getApp());
1899 entry.setAction(action);
1903 entry.setAction("created.");
1905 entry.setDate(new java.util.Date());
1906 entry.setUser(this.provEntry.getUser());
1910 Provenance dummyProvenance(String action)
1912 Provenance prov = new Provenance();
1913 prov.addEntry(dummyPEntry(action));
1917 void addProvenance(Provenance p, String action)
1919 p.addEntry(dummyPEntry(action));
1922 public Entry getProvEntry()
1927 public IClientDocument getClientDocument()
1932 public IdentityHashMap getJvObjectBinding()
1936 public Hashtable getVamsasObjectBinding() {