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 uk.ac.vamsas.client.*;
40 import uk.ac.vamsas.objects.core.*;
45 * org.exolab.castor.util.LocalConfiguration.getInstance().getProperties().setProperty(
46 * "org.exolab.castor.serializer", "org.apache.xml.serialize.XMLSerilazizer"); }
50 public class VamsasAppDatastore
52 Entry provEntry = null;
56 org.exolab.castor.types.Date date = new org.exolab.castor.types.Date(
57 new java.util.Date());
63 IdentityHashMap jv2vobj;
65 public VamsasAppDatastore(IClientDocument cdoc, Hashtable vobj2jv,
66 IdentityHashMap jv2vobj, Entry provEntry)
69 this.vobj2jv = vobj2jv;
70 this.jv2vobj = jv2vobj;
71 this.provEntry = provEntry;
75 * public void storeJalview(String file, AlignFrame af) { try { // 1. Load the
76 * mapping information from the file Mapping map = new
77 * Mapping(getClass().getClassLoader()); java.net.URL url =
78 * getClass().getResource("/jalview_mapping.xml"); map.loadMapping(url); // 2.
79 * Unmarshal the data // Unmarshaller unmar = new Unmarshaller();
80 * //unmar.setIgnoreExtraElements(true); //unmar.setMapping(map); // uni =
81 * (UniprotFile) unmar.unmarshal(new FileReader(file)); // 3. marshal the data
82 * with the total price back and print the XML in the console Marshaller
83 * marshaller = new Marshaller( new FileWriter(file) );
85 * marshaller.setMapping(map); marshaller.marshal(af); } catch (Exception e) {
86 * e.printStackTrace(); } }
91 * @return the Vobject bound to Jalview datamodel object
93 protected Vobject getjv2vObj(Object jvobj)
95 if (jv2vobj.containsKey(jvobj))
97 return cdoc.getObject( (VorbaId) jv2vobj.get(jvobj));
99 if (Cache.log.isDebugEnabled())
101 Cache.log.debug("Returning null VorbaID binding for jalview object "+jvobj);
109 * @return Jalview datamodel object bound to the vamsas document object
111 protected Object getvObj2jv(uk.ac.vamsas.client.Vobject vobj)
113 VorbaId id = vobj.getVorbaId();
116 id = cdoc.registerObject(vobj);
118 .debug("Registering new object and returning null for getvObj2jv");
121 if (vobj2jv.containsKey(vobj.getVorbaId()))
123 return vobj2jv.get(vobj.getVorbaId());
128 protected void bindjvvobj(Object jvobj, uk.ac.vamsas.client.Vobject vobj)
130 VorbaId id = vobj.getVorbaId();
133 id = cdoc.registerObject(vobj);
134 if (id == null || vobj.getVorbaId() == null || cdoc.getObject(id)!=vobj)
136 Cache.log.error("Failed to get id for " +
137 (vobj.isRegisterable() ? "registerable" :
138 "unregisterable") + " object " + vobj);
142 if (vobj2jv.containsKey(vobj.getVorbaId()) &&
143 ! ( (VorbaId) vobj2jv.get(vobj.getVorbaId())).equals(jvobj))
145 Cache.log.debug("Warning? Overwriting existing vamsas id binding for " +
147 new Exception("Overwriting vamsas id binding."));
149 else if (jv2vobj.containsKey(jvobj) &&
150 ! ( (VorbaId) jv2vobj.get(jvobj)).equals(vobj.getVorbaId()))
153 "Warning? Overwriting existing jalview object binding for " + jvobj,
154 new Exception("Overwriting jalview object binding."));
156 /* 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"));
158 // we just update the hash's regardless!
159 Cache.log.debug("Binding "+vobj.getVorbaId()+" to "+jvobj);
160 vobj2jv.put(vobj.getVorbaId(), jvobj);
161 // JBPNote - better implementing a hybrid invertible hash.
162 jv2vobj.put(jvobj, vobj.getVorbaId());
166 * put the alignment viewed by AlignViewport into cdoc.
168 * @param av alignViewport to be stored
169 * @param aFtitle title for alignment
171 public void storeVAMSAS(AlignViewport av, String aFtitle)
175 jalview.datamodel.AlignmentI jal = av.getAlignment();
177 VAMSAS root = null; // will be resolved based on Dataset Parent.
178 // /////////////////////////////////////////
180 if (jal.getDataset() == null)
182 Cache.log.warn("Creating new dataset for an alignment.");
183 jal.setDataset(null);
185 DataSet dataset = (DataSet) getjv2vObj(jal.getDataset());
188 root = cdoc.getVamsasRoots()[0]; // default vamsas root for modifying.
189 dataset = new DataSet();
190 root.addDataSet(dataset);
191 bindjvvobj(jal.getDataset(), dataset);
192 dataset.setProvenance(dummyProvenance());
193 dataset.getProvenance().addEntry(provEntry);
198 root = (VAMSAS) dataset.getV_parent();
203 // set new dataset and alignment sequences based on alignment Nucleotide
205 // this *will* break when alignment contains both nucleotide and amino
207 String dict = jal.isNucleotide() ?
208 uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_NA
209 : uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_AA;
210 for (int i = 0; i < jal.getHeight(); i++)
212 SequenceI sq = jal.getSequenceAt(i).getDatasetSequence(); // only insert
216 sequence = (Sequence) getjv2vObj(sq);
217 if (sequence == null)
219 sequence = new Sequence();
220 bindjvvobj(sq, sequence);
221 sq.setVamsasId(sequence.getVorbaId().getId());
222 sequence.setSequence(sq.getSequenceAsString());
223 sequence.setDictionary(dict);
224 sequence.setName(jal.getDataset().getSequenceAt(i).getName());
225 sequence.setStart(jal.getDataset().getSequenceAt(i).getStart());
226 sequence.setEnd(jal.getDataset().getSequenceAt(i).getEnd());
227 dataset.addSequence(sequence);
231 // verify principal attributes. and update any new
232 // features/references.
233 System.out.println("update dataset sequence object.");
235 if (sq.getSequenceFeatures() != null)
237 int sfSize = sq.getSequenceFeatures().length;
239 for (int sf = 0; sf < sfSize; sf++)
241 jalview.datamodel.SequenceFeature feature = (jalview.datamodel.
243 .getSequenceFeatures()[sf];
245 DataSetAnnotations dsa = (DataSetAnnotations) getjv2vObj(feature);
248 dsa = (DataSetAnnotations) getDSAnnotationFromJalview(
249 new DataSetAnnotations(), feature);
250 if (dsa.getProvenance() == null)
252 dsa.setProvenance(new Provenance());
254 addProvenance(dsa.getProvenance(), "created"); // JBPNote - need
256 dsa.setSeqRef(sequence);
257 bindjvvobj(feature, dsa);
258 dataset.addDataSetAnnotations(dsa);
262 // todo: verify and update dataset annotations for sequence
263 System.out.println("update dataset sequence annotations.");
268 if (sq.getDBRef() != null)
270 DBRefEntry[] entries = sq.getDBRef();
271 jalview.datamodel.DBRefEntry dbentry;
272 for (int db = 0; db < entries.length; db++)
274 dbentry = entries[db];
275 dbref = (DbRef) getjv2vObj(dbentry);
279 bindjvvobj(dbentry, dbref);
280 dbref.setAccessionId(dbentry.getAccessionId());
281 dbref.setSource(dbentry.getSource());
282 dbref.setVersion(dbentry.getVersion());
284 * TODO: Maps are not yet supported by Jalview. Map vMap = new
285 * Map(); vMap.set dbref.addMap(vMap);
287 sequence.addDbRef(dbref);
291 // TODO: verify and update dbrefs in vamsas document
292 // there will be trouble when a dataset sequence is modified to
293 // contain more residues than were originally referenced - we must
294 // then make a number of dataset sequence entries
296 .println("update dataset sequence database references.");
302 // dataset.setProvenance(getVamsasProvenance(jal.getDataset().getProvenance()));
303 // ////////////////////////////////////////////
305 // ////////////////////////////////////////////
306 // Save the Alignments
308 Alignment alignment = (Alignment) getjv2vObj(av); // this is so we can get the alignviewport back
309 if (alignment == null)
311 alignment = new Alignment();
312 bindjvvobj(av, alignment);
313 if (alignment.getProvenance() == null)
315 alignment.setProvenance(new Provenance());
317 addProvenance(alignment.getProvenance(), "added"); // TODO: insert some
320 dataset.addAlignment(alignment);
322 Property title = new Property();
323 title.setName("jalview:AlTitle");
324 title.setType("string");
325 title.setContent(aFtitle);
326 alignment.addProperty(title);
328 alignment.setGapChar(String.valueOf(av.getGapCharacter()));
329 AlignmentSequence alseq = null;
330 for (int i = 0; i < jal.getHeight(); i++)
332 alseq = new AlignmentSequence();
333 // TODO: VAMSAS: translate lowercase symbols to annotation ?
334 alseq.setSequence(jal.getSequenceAt(i).getSequenceAsString());
335 alseq.setName(jal.getSequenceAt(i).getName());
336 alseq.setStart(jal.getSequenceAt(i).getStart());
337 alseq.setEnd(jal.getSequenceAt(i).getEnd());
338 if (getjv2vObj(jal.getSequenceAt(i).getDatasetSequence())==null)
340 Cache.log.warn("Serious. Unbound dataset sequence in alignment: "+jal.getSequenceAt(i).getDatasetSequence());
342 alseq.setRefid(getjv2vObj(jal.getSequenceAt(i).getDatasetSequence()));
343 alignment.addAlignmentSequence(alseq);
344 bindjvvobj(jal.getSequenceAt(i), alseq);
349 // todo: verify and update mutable alignment props.
350 if (alignment.getModifiable()==null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK METHODS
352 System.out.println("update alignment in document.");
357 .println("update edited alignment to new alignment in document.");
360 // ////////////////////////////////////////////
361 // SAVE Alignment Sequence Features
362 for (int i = 0, iSize = alignment.getAlignmentSequenceCount(); i < iSize;
365 AlignmentSequence valseq;
366 SequenceI alseq = (SequenceI) getvObj2jv(valseq = alignment
367 .getAlignmentSequence(i));
368 if (alseq != null && alseq.getSequenceFeatures() != null)
370 jalview.datamodel.SequenceFeature[] features = alseq
371 .getSequenceFeatures();
372 for (int f = 0; f < features.length; f++)
374 if (features[f] != null)
376 AlignmentSequenceAnnotation valseqf = (
377 AlignmentSequenceAnnotation) getjv2vObj(features[i]);
381 valseqf = (AlignmentSequenceAnnotation)
382 getDSAnnotationFromJalview(
383 new AlignmentSequenceAnnotation(), features[i]);
384 if (valseqf.getProvenance() == null)
386 valseqf.setProvenance(new Provenance());
388 addProvenance(valseqf.getProvenance(), "created"); // JBPNote -
391 bindjvvobj(features[i], valseqf);
392 valseq.addAlignmentSequenceAnnotation(valseqf);
400 // ////////////////////////////////////////////
402 if (jal.getAlignmentAnnotation() != null)
404 jalview.datamodel.AlignmentAnnotation[] aa = jal
405 .getAlignmentAnnotation();
406 java.util.HashMap AlSeqMaps = new HashMap(); // stores int maps from
407 // alignment columns to
408 // sequence positions.
409 for (int i = 0; i < aa.length; i++)
411 if (aa[i] == null || isJalviewOnly(aa[i]))
415 if (aa[i].sequenceRef != null)
417 uk.ac.vamsas.objects.core.AlignmentSequence alsref = (uk.ac.vamsas.
418 objects.core.AlignmentSequence) getjv2vObj(aa[i].sequenceRef);
419 uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation an = (uk.ac.
420 vamsas.objects.core.AlignmentSequenceAnnotation) getjv2vObj(aa[
423 if (AlSeqMaps.containsKey(aa[i].sequenceRef))
425 gapMap = (int[]) AlSeqMaps.get(aa[i].sequenceRef);
429 gapMap = new int[aa[i].sequenceRef.getLength()];
430 // map from alignment position to sequence position.
431 int[] sgapMap = aa[i].sequenceRef.gapMap();
432 for (int a = 0; a < sgapMap.length; a++)
434 gapMap[sgapMap[a]] = a;
439 an = new uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation();
440 Seg vSeg = new Seg();
442 vSeg.setInclusive(true);
443 vSeg.setEnd(gapMap.length);
445 an.setType("jalview:SecondaryStructurePrediction"); // TODO: better fix this rough guess ;)
446 alsref.addAlignmentSequenceAnnotation(an);
447 bindjvvobj(aa[i], an);
448 // LATER: much of this is verbatim from the alignmentAnnotation
449 // method below. suggests refactoring to make rangeAnnotation the
451 an.setDescription(aa[i].description);
454 an.setGraph(true); // aa[i].graph);
460 an.setLabel(aa[i].label);
461 an.setProvenance(dummyProvenance()); // get provenance as user
462 // created, or jnet, or
464 an.setGroup(Integer.toString(aa[i].graphGroup)); // // JBPNote -
472 AnnotationElement ae;
473 for (int a = 0; a < aa[i].annotations.length; a++)
475 if (aa[i].annotations[a] == null)
480 ae = new AnnotationElement();
481 ae.setDescription(aa[i].annotations[a].description);
482 ae.addGlyph(new Glyph());
484 .setContent(aa[i].annotations[a].displayCharacter); // assume
492 jalview.datamodel.AlignmentAnnotation.NO_GRAPH)
494 ae.addValue(aa[i].annotations[a].value);
496 ae.setPosition(gapMap[a] + 1); // position w.r.t. AlignmentSequence
498 if (aa[i].annotations[a].secondaryStructure != ' ')
500 // we only write an annotation where it really exists.
501 Glyph ss = new Glyph();
503 .setDict(uk.ac.vamsas.objects.utils.GlyphDictionary.
506 .valueOf(aa[i].annotations[a].
507 secondaryStructure));
510 an.addAnnotationElement(ae);
515 // update reference sequence Annotation
516 if (an.getModifiable()==null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK METHODS)
518 // verify existing alignment sequence annotation is up to date
519 System.out.println("update alignment sequence annotation.");
523 // verify existing alignment sequence annotation is up to date
526 "make new alignment sequence annotation if modification has happened.");
532 // add Alignment Annotation
533 uk.ac.vamsas.objects.core.AlignmentAnnotation an = (uk.ac.vamsas.
534 objects.core.AlignmentAnnotation) getjv2vObj(aa[i]);
537 an = new uk.ac.vamsas.objects.core.AlignmentAnnotation();
538 an.setType("jalview:AnnotationRow");
539 an.setDescription(aa[i].description);
540 alignment.addAlignmentAnnotation(an);
541 Seg vSeg = new Seg();
543 vSeg.setInclusive(true);
544 vSeg.setEnd(jal.getWidth());
548 an.setGraph(true); // aa[i].graph);
550 an.setLabel(aa[i].label);
551 an.setProvenance(dummyProvenance());
552 if (aa[i].graph != aa[i].NO_GRAPH)
554 an.setGroup(Integer.toString(aa[i].graphGroup)); // // JBPNote -
568 AnnotationElement ae;
570 for (int a = 0; a < aa[i].annotations.length; a++)
572 if ( (aa[i] == null) || (aa[i].annotations[a] == null))
577 ae = new AnnotationElement();
578 ae.setDescription(aa[i].annotations[a].description);
579 ae.addGlyph(new Glyph());
581 .setContent(aa[i].annotations[a].displayCharacter); // assume
588 ae.addValue(aa[i].annotations[a].value);
589 ae.setPosition(a + 1);
590 if (aa[i].annotations[a].secondaryStructure != ' ')
592 Glyph ss = new Glyph();
594 .setDict(uk.ac.vamsas.objects.utils.GlyphDictionary.
597 .valueOf(aa[i].annotations[a].
598 secondaryStructure));
601 an.addAnnotationElement(ae);
605 //an.addProperty(newProperty("jalview:editable", null, "true"));
606 // an.setModifiable(""); // TODO: This is not the way the modifiable flag is supposed to be used.
608 if (aa[i].graph != jalview.datamodel.AlignmentAnnotation.NO_GRAPH)
611 an.setGroup(Integer.toString(aa[i].graphGroup));
612 an.addProperty(newProperty("jalview:graphType", null,
614 jalview.datamodel.AlignmentAnnotation.
615 BAR_GRAPH) ? "BAR_GRAPH" :
619 vProperty=new Property();
620 vProperty.setName("jalview:graphThreshhold");
621 vProperty.setContent(aa[i].threshold);
628 if (an.getModifiable()==null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK METHODS)
630 // verify annotation - update (perhaps)
632 "update alignment sequence annotation. not yet implemented.");
636 // verify annotation - update (perhaps)
637 Cache.log.info("updated alignment sequence annotation added.");
643 // /////////////////////////////////////////////////////
645 // //////////////////////////////////////////////
647 // /////////////////////////////////
648 // FIND ANY ASSOCIATED TREES
649 if (Desktop.desktop != null)
651 javax.swing.JInternalFrame[] frames = Desktop.instance.getAllFrames();
653 for (int t = 0; t < frames.length; t++)
655 if (frames[t] instanceof TreePanel)
657 TreePanel tp = (TreePanel) frames[t];
659 if (tp.getAlignment() == jal)
661 Tree tree = (Tree) getjv2vObj(tp);
665 bindjvvobj(tp, tree);
666 tree.setTitle(tp.getTitle());
667 Newick newick = new Newick();
668 // TODO: translate sequenceI to leaf mappings to vamsas
669 // references - see tree specification in schema.
670 newick.setContent(tp.getTree().toString());
671 newick.setTitle(tp.getTitle());
672 tree.addNewick(newick);
673 tree.setProvenance(makeTreeProvenance(jal, tp));
674 alignment.addTree(tree);
678 if (tree.getModifiable()==null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK METHODS)
680 // verify any changes.
681 System.out.println("Update tree in document.");
686 .println("Add modified tree as new tree in document.");
693 // Store Jalview specific stuff in the Jalview appData
694 // not implemented in the SimpleDoc interface.
699 ex.printStackTrace();
704 private Property newProperty(String name, String type, String content)
706 Property vProperty = new Property();
707 vProperty.setName(name);
710 vProperty.setType(type);
714 vProperty.setType("String");
716 vProperty.setContent(content);
721 * correctly create a RangeAnnotation from a jalview sequence feature
724 * (typically DataSetAnnotations or AlignmentSequenceAnnotation)
726 * (the feature to be mapped from)
729 private RangeAnnotation getDSAnnotationFromJalview(RangeAnnotation dsa,
730 SequenceFeature feature)
732 dsa.setType(feature.getType());
733 Seg vSeg = new Seg();
734 vSeg.setStart(feature.getBegin());
735 vSeg.setEnd(feature.getEnd());
736 vSeg.setInclusive(true);
738 dsa.setDescription(feature.getDescription());
739 dsa.setStatus(feature.getStatus());
740 if (feature.links != null && feature.links.size() > 0)
742 for (int i = 0, iSize = feature.links.size(); i < iSize; i++)
744 String link = (String) feature.links.elementAt(i);
745 int sep = link.indexOf('|');
748 Link vLink = new Link();
751 vLink.setContent(link.substring(0, sep - 1));
755 vLink.setContent("");
757 vLink.setHref(link.substring(sep + 1)); // TODO: validate href.
762 dsa.setGroup(feature.getFeatureGroup());
767 * correctly creates provenance for trees calculated on an alignment by
774 private Provenance makeTreeProvenance(AlignmentI jal, TreePanel tp)
776 Provenance prov = new Provenance();
777 prov.addEntry(new Entry());
778 prov.getEntry(0).setAction("imported " + tp.getTitle());
779 prov.getEntry(0).setUser(provEntry.getUser());
780 prov.getEntry(0).setApp(provEntry.getApp());
781 prov.getEntry(0).setDate(provEntry.getDate());
782 if (tp.getTree().hasOriginalSequenceData())
784 Input vInput = new Input();
785 // LATER: check to see if tree input data is contained in this alignment -
786 // or just correctly resolve the tree's seqData to the correct alignment in
788 // vInput.setObjRef(getjv2vObj(jal));
789 vInput.setObjRef(getjv2vObj(tp.getViewPort()));
790 prov.getEntry(0).setAction("created " + tp.getTitle());
791 prov.getEntry(0).addInput(vInput);
792 vInput.setName("jalview:seqdist");
793 prov.getEntry(0).addParam(new Param());
794 prov.getEntry(0).getParam(0).setName("treeType");
795 prov.getEntry(0).getParam(0).setType("utf8");
796 prov.getEntry(0).getParam(0).setContent("NJ");
798 int ranges[] = tp.getTree().seqData.getVisibleContigs();
799 // VisibleContigs are with respect to alignment coordinates. Still need offsets
800 int start = tp.getTree().seqData.getAlignmentOrigin();
801 for (int r = 0; r < ranges.length; r += 2)
803 Seg visSeg = new Seg();
804 visSeg.setStart(1 + start + ranges[r]);
805 visSeg.setEnd(start + ranges[r + 1]);
806 visSeg.setInclusive(true);
807 vInput.addSeg(visSeg);
816 * @return Object[] { AlignmentView, AlignmentI - reference alignment for
819 private Object[] recoverInputData(Provenance tp)
821 for (int pe = 0; pe < tp.getEntryCount(); pe++)
823 if (tp.getEntry(pe).getInputCount() > 0)
825 if (tp.getEntry(pe).getInputCount() > 1)
827 Cache.log.warn("Ignoring additional input spec in provenance entry "
828 + tp.getEntry(pe).toString());
830 // LATER: deal sensibly with multiple inputs.
831 Input vInput = tp.getEntry(pe).getInput(0);
832 if (vInput.getObjRef() instanceof uk.ac.vamsas.objects.core.Alignment)
834 // recover an AlignmentView for the input data
835 AlignViewport javport = (AlignViewport) getvObj2jv( (uk.ac.vamsas.
836 client.Vobject) vInput
838 jalview.datamodel.AlignmentI jal = javport.getAlignment();
839 jalview.datamodel.CigarArray view = javport.getAlignment().
840 getCompactAlignment();
841 int from = 1, to = jal.getWidth();
842 int offset = 0; // deleteRange modifies its frame of reference
843 for (int r = 0, s = vInput.getSegCount(); r < s; r++)
845 Seg visSeg = vInput.getSeg(r);
846 int se[] = getSegRange(visSeg, true); // jalview doesn't do bidirection alignments yet.
849 Cache.log.warn("Ignoring invalid segment in InputData spec.");
855 view.deleteRange(offset + from - 1, offset + se[0] - 2);
856 offset -= se[0] - from;
863 view.deleteRange(offset + from - 1, offset + to - 1); // final deletion - TODO: check off by
868 new AlignmentView(view), jal};
872 Cache.log.debug("Returning null for input data recovery from provenance.");
877 * get start<end range of segment, adjusting for inclusivity flag and
881 * @param ensureDirection when true - always ensure start is less than end.
882 * @return int[] { start, end, direction} where direction==1 for range running from end to start.
884 private int[] getSegRange(Seg visSeg, boolean ensureDirection)
886 boolean incl = visSeg.getInclusive();
887 // adjust for inclusive flag.
888 int pol = (visSeg.getStart() <= visSeg.getEnd()) ? 1 : -1; // polarity of
890 int start = visSeg.getStart() + (incl ? 0 : pol);
891 int end = visSeg.getEnd() + (incl ? 0 : -pol);
892 if (ensureDirection && pol == -1)
894 // jalview doesn't deal with inverted ranges, yet.
901 start, end, pol < 0 ? 1 : 0};
907 * @return true if annotation is not to be stored in document
909 private boolean isJalviewOnly(AlignmentAnnotation annotation)
911 return annotation.label.equals("Quality")
912 || annotation.label.equals("Conservation")
913 || annotation.label.equals("Consensus");
917 * This will return the first AlignFrame viewing AlignViewport av.
918 * It will break if there are more than one AlignFrames viewing a particular av.
919 * This also shouldn't be in the io package.
921 * @return alignFrame for av
923 public AlignFrame getAlignFrameFor(AlignViewport av)
925 if (Desktop.desktop != null)
927 javax.swing.JInternalFrame[] frames = Desktop.instance.getAllFrames();
929 for (int t = 0; t < frames.length; t++)
931 if (frames[t] instanceof AlignFrame)
933 if ( ( (AlignFrame) frames[t]).getViewport() == av)
935 return (AlignFrame) frames[t];
943 public void updateToJalview()
945 VAMSAS _roots[] = cdoc.getVamsasRoots();
947 for (int _root = 0; _root < _roots.length; _root++)
949 VAMSAS root = _roots[_root];
950 boolean newds = false;
951 for (int _ds = 0, _nds = root.getDataSetCount(); _ds < _nds; _ds++)
953 // ///////////////////////////////////
955 DataSet dataset = root.getDataSet(_ds);
956 int i, iSize = dataset.getSequenceCount();
958 jalview.datamodel.Alignment jdataset = (jalview.datamodel.Alignment)
961 if (jdataset == null)
963 Cache.log.debug("Initialising new jalview dataset fields");
965 dsseqs = new Vector();
969 Cache.log.debug("Update jalview dataset from vamsas.");
970 jremain = jdataset.getHeight();
971 dsseqs = jdataset.getSequences();
974 // TODO: test sequence merging - we preserve existing non vamsas
975 // sequences but add in any new vamsas ones, and don't yet update any
976 // sequence attributes
977 for (i = 0; i < iSize; i++)
979 Sequence vdseq = dataset.getSequence(i);
980 jalview.datamodel.SequenceI dsseq = (SequenceI) getvObj2jv(vdseq);
983 if (!dsseq.getSequenceAsString().equals(vdseq.getSequence()))
986 "Broken! - mismatch of dataset sequence: and jalview internal dataset sequence.");
992 dsseq = new jalview.datamodel.Sequence(
993 dataset.getSequence(i).getName(),
994 dataset.getSequence(i).getSequence(),
995 (int)dataset.getSequence(i).getStart(),
996 (int)dataset.getSequence(i).getEnd());
997 dsseq.setDescription(dataset.getSequence(i).getDescription());
998 bindjvvobj(dsseq, dataset.getSequence(i));
999 dsseq.setVamsasId(dataset.getSequence(i).getVorbaId().getId());
1002 if (vdseq.getDbRefCount() > 0)
1004 DbRef[] dbref = vdseq.getDbRef();
1005 for (int db = 0; db < dbref.length; db++)
1007 jalview.datamodel.DBRefEntry dbr = (jalview.datamodel.DBRefEntry)
1008 getvObj2jv(dbref[db]);
1012 dsseq.addDBRef(dbr = new jalview.datamodel.DBRefEntry
1014 dbref[db].getSource().toString(),
1015 dbref[db].getVersion().toString(),
1016 dbref[db].getAccessionId().toString()));
1017 bindjvvobj(dbr, dbref[db]);
1025 SequenceI[] seqs = new SequenceI[dsseqs.size()];
1026 for (i = 0, iSize = dsseqs.size(); i < iSize; i++)
1028 seqs[i] = (SequenceI) dsseqs.elementAt(i);
1029 dsseqs.setElementAt(null, i);
1031 jdataset = new jalview.datamodel.Alignment(seqs);
1032 Cache.log.debug("New vamsas dataset imported into jalview.");
1033 bindjvvobj(jdataset, dataset);
1036 // add any new dataset sequence feature annotations
1037 if (dataset.getDataSetAnnotations() != null)
1039 for (int dsa = 0; dsa < dataset.getDataSetAnnotationsCount(); dsa++)
1041 DataSetAnnotations dseta = dataset.getDataSetAnnotations(dsa);
1042 SequenceI dsSeq = (SequenceI) getvObj2jv( (Vobject) dseta.getSeqRef());
1045 jalview.bin.Cache.log.warn(
1046 "Couldn't resolve jalview sequenceI for dataset object reference " +
1047 ( (Vobject) dataset.getDataSetAnnotations(dsa).getSeqRef()).
1048 getVorbaId().getId());
1052 if (dseta.getAnnotationElementCount() == 0)
1054 jalview.datamodel.SequenceFeature sf = (jalview.datamodel.
1055 SequenceFeature) getvObj2jv(dseta);
1058 dsSeq.addSequenceFeature(sf = getJalviewSeqFeature(dseta));
1059 bindjvvobj(sf, dseta);
1064 // TODO: deal with alignmentAnnotation style annotation
1065 // appearing on dataset sequences.
1066 // JBPNote: we could just add them to all alignments but
1067 // that may complicate cross references in the jalview
1069 Cache.log.warn("Ignoring dataset annotation with annotationElements. Not yet supported in jalview.");
1075 if (dataset.getAlignmentCount() > 0)
1077 // LOAD ALIGNMENTS from DATASET
1079 for (int al = 0, nal = dataset.getAlignmentCount(); al < nal; al++)
1081 uk.ac.vamsas.objects.core.Alignment alignment = dataset.getAlignment(
1083 AlignViewport av = (AlignViewport) getvObj2jv(alignment);
1084 jalview.datamodel.AlignmentI jal = null;
1087 jal = av.getAlignment();
1089 iSize = alignment.getAlignmentSequenceCount();
1090 boolean newal = (jal == null) ? true : false;
1091 Vector newasAnnots = new Vector();
1092 char gapChar = ' '; // default for new alignments read in from the document
1095 dsseqs = jal.getSequences(); // for merge/update
1096 gapChar = jal.getGapCharacter();
1100 dsseqs = new Vector();
1102 char valGapchar = alignment.getGapChar().charAt(0);
1103 for (i = 0; i < iSize; i++)
1105 AlignmentSequence valseq = alignment.getAlignmentSequence(i);
1106 jalview.datamodel.SequenceI alseq = (SequenceI) getvObj2jv(valseq);
1109 //TODO: upperCase/LowerCase situation here ? do we allow it ?
1110 //if (!alseq.getSequence().equals(valseq.getSequence())) {
1111 // throw new Error("Broken! - mismatch of dataset sequence and jalview internal dataset sequence.");
1112 if (Cache.log.isDebugEnabled())
1114 Cache.log.debug("Updating apparently edited sequence " +
1117 // this might go *horribly* wrong
1118 alseq.setSequence(new String(valseq.getSequence()).replace(
1119 valGapchar, gapChar));
1124 alseq = new jalview.datamodel.Sequence(
1126 valseq.getSequence().replace(valGapchar, gapChar),
1127 (int)valseq.getStart(),
1128 (int)valseq.getEnd());
1130 Vobject datsetseq = (Vobject) valseq.getRefid();
1131 if (datsetseq != null)
1133 alseq.setDatasetSequence( (SequenceI) getvObj2jv(datsetseq)); // exceptions if AlignemntSequence reference isn't a simple SequenceI
1138 "Invalid dataset sequence id (null) for alignment sequence " +
1139 valseq.getVorbaId());
1141 bindjvvobj(alseq, valseq);
1142 alseq.setVamsasId(valseq.getVorbaId().getId());
1145 if (valseq.getAlignmentSequenceAnnotationCount() > 0)
1147 AlignmentSequenceAnnotation[] vasannot = valseq.
1148 getAlignmentSequenceAnnotation();
1149 for (int a = 0; a < vasannot.length; a++)
1151 jalview.datamodel.AlignmentAnnotation asa = (jalview.
1152 datamodel.AlignmentAnnotation) getvObj2jv(vasannot[a]); // TODO: 1:many jalview alignment sequence annotations
1155 int se[] = getBounds(vasannot[a]);
1156 asa = getjAlignmentAnnotation(jal, vasannot[a]);
1157 asa.sequenceRef = alseq;
1158 asa.createSequenceMapping(alseq, alseq.getStart() + se[0], false); // TODO: verify that positions in alseqAnnotation correspond to ungapped residue positions.
1159 bindjvvobj(asa, vasannot[a]);
1160 newasAnnots.add(asa);
1164 // update existing annotation - can do this in place
1165 if (vasannot[a].getModifiable()==null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK METHODS)
1168 "UNIMPLEMENTED: not recovering user modifiable sequence alignment annotation");
1169 // TODO: should at least replace with new one - otherwise things will break
1170 // basically do this:
1171 // int se[] = getBounds(vasannot[a]);
1172 // asa.update(getjAlignmentAnnotation(jal, vasannot[a])); // update from another annotation object in place.
1173 // asa.createSequenceMapping(alseq, se[0], false);
1182 SequenceI[] seqs = new SequenceI[dsseqs.size()];
1183 for (i = 0, iSize = dsseqs.size(); i < iSize; i++)
1185 seqs[i] = (SequenceI) dsseqs.elementAt(i);
1186 dsseqs.setElementAt(null, i);
1188 jal = new jalview.datamodel.Alignment(seqs);
1189 Cache.log.debug("New vamsas alignment imported into jalview " +
1190 alignment.getVorbaId().getId());
1191 jal.setDataset(jdataset);
1193 if (newasAnnots != null && newasAnnots.size() > 0)
1195 // Add the new sequence annotations in to the alignment.
1196 for (int an = 0, anSize = newasAnnots.size(); an < anSize; an++)
1198 jal.addAnnotation( (AlignmentAnnotation) newasAnnots.elementAt(
1200 // TODO: check if anything has to be done - like calling adjustForAlignment or something.
1201 newasAnnots.setElementAt(null, an);
1205 // //////////////////////////////////////////
1206 // //LOAD ANNOTATIONS FOR THE ALIGNMENT
1207 // ////////////////////////////////////
1208 if (alignment.getAlignmentAnnotationCount() > 0)
1210 uk.ac.vamsas.objects.core.AlignmentAnnotation[] an = alignment.
1211 getAlignmentAnnotation();
1213 for (int j = 0; j < an.length; j++)
1215 jalview.datamodel.AlignmentAnnotation jan = (jalview.datamodel.
1216 AlignmentAnnotation) getvObj2jv(an[j]);
1219 // update or stay the same.
1220 // TODO: should at least replace with a new one - otherwise things will break
1221 // basically do this:
1222 // jan.update(getjAlignmentAnnotation(jal, an[a])); // update from another annotation object in place.
1224 Cache.log.debug("update from vamsas alignment annotation to existing jalview alignment annotation.");
1225 if (an[j].getModifiable()==null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK METHODS)
1227 // TODO: user defined annotation is totally mutable... - so load it up or throw away if locally edited.
1229 "NOT IMPLEMENTED - Recovering user-modifiable annotation - yet...");
1231 // TODO: compare annotation element rows
1232 // TODO: compare props.
1236 jan = getjAlignmentAnnotation(jal, an[j]);
1237 jal.addAnnotation(jan);
1238 bindjvvobj(jan, an[j]);
1242 AlignFrame alignFrame;
1245 Cache.log.debug("New alignframe for alignment " +
1246 alignment.getVorbaId());
1247 // ///////////////////////////////
1248 // construct alignment view
1249 alignFrame = new AlignFrame(jal, AlignFrame.DEFAULT_WIDTH,
1250 AlignFrame.DEFAULT_HEIGHT);
1251 av = alignFrame.getViewport();
1252 String title = alignment.getProvenance().getEntry(alignment.
1253 getProvenance().getEntryCount() - 1).getAction();
1254 if (alignment.getPropertyCount() > 0)
1256 for (int p = 0, pe = alignment.getPropertyCount(); p < pe; p++)
1258 if (alignment.getProperty(p).getName().equals(
1261 title = alignment.getProperty(p).getContent();
1265 // TODO: automatically create meaningful title for a vamsas alignment using its provenance.
1266 jalview.gui.Desktop.addInternalFrame(alignFrame,
1267 title + "(" + alignment.getVorbaId() + ")",
1268 AlignFrame.DEFAULT_WIDTH,
1269 AlignFrame.DEFAULT_HEIGHT);
1270 bindjvvobj(av, alignment);
1274 // find the alignFrame for jal.
1275 // TODO: fix this so we retrieve the alignFrame handing av *directly*
1276 alignFrame = getAlignFrameFor(av);
1279 // /////////////////////////////////////
1280 if (alignment.getTreeCount() > 0)
1283 for (int t = 0; t < alignment.getTreeCount(); t++)
1285 Tree tree = alignment.getTree(t);
1286 TreePanel tp = (TreePanel) getvObj2jv(tree);
1290 "Update from vamsas document to alignment associated tree not implemented yet.");
1295 Object[] idata = this.recoverInputData(tree.getProvenance());
1298 AlignmentView inputData = null;
1299 if (idata != null && idata[0] != null)
1301 inputData = (AlignmentView) idata[0];
1303 tp = alignFrame.ShowNewickTree(
1304 new jalview.io.NewickFile(tree.getNewick(0).getContent()),
1305 tree.getNewick(0).getTitle() + " (" + tree.getVorbaId() +
1308 t * 20 + 50, t * 20 + 50);
1309 bindjvvobj(tp, tree);
1313 Cache.log.warn("Problems parsing treefile '" +
1314 tree.getNewick(0).getContent() + "'", e);
1326 // bitfields - should be a template in j1.5
1327 private static int HASSECSTR = 0;
1328 private static int HASVALS = 1;
1329 private static int HASHPHOB = 2;
1330 private static int HASDC = 3;
1331 private static int HASDESCSTR = 4;
1332 private static int HASTWOSTATE = 5; // not used yet.
1334 * parses the AnnotationElements - if they exist - into jalview.datamodel.Annotation[] rows
1335 * Two annotation rows are made if there are distinct annotation for both at 'pos' and 'after pos' at any particular site.
1337 * @return { boolean[static int constants ], int[ae.length] - map to annotated object frame, jalview.datamodel.Annotation[], jalview.datamodel.Annotation[] (after)}
1339 private Object[] parseRangeAnnotation(uk.ac.vamsas.objects.core.RangeAnnotation
1342 // set these attributes by looking in the annotation to decide what kind of alignment annotation rows will be made
1343 // TODO: potentially we might make several annotation rows from one vamsas alignment annotation. the jv2Vobj binding mechanism
1344 // may not quite cope with this (without binding an array of annotations to a vamsas alignment annotation)
1345 // summary flags saying what we found over the set of annotation rows.
1346 boolean[] AeContent = new boolean[]
1348 false, false, false, false, false};
1349 int[] rangeMap = getMapping(annotation);
1350 jalview.datamodel.Annotation[][] anot = new jalview.datamodel.Annotation[][]
1352 new jalview.datamodel.Annotation[rangeMap.length],
1353 new jalview.datamodel.Annotation[rangeMap.length]
1355 boolean mergeable = true; //false if 'after positions cant be placed on same annotation row as positions.
1357 if (annotation.getAnnotationElementCount() > 0)
1359 AnnotationElement ae[] = annotation.getAnnotationElement();
1360 for (int aa = 0; aa < ae.length; aa++)
1362 int pos = (int) ae[aa].getPosition() - 1; // pos counts from 1 to (|seg.start-seg.end|+1)
1363 if (pos >= 0 && pos < rangeMap.length)
1365 int row = ae[aa].getAfter() ? 1 : 0;
1366 if (anot[row][pos] != null)
1368 // only time this should happen is if the After flag is set.
1369 Cache.log.debug("Ignoring duplicate annotation site at " + pos);
1372 if (anot[1 - row][pos] != null)
1377 if (ae[aa].getDescription() != null)
1379 desc = ae[aa].getDescription();
1380 if (desc.length() > 0)
1382 // have imported valid description string
1383 AeContent[HASDESCSTR] = true;
1386 String dc = null; //ae[aa].getDisplayCharacter()==null ? "dc" : ae[aa].getDisplayCharacter();
1387 String ss = null; //ae[aa].getSecondaryStructure()==null ? "ss" : ae[aa].getSecondaryStructure();
1388 java.awt.Color colour = null;
1389 if (ae[aa].getGlyphCount() > 0)
1391 Glyph[] glyphs = ae[aa].getGlyph();
1392 for (int g = 0; g < glyphs.length; g++)
1394 if (glyphs[g].getDict().equals(uk.ac.vamsas.objects.utils.
1395 GlyphDictionary.PROTEIN_SS_3STATE))
1397 ss = glyphs[g].getContent();
1398 AeContent[HASSECSTR] = true;
1400 else if (glyphs[g].getDict().equals(uk.ac.vamsas.objects.utils.
1404 Cache.log.debug("ignoring hydrophobicity glyph marker.");
1405 AeContent[HASHPHOB] = true;
1406 char c = (dc = glyphs[g].getContent()).charAt(0);
1407 // dc may get overwritten - but we still set the colour.
1408 colour = new java.awt.Color(c == '+' ? 255 : 0,
1410 c == '-' ? 255 : 0);
1413 else if (glyphs[g].getDict().equals(uk.ac.vamsas.objects.utils.
1414 GlyphDictionary.DEFAULT))
1416 dc = glyphs[g].getContent();
1417 AeContent[HASDC] = true;
1421 Cache.log.debug("Ignoring unknown glyph type " +
1422 glyphs[g].getDict());
1427 if (ae[aa].getValueCount() > 0)
1429 AeContent[HASVALS] = true;
1430 if (ae[aa].getValueCount() > 1)
1432 Cache.log.warn("ignoring additional " +
1433 (ae[aa].getValueCount() - 1) +
1434 "values in annotation element.");
1436 val = ae[aa].getValue(0);
1440 anot[row][pos] = new jalview.datamodel.Annotation( (dc != null) ?
1441 dc : "", desc, (ss != null) ? ss.charAt(0) : ' ', val);
1445 anot[row][pos] = new jalview.datamodel.Annotation( (dc != null) ?
1446 dc : "", desc, (ss != null) ? ss.charAt(0) : ' ', val, colour);
1451 Cache.log.warn("Ignoring out of bound annotation element " + aa +
1452 " in " + annotation.getVorbaId().getId());
1455 // decide on how many annotation rows are needed.
1458 for (int i = 0; i < anot[0].length; i++)
1460 if (anot[1][i] != null)
1462 anot[0][i] = anot[1][i];
1463 anot[0][i].description = anot[0][i].description + " (after)";
1464 AeContent[HASDESCSTR] = true; // we have valid description string data
1472 for (int i = 0; i < anot[0].length; i++)
1474 anot[1][i].description = anot[1][i].description + " (after)";
1479 AeContent, rangeMap, anot[0], anot[1]};
1483 // no annotations to parse. Just return an empty annotationElement[] array.
1486 AeContent, rangeMap, anot[0], anot[1]};
1492 * @param jal the jalview alignment to which the annotation will be attached (ideally - freshly updated from corresponding vamsas alignment)
1494 * @return unbound jalview alignment annotation object.
1496 private jalview.datamodel.AlignmentAnnotation getjAlignmentAnnotation(jalview.
1497 datamodel.AlignmentI jal,
1498 uk.ac.vamsas.objects.core.RangeAnnotation annotation)
1500 jalview.datamodel.AlignmentAnnotation jan = null;
1501 if (annotation == null)
1505 // boolean hasSequenceRef=annotation.getClass().equals(uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation.class);
1506 //boolean hasProvenance=hasSequenceRef || (annotation.getClass().equals(uk.ac.vamsas.objects.core.AlignmentAnnotation.class));
1507 /*int se[] = getBounds(annotation);
1509 se=new int[] {0,jal.getWidth()-1};
1511 Object[] parsedRangeAnnotation = parseRangeAnnotation(annotation);
1512 String a_label = annotation.getLabel();
1513 String a_descr = annotation.getDescription();
1514 if (a_label == null || a_label.length() == 0)
1516 a_label = annotation.getType();
1517 if (a_label.length() == 0)
1519 a_label = "Unamed annotation";
1522 if (a_descr == null || a_descr.length() == 0)
1524 a_descr = "Annotation of type '" + annotation.getType() + "'";
1526 if (parsedRangeAnnotation == null)
1529 "Inserting empty annotation row elements for a whole-alignment annotation.");
1534 if (parsedRangeAnnotation[3] != null)
1536 Cache.log.warn("Ignoring 'After' annotation row in " +
1537 annotation.getVorbaId());
1539 jalview.datamodel.Annotation[] arow = (jalview.datamodel.Annotation[])
1540 parsedRangeAnnotation[2];
1541 boolean[] has = (boolean[]) parsedRangeAnnotation[0];
1542 // 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
1543 /*if ((annotation.getClass().equals(uk.ac.vamsas.objects.core.AlignmentAnnotation.class) && ((uk.ac.vamsas.objects.core.AlignmentAnnotation)annotation).getGraph())
1544 || (hasSequenceRef=true && ((uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation)annotation).getGraph())) {
1548 // make bounds and automatic description strings for jalview user's benefit (these shouldn't be written back to vamsas document)
1549 boolean first = true;
1550 float min = 0, max = 1;
1552 for (int i = 0; i < arow.length; i++)
1554 if (arow[i] != null)
1556 if (i - lastval > 1)
1558 // do some interpolation *between* points
1559 if (arow[lastval] != null)
1561 float interval = arow[i].value - arow[lastval].value;
1562 interval /= i - lastval;
1563 float base = arow[lastval].value;
1564 for (int ip = lastval + 1, np = 0; ip < i; np++, ip++)
1566 arow[ip] = new jalview.datamodel.Annotation("", "", ' ',
1567 interval * np + base);
1568 // NB - Interpolated points don't get a tooltip and description.
1573 // check range - shouldn't we have a min and max property in the annotation object ?
1576 min = max = arow[i].value;
1581 if (arow[i].value < min)
1583 min = arow[i].value;
1585 else if (arow[i].value > max)
1587 max = arow[i].value;
1590 // make tooltip and display char value
1591 if (!has[HASDESCSTR])
1593 arow[i].description = arow[i].value + "";
1597 arow[i].displayCharacter = arow[i].value + "";
1601 int type = jalview.datamodel.AlignmentAnnotation.LINE_GRAPH;
1604 type = jalview.datamodel.AlignmentAnnotation.BAR_GRAPH;
1606 jan = new jalview.datamodel.AlignmentAnnotation(a_label, a_descr, arow,
1611 jan = new jalview.datamodel.AlignmentAnnotation(a_label, a_descr, arow);
1612 jan.setThreshold(null);
1614 if (annotation.getLinkCount() > 0)
1616 Cache.log.warn("Ignoring " + annotation.getLinkCount() +
1617 "links added to AlignmentAnnotation.");
1619 if (annotation.getModifiable()==null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK METHODS)
1621 jan.editable = true;
1624 if (annotation.getPropertyCount() > 0)
1626 // look for special jalview properties
1627 uk.ac.vamsas.objects.core.Property[] props = annotation.getProperty();
1628 for (int p = 0; p < props.length; p++)
1630 if (props[p].getName().equalsIgnoreCase("jalview:graphType"))
1634 // probably a jalview annotation graph so recover the visualization hints.
1635 jan.graph = jalview.datamodel.AlignmentAnnotation.
1636 getGraphValueFromString(props[p].getContent());
1641 "Invalid graph type value in jalview:graphType property.");
1645 if (annotation.getGroup() != null &&
1646 annotation.getGroup().length() > 0)
1648 jan.graphGroup = Integer.parseInt(annotation.getGroup());
1653 Cache.log.info("UNIMPLEMENTED : Couldn't parse non-integer group value for setting graphGroup correctly.");
1666 private SequenceFeature getJalviewSeqFeature(RangeAnnotation dseta)
1668 int[] se = getBounds(dseta);
1669 SequenceFeature sf = new jalview.datamodel.SequenceFeature(dseta.getType(),
1670 dseta.getDescription(), dseta.getStatus(), se[0], se[1], dseta
1672 if (dseta.getLinkCount() > 0)
1674 Link[] links = dseta.getLink();
1675 for (int i = 0; i < links.length; i++)
1677 sf.addLink(links[i].getContent() + "|" + links[i].getHref());
1684 * get real bounds of a RangeType's specification. start and end are an
1685 * inclusive range within which all segments and positions lie.
1686 * TODO: refactor to vamsas utils
1688 * @return int[] { start, end}
1690 private int[] getBounds(RangeType dseta)
1695 if (dseta.getSegCount() > 0 && dseta.getPosCount() > 0)
1697 throw new Error("Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!");
1699 if (dseta.getSegCount() > 0)
1701 se = getSegRange(dseta.getSeg(0), true);
1702 for (int s = 1, sSize = dseta.getSegCount(); s < sSize; s++)
1704 int nse[] = getSegRange(dseta.getSeg(s), true);
1715 if (dseta.getPosCount() > 0)
1717 // could do a polarity for pos range too. and pass back indication of discontinuities.
1718 int pos = dseta.getPos(0).getI();
1722 for (int p = 0, pSize = dseta.getPosCount(); p < pSize; p++)
1724 pos = dseta.getPos(p).getI();
1741 * map from a rangeType's internal frame to the referenced object's coordinate frame.
1743 * @return int [] { ref(pos)...} for all pos in rangeType's frame.
1745 private int[] getMapping(RangeType dseta)
1747 Vector posList = new Vector();
1751 if (dseta.getSegCount() > 0 && dseta.getPosCount() > 0)
1753 throw new Error("Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!");
1755 if (dseta.getSegCount() > 0)
1757 for (int s = 0, sSize = dseta.getSegCount(); s < sSize; s++)
1759 se = getSegRange(dseta.getSeg(s), false);
1760 int se_end = se[1 - se[2]] + (se[2] == 0 ? 1 : -1);
1761 for (int p = se[se[2]]; p != se_end; p += se[2] == 0 ? 1 : -1)
1763 posList.add(new Integer(p));
1767 else if (dseta.getPosCount() > 0)
1769 int pos = dseta.getPos(0).getI();
1771 for (int p = 0, pSize = dseta.getPosCount(); p < pSize; p++)
1773 pos = dseta.getPos(p).getI();
1774 posList.add(new Integer(pos));
1778 if (posList != null && posList.size() > 0)
1780 int[] range = new int[posList.size()];
1781 for (int i = 0; i < range.length; i++)
1783 range[i] = ( (Integer) posList.elementAt(i)).intValue();
1792 * Provenance getVamsasProvenance(jalview.datamodel.Provenance jprov) {
1793 jalview.datamodel.ProvenanceEntry[] entries = null;
1794 // TODO: fix App and Action here.
1795 Provenance prov = new Provenance();
1796 org.exolab.castor.types.Date date = new org.exolab.castor.types.Date(
1797 new java.util.Date());
1802 entries = jprov.getEntries();
1803 for (int i = 0; i < entries.length; i++)
1805 provEntry = new Entry();
1808 date = new org.exolab.castor.types.Date(entries[i].getDate());
1809 } catch (Exception ex)
1811 ex.printStackTrace();
1813 date = new org.exolab.castor.types.Date(entries[i].getDate());
1815 provEntry.setDate(date);
1816 provEntry.setUser(entries[i].getUser());
1817 provEntry.setAction(entries[i].getAction());
1818 prov.addEntry(provEntry);
1823 provEntry = new Entry();
1824 provEntry.setDate(date);
1825 provEntry.setUser(System.getProperty("user.name")); // TODO: ext string
1826 provEntry.setApp("JVAPP"); // TODO: ext string
1827 provEntry.setAction(action);
1828 prov.addEntry(provEntry);
1834 jalview.datamodel.Provenance getJalviewProvenance(Provenance prov)
1836 // TODO: fix App and Action entries and check use of provenance in jalview.
1837 jalview.datamodel.Provenance jprov = new jalview.datamodel.Provenance();
1838 for (int i = 0; i < prov.getEntryCount(); i++)
1840 jprov.addEntry(prov.getEntry(i).getUser(), prov.getEntry(i).getAction(),
1841 prov.getEntry(i).getDate().toDate(),
1842 prov.getEntry(i).getId());
1850 * @return default initial provenance list for a Jalview created vamsas
1853 Provenance dummyProvenance()
1855 return dummyProvenance(null);
1858 Entry dummyPEntry(String action)
1860 Entry entry = new Entry();
1861 entry.setApp(this.provEntry.getApp());
1864 entry.setAction(action);
1868 entry.setAction("created.");
1870 entry.setDate(new org.exolab.castor.types.Date(new java.util.Date()));
1871 entry.setUser(this.provEntry.getUser());
1875 Provenance dummyProvenance(String action)
1877 Provenance prov = new Provenance();
1878 prov.addEntry(dummyPEntry(action));
1882 void addProvenance(Provenance p, String action)
1884 p.addEntry(dummyPEntry(action));