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;
34 import java.util.HashMap;
35 import java.util.Hashtable;
36 import java.util.IdentityHashMap;
37 import java.util.Vector;
39 import org.vamsas.client.Vobject;
40 import org.vamsas.client.VorbaId;
41 import org.vamsas.objects.core.Alignment;
42 import org.vamsas.objects.core.AlignmentSequence;
43 import org.vamsas.objects.core.AlignmentSequenceAnnotation;
44 import org.vamsas.objects.core.AnnotationElement;
45 import org.vamsas.objects.core.DataSet;
46 import org.vamsas.objects.core.DataSetAnnotations;
47 import org.vamsas.objects.core.DbRef;
48 import org.vamsas.objects.core.Entry;
49 import org.vamsas.objects.core.Glyph;
50 import org.vamsas.objects.core.Input;
51 import org.vamsas.objects.core.Link;
52 import org.vamsas.objects.core.Newick;
53 import org.vamsas.objects.core.Param;
54 import org.vamsas.objects.core.Property;
55 import org.vamsas.objects.core.Provenance;
56 import org.vamsas.objects.core.RangeAnnotation;
57 import org.vamsas.objects.core.RangeType;
58 import org.vamsas.objects.core.Seg;
59 import org.vamsas.objects.core.Sequence;
60 import org.vamsas.objects.core.Tree;
61 import org.vamsas.objects.core.VAMSAS;
62 import org.vamsas.test.simpleclient.ClientDoc;
67 * org.exolab.castor.util.LocalConfiguration.getInstance().getProperties().setProperty(
68 * "org.exolab.castor.serializer", "org.apache.xml.serialize.XMLSerilazizer"); }
72 public class VamsasDatastore
74 Entry provEntry = null;
78 org.exolab.castor.types.Date date = new org.exolab.castor.types.Date(
79 new java.util.Date());
85 IdentityHashMap jv2vobj;
87 public VamsasDatastore(ClientDoc cdoc, Hashtable vobj2jv,
88 IdentityHashMap jv2vobj, Entry provEntry)
91 this.vobj2jv = vobj2jv;
92 this.jv2vobj = jv2vobj;
93 this.provEntry = provEntry;
97 * public void storeJalview(String file, AlignFrame af) { try { // 1. Load the
98 * mapping information from the file Mapping map = new
99 * Mapping(getClass().getClassLoader()); java.net.URL url =
100 * getClass().getResource("/jalview_mapping.xml"); map.loadMapping(url); // 2.
101 * Unmarshal the data // Unmarshaller unmar = new Unmarshaller();
102 * //unmar.setIgnoreExtraElements(true); //unmar.setMapping(map); // uni =
103 * (UniprotFile) unmar.unmarshal(new FileReader(file)); // 3. marshal the data
104 * with the total price back and print the XML in the console Marshaller
105 * marshaller = new Marshaller( new FileWriter(file) );
107 * marshaller.setMapping(map); marshaller.marshal(af); } catch (Exception e) {
108 * e.printStackTrace(); } }
113 * @return the Vobject bound to Jalview datamodel object
115 protected Vobject getjv2vObj(Object jvobj)
117 if (jv2vobj.containsKey(jvobj))
119 return cdoc.getObject( (VorbaId) jv2vobj.get(jvobj));
127 * @return Jalview datamodel object bound to the vamsas document object
129 protected Object getvObj2jv(org.vamsas.client.Vobject vobj)
131 VorbaId id = vobj.getVorbaId();
134 id = cdoc.registerObject(vobj);
136 .debug("Registering new object and returning null for getvObj2jv");
139 if (vobj2jv.containsKey(vobj.getVorbaId()))
141 return vobj2jv.get(vobj.getVorbaId());
146 protected void bindjvvobj(Object jvobj, org.vamsas.client.Vobject vobj)
148 VorbaId id = vobj.getVorbaId();
151 id = cdoc.registerObject(vobj);
152 if (id == null || vobj.getVorbaId() == null)
154 Cache.log.error("Failed to get id for " +
155 (vobj.isRegisterable() ? "registerable" :
156 "unregisterable") + " object " + vobj);
160 if (vobj2jv.containsKey(vobj.getVorbaId()) &&
161 ! ( (VorbaId) vobj2jv.get(vobj.getVorbaId())).equals(jvobj))
163 Cache.log.debug("Warning? Overwriting existing vamsas id binding for " +
165 new Exception("Overwriting vamsas id binding."));
167 else if (jv2vobj.containsKey(jvobj) &&
168 ! ( (VorbaId) jv2vobj.get(jvobj)).equals(vobj.getVorbaId()))
171 "Warning? Overwriting existing jalview object binding for " + jvobj,
172 new Exception("Overwriting jalview object binding."));
174 /* 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"));
176 // we just update the hash's regardless!
177 vobj2jv.put(vobj.getVorbaId(), jvobj);
178 // JBPNote - better implementing a hybrid invertible hash.
179 jv2vobj.put(jvobj, vobj.getVorbaId());
183 * put the alignment viewed by AlignViewport into cdoc.
185 * @param av alignViewport to be stored
186 * @param aFtitle title for alignment
188 public void storeVAMSAS(AlignViewport av, String aFtitle)
192 jalview.datamodel.AlignmentI jal = av.getAlignment();
194 VAMSAS root = null; // will be resolved based on Dataset Parent.
195 // /////////////////////////////////////////
197 if (jal.getDataset() == null)
199 Cache.log.warn("Creating new dataset for an alignment.");
200 jal.setDataset(null);
202 DataSet dataset = (DataSet) getjv2vObj(jal.getDataset());
205 root = cdoc.getVamsasRoots()[0]; // default vamsas root for modifying.
206 dataset = new DataSet();
207 root.addDataSet(dataset);
208 bindjvvobj(jal.getDataset(), dataset);
209 dataset.setProvenance(dummyProvenance());
210 dataset.getProvenance().addEntry(provEntry);
215 root = (VAMSAS) dataset.getV_parent();
220 // set new dataset and alignment sequences based on alignment Nucleotide
222 // this *will* break when alignment contains both nucleotide and amino
224 String dict = jal.isNucleotide() ?
225 org.vamsas.objects.utils.SymbolDictionary.STANDARD_NA
226 : org.vamsas.objects.utils.SymbolDictionary.STANDARD_AA;
227 for (int i = 0; i < jal.getHeight(); i++)
229 SequenceI sq = jal.getSequenceAt(i).getDatasetSequence(); // only insert
233 sequence = (Sequence) getjv2vObj(sq);
234 if (sequence == null)
236 sequence = new Sequence();
237 bindjvvobj(sq, sequence);
238 sq.setVamsasId(sequence.getVorbaId().getId());
239 sequence.setSequence(sq.getSequenceAsString());
240 sequence.setDictionary(dict);
241 sequence.setName(jal.getDataset().getSequenceAt(i).getName());
242 sequence.setStart(jal.getDataset().getSequenceAt(i).getStart());
243 sequence.setEnd(jal.getDataset().getSequenceAt(i).getEnd());
244 dataset.addSequence(sequence);
248 // verify principal attributes. and update any new
249 // features/references.
250 System.out.println("update dataset sequence object.");
252 if (sq.getSequenceFeatures() != null)
254 int sfSize = sq.getSequenceFeatures().length;
256 for (int sf = 0; sf < sfSize; sf++)
258 jalview.datamodel.SequenceFeature feature = (jalview.datamodel.
260 .getSequenceFeatures()[sf];
262 DataSetAnnotations dsa = (DataSetAnnotations) getjv2vObj(feature);
265 dsa = (DataSetAnnotations) getDSAnnotationFromJalview(
266 new DataSetAnnotations(), feature);
267 if (dsa.getProvenance() == null)
269 dsa.setProvenance(new Provenance());
271 addProvenance(dsa.getProvenance(), "created"); // JBPNote - need
273 dsa.setSeqRef(sequence);
274 bindjvvobj(feature, dsa);
275 dataset.addDataSetAnnotations(dsa);
279 // todo: verify and update dataset annotations for sequence
280 System.out.println("update dataset sequence annotations.");
285 if (sq.getDBRef() != null)
287 DBRefEntry[] entries = sq.getDBRef();
288 jalview.datamodel.DBRefEntry dbentry;
289 for (int db = 0; db < entries.length; db++)
291 dbentry = entries[db];
292 dbref = (DbRef) getjv2vObj(dbentry);
296 bindjvvobj(dbentry, dbref);
297 dbref.setAccessionId(dbentry.getAccessionId());
298 dbref.setSource(dbentry.getSource());
299 dbref.setVersion(dbentry.getVersion());
301 * TODO: Maps are not yet supported by Jalview. Map vMap = new
302 * Map(); vMap.set dbref.addMap(vMap);
304 sequence.addDbRef(dbref);
308 // TODO: verify and update dbrefs in vamsas document
309 // there will be trouble when a dataset sequence is modified to
310 // contain more residues than were originally referenced - we must
311 // then make a number of dataset sequence entries
313 .println("update dataset sequence database references.");
319 // dataset.setProvenance(getVamsasProvenance(jal.getDataset().getProvenance()));
320 // ////////////////////////////////////////////
322 // ////////////////////////////////////////////
323 // Save the Alignments
325 Alignment alignment = (Alignment) getjv2vObj(av); // this is so we can get the alignviewport back
326 if (alignment == null)
328 alignment = new Alignment();
329 bindjvvobj(av, alignment);
330 if (alignment.getProvenance() == null)
332 alignment.setProvenance(new Provenance());
334 addProvenance(alignment.getProvenance(), "added"); // TODO: insert some
337 dataset.addAlignment(alignment);
339 Property title = new Property();
340 title.setName("jalview:AlTitle");
341 title.setType("string");
342 title.setContent(aFtitle);
343 alignment.addProperty(title);
345 alignment.setGapChar(String.valueOf(av.getGapCharacter()));
346 AlignmentSequence alseq = null;
347 for (int i = 0; i < jal.getHeight(); i++)
349 alseq = new AlignmentSequence();
350 // TODO: VAMSAS: translate lowercase symbols to annotation ?
351 alseq.setSequence(jal.getSequenceAt(i).getSequenceAsString());
352 alseq.setName(jal.getSequenceAt(i).getName());
353 alseq.setStart(jal.getSequenceAt(i).getStart());
354 alseq.setEnd(jal.getSequenceAt(i).getEnd());
355 alseq.setRefid(getjv2vObj(jal.getSequenceAt(i).getDatasetSequence()));
356 alignment.addAlignmentSequence(alseq);
357 bindjvvobj(jal.getSequenceAt(i), alseq);
362 // todo: verify and update mutable alignment props.
363 if (alignment.getModifiable())
365 System.out.println("update alignment in document.");
370 .println("update edited alignment to new alignment in document.");
373 // ////////////////////////////////////////////
374 // SAVE Alignment Sequence Features
375 for (int i = 0, iSize = alignment.getAlignmentSequenceCount(); i < iSize;
378 AlignmentSequence valseq;
379 SequenceI alseq = (SequenceI) getvObj2jv(valseq = alignment
380 .getAlignmentSequence(i));
381 if (alseq != null && alseq.getSequenceFeatures() != null)
383 jalview.datamodel.SequenceFeature[] features = alseq
384 .getSequenceFeatures();
385 for (int f = 0; f < features.length; f++)
387 if (features[f] != null)
389 AlignmentSequenceAnnotation valseqf = (
390 AlignmentSequenceAnnotation) getjv2vObj(features[i]);
394 valseqf = (AlignmentSequenceAnnotation)
395 getDSAnnotationFromJalview(
396 new AlignmentSequenceAnnotation(), features[i]);
397 if (valseqf.getProvenance() == null)
399 valseqf.setProvenance(new Provenance());
401 addProvenance(valseqf.getProvenance(), "created"); // JBPNote -
404 bindjvvobj(features[i], valseqf);
405 valseq.addAlignmentSequenceAnnotation(valseqf);
413 // ////////////////////////////////////////////
415 if (jal.getAlignmentAnnotation() != null)
417 jalview.datamodel.AlignmentAnnotation[] aa = jal
418 .getAlignmentAnnotation();
419 java.util.HashMap AlSeqMaps = new HashMap(); // stores int maps from
420 // alignment columns to
421 // sequence positions.
422 for (int i = 0; i < aa.length; i++)
424 if (aa[i] == null || isJalviewOnly(aa[i]))
428 if (aa[i].sequenceRef != null)
430 org.vamsas.objects.core.AlignmentSequence alsref = (org.vamsas.
431 objects.core.AlignmentSequence) getjv2vObj(aa[i].sequenceRef);
432 org.vamsas.objects.core.AlignmentSequenceAnnotation an = (org.
433 vamsas.objects.core.AlignmentSequenceAnnotation) getjv2vObj(aa[
436 if (AlSeqMaps.containsKey(aa[i].sequenceRef))
438 gapMap = (int[]) AlSeqMaps.get(aa[i].sequenceRef);
442 gapMap = new int[aa[i].sequenceRef.getLength()];
443 // map from alignment position to sequence position.
444 int[] sgapMap = aa[i].sequenceRef.gapMap();
445 for (int a = 0; a < sgapMap.length; a++)
447 gapMap[sgapMap[a]] = a;
452 an = new org.vamsas.objects.core.AlignmentSequenceAnnotation();
453 Seg vSeg = new Seg();
455 vSeg.setInclusive(true);
456 vSeg.setEnd(gapMap.length);
458 an.setType("jalview:SecondaryStructurePrediction"); // TODO: better fix this rough guess ;)
459 alsref.addAlignmentSequenceAnnotation(an);
460 bindjvvobj(aa[i], an);
461 // LATER: much of this is verbatim from the alignmentAnnotation
462 // method below. suggests refactoring to make rangeAnnotation the
464 an.setDescription(aa[i].description);
467 an.setGraph(true); // aa[i].graph);
473 an.setLabel(aa[i].label);
474 an.setProvenance(dummyProvenance()); // get provenance as user
475 // created, or jnet, or
477 an.setGroup(Integer.toString(aa[i].graphGroup)); // // JBPNote -
485 AnnotationElement ae;
486 for (int a = 0; a < aa[i].annotations.length; a++)
488 if (aa[i].annotations[a] == null)
493 ae = new AnnotationElement();
494 ae.setDescription(aa[i].annotations[a].description);
495 ae.addGlyph(new Glyph());
497 .setContent(aa[i].annotations[a].displayCharacter); // assume
505 jalview.datamodel.AlignmentAnnotation.NO_GRAPH)
507 ae.addValue(aa[i].annotations[a].value);
509 ae.setPosition(gapMap[a] + 1); // position w.r.t. AlignmentSequence
511 if (aa[i].annotations[a].secondaryStructure != ' ')
513 // we only write an annotation where it really exists.
514 Glyph ss = new Glyph();
516 .setDict(org.vamsas.objects.utils.GlyphDictionary.
519 .valueOf(aa[i].annotations[a].
520 secondaryStructure));
523 an.addAnnotationElement(ae);
528 // update reference sequence Annotation
529 if (an.getModifiable())
531 // verify existing alignment sequence annotation is up to date
532 System.out.println("update alignment sequence annotation.");
536 // verify existing alignment sequence annotation is up to date
539 "make new alignment sequence annotation if modification has happened.");
545 // add Alignment Annotation
546 org.vamsas.objects.core.AlignmentAnnotation an = (org.vamsas.
547 objects.core.AlignmentAnnotation) getjv2vObj(aa[i]);
550 an = new org.vamsas.objects.core.AlignmentAnnotation();
551 an.setType("jalview:AnnotationRow");
552 an.setDescription(aa[i].description);
553 alignment.addAlignmentAnnotation(an);
554 Seg vSeg = new Seg();
556 vSeg.setInclusive(true);
557 vSeg.setEnd(jal.getWidth());
561 an.setGraph(true); // aa[i].graph);
563 an.setLabel(aa[i].label);
564 an.setProvenance(dummyProvenance());
565 if (aa[i].graph != aa[i].NO_GRAPH)
567 an.setGroup(Integer.toString(aa[i].graphGroup)); // // JBPNote -
581 AnnotationElement ae;
583 for (int a = 0; a < aa[i].annotations.length; a++)
585 if ( (aa[i] == null) || (aa[i].annotations[a] == null))
590 ae = new AnnotationElement();
591 ae.setDescription(aa[i].annotations[a].description);
592 ae.addGlyph(new Glyph());
594 .setContent(aa[i].annotations[a].displayCharacter); // assume
601 ae.addValue(aa[i].annotations[a].value);
602 ae.setPosition(a + 1);
603 if (aa[i].annotations[a].secondaryStructure != ' ')
605 Glyph ss = new Glyph();
607 .setDict(org.vamsas.objects.utils.GlyphDictionary.
610 .valueOf(aa[i].annotations[a].
611 secondaryStructure));
614 an.addAnnotationElement(ae);
618 //an.addProperty(newProperty("jalview:editable", null, "true"));
619 an.setModifiable(true);
621 if (aa[i].graph != jalview.datamodel.AlignmentAnnotation.NO_GRAPH)
624 an.setGroup(Integer.toString(aa[i].graphGroup));
625 an.addProperty(newProperty("jalview:graphType", null,
627 jalview.datamodel.AlignmentAnnotation.
628 BAR_GRAPH) ? "BAR_GRAPH" :
632 vProperty=new Property();
633 vProperty.setName("jalview:graphThreshhold");
634 vProperty.setContent(aa[i].threshold);
641 if (an.getModifiable())
643 // verify annotation - update (perhaps)
645 "update alignment sequence annotation. not yet implemented.");
649 // verify annotation - update (perhaps)
650 Cache.log.info("updated alignment sequence annotation added.");
656 // /////////////////////////////////////////////////////
658 // //////////////////////////////////////////////
660 // /////////////////////////////////
661 // FIND ANY ASSOCIATED TREES
662 if (Desktop.desktop != null)
664 javax.swing.JInternalFrame[] frames = Desktop.instance.getAllFrames();
666 for (int t = 0; t < frames.length; t++)
668 if (frames[t] instanceof TreePanel)
670 TreePanel tp = (TreePanel) frames[t];
672 if (tp.getAlignment() == jal)
674 Tree tree = (Tree) getjv2vObj(tp);
678 bindjvvobj(tp, tree);
679 tree.setTitle(tp.getTitle());
680 Newick newick = new Newick();
681 // TODO: translate sequenceI to leaf mappings to vamsas
682 // references - see tree specification in schema.
683 newick.setContent(tp.getTree().toString());
684 newick.setTitle(tp.getTitle());
685 tree.addNewick(newick);
686 tree.setProvenance(makeTreeProvenance(jal, tp));
687 alignment.addTree(tree);
691 if (tree.getModifiable())
693 // verify any changes.
694 System.out.println("Update tree in document.");
699 .println("Add modified tree as new tree in document.");
706 // Store Jalview specific stuff in the Jalview appData
707 // not implemented in the SimpleDoc interface.
712 ex.printStackTrace();
717 private Property newProperty(String name, String type, String content)
719 Property vProperty = new Property();
720 vProperty.setName(name);
723 vProperty.setType(type);
727 vProperty.setType("String");
729 vProperty.setContent(content);
734 * correctly create a RangeAnnotation from a jalview sequence feature
737 * (typically DataSetAnnotations or AlignmentSequenceAnnotation)
739 * (the feature to be mapped from)
742 private RangeAnnotation getDSAnnotationFromJalview(RangeAnnotation dsa,
743 SequenceFeature feature)
745 dsa.setType(feature.getType());
746 Seg vSeg = new Seg();
747 vSeg.setStart(feature.getBegin());
748 vSeg.setEnd(feature.getEnd());
749 vSeg.setInclusive(true);
751 dsa.setDescription(feature.getDescription());
752 dsa.setStatus(feature.getStatus());
753 if (feature.links != null && feature.links.size() > 0)
755 for (int i = 0, iSize = feature.links.size(); i < iSize; i++)
757 String link = (String) feature.links.elementAt(i);
758 int sep = link.indexOf('|');
761 Link vLink = new Link();
764 vLink.setContent(link.substring(0, sep - 1));
768 vLink.setContent("");
770 vLink.setHref(link.substring(sep + 1)); // TODO: validate href.
775 dsa.setGroup(feature.getFeatureGroup());
780 * correctly creates provenance for trees calculated on an alignment by
787 private Provenance makeTreeProvenance(AlignmentI jal, TreePanel tp)
789 Provenance prov = new Provenance();
790 prov.addEntry(new Entry());
791 prov.getEntry(0).setAction("imported " + tp.getTitle());
792 prov.getEntry(0).setUser(provEntry.getUser());
793 prov.getEntry(0).setApp(provEntry.getApp());
794 prov.getEntry(0).setDate(provEntry.getDate());
795 if (tp.getTree().hasOriginalSequenceData())
797 Input vInput = new Input();
798 // LATER: check to see if tree input data is contained in this alignment -
799 // or just correctly resolve the tree's seqData to the correct alignment in
801 // vInput.setObjRef(getjv2vObj(jal));
802 vInput.setObjRef(getjv2vObj(tp.getViewPort()));
803 prov.getEntry(0).setAction("created " + tp.getTitle());
804 prov.getEntry(0).addInput(vInput);
805 vInput.setName("jalview:seqdist");
806 prov.getEntry(0).addParam(new Param());
807 prov.getEntry(0).getParam(0).setName("treeType");
808 prov.getEntry(0).getParam(0).setType("utf8");
809 prov.getEntry(0).getParam(0).setContent("NJ");
811 int ranges[] = tp.getTree().seqData.getVisibleContigs();
812 // VisibleContigs are with respect to alignment coordinates. Still need offsets
813 int start = tp.getTree().seqData.getAlignmentOrigin();
814 for (int r = 0; r < ranges.length; r += 2)
816 Seg visSeg = new Seg();
817 visSeg.setStart(1 + start + ranges[r]);
818 visSeg.setEnd(start + ranges[r + 1]);
819 visSeg.setInclusive(true);
820 vInput.addSeg(visSeg);
829 * @return Object[] { AlignmentView, AlignmentI - reference alignment for
832 private Object[] recoverInputData(Provenance tp)
834 for (int pe = 0; pe < tp.getEntryCount(); pe++)
836 if (tp.getEntry(pe).getInputCount() > 0)
838 if (tp.getEntry(pe).getInputCount() > 1)
840 Cache.log.warn("Ignoring additional input spec in provenance entry "
841 + tp.getEntry(pe).toString());
843 // LATER: deal sensibly with multiple inputs.
844 Input vInput = tp.getEntry(pe).getInput(0);
845 if (vInput.getObjRef() instanceof org.vamsas.objects.core.Alignment)
847 // recover an AlignmentView for the input data
848 AlignViewport javport = (AlignViewport) getvObj2jv( (org.vamsas.
849 client.Vobject) vInput
851 jalview.datamodel.AlignmentI jal = javport.getAlignment();
852 jalview.datamodel.CigarArray view = javport.getAlignment().
853 getCompactAlignment();
854 int from = 1, to = jal.getWidth();
855 int offset = 0; // deleteRange modifies its frame of reference
856 for (int r = 0, s = vInput.getSegCount(); r < s; r++)
858 Seg visSeg = vInput.getSeg(r);
859 int se[] = getSegRange(visSeg, true); // jalview doesn't do bidirection alignments yet.
862 Cache.log.warn("Ignoring invalid segment in InputData spec.");
868 view.deleteRange(offset + from - 1, offset + se[0] - 2);
869 offset -= se[0] - from;
876 view.deleteRange(offset + from - 1, offset + to - 1); // final deletion - TODO: check off by
881 new AlignmentView(view), jal};
885 Cache.log.debug("Returning null for input data recovery from provenance.");
890 * get start<end range of segment, adjusting for inclusivity flag and
894 * @param ensureDirection when true - always ensure start is less than end.
895 * @return int[] { start, end, direction} where direction==1 for range running from end to start.
897 private int[] getSegRange(Seg visSeg, boolean ensureDirection)
899 boolean incl = visSeg.getInclusive();
900 // adjust for inclusive flag.
901 int pol = (visSeg.getStart() <= visSeg.getEnd()) ? 1 : -1; // polarity of
903 int start = visSeg.getStart() + (incl ? 0 : pol);
904 int end = visSeg.getEnd() + (incl ? 0 : -pol);
905 if (ensureDirection && pol == -1)
907 // jalview doesn't deal with inverted ranges, yet.
914 start, end, pol < 0 ? 1 : 0};
920 * @return true if annotation is not to be stored in document
922 private boolean isJalviewOnly(AlignmentAnnotation annotation)
924 return annotation.label.equals("Quality")
925 || annotation.label.equals("Conservation")
926 || annotation.label.equals("Consensus");
930 * This will return the first AlignFrame viewing AlignViewport av.
931 * It will break if there are more than one AlignFrames viewing a particular av.
932 * This also shouldn't be in the io package.
934 * @return alignFrame for av
936 public AlignFrame getAlignFrameFor(AlignViewport av)
938 if (Desktop.desktop != null)
940 javax.swing.JInternalFrame[] frames = Desktop.instance.getAllFrames();
942 for (int t = 0; t < frames.length; t++)
944 if (frames[t] instanceof AlignFrame)
946 if ( ( (AlignFrame) frames[t]).getViewport() == av)
948 return (AlignFrame) frames[t];
956 public void updateToJalview()
958 VAMSAS _roots[] = cdoc.getVamsasRoots();
960 for (int _root = 0; _root < _roots.length; _root++)
962 VAMSAS root = _roots[_root];
963 boolean newds = false;
964 for (int _ds = 0, _nds = root.getDataSetCount(); _ds < _nds; _ds++)
966 // ///////////////////////////////////
968 DataSet dataset = root.getDataSet(_ds);
969 int i, iSize = dataset.getSequenceCount();
971 jalview.datamodel.Alignment jdataset = (jalview.datamodel.Alignment)
974 if (jdataset == null)
976 Cache.log.debug("Initialising new jalview dataset fields");
978 dsseqs = new Vector();
982 Cache.log.debug("Update jalview dataset from vamsas.");
983 jremain = jdataset.getHeight();
984 dsseqs = jdataset.getSequences();
987 // TODO: test sequence merging - we preserve existing non vamsas
988 // sequences but add in any new vamsas ones, and don't yet update any
989 // sequence attributes
990 for (i = 0; i < iSize; i++)
992 Sequence vdseq = dataset.getSequence(i);
993 jalview.datamodel.SequenceI dsseq = (SequenceI) getvObj2jv(vdseq);
996 if (!dsseq.getSequence().equals(vdseq.getSequence()))
999 "Broken! - mismatch of dataset sequence and jalview internal dataset sequence.");
1005 dsseq = new jalview.datamodel.Sequence(
1006 dataset.getSequence(i).getName(),
1007 dataset.getSequence(i).getSequence(),
1008 dataset.getSequence(i).getStart(),
1009 dataset.getSequence(i).getEnd());
1010 dsseq.setDescription(dataset.getSequence(i).getDescription());
1011 bindjvvobj(dsseq, dataset.getSequence(i));
1012 dsseq.setVamsasId(dataset.getSequence(i).getVorbaId().getId());
1015 if (vdseq.getDbRefCount() > 0)
1017 DbRef[] dbref = vdseq.getDbRef();
1018 for (int db = 0; db < dbref.length; db++)
1020 jalview.datamodel.DBRefEntry dbr = (jalview.datamodel.DBRefEntry)
1021 getvObj2jv(dbref[db]);
1025 dsseq.addDBRef(dbr = new jalview.datamodel.DBRefEntry
1027 dbref[db].getSource().toString(),
1028 dbref[db].getVersion().toString(),
1029 dbref[db].getAccessionId().toString()));
1030 bindjvvobj(dbr, dbref[db]);
1038 SequenceI[] seqs = new SequenceI[dsseqs.size()];
1039 for (i = 0, iSize = dsseqs.size(); i < iSize; i++)
1041 seqs[i] = (SequenceI) dsseqs.elementAt(i);
1042 dsseqs.setElementAt(null, i);
1044 jdataset = new jalview.datamodel.Alignment(seqs);
1045 Cache.log.debug("New vamsas dataset imported into jalview.");
1046 bindjvvobj(jdataset, dataset);
1049 // add any new dataset sequence feature annotations
1050 if (dataset.getDataSetAnnotations() != null)
1052 for (int dsa = 0; dsa < dataset.getDataSetAnnotationsCount(); dsa++)
1054 DataSetAnnotations dseta = dataset.getDataSetAnnotations(dsa);
1055 SequenceI dsSeq = (SequenceI) getvObj2jv( (Vobject) dseta.getSeqRef());
1058 jalview.bin.Cache.log.warn(
1059 "Couldn't resolve jalview sequenceI for dataset object reference " +
1060 ( (Vobject) dataset.getDataSetAnnotations(dsa).getSeqRef()).
1061 getVorbaId().getId());
1065 if (dseta.getAnnotationElementCount() == 0)
1067 jalview.datamodel.SequenceFeature sf = (jalview.datamodel.
1068 SequenceFeature) getvObj2jv(dseta);
1071 dsSeq.addSequenceFeature(sf = getJalviewSeqFeature(dseta));
1072 bindjvvobj(sf, dseta);
1077 // TODO: deal with alignmentAnnotation style annotation
1078 // appearing on dataset sequences.
1079 // JBPNote: we could just add them to all alignments but
1080 // that may complicate cross references in the jalview
1082 Cache.log.warn("Ignoring dataset annotation with annotationElements. Not yet supported in jalview.");
1088 if (dataset.getAlignmentCount() > 0)
1090 // LOAD ALIGNMENTS from DATASET
1092 for (int al = 0, nal = dataset.getAlignmentCount(); al < nal; al++)
1094 org.vamsas.objects.core.Alignment alignment = dataset.getAlignment(
1096 AlignViewport av = (AlignViewport) getvObj2jv(alignment);
1097 jalview.datamodel.AlignmentI jal = null;
1100 jal = av.getAlignment();
1102 iSize = alignment.getAlignmentSequenceCount();
1103 boolean newal = (jal == null) ? true : false;
1104 Vector newasAnnots = new Vector();
1105 char gapChar = ' '; // default for new alignments read in from the document
1108 dsseqs = jal.getSequences(); // for merge/update
1109 gapChar = jal.getGapCharacter();
1113 dsseqs = new Vector();
1115 char valGapchar = alignment.getGapChar().charAt(0);
1116 for (i = 0; i < iSize; i++)
1118 AlignmentSequence valseq = alignment.getAlignmentSequence(i);
1119 jalview.datamodel.SequenceI alseq = (SequenceI) getvObj2jv(valseq);
1122 //TODO: upperCase/LowerCase situation here ? do we allow it ?
1123 //if (!alseq.getSequence().equals(valseq.getSequence())) {
1124 // throw new Error("Broken! - mismatch of dataset sequence and jalview internal dataset sequence.");
1125 if (Cache.log.isDebugEnabled())
1127 Cache.log.debug("Updating apparently edited sequence " +
1130 // this might go *horribly* wrong
1131 alseq.setSequence(new String(valseq.getSequence()).replace(
1132 valGapchar, gapChar));
1137 alseq = new jalview.datamodel.Sequence(
1139 valseq.getSequence().replace(valGapchar, gapChar),
1143 Vobject datsetseq = (Vobject) valseq.getRefid();
1144 if (datsetseq != null)
1146 alseq.setDatasetSequence( (SequenceI) getvObj2jv(datsetseq)); // exceptions if AlignemntSequence reference isn't a simple SequenceI
1151 "Invalid dataset sequence id (null) for alignment sequence " +
1152 valseq.getVorbaId());
1154 bindjvvobj(alseq, valseq);
1155 alseq.setVamsasId(valseq.getVorbaId().getId());
1158 if (valseq.getAlignmentSequenceAnnotationCount() > 0)
1160 AlignmentSequenceAnnotation[] vasannot = valseq.
1161 getAlignmentSequenceAnnotation();
1162 for (int a = 0; a < vasannot.length; a++)
1164 jalview.datamodel.AlignmentAnnotation asa = (jalview.
1165 datamodel.AlignmentAnnotation) getvObj2jv(vasannot[a]); // TODO: 1:many jalview alignment sequence annotations
1168 int se[] = getBounds(vasannot[a]);
1169 asa = getjAlignmentAnnotation(jal, vasannot[a]);
1170 asa.sequenceRef = alseq;
1171 asa.createSequenceMapping(alseq, alseq.getStart() + se[0], false); // TODO: verify that positions in alseqAnnotation correspond to ungapped residue positions.
1172 bindjvvobj(asa, vasannot[a]);
1173 newasAnnots.add(asa);
1177 // update existing annotation - can do this in place
1178 if (vasannot[a].getModifiable())
1181 "UNIMPLEMENTED: not recovering user modifiable sequence alignment annotation");
1182 // TODO: should at least replace with new one - otherwise things will break
1183 // basically do this:
1184 // int se[] = getBounds(vasannot[a]);
1185 // asa.update(getjAlignmentAnnotation(jal, vasannot[a])); // update from another annotation object in place.
1186 // asa.createSequenceMapping(alseq, se[0], false);
1195 SequenceI[] seqs = new SequenceI[dsseqs.size()];
1196 for (i = 0, iSize = dsseqs.size(); i < iSize; i++)
1198 seqs[i] = (SequenceI) dsseqs.elementAt(i);
1199 dsseqs.setElementAt(null, i);
1201 jal = new jalview.datamodel.Alignment(seqs);
1202 Cache.log.debug("New vamsas alignment imported into jalview " +
1203 alignment.getVorbaId().getId());
1204 jal.setDataset(jdataset);
1206 if (newasAnnots != null && newasAnnots.size() > 0)
1208 // Add the new sequence annotations in to the alignment.
1209 for (int an = 0, anSize = newasAnnots.size(); an < anSize; an++)
1211 jal.addAnnotation( (AlignmentAnnotation) newasAnnots.elementAt(
1213 // TODO: check if anything has to be done - like calling adjustForAlignment or something.
1214 newasAnnots.setElementAt(null, an);
1218 // //////////////////////////////////////////
1219 // //LOAD ANNOTATIONS FOR THE ALIGNMENT
1220 // ////////////////////////////////////
1221 if (alignment.getAlignmentAnnotationCount() > 0)
1223 org.vamsas.objects.core.AlignmentAnnotation[] an = alignment.
1224 getAlignmentAnnotation();
1226 for (int j = 0; j < an.length; j++)
1228 jalview.datamodel.AlignmentAnnotation jan = (jalview.datamodel.
1229 AlignmentAnnotation) getvObj2jv(an[j]);
1232 // update or stay the same.
1233 // TODO: should at least replace with a new one - otherwise things will break
1234 // basically do this:
1235 // jan.update(getjAlignmentAnnotation(jal, an[a])); // update from another annotation object in place.
1237 Cache.log.debug("update from vamsas alignment annotation to existing jalview alignment annotation.");
1238 if (an[j].getModifiable())
1240 // TODO: user defined annotation is totally mutable... - so load it up or throw away if locally edited.
1242 "NOT IMPLEMENTED - Recovering user-modifiable annotation - yet...");
1244 // TODO: compare annotation element rows
1245 // TODO: compare props.
1249 jan = getjAlignmentAnnotation(jal, an[j]);
1250 jal.addAnnotation(jan);
1251 bindjvvobj(jan, an[j]);
1255 AlignFrame alignFrame;
1258 Cache.log.debug("New alignframe for alignment " +
1259 alignment.getVorbaId());
1260 // ///////////////////////////////
1261 // construct alignment view
1262 alignFrame = new AlignFrame(jal, AlignFrame.DEFAULT_WIDTH,
1263 AlignFrame.DEFAULT_HEIGHT);
1264 av = alignFrame.getViewport();
1265 String title = alignment.getProvenance().getEntry(alignment.
1266 getProvenance().getEntryCount() - 1).getAction();
1267 if (alignment.getPropertyCount() > 0)
1269 for (int p = 0, pe = alignment.getPropertyCount(); p < pe; p++)
1271 if (alignment.getProperty(p).getName().equals(
1274 title = alignment.getProperty(p).getContent();
1278 // TODO: automatically create meaningful title for a vamsas alignment using its provenance.
1279 jalview.gui.Desktop.addInternalFrame(alignFrame,
1280 title + "(" + alignment.getVorbaId() + ")",
1281 AlignFrame.DEFAULT_WIDTH,
1282 AlignFrame.DEFAULT_HEIGHT);
1283 bindjvvobj(av, alignment);
1287 // find the alignFrame for jal.
1288 // TODO: fix this so we retrieve the alignFrame handing av *directly*
1289 alignFrame = getAlignFrameFor(av);
1292 // /////////////////////////////////////
1293 if (alignment.getTreeCount() > 0)
1296 for (int t = 0; t < alignment.getTreeCount(); t++)
1298 Tree tree = alignment.getTree(t);
1299 TreePanel tp = (TreePanel) getvObj2jv(tree);
1303 "Update from vamsas document to alignment associated tree not implemented yet.");
1308 Object[] idata = this.recoverInputData(tree.getProvenance());
1311 AlignmentView inputData = null;
1312 if (idata != null && idata[0] != null)
1314 inputData = (AlignmentView) idata[0];
1316 tp = alignFrame.ShowNewickTree(
1317 new jalview.io.NewickFile(tree.getNewick(0).getContent()),
1318 tree.getNewick(0).getTitle() + " (" + tree.getVorbaId() +
1321 t * 20 + 50, t * 20 + 50);
1322 bindjvvobj(tp, tree);
1326 Cache.log.warn("Problems parsing treefile '" +
1327 tree.getNewick(0).getContent() + "'", e);
1339 // bitfields - should be a template in j1.5
1340 private static int HASSECSTR = 0;
1341 private static int HASVALS = 1;
1342 private static int HASHPHOB = 2;
1343 private static int HASDC = 3;
1344 private static int HASDESCSTR = 4;
1345 private static int HASTWOSTATE = 5; // not used yet.
1347 * parses the AnnotationElements - if they exist - into jalview.datamodel.Annotation[] rows
1348 * Two annotation rows are made if there are distinct annotation for both at 'pos' and 'after pos' at any particular site.
1350 * @return { boolean[static int constants ], int[ae.length] - map to annotated object frame, jalview.datamodel.Annotation[], jalview.datamodel.Annotation[] (after)}
1352 private Object[] parseRangeAnnotation(org.vamsas.objects.core.RangeAnnotation
1355 // set these attributes by looking in the annotation to decide what kind of alignment annotation rows will be made
1356 // TODO: potentially we might make several annotation rows from one vamsas alignment annotation. the jv2Vobj binding mechanism
1357 // may not quite cope with this (without binding an array of annotations to a vamsas alignment annotation)
1358 // summary flags saying what we found over the set of annotation rows.
1359 boolean[] AeContent = new boolean[]
1361 false, false, false, false, false};
1362 int[] rangeMap = getMapping(annotation);
1363 jalview.datamodel.Annotation[][] anot = new jalview.datamodel.Annotation[][]
1365 new jalview.datamodel.Annotation[rangeMap.length],
1366 new jalview.datamodel.Annotation[rangeMap.length]
1368 boolean mergeable = true; //false if 'after positions cant be placed on same annotation row as positions.
1370 if (annotation.getAnnotationElementCount() > 0)
1372 AnnotationElement ae[] = annotation.getAnnotationElement();
1373 for (int aa = 0; aa < ae.length; aa++)
1375 int pos = ae[aa].getPosition() - 1; // pos counts from 1 to (|seg.start-seg.end|+1)
1376 if (pos >= 0 && pos < rangeMap.length)
1378 int row = ae[aa].getAfter() ? 1 : 0;
1379 if (anot[row][pos] != null)
1381 // only time this should happen is if the After flag is set.
1382 Cache.log.debug("Ignoring duplicate annotation site at " + pos);
1385 if (anot[1 - row][pos] != null)
1390 if (ae[aa].getDescription() != null)
1392 desc = ae[aa].getDescription();
1393 if (desc.length() > 0)
1395 // have imported valid description string
1396 AeContent[HASDESCSTR] = true;
1399 String dc = null; //ae[aa].getDisplayCharacter()==null ? "dc" : ae[aa].getDisplayCharacter();
1400 String ss = null; //ae[aa].getSecondaryStructure()==null ? "ss" : ae[aa].getSecondaryStructure();
1401 java.awt.Color colour = null;
1402 if (ae[aa].getGlyphCount() > 0)
1404 Glyph[] glyphs = ae[aa].getGlyph();
1405 for (int g = 0; g < glyphs.length; g++)
1407 if (glyphs[g].getDict().equals(org.vamsas.objects.utils.
1408 GlyphDictionary.PROTEIN_SS_3STATE))
1410 ss = glyphs[g].getContent();
1411 AeContent[HASSECSTR] = true;
1413 else if (glyphs[g].getDict().equals(org.vamsas.objects.utils.
1417 Cache.log.debug("ignoring hydrophobicity glyph marker.");
1418 AeContent[HASHPHOB] = true;
1419 char c = (dc = glyphs[g].getContent()).charAt(0);
1420 // dc may get overwritten - but we still set the colour.
1421 colour = new java.awt.Color(c == '+' ? 255 : 0,
1423 c == '-' ? 255 : 0);
1426 else if (glyphs[g].getDict().equals(org.vamsas.objects.utils.
1427 GlyphDictionary.DEFAULT))
1429 dc = glyphs[g].getContent();
1430 AeContent[HASDC] = true;
1434 Cache.log.debug("Ignoring unknown glyph type " +
1435 glyphs[g].getDict());
1440 if (ae[aa].getValueCount() > 0)
1442 AeContent[HASVALS] = true;
1443 if (ae[aa].getValueCount() > 1)
1445 Cache.log.warn("ignoring additional " +
1446 (ae[aa].getValueCount() - 1) +
1447 "values in annotation element.");
1449 val = ae[aa].getValue(0);
1453 anot[row][pos] = new jalview.datamodel.Annotation( (dc != null) ?
1454 dc : "", desc, (ss != null) ? ss.charAt(0) : ' ', val);
1458 anot[row][pos] = new jalview.datamodel.Annotation( (dc != null) ?
1459 dc : "", desc, (ss != null) ? ss.charAt(0) : ' ', val, colour);
1464 Cache.log.warn("Ignoring out of bound annotation element " + aa +
1465 " in " + annotation.getVorbaId().getId());
1468 // decide on how many annotation rows are needed.
1471 for (int i = 0; i < anot[0].length; i++)
1473 if (anot[1][i] != null)
1475 anot[0][i] = anot[1][i];
1476 anot[0][i].description = anot[0][i].description + " (after)";
1477 AeContent[HASDESCSTR] = true; // we have valid description string data
1485 for (int i = 0; i < anot[0].length; i++)
1487 anot[1][i].description = anot[1][i].description + " (after)";
1492 AeContent, rangeMap, anot[0], anot[1]};
1496 // no annotations to parse. Just return an empty annotationElement[] array.
1499 AeContent, rangeMap, anot[0], anot[1]};
1505 * @param jal the jalview alignment to which the annotation will be attached (ideally - freshly updated from corresponding vamsas alignment)
1507 * @return unbound jalview alignment annotation object.
1509 private jalview.datamodel.AlignmentAnnotation getjAlignmentAnnotation(jalview.
1510 datamodel.AlignmentI jal,
1511 org.vamsas.objects.core.RangeAnnotation annotation)
1513 jalview.datamodel.AlignmentAnnotation jan = null;
1514 if (annotation == null)
1518 // boolean hasSequenceRef=annotation.getClass().equals(org.vamsas.objects.core.AlignmentSequenceAnnotation.class);
1519 //boolean hasProvenance=hasSequenceRef || (annotation.getClass().equals(org.vamsas.objects.core.AlignmentAnnotation.class));
1520 /*int se[] = getBounds(annotation);
1522 se=new int[] {0,jal.getWidth()-1};
1524 Object[] parsedRangeAnnotation = parseRangeAnnotation(annotation);
1525 String a_label = annotation.getLabel();
1526 String a_descr = annotation.getDescription();
1527 if (a_label == null || a_label.length() == 0)
1529 a_label = annotation.getType();
1530 if (a_label.length() == 0)
1532 a_label = "Unamed annotation";
1535 if (a_descr == null || a_descr.length() == 0)
1537 a_descr = "Annotation of type '" + annotation.getType() + "'";
1539 if (parsedRangeAnnotation == null)
1542 "Inserting empty annotation row elements for a whole-alignment annotation.");
1547 if (parsedRangeAnnotation[3] != null)
1549 Cache.log.warn("Ignoring 'After' annotation row in " +
1550 annotation.getVorbaId());
1552 jalview.datamodel.Annotation[] arow = (jalview.datamodel.Annotation[])
1553 parsedRangeAnnotation[2];
1554 boolean[] has = (boolean[]) parsedRangeAnnotation[0];
1555 // 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
1556 /*if ((annotation.getClass().equals(org.vamsas.objects.core.AlignmentAnnotation.class) && ((org.vamsas.objects.core.AlignmentAnnotation)annotation).getGraph())
1557 || (hasSequenceRef=true && ((org.vamsas.objects.core.AlignmentSequenceAnnotation)annotation).getGraph())) {
1561 // make bounds and automatic description strings for jalview user's benefit (these shouldn't be written back to vamsas document)
1562 boolean first = true;
1563 float min = 0, max = 1;
1565 for (int i = 0; i < arow.length; i++)
1567 if (arow[i] != null)
1569 if (i - lastval > 1)
1571 // do some interpolation *between* points
1572 if (arow[lastval] != null)
1574 float interval = arow[i].value - arow[lastval].value;
1575 interval /= i - lastval;
1576 float base = arow[lastval].value;
1577 for (int ip = lastval + 1, np = 0; ip < i; np++, ip++)
1579 arow[ip] = new jalview.datamodel.Annotation("", "", ' ',
1580 interval * np + base);
1581 // NB - Interpolated points don't get a tooltip and description.
1586 // check range - shouldn't we have a min and max property in the annotation object ?
1589 min = max = arow[i].value;
1594 if (arow[i].value < min)
1596 min = arow[i].value;
1598 else if (arow[i].value > max)
1600 max = arow[i].value;
1603 // make tooltip and display char value
1604 if (!has[HASDESCSTR])
1606 arow[i].description = arow[i].value + "";
1610 arow[i].displayCharacter = arow[i].value + "";
1614 int type = jalview.datamodel.AlignmentAnnotation.LINE_GRAPH;
1617 type = jalview.datamodel.AlignmentAnnotation.BAR_GRAPH;
1619 jan = new jalview.datamodel.AlignmentAnnotation(a_label, a_descr, arow,
1624 jan = new jalview.datamodel.AlignmentAnnotation(a_label, a_descr, arow);
1625 jan.setThreshold(null);
1627 if (annotation.getLinkCount() > 0)
1629 Cache.log.warn("Ignoring " + annotation.getLinkCount() +
1630 "links added to AlignmentAnnotation.");
1632 if (annotation.getModifiable())
1634 jan.editable = true;
1637 if (annotation.getPropertyCount() > 0)
1639 // look for special jalview properties
1640 org.vamsas.objects.core.Property[] props = annotation.getProperty();
1641 for (int p = 0; p < props.length; p++)
1643 if (props[p].getName().equalsIgnoreCase("jalview:graphType"))
1647 // probably a jalview annotation graph so recover the visualization hints.
1648 jan.graph = jalview.datamodel.AlignmentAnnotation.
1649 getGraphValueFromString(props[p].getContent());
1654 "Invalid graph type value in jalview:graphType property.");
1658 if (annotation.getGroup() != null &&
1659 annotation.getGroup().length() > 0)
1661 jan.graphGroup = Integer.parseInt(annotation.getGroup());
1666 Cache.log.info("UNIMPLEMENTED : Couldn't parse non-integer group value for setting graphGroup correctly.");
1679 private SequenceFeature getJalviewSeqFeature(RangeAnnotation dseta)
1681 int[] se = getBounds(dseta);
1682 SequenceFeature sf = new jalview.datamodel.SequenceFeature(dseta.getType(),
1683 dseta.getDescription(), dseta.getStatus(), se[0], se[1], dseta
1685 if (dseta.getLinkCount() > 0)
1687 Link[] links = dseta.getLink();
1688 for (int i = 0; i < links.length; i++)
1690 sf.addLink(links[i].getContent() + "|" + links[i].getHref());
1697 * get real bounds of a RangeType's specification. start and end are an
1698 * inclusive range within which all segments and positions lie.
1699 * TODO: refactor to vamsas utils
1701 * @return int[] { start, end}
1703 private int[] getBounds(RangeType dseta)
1708 if (dseta.getSegCount() > 0 && dseta.getPosCount() > 0)
1710 throw new Error("Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!");
1712 if (dseta.getSegCount() > 0)
1714 se = getSegRange(dseta.getSeg(0), true);
1715 for (int s = 1, sSize = dseta.getSegCount(); s < sSize; s++)
1717 int nse[] = getSegRange(dseta.getSeg(s), true);
1728 if (dseta.getPosCount() > 0)
1730 // could do a polarity for pos range too. and pass back indication of discontinuities.
1731 int pos = dseta.getPos(0).getI();
1735 for (int p = 0, pSize = dseta.getPosCount(); p < pSize; p++)
1737 pos = dseta.getPos(p).getI();
1754 * map from a rangeType's internal frame to the referenced object's coordinate frame.
1756 * @return int [] { ref(pos)...} for all pos in rangeType's frame.
1758 private int[] getMapping(RangeType dseta)
1760 Vector posList = new Vector();
1764 if (dseta.getSegCount() > 0 && dseta.getPosCount() > 0)
1766 throw new Error("Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!");
1768 if (dseta.getSegCount() > 0)
1770 for (int s = 0, sSize = dseta.getSegCount(); s < sSize; s++)
1772 se = getSegRange(dseta.getSeg(s), false);
1773 int se_end = se[1 - se[2]] + (se[2] == 0 ? 1 : -1);
1774 for (int p = se[se[2]]; p != se_end; p += se[2] == 0 ? 1 : -1)
1776 posList.add(new Integer(p));
1780 else if (dseta.getPosCount() > 0)
1782 int pos = dseta.getPos(0).getI();
1784 for (int p = 0, pSize = dseta.getPosCount(); p < pSize; p++)
1786 pos = dseta.getPos(p).getI();
1787 posList.add(new Integer(pos));
1791 if (posList != null && posList.size() > 0)
1793 int[] range = new int[posList.size()];
1794 for (int i = 0; i < range.length; i++)
1796 range[i] = ( (Integer) posList.elementAt(i)).intValue();
1805 * Provenance getVamsasProvenance(jalview.datamodel.Provenance jprov) {
1806 jalview.datamodel.ProvenanceEntry[] entries = null;
1807 // TODO: fix App and Action here.
1808 Provenance prov = new Provenance();
1809 org.exolab.castor.types.Date date = new org.exolab.castor.types.Date(
1810 new java.util.Date());
1815 entries = jprov.getEntries();
1816 for (int i = 0; i < entries.length; i++)
1818 provEntry = new Entry();
1821 date = new org.exolab.castor.types.Date(entries[i].getDate());
1822 } catch (Exception ex)
1824 ex.printStackTrace();
1826 date = new org.exolab.castor.types.Date(entries[i].getDate());
1828 provEntry.setDate(date);
1829 provEntry.setUser(entries[i].getUser());
1830 provEntry.setAction(entries[i].getAction());
1831 prov.addEntry(provEntry);
1836 provEntry = new Entry();
1837 provEntry.setDate(date);
1838 provEntry.setUser(System.getProperty("user.name")); // TODO: ext string
1839 provEntry.setApp("JVAPP"); // TODO: ext string
1840 provEntry.setAction(action);
1841 prov.addEntry(provEntry);
1847 jalview.datamodel.Provenance getJalviewProvenance(Provenance prov)
1849 // TODO: fix App and Action entries and check use of provenance in jalview.
1850 jalview.datamodel.Provenance jprov = new jalview.datamodel.Provenance();
1851 for (int i = 0; i < prov.getEntryCount(); i++)
1853 jprov.addEntry(prov.getEntry(i).getUser(), prov.getEntry(i).getAction(),
1854 prov.getEntry(i).getDate().toDate(),
1855 prov.getEntry(i).getId());
1863 * @return default initial provenance list for a Jalview created vamsas
1866 Provenance dummyProvenance()
1868 return dummyProvenance(null);
1871 Entry dummyPEntry(String action)
1873 Entry entry = new Entry();
1874 entry.setApp(this.provEntry.getApp());
1877 entry.setAction(action);
1881 entry.setAction("created.");
1883 entry.setDate(new org.exolab.castor.types.Date(new java.util.Date()));
1884 entry.setUser(this.provEntry.getUser());
1888 Provenance dummyProvenance(String action)
1890 Provenance prov = new Provenance();
1891 prov.addEntry(dummyPEntry(action));
1895 void addProvenance(Provenance p, String action)
1897 p.addEntry(dummyPEntry(action));