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 {
73 Entry provEntry = null;
77 org.exolab.castor.types.Date date = new org.exolab.castor.types.Date(
78 new java.util.Date());
84 IdentityHashMap jv2vobj;
86 public VamsasDatastore(ClientDoc cdoc, Hashtable vobj2jv,
87 IdentityHashMap jv2vobj, Entry provEntry) {
89 this.vobj2jv = vobj2jv;
90 this.jv2vobj = jv2vobj;
91 this.provEntry = provEntry;
95 * public void storeJalview(String file, AlignFrame af) { try { // 1. Load the
96 * mapping information from the file Mapping map = new
97 * Mapping(getClass().getClassLoader()); java.net.URL url =
98 * getClass().getResource("/jalview_mapping.xml"); map.loadMapping(url); // 2.
99 * Unmarshal the data // Unmarshaller unmar = new Unmarshaller();
100 * //unmar.setIgnoreExtraElements(true); //unmar.setMapping(map); // uni =
101 * (UniprotFile) unmar.unmarshal(new FileReader(file)); // 3. marshal the data
102 * with the total price back and print the XML in the console Marshaller
103 * marshaller = new Marshaller( new FileWriter(file) );
105 * marshaller.setMapping(map); marshaller.marshal(af); } catch (Exception e) {
106 * e.printStackTrace(); } }
111 * @return the Vobject bound to Jalview datamodel object
113 protected Vobject getjv2vObj(Object jvobj) {
114 if (jv2vobj.containsKey(jvobj))
115 return cdoc.getObject((VorbaId) jv2vobj.get(jvobj));
122 * @return Jalview datamodel object bound to the vamsas document object
124 protected Object getvObj2jv(org.vamsas.client.Vobject vobj) {
125 VorbaId id = vobj.getVorbaId();
128 id = cdoc.registerObject(vobj);
130 .debug("Registering new object and returning null for getvObj2jv");
133 if (vobj2jv.containsKey(vobj.getVorbaId()))
134 return vobj2jv.get(vobj.getVorbaId());
138 protected void bindjvvobj(Object jvobj, org.vamsas.client.Vobject vobj) {
139 VorbaId id = vobj.getVorbaId();
142 id = cdoc.registerObject(vobj);
143 if (id==null || vobj.getVorbaId()==null)
144 Cache.log.error("Failed to get id for "+(vobj.isRegisterable() ? "registerable" : "unregisterable") +" object "+vobj);
147 if (vobj2jv.containsKey(vobj.getVorbaId()) && !((VorbaId)vobj2jv.get(vobj.getVorbaId())).equals(jvobj)) {
148 Cache.log.debug("Warning? Overwriting existing vamsas id binding for "+vobj.getVorbaId(), new Exception("Overwriting vamsas id binding."));
150 else if (jv2vobj.containsKey(jvobj) && !((VorbaId)jv2vobj.get(jvobj)).equals(vobj.getVorbaId()))
152 Cache.log.debug("Warning? Overwriting existing jalview object binding for "+jvobj, new Exception("Overwriting jalview object binding."));
154 /* 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"));
156 // we just update the hash's regardless!
157 vobj2jv.put(vobj.getVorbaId(), jvobj);
158 // JBPNote - better implementing a hybrid invertible hash.
159 jv2vobj.put(jvobj, vobj.getVorbaId());
163 * put the alignment viewed by AlignViewport into cdoc.
165 * @param av alignViewport to be stored
166 * @param aFtitle title for alignment
168 public void storeVAMSAS(AlignViewport av, String aFtitle) {
171 jalview.datamodel.AlignmentI jal = av.getAlignment();
173 VAMSAS root = null; // will be resolved based on Dataset Parent.
174 // /////////////////////////////////////////
176 if (jal.getDataset() == null)
178 Cache.log.warn("Creating new dataset for an alignment.");
179 jal.setDataset(null);
181 DataSet dataset = (DataSet) getjv2vObj(jal.getDataset());
184 root = cdoc.getVamsasRoots()[0]; // default vamsas root for modifying.
185 dataset = new DataSet();
186 root.addDataSet(dataset);
187 bindjvvobj(jal.getDataset(), dataset);
188 dataset.setProvenance(dummyProvenance());
189 dataset.getProvenance().addEntry(provEntry);
194 root = (VAMSAS) dataset.getV_parent();
199 // set new dataset and alignment sequences based on alignment Nucleotide
201 // this *will* break when alignment contains both nucleotide and amino
203 String dict = jal.isNucleotide() ? org.vamsas.objects.utils.SymbolDictionary.STANDARD_NA
204 : org.vamsas.objects.utils.SymbolDictionary.STANDARD_AA;
205 for (int i = 0; i < jal.getHeight(); i++)
207 SequenceI sq = jal.getSequenceAt(i).getDatasetSequence(); // only insert
211 sequence = (Sequence) getjv2vObj(sq);
212 if (sequence == null)
214 sequence = new Sequence();
215 bindjvvobj(sq, sequence);
216 sq.setVamsasId(sequence.getVorbaId().getId());
217 sequence.setSequence(sq.getSequenceAsString());
218 sequence.setDictionary(dict);
219 sequence.setName(jal.getDataset().getSequenceAt(i).getName());
220 sequence.setStart(jal.getDataset().getSequenceAt(i).getStart());
221 sequence.setEnd(jal.getDataset().getSequenceAt(i).getEnd());
222 dataset.addSequence(sequence);
226 // verify principal attributes. and update any new
227 // features/references.
228 System.out.println("update dataset sequence object.");
230 if (sq.getSequenceFeatures() != null)
232 int sfSize = sq.getSequenceFeatures().length;
234 for (int sf = 0; sf < sfSize; sf++)
236 jalview.datamodel.SequenceFeature feature = (jalview.datamodel.SequenceFeature) sq
237 .getSequenceFeatures()[sf];
239 DataSetAnnotations dsa = (DataSetAnnotations) getjv2vObj(feature);
242 dsa = (DataSetAnnotations) getDSAnnotationFromJalview(
243 new DataSetAnnotations(), feature);
244 if (dsa.getProvenance() == null)
246 dsa.setProvenance(new Provenance());
248 addProvenance(dsa.getProvenance(), "created"); // JBPNote - need
250 dsa.setSeqRef(sequence);
251 bindjvvobj(feature, dsa);
252 dataset.addDataSetAnnotations(dsa);
256 // todo: verify and update dataset annotations for sequence
257 System.out.println("update dataset sequence annotations.");
262 if (sq.getDBRef() != null)
264 DBRefEntry[] entries = sq.getDBRef();
265 jalview.datamodel.DBRefEntry dbentry;
266 for (int db = 0; db < entries.length; db++)
268 dbentry = entries[db];
269 dbref = (DbRef) getjv2vObj(dbentry);
273 bindjvvobj(dbentry, dbref);
274 dbref.setAccessionId(dbentry.getAccessionId());
275 dbref.setSource(dbentry.getSource());
276 dbref.setVersion(dbentry.getVersion());
278 * TODO: Maps are not yet supported by Jalview. Map vMap = new
279 * Map(); vMap.set dbref.addMap(vMap);
281 sequence.addDbRef(dbref);
285 // TODO: verify and update dbrefs in vamsas document
286 // there will be trouble when a dataset sequence is modified to
287 // contain more residues than were originally referenced - we must
288 // then make a number of dataset sequence entries
290 .println("update dataset sequence database references.");
296 // dataset.setProvenance(getVamsasProvenance(jal.getDataset().getProvenance()));
297 // ////////////////////////////////////////////
299 // ////////////////////////////////////////////
300 // Save the Alignments
302 Alignment alignment = (Alignment) getjv2vObj(av); // this is so we can get the alignviewport back
303 if (alignment == null)
305 alignment = new Alignment();
306 bindjvvobj(av, alignment);
307 if (alignment.getProvenance() == null)
308 alignment.setProvenance(new Provenance());
309 addProvenance(alignment.getProvenance(), "added"); // TODO: insert some
312 dataset.addAlignment(alignment);
314 Property title = new Property();
315 title.setName("jalview:AlTitle");
316 title.setType("string");
317 title.setContent(aFtitle);
318 alignment.addProperty(title);
320 alignment.setGapChar(String.valueOf(av.getGapCharacter()));
321 AlignmentSequence alseq = null;
322 for (int i = 0; i < jal.getHeight(); i++)
324 alseq = new AlignmentSequence();
325 // TODO: VAMSAS: translate lowercase symbols to annotation ?
326 alseq.setSequence(jal.getSequenceAt(i).getSequenceAsString());
327 alseq.setName(jal.getSequenceAt(i).getName());
328 alseq.setStart(jal.getSequenceAt(i).getStart());
329 alseq.setEnd(jal.getSequenceAt(i).getEnd());
330 alseq.setRefid(getjv2vObj(jal.getSequenceAt(i).getDatasetSequence()));
331 alignment.addAlignmentSequence(alseq);
332 bindjvvobj(jal.getSequenceAt(i), alseq);
337 // todo: verify and update mutable alignment props.
338 if (alignment.getModifiable())
340 System.out.println("update alignment in document.");
345 .println("update edited alignment to new alignment in document.");
348 // ////////////////////////////////////////////
349 // SAVE Alignment Sequence Features
350 for (int i = 0, iSize = alignment.getAlignmentSequenceCount(); i < iSize; i++)
352 AlignmentSequence valseq;
353 SequenceI alseq = (SequenceI) getvObj2jv(valseq = alignment
354 .getAlignmentSequence(i));
355 if (alseq != null && alseq.getSequenceFeatures() != null)
357 jalview.datamodel.SequenceFeature[] features = alseq
358 .getSequenceFeatures();
359 for (int f = 0; f < features.length; f++)
361 if (features[f] != null)
363 AlignmentSequenceAnnotation valseqf = (AlignmentSequenceAnnotation) getjv2vObj(features[i]);
367 valseqf = (AlignmentSequenceAnnotation) getDSAnnotationFromJalview(
368 new AlignmentSequenceAnnotation(), features[i]);
369 if (valseqf.getProvenance() == null)
371 valseqf.setProvenance(new Provenance());
373 addProvenance(valseqf.getProvenance(), "created"); // JBPNote -
376 bindjvvobj(features[i], valseqf);
377 valseq.addAlignmentSequenceAnnotation(valseqf);
385 // ////////////////////////////////////////////
387 if (jal.getAlignmentAnnotation() != null)
389 jalview.datamodel.AlignmentAnnotation[] aa = jal
390 .getAlignmentAnnotation();
391 java.util.HashMap AlSeqMaps = new HashMap(); // stores int maps from
392 // alignment columns to
393 // sequence positions.
394 for (int i = 0; i < aa.length; i++)
396 if (aa[i] == null || isJalviewOnly(aa[i]))
400 if (aa[i].sequenceRef != null)
402 org.vamsas.objects.core.AlignmentSequence alsref = (org.vamsas.objects.core.AlignmentSequence) getjv2vObj(aa[i].sequenceRef);
403 org.vamsas.objects.core.AlignmentSequenceAnnotation an = (org.vamsas.objects.core.AlignmentSequenceAnnotation) getjv2vObj(aa[i]);
405 if (AlSeqMaps.containsKey(aa[i].sequenceRef))
407 gapMap = (int[]) AlSeqMaps.get(aa[i].sequenceRef);
411 gapMap = new int[aa[i].sequenceRef.getLength()];
412 // map from alignment position to sequence position.
413 int[] sgapMap = aa[i].sequenceRef.gapMap();
414 for (int a = 0; a < sgapMap.length; a++)
415 gapMap[sgapMap[a]] = a;
419 an = new org.vamsas.objects.core.AlignmentSequenceAnnotation();
420 Seg vSeg = new Seg();
422 vSeg.setInclusive(true);
423 vSeg.setEnd(gapMap.length);
425 an.setType("jalview:SecondaryStructurePrediction");// TODO: better fix this rough guess ;)
426 alsref.addAlignmentSequenceAnnotation(an);
427 bindjvvobj(aa[i],an);
428 // LATER: much of this is verbatim from the alignmentAnnotation
429 // method below. suggests refactoring to make rangeAnnotation the
431 an.setDescription(aa[i].description);
433 an.setGraph(true); // aa[i].graph);
436 an.setLabel(aa[i].label);
437 an.setProvenance(dummyProvenance()); // get provenance as user
438 // created, or jnet, or
440 an.setGroup(Integer.toString(aa[i].graphGroup)); // // JBPNote -
448 AnnotationElement ae;
449 for (int a = 0; a < aa[i].annotations.length; a++)
451 if (aa[i].annotations[a] == null)
456 ae = new AnnotationElement();
457 ae.setDescription(aa[i].annotations[a].description);
458 ae.addGlyph(new Glyph());
460 .setContent(aa[i].annotations[a].displayCharacter); // assume
467 if (aa[i].graph!=jalview.datamodel.AlignmentAnnotation.NO_GRAPH)
468 ae.addValue(aa[i].annotations[a].value);
469 ae.setPosition(gapMap[a]+1); // position w.r.t. AlignmentSequence
471 if (aa[i].annotations[a].secondaryStructure != ' ')
473 // we only write an annotation where it really exists.
474 Glyph ss = new Glyph();
476 .setDict(org.vamsas.objects.utils.GlyphDictionary.PROTEIN_SS_3STATE);
478 .valueOf(aa[i].annotations[a].secondaryStructure));
481 an.addAnnotationElement(ae);
486 // update reference sequence Annotation
487 if (an.getModifiable())
489 // verify existing alignment sequence annotation is up to date
490 System.out.println("update alignment sequence annotation.");
494 // verify existing alignment sequence annotation is up to date
496 .println("make new alignment sequence annotation if modification has happened.");
502 // add Alignment Annotation
503 org.vamsas.objects.core.AlignmentAnnotation an = (org.vamsas.objects.core.AlignmentAnnotation) getjv2vObj(aa[i]);
506 an = new org.vamsas.objects.core.AlignmentAnnotation();
507 an.setType("jalview:AnnotationRow");
508 an.setDescription(aa[i].description);
509 alignment.addAlignmentAnnotation(an);
510 Seg vSeg = new Seg();
512 vSeg.setInclusive(true);
513 vSeg.setEnd(jal.getWidth());
516 an.setGraph(true); // aa[i].graph);
517 an.setLabel(aa[i].label);
518 an.setProvenance(dummyProvenance());
519 if (aa[i].graph!=aa[i].NO_GRAPH) {
520 an.setGroup(Integer.toString(aa[i].graphGroup)); // // JBPNote -
532 AnnotationElement ae;
534 for (int a = 0; a < aa[i].annotations.length; a++)
536 if ((aa[i] == null) || (aa[i].annotations[a] == null))
541 ae = new AnnotationElement();
542 ae.setDescription(aa[i].annotations[a].description);
543 ae.addGlyph(new Glyph());
545 .setContent(aa[i].annotations[a].displayCharacter); // assume
552 ae.addValue(aa[i].annotations[a].value);
554 if (aa[i].annotations[a].secondaryStructure != ' ')
556 Glyph ss = new Glyph();
558 .setDict(org.vamsas.objects.utils.GlyphDictionary.PROTEIN_SS_3STATE);
560 .valueOf(aa[i].annotations[a].secondaryStructure));
563 an.addAnnotationElement(ae);
565 if (aa[i].editable) {
566 //an.addProperty(newProperty("jalview:editable", null, "true"));
567 an.setModifiable(true);
569 if (aa[i].graph!=jalview.datamodel.AlignmentAnnotation.NO_GRAPH) {
571 an.setGroup(Integer.toString(aa[i].graphGroup));
572 an.addProperty(newProperty("jalview:graphType",null,
573 ((aa[i].graph==jalview.datamodel.AlignmentAnnotation.BAR_GRAPH) ? "BAR_GRAPH" : "LINE_GRAPH")));
576 vProperty=new Property();
577 vProperty.setName("jalview:graphThreshhold");
578 vProperty.setContent(aa[i].threshold);
585 if (an.getModifiable())
587 // verify annotation - update (perhaps)
588 Cache.log.info("update alignment sequence annotation. not yet implemented.");
592 // verify annotation - update (perhaps)
593 Cache.log.info("updated alignment sequence annotation added.");
599 // /////////////////////////////////////////////////////
601 // //////////////////////////////////////////////
603 // /////////////////////////////////
604 // FIND ANY ASSOCIATED TREES
605 if (Desktop.desktop != null)
607 javax.swing.JInternalFrame[] frames = Desktop.desktop.getAllFrames();
609 for (int t = 0; t < frames.length; t++)
611 if (frames[t] instanceof TreePanel)
613 TreePanel tp = (TreePanel) frames[t];
615 if (tp.getAlignment() == jal)
617 Tree tree = (Tree) getjv2vObj(tp);
621 bindjvvobj(tp, tree);
622 tree.setTitle(tp.getTitle());
623 Newick newick = new Newick();
624 // TODO: translate sequenceI to leaf mappings to vamsas
625 // references - see tree specification in schema.
626 newick.setContent(tp.getTree().toString());
627 newick.setTitle(tp.getTitle());
628 tree.addNewick(newick);
629 tree.setProvenance(makeTreeProvenance(jal, tp));
630 alignment.addTree(tree);
634 if (tree.getModifiable())
636 // verify any changes.
637 System.out.println("Update tree in document.");
642 .println("Add modified tree as new tree in document.");
649 // Store Jalview specific stuff in the Jalview appData
650 // not implemented in the SimpleDoc interface.
655 ex.printStackTrace();
660 private Property newProperty(String name, String type, String content) {
661 Property vProperty=new Property();
662 vProperty.setName(name);
664 vProperty.setType(type);
666 vProperty.setType("String");
667 vProperty.setContent(content);
672 * correctly create a RangeAnnotation from a jalview sequence feature
675 * (typically DataSetAnnotations or AlignmentSequenceAnnotation)
677 * (the feature to be mapped from)
680 private RangeAnnotation getDSAnnotationFromJalview(RangeAnnotation dsa,
681 SequenceFeature feature) {
682 dsa.setType(feature.getType());
683 Seg vSeg = new Seg();
684 vSeg.setStart(feature.getBegin());
685 vSeg.setEnd(feature.getEnd());
686 vSeg.setInclusive(true);
688 dsa.setDescription(feature.getDescription());
689 dsa.setStatus(feature.getStatus());
690 if (feature.links != null && feature.links.size() > 0)
692 for (int i = 0, iSize = feature.links.size(); i < iSize; i++)
694 String link = (String) feature.links.elementAt(i);
695 int sep = link.indexOf('|');
698 Link vLink = new Link();
700 vLink.setContent(link.substring(0, sep - 1));
702 vLink.setContent("");
703 vLink.setHref(link.substring(sep + 1)); // TODO: validate href.
708 dsa.setGroup(feature.getFeatureGroup());
713 * correctly creates provenance for trees calculated on an alignment by
720 private Provenance makeTreeProvenance(AlignmentI jal, TreePanel tp) {
721 Provenance prov = new Provenance();
722 prov.addEntry(new Entry());
723 prov.getEntry(0).setAction("imported "+tp.getTitle());
724 prov.getEntry(0).setUser(provEntry.getUser());
725 prov.getEntry(0).setApp(provEntry.getApp());
726 prov.getEntry(0).setDate(provEntry.getDate());
727 if (tp.getTree().hasOriginalSequenceData())
729 Input vInput = new Input();
730 // LATER: check to see if tree input data is contained in this alignment -
731 // or just correctly resolve the tree's seqData to the correct alignment in
733 // vInput.setObjRef(getjv2vObj(jal));
734 vInput.setObjRef(getjv2vObj(tp.getViewPort()));
735 prov.getEntry(0).setAction("created "+tp.getTitle());
736 prov.getEntry(0).addInput(vInput);
737 vInput.setName("jalview:seqdist");
738 prov.getEntry(0).addParam(new Param());
739 prov.getEntry(0).getParam(0).setName("treeType");
740 prov.getEntry(0).getParam(0).setType("utf8");
741 prov.getEntry(0).getParam(0).setContent("NJ");
743 int ranges[] = tp.getTree().seqData.getVisibleContigs();
744 // VisibleContigs are with respect to alignment coordinates. Still need offsets
745 int start= tp.getTree().seqData.getAlignmentOrigin();
746 for (int r = 0; r < ranges.length; r += 2)
748 Seg visSeg = new Seg();
749 visSeg.setStart(1+start+ranges[r]);
750 visSeg.setEnd(start+ranges[r + 1]);
751 visSeg.setInclusive(true);
752 vInput.addSeg(visSeg);
761 * @return Object[] { AlignmentView, AlignmentI - reference alignment for
764 private Object[] recoverInputData(Provenance tp) {
765 for (int pe = 0; pe < tp.getEntryCount(); pe++)
767 if (tp.getEntry(pe).getInputCount() > 0)
769 if (tp.getEntry(pe).getInputCount() > 1)
770 Cache.log.warn("Ignoring additional input spec in provenance entry "
771 + tp.getEntry(pe).toString());
772 // LATER: deal sensibly with multiple inputs.
773 Input vInput = tp.getEntry(pe).getInput(0);
774 if (vInput.getObjRef() instanceof org.vamsas.objects.core.Alignment)
776 // recover an AlignmentView for the input data
777 AlignViewport javport = (AlignViewport) getvObj2jv((org.vamsas.client.Vobject) vInput
779 jalview.datamodel.AlignmentI jal = javport.getAlignment();
780 jalview.datamodel.CigarArray view = javport.getAlignment().getCompactAlignment();
781 int from = 1, to = jal.getWidth();
782 int offset=0; // deleteRange modifies its frame of reference
783 for (int r = 0, s = vInput.getSegCount(); r < s; r++)
785 Seg visSeg = vInput.getSeg(r);
786 int se[] = getSegRange(visSeg,true); // jalview doesn't do bidirection alignments yet.
788 Cache.log.warn("Ignoring invalid segment in InputData spec.");
793 view.deleteRange(offset+from-1, offset+se[0] - 2);
801 view.deleteRange(offset+from-1, offset+to-1); // final deletion - TODO: check off by
804 return new Object[] { new AlignmentView(view), jal };
808 Cache.log.debug("Returning null for input data recovery from provenance.");
813 * get start<end range of segment, adjusting for inclusivity flag and
817 * @param ensureDirection when true - always ensure start is less than end.
818 * @return int[] { start, end, direction} where direction==1 for range running from end to start.
820 private int[] getSegRange(Seg visSeg, boolean ensureDirection) {
821 boolean incl = visSeg.getInclusive();
822 // adjust for inclusive flag.
823 int pol = (visSeg.getStart() <= visSeg.getEnd()) ? 1 : -1; // polarity of
825 int start = visSeg.getStart() + (incl ? 0 : pol);
826 int end = visSeg.getEnd() + (incl ? 0 : -pol);
827 if (ensureDirection && pol==-1)
829 // jalview doesn't deal with inverted ranges, yet.
834 return new int[] { start, end, pol<0 ? 1 : 0 };
840 * @return true if annotation is not to be stored in document
842 private boolean isJalviewOnly(AlignmentAnnotation annotation) {
843 return annotation.label.equals("Quality")
844 || annotation.label.equals("Conservation")
845 || annotation.label.equals("Consensus");
848 * This will return the first AlignFrame viewing AlignViewport av.
849 * It will break if there are more than one AlignFrames viewing a particular av.
850 * This also shouldn't be in the io package.
852 * @return alignFrame for av
854 public AlignFrame getAlignFrameFor(AlignViewport av) {
855 if (Desktop.desktop != null)
857 javax.swing.JInternalFrame[] frames = Desktop.desktop.getAllFrames();
859 for (int t = 0; t < frames.length; t++)
861 if (frames[t] instanceof AlignFrame) {
862 if (((AlignFrame) frames[t]).getViewport()==av)
863 return (AlignFrame) frames[t];
869 public void updateToJalview() {
870 VAMSAS _roots[] = cdoc.getVamsasRoots();
872 for (int _root = 0; _root<_roots.length; _root++) {
873 VAMSAS root = _roots[_root];
875 for (int _ds=0,_nds=root.getDataSetCount(); _ds<_nds; _ds++) {
876 // ///////////////////////////////////
878 DataSet dataset = root.getDataSet(_ds);
879 int i, iSize = dataset.getSequenceCount();
881 jalview.datamodel.Alignment jdataset = (jalview.datamodel.Alignment) getvObj2jv(dataset);
883 if (jdataset==null) {
884 Cache.log.debug("Initialising new jalview dataset fields");
888 Cache.log.debug("Update jalview dataset from vamsas.");
889 jremain=jdataset.getHeight();
890 dsseqs=jdataset.getSequences();
893 // TODO: test sequence merging - we preserve existing non vamsas
894 // sequences but add in any new vamsas ones, and don't yet update any
895 // sequence attributes
896 for (i = 0; i < iSize ; i++)
898 Sequence vdseq = dataset.getSequence(i);
899 jalview.datamodel.SequenceI dsseq = (SequenceI) getvObj2jv(vdseq);
901 if (!dsseq.getSequence().equals(vdseq.getSequence()))
902 throw new Error("Broken! - mismatch of dataset sequence and jalview internal dataset sequence.");
905 dsseq = new jalview.datamodel.Sequence(
906 dataset.getSequence(i).getName(),
907 dataset.getSequence(i).getSequence(),
908 dataset.getSequence(i).getStart(),
909 dataset.getSequence(i).getEnd() );
910 dsseq.setDescription(dataset.getSequence(i).getDescription());
911 bindjvvobj(dsseq, dataset.getSequence(i));
912 dsseq.setVamsasId(dataset.getSequence(i).getVorbaId().getId());
915 if (vdseq.getDbRefCount()>0) {
916 DbRef [] dbref = vdseq.getDbRef();
917 for(int db=0; db<dbref.length; db++)
919 jalview.datamodel.DBRefEntry dbr=(jalview.datamodel.DBRefEntry) getvObj2jv(dbref[db]);
922 dsseq.addDBRef(dbr= new jalview.datamodel.DBRefEntry
924 dbref[db].getSource().toString(),
925 dbref[db].getVersion().toString(),
926 dbref[db].getAccessionId().toString()));
927 bindjvvobj(dbr, dbref[db]);
934 SequenceI[] seqs = new SequenceI[dsseqs.size()];
935 for (i=0,iSize=dsseqs.size(); i<iSize; i++) {
936 seqs[i]=(SequenceI) dsseqs.elementAt(i);
937 dsseqs.setElementAt(null, i);
939 jdataset = new jalview.datamodel.Alignment(seqs);
940 Cache.log.debug("New vamsas dataset imported into jalview.");
941 bindjvvobj(jdataset, dataset);
944 // add any new dataset sequence feature annotations
945 if (dataset.getDataSetAnnotations() != null) {
946 for (int dsa = 0; dsa < dataset.getDataSetAnnotationsCount(); dsa++) {
947 DataSetAnnotations dseta=dataset.getDataSetAnnotations(dsa);
948 SequenceI dsSeq=(SequenceI) getvObj2jv((Vobject) dseta.getSeqRef());
950 jalview.bin.Cache.log.warn("Couldn't resolve jalview sequenceI for dataset object reference "+((Vobject)dataset.getDataSetAnnotations(dsa).getSeqRef()).getVorbaId().getId());
952 if (dseta.getAnnotationElementCount()==0) {
953 jalview.datamodel.SequenceFeature sf=(jalview.datamodel.SequenceFeature) getvObj2jv(dseta);
955 dsSeq.addSequenceFeature(sf=getJalviewSeqFeature(dseta));
956 bindjvvobj(sf, dseta);
959 // TODO: deal with alignmentAnnotation style annotation
960 // appearing on dataset sequences.
961 // JBPNote: we could just add them to all alignments but
962 // that may complicate cross references in the jalview
964 Cache.log.warn("Ignoring dataset annotation with annotationElements. Not yet supported in jalview.");
970 if (dataset.getAlignmentCount()>0) {
971 // LOAD ALIGNMENTS from DATASET
973 for (int al=0,nal=dataset.getAlignmentCount(); al<nal; al++) {
974 org.vamsas.objects.core.Alignment alignment = dataset.getAlignment(al);
975 AlignViewport av = (AlignViewport) getvObj2jv(alignment);
976 jalview.datamodel.AlignmentI jal=null;
978 jal = av.getAlignment();
979 iSize = alignment.getAlignmentSequenceCount();
980 boolean newal=(jal==null) ? true : false;
981 Vector newasAnnots=new Vector();
982 char gapChar=' '; // default for new alignments read in from the document
984 dsseqs=jal.getSequences(); // for merge/update
985 gapChar=jal.getGapCharacter();
989 char valGapchar=alignment.getGapChar().charAt(0);
990 for (i = 0; i < iSize; i++)
992 AlignmentSequence valseq = alignment.getAlignmentSequence(i);
993 jalview.datamodel.SequenceI alseq = (SequenceI) getvObj2jv(valseq);
995 //TODO: upperCase/LowerCase situation here ? do we allow it ?
996 //if (!alseq.getSequence().equals(valseq.getSequence())) {
997 // throw new Error("Broken! - mismatch of dataset sequence and jalview internal dataset sequence.");
998 if (Cache.log.isDebugEnabled())
999 Cache.log.debug("Updating apparently edited sequence "+alseq.getName());
1000 // this might go *horribly* wrong
1001 alseq.setSequence(new String(valseq.getSequence()).replace(valGapchar, gapChar));
1004 alseq = new jalview.datamodel.Sequence(
1006 valseq.getSequence().replace(valGapchar, gapChar),
1010 Vobject datsetseq = (Vobject)valseq.getRefid();
1011 if (datsetseq!=null) {
1012 alseq.setDatasetSequence((SequenceI)getvObj2jv(datsetseq)); // exceptions if AlignemntSequence reference isn't a simple SequenceI
1014 Cache.log.error("Invalid dataset sequence id (null) for alignment sequence "+valseq.getVorbaId());
1016 bindjvvobj(alseq, valseq);
1017 alseq.setVamsasId(valseq.getVorbaId().getId());
1020 if (valseq.getAlignmentSequenceAnnotationCount()>0) {
1021 AlignmentSequenceAnnotation[] vasannot=valseq.getAlignmentSequenceAnnotation();
1022 for (int a=0; a<vasannot.length; a++) {
1023 jalview.datamodel.AlignmentAnnotation asa = (jalview.datamodel.AlignmentAnnotation) getvObj2jv(vasannot[a]); // TODO: 1:many jalview alignment sequence annotations
1025 int se[] = getBounds(vasannot[a]);
1026 asa = getjAlignmentAnnotation(jal, vasannot[a]);
1027 asa.sequenceRef=alseq;
1028 asa.createSequenceMapping(alseq, alseq.getStart()+se[0], false); // TODO: verify that positions in alseqAnnotation correspond to ungapped residue positions.
1029 bindjvvobj(asa, vasannot[a]);
1030 newasAnnots.add(asa);
1032 // update existing annotation - can do this in place
1033 if (vasannot[a].getModifiable()) {
1034 Cache.log.info("UNIMPLEMENTED: not recovering user modifiable sequence alignment annotation");
1035 // TODO: should at least replace with new one - otherwise things will break
1036 // basically do this:
1037 // int se[] = getBounds(vasannot[a]);
1038 // asa.update(getjAlignmentAnnotation(jal, vasannot[a])); // update from another annotation object in place.
1039 // asa.createSequenceMapping(alseq, se[0], false);
1047 SequenceI[] seqs = new SequenceI[dsseqs.size()];
1048 for (i=0,iSize=dsseqs.size(); i<iSize; i++) {
1049 seqs[i]=(SequenceI) dsseqs.elementAt(i);
1050 dsseqs.setElementAt(null, i);
1052 jal = new jalview.datamodel.Alignment(seqs);
1053 Cache.log.debug("New vamsas alignment imported into jalview "+alignment.getVorbaId().getId());
1054 jal.setDataset(jdataset);
1056 if (newasAnnots!=null && newasAnnots.size()>0) {
1057 // Add the new sequence annotations in to the alignment.
1058 for (int an=0,anSize=newasAnnots.size(); an<anSize; an++) {
1059 jal.addAnnotation((AlignmentAnnotation) newasAnnots.elementAt(an));
1060 // TODO: check if anything has to be done - like calling adjustForAlignment or something.
1061 newasAnnots.setElementAt(null, an);
1065 // //////////////////////////////////////////
1066 // //LOAD ANNOTATIONS FOR THE ALIGNMENT
1067 // ////////////////////////////////////
1068 if (alignment.getAlignmentAnnotationCount()>0)
1070 org.vamsas.objects.core.AlignmentAnnotation[] an = alignment.getAlignmentAnnotation();
1072 for (int j = 0; j < an.length; j++)
1074 jalview.datamodel.AlignmentAnnotation jan=(jalview.datamodel.AlignmentAnnotation) getvObj2jv(an[j]);
1076 // update or stay the same.
1077 // TODO: should at least replace with a new one - otherwise things will break
1078 // basically do this:
1079 // jan.update(getjAlignmentAnnotation(jal, an[a])); // update from another annotation object in place.
1081 Cache.log.debug("update from vamsas alignment annotation to existing jalview alignment annotation.");
1082 if (an[j].getModifiable()) {
1083 // TODO: user defined annotation is totally mutable... - so load it up or throw away if locally edited.
1084 Cache.log.info("NOT IMPLEMENTED - Recovering user-modifiable annotation - yet...");
1086 // TODO: compare annotation element rows
1087 // TODO: compare props.
1089 jan = getjAlignmentAnnotation(jal, an[j]);
1090 jal.addAnnotation(jan);
1091 bindjvvobj(jan, an[j]);
1095 AlignFrame alignFrame;
1097 Cache.log.debug("New alignframe for alignment "+alignment.getVorbaId());
1098 // ///////////////////////////////
1099 // construct alignment view
1100 alignFrame = new AlignFrame(jal, AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
1101 av=alignFrame.getViewport();
1102 String title = alignment.getProvenance().getEntry(alignment.getProvenance().getEntryCount()-1).getAction();
1103 if (alignment.getPropertyCount()>0) {
1104 for (int p=0,pe=alignment.getPropertyCount(); p<pe; p++) {
1105 if (alignment.getProperty(p).getName().equals("jalview:AlTitle")) {
1106 title = alignment.getProperty(p).getContent();
1110 // TODO: automatically create meaningful title for a vamsas alignment using its provenance.
1111 jalview.gui.Desktop.addInternalFrame(alignFrame, title + "("+alignment.getVorbaId()+")",
1112 AlignFrame.DEFAULT_WIDTH,
1113 AlignFrame.DEFAULT_HEIGHT);
1114 bindjvvobj(av, alignment);
1116 // find the alignFrame for jal.
1117 // TODO: fix this so we retrieve the alignFrame handing av *directly*
1118 alignFrame=getAlignFrameFor(av);
1121 // /////////////////////////////////////
1122 if (alignment.getTreeCount() > 0)
1125 for (int t = 0; t < alignment.getTreeCount(); t++)
1127 Tree tree = alignment.getTree(t);
1128 TreePanel tp=(TreePanel) getvObj2jv(tree);
1130 Cache.log.info("Update from vamsas document to alignment associated tree not implemented yet.");
1133 Object[] idata = this.recoverInputData(tree.getProvenance());
1135 AlignmentView inputData=null;
1136 if (idata!=null && idata[0]!=null)
1137 inputData = (AlignmentView) idata[0];
1138 tp = alignFrame.ShowNewickTree(
1139 new jalview.io.NewickFile(tree.getNewick(0).getContent()),
1140 tree.getNewick(0).getTitle()+" ("+tree.getVorbaId()+")",inputData,
1142 t * 20 + 50, t * 20 + 50);
1143 bindjvvobj(tp, tree);
1144 } catch (Exception e) {
1145 Cache.log.warn("Problems parsing treefile '"+tree.getNewick(0).getContent()+"'",e);
1156 // bitfields - should be a template in j1.5
1157 private static int HASSECSTR=0;
1158 private static int HASVALS=1;
1159 private static int HASHPHOB=2;
1160 private static int HASDC=3;
1161 private static int HASDESCSTR=4;
1162 private static int HASTWOSTATE=5; // not used yet.
1164 * parses the AnnotationElements - if they exist - into jalview.datamodel.Annotation[] rows
1165 * Two annotation rows are made if there are distinct annotation for both at 'pos' and 'after pos' at any particular site.
1167 * @return { boolean[static int constants ], int[ae.length] - map to annotated object frame, jalview.datamodel.Annotation[], jalview.datamodel.Annotation[] (after)}
1169 private Object[] parseRangeAnnotation(org.vamsas.objects.core.RangeAnnotation annotation) {
1170 // set these attributes by looking in the annotation to decide what kind of alignment annotation rows will be made
1171 // TODO: potentially we might make several annotation rows from one vamsas alignment annotation. the jv2Vobj binding mechanism
1172 // may not quite cope with this (without binding an array of annotations to a vamsas alignment annotation)
1173 // summary flags saying what we found over the set of annotation rows.
1174 boolean[] AeContent = new boolean[] { false, false, false, false, false};
1175 int[] rangeMap = getMapping(annotation);
1176 jalview.datamodel.Annotation[][] anot=new jalview.datamodel.Annotation[][] {
1177 new jalview.datamodel.Annotation[rangeMap.length],
1178 new jalview.datamodel.Annotation[rangeMap.length]
1180 boolean mergeable=true; //false if 'after positions cant be placed on same annotation row as positions.
1182 if (annotation.getAnnotationElementCount()>0) {
1183 AnnotationElement ae[] = annotation.getAnnotationElement();
1184 for (int aa = 0; aa < ae.length; aa++)
1186 int pos = ae[aa].getPosition()-1;// pos counts from 1 to (|seg.start-seg.end|+1)
1187 if (pos>=0 && pos<rangeMap.length) {
1188 int row=ae[aa].getAfter()?1:0;
1189 if (anot[row][pos]!=null) {
1190 // only time this should happen is if the After flag is set.
1191 Cache.log.debug("Ignoring duplicate annotation site at "+pos);
1194 if (anot[1-row][pos]!=null)
1197 if (ae[aa].getDescription()!=null) {
1198 desc = ae[aa].getDescription();
1199 if (desc.length()>0) {
1200 // have imported valid description string
1201 AeContent[HASDESCSTR]=true;
1204 String dc = null;//ae[aa].getDisplayCharacter()==null ? "dc" : ae[aa].getDisplayCharacter();
1205 String ss = null;//ae[aa].getSecondaryStructure()==null ? "ss" : ae[aa].getSecondaryStructure();
1206 java.awt.Color colour = null;
1207 if (ae[aa].getGlyphCount()>0) {
1208 Glyph[] glyphs = ae[aa].getGlyph();
1209 for (int g=0; g<glyphs.length; g++) {
1210 if (glyphs[g].getDict().equals(org.vamsas.objects.utils.GlyphDictionary.PROTEIN_SS_3STATE)) {
1211 ss=glyphs[g].getContent();
1212 AeContent[HASSECSTR]=true;
1213 } else if (glyphs[g].getDict().equals(org.vamsas.objects.utils.GlyphDictionary.PROTEIN_HD_HYDRO)) {
1214 Cache.log.debug("ignoring hydrophobicity glyph marker.");
1215 AeContent[HASHPHOB]=true;
1216 char c=(dc=glyphs[g].getContent()).charAt(0);
1217 // dc may get overwritten - but we still set the colour.
1218 colour = new java.awt.Color(c=='+'?255:0,c=='.'?255:0,c=='-'?255:0);
1220 } else if (glyphs[g].getDict().equals(org.vamsas.objects.utils.GlyphDictionary.DEFAULT)) {
1221 dc = glyphs[g].getContent();
1222 AeContent[HASDC]=true;
1224 Cache.log.debug("Ignoring unknown glyph type "+glyphs[g].getDict());
1229 if (ae[aa].getValueCount()>0) {
1230 AeContent[HASVALS]=true;
1231 if (ae[aa].getValueCount()>1) {
1232 Cache.log.warn("ignoring additional "+(ae[aa].getValueCount()-1)+"values in annotation element.");
1234 val = ae[aa].getValue(0);
1237 anot[row][pos]=new jalview.datamodel.Annotation((dc!=null) ? dc : "", desc, (ss!=null)?ss.charAt(0):' ', val);
1239 anot[row][pos]=new jalview.datamodel.Annotation((dc!=null) ? dc : "", desc, (ss!=null)?ss.charAt(0):' ', val, colour);
1242 Cache.log.warn("Ignoring out of bound annotation element "+aa+" in "+annotation.getVorbaId().getId());
1245 // decide on how many annotation rows are needed.
1247 for (int i=0; i<anot[0].length;i++) {
1248 if (anot[1][i]!=null) {
1249 anot[0][i] = anot[1][i];
1250 anot[0][i].description = anot[0][i].description+" (after)";
1251 AeContent[HASDESCSTR]=true; // we have valid description string data
1257 for (int i=0; i<anot[0].length;i++) {
1258 anot[1][i].description = anot[1][i].description+" (after)";
1261 return new Object[] { AeContent, rangeMap, anot[0], anot[1] };
1263 // no annotations to parse. Just return an empty annotationElement[] array.
1264 return new Object[] { AeContent, rangeMap, anot[0], anot[1] };
1269 * @param jal the jalview alignment to which the annotation will be attached (ideally - freshly updated from corresponding vamsas alignment)
1271 * @return unbound jalview alignment annotation object.
1273 private jalview.datamodel.AlignmentAnnotation getjAlignmentAnnotation(jalview.datamodel.AlignmentI jal, org.vamsas.objects.core.RangeAnnotation annotation) {
1274 jalview.datamodel.AlignmentAnnotation jan =null;
1275 if (annotation==null)
1277 // boolean hasSequenceRef=annotation.getClass().equals(org.vamsas.objects.core.AlignmentSequenceAnnotation.class);
1278 //boolean hasProvenance=hasSequenceRef || (annotation.getClass().equals(org.vamsas.objects.core.AlignmentAnnotation.class));
1279 /*int se[] = getBounds(annotation);
1281 se=new int[] {0,jal.getWidth()-1};
1283 Object[] parsedRangeAnnotation = parseRangeAnnotation(annotation);
1284 String a_label=annotation.getLabel();
1285 String a_descr=annotation.getDescription();
1286 if (a_label==null || a_label.length()==0) {
1287 a_label = annotation.getType();
1288 if (a_label.length()==0)
1289 a_label = "Unamed annotation";
1291 if (a_descr==null || a_descr.length()==0) {
1292 a_descr = "Annotation of type '"+annotation.getType()+"'";
1294 if (parsedRangeAnnotation==null) {
1295 Cache.log.debug("Inserting empty annotation row elements for a whole-alignment annotation.");
1299 if (parsedRangeAnnotation[3]!=null) {
1300 Cache.log.warn("Ignoring 'After' annotation row in "+annotation.getVorbaId());
1302 jalview.datamodel.Annotation[] arow = (jalview.datamodel.Annotation[]) parsedRangeAnnotation[2];
1303 boolean[] has=(boolean[])parsedRangeAnnotation[0];
1304 // 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
1305 /*if ((annotation.getClass().equals(org.vamsas.objects.core.AlignmentAnnotation.class) && ((org.vamsas.objects.core.AlignmentAnnotation)annotation).getGraph())
1306 || (hasSequenceRef=true && ((org.vamsas.objects.core.AlignmentSequenceAnnotation)annotation).getGraph())) {
1309 // make bounds and automatic description strings for jalview user's benefit (these shouldn't be written back to vamsas document)
1313 for (int i=0;i<arow.length; i++) {
1314 if (arow[i]!=null) {
1316 // do some interpolation *between* points
1317 if (arow[lastval]!=null) {
1318 float interval = arow[i].value-arow[lastval].value;
1319 interval/=i-lastval;
1320 float base = arow[lastval].value;
1321 for (int ip=lastval+1,np=0; ip<i; np++,ip++) {
1322 arow[ip] = new jalview.datamodel.Annotation("","",' ', interval*np+base);
1323 // NB - Interpolated points don't get a tooltip and description.
1328 // check range - shouldn't we have a min and max property in the annotation object ?
1329 if (first) { min=max=arow[i].value; first=false;}
1330 else { if (arow[i].value<min) { min=arow[i].value; }
1331 else if (arow[i].value>max) { max=arow[i].value; }
1333 // make tooltip and display char value
1334 if (!has[HASDESCSTR]) arow[i].description = arow[i].value + "";
1335 if (!has[HASDC]) arow[i].displayCharacter=arow[i].value+"";
1338 int type=jalview.datamodel.AlignmentAnnotation.LINE_GRAPH;
1339 if (has[HASHPHOB]) {
1340 type = jalview.datamodel.AlignmentAnnotation.BAR_GRAPH;
1342 jan = new jalview.datamodel.AlignmentAnnotation(a_label, a_descr, arow, min, max, type);
1344 jan = new jalview.datamodel.AlignmentAnnotation(a_label, a_descr, arow);
1345 jan.setThreshold(null);
1347 if (annotation.getLinkCount()>0) {
1348 Cache.log.warn("Ignoring "+annotation.getLinkCount()+"links added to AlignmentAnnotation.");
1350 if (annotation.getModifiable()) {
1354 if (annotation.getPropertyCount()>0) {
1355 // look for special jalview properties
1356 org.vamsas.objects.core.Property[] props=annotation.getProperty();
1357 for (int p=0;p<props.length; p++) {
1358 if (props[p].getName().equalsIgnoreCase("jalview:graphType")) {
1360 // probably a jalview annotation graph so recover the visualization hints.
1361 jan.graph = jalview.datamodel.AlignmentAnnotation.getGraphValueFromString(props[p].getContent());
1362 } catch (Exception e) {
1363 Cache.log.debug("Invalid graph type value in jalview:graphType property.");
1366 if (annotation.getGroup()!=null && annotation.getGroup().length()>0)
1367 jan.graphGroup = Integer.parseInt(annotation.getGroup());
1368 } catch (Exception e) {
1369 Cache.log.info("UNIMPLEMENTED : Couldn't parse non-integer group value for setting graphGroup correctly.");
1382 private SequenceFeature getJalviewSeqFeature(RangeAnnotation dseta) {
1383 int[] se = getBounds(dseta);
1384 SequenceFeature sf = new jalview.datamodel.SequenceFeature(dseta.getType(),
1385 dseta.getDescription(), dseta.getStatus(), se[0], se[1], dseta
1387 if (dseta.getLinkCount() > 0)
1389 Link[] links = dseta.getLink();
1390 for (int i = 0; i < links.length; i++)
1392 sf.addLink(links[i].getContent() + "|" + links[i].getHref());
1399 * get real bounds of a RangeType's specification. start and end are an
1400 * inclusive range within which all segments and positions lie.
1401 * TODO: refactor to vamsas utils
1403 * @return int[] { start, end}
1405 private int[] getBounds(RangeType dseta) {
1409 if (dseta.getSegCount()>0 && dseta.getPosCount()>0)
1410 throw new Error("Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!");
1411 if (dseta.getSegCount() > 0)
1413 se = getSegRange(dseta.getSeg(0),true);
1414 for (int s = 1, sSize = dseta.getSegCount(); s < sSize; s++)
1416 int nse[] = getSegRange(dseta.getSeg(s), true);
1423 if (dseta.getPosCount() > 0)
1425 // could do a polarity for pos range too. and pass back indication of discontinuities.
1426 int pos = dseta.getPos(0).getI();
1427 se = new int[] { pos, pos };
1428 for (int p = 0, pSize = dseta.getPosCount(); p < pSize; p++)
1430 pos = dseta.getPos(p).getI();
1442 * map from a rangeType's internal frame to the referenced object's coordinate frame.
1444 * @return int [] { ref(pos)...} for all pos in rangeType's frame.
1446 private int[] getMapping(RangeType dseta) {
1447 Vector posList=new Vector();
1451 if (dseta.getSegCount()>0 && dseta.getPosCount()>0)
1452 throw new Error("Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!");
1453 if (dseta.getSegCount() > 0)
1455 for (int s = 0, sSize = dseta.getSegCount(); s < sSize; s++)
1457 se = getSegRange(dseta.getSeg(s), false);
1458 int se_end=se[1-se[2]]+(se[2]==0 ? 1 : -1);
1459 for (int p=se[se[2]]; p!=se_end; p+=se[2]==0 ? 1 : -1 ) {
1460 posList.add(new Integer(p));
1464 else if (dseta.getPosCount() > 0)
1466 int pos = dseta.getPos(0).getI();
1468 for (int p = 0, pSize = dseta.getPosCount(); p < pSize; p++)
1470 pos = dseta.getPos(p).getI();
1471 posList.add(new Integer(pos));
1475 if (posList!=null && posList.size()>0) {
1476 int[] range=new int[posList.size()];
1477 for (int i=0; i<range.length; i++)
1478 range[i] = ((Integer)posList.elementAt(i)).intValue();
1485 * Provenance getVamsasProvenance(jalview.datamodel.Provenance jprov) {
1486 jalview.datamodel.ProvenanceEntry[] entries = null;
1487 // TODO: fix App and Action here.
1488 Provenance prov = new Provenance();
1489 org.exolab.castor.types.Date date = new org.exolab.castor.types.Date(
1490 new java.util.Date());
1495 entries = jprov.getEntries();
1496 for (int i = 0; i < entries.length; i++)
1498 provEntry = new Entry();
1501 date = new org.exolab.castor.types.Date(entries[i].getDate());
1502 } catch (Exception ex)
1504 ex.printStackTrace();
1506 date = new org.exolab.castor.types.Date(entries[i].getDate());
1508 provEntry.setDate(date);
1509 provEntry.setUser(entries[i].getUser());
1510 provEntry.setAction(entries[i].getAction());
1511 prov.addEntry(provEntry);
1516 provEntry = new Entry();
1517 provEntry.setDate(date);
1518 provEntry.setUser(System.getProperty("user.name")); // TODO: ext string
1519 provEntry.setApp("JVAPP"); // TODO: ext string
1520 provEntry.setAction(action);
1521 prov.addEntry(provEntry);
1527 jalview.datamodel.Provenance getJalviewProvenance(Provenance prov) {
1528 // TODO: fix App and Action entries and check use of provenance in jalview.
1529 jalview.datamodel.Provenance jprov = new jalview.datamodel.Provenance();
1530 for (int i = 0; i < prov.getEntryCount(); i++)
1532 jprov.addEntry(prov.getEntry(i).getUser(), prov.getEntry(i).getAction(),
1533 prov.getEntry(i).getDate().toDate(), prov.getEntry(i).getId());
1541 * @return default initial provenance list for a Jalview created vamsas
1544 Provenance dummyProvenance() {
1545 return dummyProvenance(null);
1548 Entry dummyPEntry(String action) {
1549 Entry entry = new Entry();
1550 entry.setApp(this.provEntry.getApp());
1552 entry.setAction(action);
1554 entry.setAction("created.");
1555 entry.setDate(new org.exolab.castor.types.Date(new java.util.Date()));
1556 entry.setUser(this.provEntry.getUser());
1560 Provenance dummyProvenance(String action) {
1561 Provenance prov = new Provenance();
1562 prov.addEntry(dummyPEntry(action));
1566 void addProvenance(Provenance p, String action) {
1567 p.addEntry(dummyPEntry(action));