X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FVamsasAppDatastore.java;h=d5801296ed3a0df7b410c2dfda1cf89297bcd22b;hb=17e77c3f2949a0729322b4a8d907f3f34b6a9914;hp=e3134701f2cdea655cc9417bc054c81a6cabaf30;hpb=96f41aa46d3e568f8734834ab36fdc9ad8e54ac1;p=jalview.git diff --git a/src/jalview/io/VamsasAppDatastore.java b/src/jalview/io/VamsasAppDatastore.java index e313470..d580129 100644 --- a/src/jalview/io/VamsasAppDatastore.java +++ b/src/jalview/io/VamsasAppDatastore.java @@ -1,31 +1,29 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1) - * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9) + * Copyright (C) 2015 The Jalview Authors * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. + * This file is part of Jalview. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.io; import jalview.bin.Cache; import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.AlignmentAnnotation; -import jalview.datamodel.AlignmentI; -import jalview.datamodel.AlignmentView; -import jalview.datamodel.DBRefEntry; import jalview.datamodel.GraphLine; -import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; import jalview.gui.AlignViewport; @@ -35,7 +33,8 @@ import jalview.io.vamsas.Datasetsequence; import jalview.io.vamsas.DatastoreItem; import jalview.io.vamsas.DatastoreRegistry; import jalview.io.vamsas.Rangetype; -import jalview.util.UrlLink; +import jalview.util.MessageManager; +import jalview.viewmodel.AlignmentViewport; import java.io.IOException; import java.util.Enumeration; @@ -43,23 +42,47 @@ import java.util.HashMap; import java.util.Hashtable; import java.util.IdentityHashMap; import java.util.Iterator; +import java.util.List; +import java.util.Set; import java.util.Vector; import java.util.jar.JarInputStream; import java.util.jar.JarOutputStream; -import uk.ac.vamsas.client.*; -import uk.ac.vamsas.objects.core.*; +import uk.ac.vamsas.client.IClientAppdata; +import uk.ac.vamsas.client.IClientDocument; +import uk.ac.vamsas.client.Vobject; +import uk.ac.vamsas.client.VorbaId; +import uk.ac.vamsas.objects.core.Alignment; +import uk.ac.vamsas.objects.core.AlignmentSequence; +import uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation; +import uk.ac.vamsas.objects.core.AnnotationElement; +import uk.ac.vamsas.objects.core.DataSet; +import uk.ac.vamsas.objects.core.DataSetAnnotations; +import uk.ac.vamsas.objects.core.DbRef; +import uk.ac.vamsas.objects.core.Entry; +import uk.ac.vamsas.objects.core.Glyph; +import uk.ac.vamsas.objects.core.Local; +import uk.ac.vamsas.objects.core.MapType; +import uk.ac.vamsas.objects.core.Mapped; +import uk.ac.vamsas.objects.core.Property; +import uk.ac.vamsas.objects.core.Provenance; +import uk.ac.vamsas.objects.core.RangeAnnotation; +import uk.ac.vamsas.objects.core.RangeType; +import uk.ac.vamsas.objects.core.Seg; +import uk.ac.vamsas.objects.core.Sequence; +import uk.ac.vamsas.objects.core.SequenceType; +import uk.ac.vamsas.objects.core.VAMSAS; import uk.ac.vamsas.objects.utils.Properties; /* - * + * * static { * org.exolab.castor.util.LocalConfiguration.getInstance().getProperties().setProperty( * "org.exolab.castor.serializer", "org.apache.xml.serialize.XMLSerilazizer"); } - * + * */ /* - * TODO: check/verify consistency for vamsas sync with group associated alignment annotation + * TODO: check/verify consistency for vamsas sync with group associated alignment annotation */ public class VamsasAppDatastore { @@ -128,7 +151,7 @@ public class VamsasAppDatastore private void buildSkipList() { skipList = new Hashtable(); - AlignFrame[] al = Desktop.getAlignframes(); + AlignFrame[] al = Desktop.getAlignFrames(); for (int f = 0; al != null && f < al.length; f++) { skipList.put(al[f].getViewport().getSequenceSetId(), al[f]); @@ -144,11 +167,11 @@ public class VamsasAppDatastore { return cdoc.getObject((VorbaId) jv2vobj.get(jvobj)); } - // check if we're working with a string - then workaround + // check if we're working with a string - then workaround // the use of IdentityHashTable because different strings // have different object IDs. if (jvobj instanceof String) - { + { Object seqsetidobj = null; seqsetidobj = getVamsasObjectBinding().get(jvobj); if (seqsetidobj != null) @@ -158,18 +181,19 @@ public class VamsasAppDatastore // what is expected. object returned by av.getSequenceSetId() - // reverse lookup to get the 'registered' instance of this string Vobject obj = getjv2vObj(seqsetidobj); - if (obj!=null && !(obj instanceof Alignment)) + if (obj != null && !(obj instanceof Alignment)) { - Cache.log.warn("IMPLEMENTATION ERROR?: Unexpected mapping for unmapped jalview string object content:" - + seqsetidobj + " to object " + obj); + Cache.log + .warn("IMPLEMENTATION ERROR?: Unexpected mapping for unmapped jalview string object content:" + + seqsetidobj + " to object " + obj); } return obj; } else { Cache.log.warn("Unexpected mapping for Jalview String Object ID " - + seqsetidobj - + " to another jalview dataset object " + seqsetidobj); + + seqsetidobj + " to another jalview dataset object " + + seqsetidobj); } } } @@ -222,10 +246,12 @@ public class VamsasAppDatastore if (vobj2jv.containsKey(vobj.getVorbaId()) && !((VorbaId) vobj2jv.get(vobj.getVorbaId())).equals(jvobj)) { - Cache.log.debug( - "Warning? Overwriting existing vamsas id binding for " - + vobj.getVorbaId(), new Exception( - "Overwriting vamsas id binding.")); + Cache.log + .debug("Warning? Overwriting existing vamsas id binding for " + + vobj.getVorbaId(), + new Exception( + MessageManager + .getString("exception.overwriting_vamsas_id_binding"))); } else if (jv2vobj.containsKey(jvobj) && !((VorbaId) jv2vobj.get(jvobj)).equals(vobj.getVorbaId())) @@ -252,10 +278,11 @@ public class VamsasAppDatastore * put the alignment viewed by AlignViewport into cdoc. * * @param av - * alignViewport to be stored + * alignViewport to be stored * @param aFtitle - * title for alignment - * @return true if alignment associated with viewport was stored/synchronized to document + * title for alignment + * @return true if alignment associated with viewport was stored/synchronized + * to document */ public boolean storeVAMSAS(AlignViewport av, String aFtitle) { @@ -274,22 +301,25 @@ public class VamsasAppDatastore jal.setDataset(null); jds = jal.getDataset(); } - + // try and get alignment and association for sequence set id Alignment alignment = (Alignment) getjv2vObj(av.getSequenceSetId()); - if (alignment!=null) + if (alignment != null) { dataset = (DataSet) alignment.getV_parent(); - } else { - // is the dataset already registered - dataset = (DataSet) getjv2vObj(jds); } - + else + { + // is the dataset already registered + dataset = (DataSet) getjv2vObj(jds); + } + if (dataset == null) { // it might be that one of the dataset sequences does actually have a - // binding, so search for it indirectly. If it does, then the local jalview dataset + // binding, so search for it indirectly. If it does, then the local + // jalview dataset // must be merged with the existing vamsas dataset. jalview.datamodel.SequenceI[] jdatset = jds.getSequencesArray(); for (int i = 0; i < jdatset.length; i++) @@ -305,10 +335,12 @@ public class VamsasAppDatastore } else { - if (vbound.getV_parent()!=null && dataset != vbound.getV_parent()) + if (vbound.getV_parent() != null + && dataset != vbound.getV_parent()) { throw new Error( - "IMPLEMENTATION ERROR: Cannot map an alignment of sequences from different datasets into a single alignment in the vamsas document."); + MessageManager + .getString("error.implementation_error_cannot_map_alignment_sequences")); // This occurs because the dataset for the alignment we are // trying to } @@ -350,11 +382,14 @@ public class VamsasAppDatastore // referenced // sequences // to dataset. - Datasetsequence dssync = new jalview.io.vamsas.Datasetsequence(this, sq, dict, dataset); + Datasetsequence dssync = new jalview.io.vamsas.Datasetsequence( + this, sq, dict, dataset); sequence = (Sequence) dssync.getVobj(); - if (dssync.getModified()) { - dssmods.addElement(sequence); - }; + if (dssync.getModified()) + { + dssmods.addElement(sequence); + } + ; } if (dssmods.size() > 0) { @@ -416,8 +451,8 @@ public class VamsasAppDatastore { boolean modified = false; // check existing sequences in local and in document. - Vector docseqs = new Vector(alignment - .getAlignmentSequenceAsReference()); + Vector docseqs = new Vector( + alignment.getAlignmentSequenceAsReference()); for (int i = 0; i < jal.getHeight(); i++) { modified |= syncToAlignmentSequence(jal.getSequenceAt(i), @@ -488,16 +523,17 @@ public class VamsasAppDatastore * jalview.datamodel.SequenceFeature[] features = alseq * .getSequenceFeatures(); for (int f = 0; f < features.length; f++) { * if (features[f] != null) { AlignmentSequenceAnnotation valseqf = ( - * AlignmentSequenceAnnotation) getjv2vObj(features[i]); if (valseqf == - * null) { + * AlignmentSequenceAnnotation) getjv2vObj(features[i]); if (valseqf + * == null) { * * valseqf = (AlignmentSequenceAnnotation) getDSAnnotationFromJalview( * new AlignmentSequenceAnnotation(), features[i]); * valseqf.setGraph(false); - * valseqf.addProperty(newProperty("jalview:feature","boolean","true")); - * if (valseqf.getProvenance() == null) { valseqf.setProvenance(new - * Provenance()); } addProvenance(valseqf.getProvenance(), "created"); // - * JBPNote - // need to // update bindjvvobj(features[i], valseqf); + * valseqf.addProperty(newProperty("jalview:feature" + * ,"boolean","true")); if (valseqf.getProvenance() == null) { + * valseqf.setProvenance(new Provenance()); } + * addProvenance(valseqf.getProvenance(), "created"); // JBPNote - // + * need to // update bindjvvobj(features[i], valseqf); * valseq.addAlignmentSequenceAnnotation(valseqf); } } } */ } @@ -518,10 +554,11 @@ public class VamsasAppDatastore { continue; } - if (aa[i].groupRef!=null) + if (aa[i].groupRef != null) { // TODO: store any group associated annotation references - Cache.log.warn("Group associated sequence annotation is not stored in VAMSAS document."); + Cache.log + .warn("Group associated sequence annotation is not stored in VAMSAS document."); continue; } if (aa[i].sequenceRef != null) @@ -536,12 +573,8 @@ public class VamsasAppDatastore else { // first find the alignment sequence to associate this with. - SequenceI jvalsq = null; - Enumeration jval = av.getAlignment().getSequences() - .elements(); - while (jval.hasMoreElements()) + for (SequenceI jvalsq : av.getAlignment().getSequences()) { - jvalsq = (SequenceI) jval.nextElement(); // saveDatasetSequenceAnnotation(AlSeqMaps,(uk.ac.vamsas.objects.core.Sequence) // sref, aa[i]); if (jvalsq.getDatasetSequence() == aa[i].sequenceRef) @@ -623,11 +656,9 @@ public class VamsasAppDatastore if (aa[i].annotations[a].secondaryStructure != ' ') { Glyph ss = new Glyph(); - ss - .setDict(uk.ac.vamsas.objects.utils.GlyphDictionary.PROTEIN_SS_3STATE); - ss - .setContent(String - .valueOf(aa[i].annotations[a].secondaryStructure)); + ss.setDict(uk.ac.vamsas.objects.utils.GlyphDictionary.PROTEIN_SS_3STATE); + ss.setContent(String + .valueOf(aa[i].annotations[a].secondaryStructure)); ae.addGlyph(ss); } an.addAnnotationElement(ae); @@ -647,12 +678,13 @@ public class VamsasAppDatastore an.setGroup(Integer.toString(aa[i].graphGroup)); if (aa[i].threshold != null && aa[i].threshold.displayed) { - an.addProperty(Properties.newProperty(THRESHOLD, Properties.FLOATTYPE, "" - + aa[i].threshold.value)); + an.addProperty(Properties.newProperty(THRESHOLD, + Properties.FLOATTYPE, "" + aa[i].threshold.value)); if (aa[i].threshold.label != null) { - an.addProperty(Properties.newProperty(THRESHOLD + "Name", Properties.STRINGTYPE, - "" + aa[i].threshold.label)); + an.addProperty(Properties.newProperty(THRESHOLD + + "Name", Properties.STRINGTYPE, "" + + aa[i].threshold.label)); } } } @@ -695,7 +727,8 @@ public class VamsasAppDatastore { TreePanel tp = (TreePanel) frames[t]; - if (tp.getViewPort().getSequenceSetId().equals(av.getSequenceSetId())) + if (tp.getViewPort().getSequenceSetId() + .equals(av.getSequenceSetId())) { DatastoreItem vtree = new jalview.io.vamsas.Tree(this, tp, jal, alignment); @@ -716,17 +749,20 @@ public class VamsasAppDatastore } /** - * very quick test to see if the viewport would be stored in the vamsas document. - * Reasons for not storing include the unaligned flag being false. + * very quick test to see if the viewport would be stored in the vamsas + * document. Reasons for not storing include the unaligned flag being false + * (for all sequences, including the hidden ones!) + * * @param av - * @return true if alignment associated with this view will be stored in document. + * @return true if alignment associated with this view will be stored in + * document. */ - public boolean alignmentWillBeSkipped(AlignViewport av) + public boolean alignmentWillBeSkipped(AlignmentViewport av) { return (!av.getAlignment().isAligned()); } - private void addToSkipList(AlignViewport av) + private void addToSkipList(AlignmentViewport av) { if (skipList == null) { @@ -871,7 +907,7 @@ public class VamsasAppDatastore * creates/syncs the jvalsq from the alignment sequence */ private boolean syncFromAlignmentSequence(AlignmentSequence valseq, - char valGapchar, char gapChar, Vector dsseqs) + char valGapchar, char gapChar, List dsseqs) { boolean modal = false; @@ -903,8 +939,9 @@ public class VamsasAppDatastore modal = true; alseq.setName(valseq.getName()); } - if (alseq.getDescription()==null || (valseq.getDescription() != null && !alseq.getDescription() - .equals(valseq.getDescription()))) + if (alseq.getDescription() == null + || (valseq.getDescription() != null && !alseq + .getDescription().equals(valseq.getDescription()))) { alseq.setDescription(valseq.getDescription()); modal = true; @@ -918,21 +955,24 @@ public class VamsasAppDatastore else { alseq = new jalview.datamodel.Sequence(valseq.getName(), valseq - .getSequence().replace(valGapchar, gapChar), (int) valseq - .getStart(), (int) valseq.getEnd()); - + .getSequence().replace(valGapchar, gapChar), + (int) valseq.getStart(), (int) valseq.getEnd()); + Vobject datsetseq = (Vobject) valseq.getRefid(); if (datsetseq != null) { alseq.setDatasetSequence((SequenceI) getvObj2jv(datsetseq)); // exceptions - if (valseq.getDescription()!=null) + if (valseq.getDescription() != null) { alseq.setDescription(valseq.getDescription()); - } else { + } + else + { // inherit description line from dataset. - if (alseq.getDatasetSequence().getDescription()!=null) + if (alseq.getDatasetSequence().getDescription() != null) { - alseq.setDescription(alseq.getDatasetSequence().getDescription()); + alseq.setDescription(alseq.getDatasetSequence() + .getDescription()); } } // if @@ -1016,8 +1056,7 @@ public class VamsasAppDatastore { // we only write an annotation where it really exists. Glyph ss = new Glyph(); - ss - .setDict(uk.ac.vamsas.objects.utils.GlyphDictionary.PROTEIN_SS_3STATE); + ss.setDict(uk.ac.vamsas.objects.utils.GlyphDictionary.PROTEIN_SS_3STATE); ss.setContent(String .valueOf(alan.annotations[a].secondaryStructure)); ae.addGlyph(ss); @@ -1055,12 +1094,13 @@ public class VamsasAppDatastore // bits. if (alan.getThreshold() != null && alan.getThreshold().displayed) { - an.addProperty(Properties.newProperty(THRESHOLD, Properties.FLOATTYPE, - "" - + alan.getThreshold().value)); + an.addProperty(Properties.newProperty(THRESHOLD, + Properties.FLOATTYPE, "" + alan.getThreshold().value)); if (alan.getThreshold().label != null) - an.addProperty(Properties.newProperty(THRESHOLD + "Name", Properties.STRINGTYPE, "" - + alan.getThreshold().label)); + { + an.addProperty(Properties.newProperty(THRESHOLD + "Name", + Properties.STRINGTYPE, "" + alan.getThreshold().label)); + } } ((DataSet) sref.getV_parent()).addDataSetAnnotations(an); bindjvvobj(alan, an); @@ -1186,24 +1226,25 @@ public class VamsasAppDatastore switch (alan.graph) { case AlignmentAnnotation.BAR_GRAPH: - an.addProperty(Properties.newProperty(DISCRETE_ANNOTATION, Properties.BOOLEANTYPE, "true")); + an.addProperty(Properties.newProperty(DISCRETE_ANNOTATION, + Properties.BOOLEANTYPE, "true")); break; case AlignmentAnnotation.LINE_GRAPH: - an.addProperty(Properties.newProperty(CONTINUOUS_ANNOTATION, Properties.BOOLEANTYPE, "true")); + an.addProperty(Properties.newProperty(CONTINUOUS_ANNOTATION, + Properties.BOOLEANTYPE, "true")); break; default: // don't add any kind of discrete or continous property info. } } - /** * get start mappings = av.getAlignment() + .getCodonFrames(); for (int i = 0; i < views.length; i++) { if (views[i] != av) @@ -1424,18 +1469,19 @@ public class VamsasAppDatastore { // ensure sequence mappings from vamsas document view still // active - if (mappings != null && mappings.length > 0) + if (mappings != null) { jalview.structure.StructureSelectionManager - .getStructureSelectionManager().addMappings(mappings); + .getStructureSelectionManager(Desktop.instance) + .registerMappings(mappings); } } } // ensure vamsas object binds to the stored views retrieved from // Jalview appdata - //jalview.structure.StructureSelectionManager - // .getStructureSelectionManager() - // .addStructureViewerListener(viewframe.alignPanel); + // jalview.structure.StructureSelectionManager + // .getStructureSelectionManager() + // .addStructureViewerListener(viewframe.alignPanel); } @@ -1448,18 +1494,21 @@ public class VamsasAppDatastore * binding tables * * @param oldjvobject - * @param newjvobject (may be null) + * @param newjvobject + * (may be null) */ private void replaceJvObjMapping(Object oldjvobject, Object newjvobject) { Object vobject = jv2vobj.remove(oldjvobject); if (vobject == null) { - throw new Error( - "IMPLEMENTATION ERROR: old jalview object is not bound ! (" - + oldjvobject + ")"); + // NOTE: this happens if user deletes object in one session then updates + // from another client + throw new Error(MessageManager.formatMessage( + "error.implementation_error_old_jalview_object_not_bound", + new String[] { oldjvobject.toString() })); } - if (newjvobject!=null) + if (newjvobject != null) { jv2vobj.put(newjvobject, vobject); vobj2jv.put(vobject, newjvobject); @@ -1482,7 +1531,7 @@ public class VamsasAppDatastore jxml.setSkipList(skipList); if (dojvsync) { - jxml.SaveState(new JarOutputStream(cappdata + jxml.saveState(new JarOutputStream(cappdata .getClientOutputStream())); } @@ -1490,8 +1539,7 @@ public class VamsasAppDatastore { // TODO raise GUI warning if user requests it. jalview.bin.Cache.log - .error( - "Couldn't update jalview client application data. Giving up - local settings probably lost.", + .error("Couldn't update jalview client application data. Giving up - local settings probably lost.", e); } } @@ -1537,8 +1585,10 @@ public class VamsasAppDatastore } return mapped; } + /** * synchronize Jalview from the vamsas document + * * @return number of new views from document */ public int updateToJalview() @@ -1555,7 +1605,7 @@ public class VamsasAppDatastore // ///LOAD DATASET DataSet dataset = root.getDataSet(_ds); int i, iSize = dataset.getSequenceCount(); - Vector dsseqs; + List dsseqs; jalview.datamodel.Alignment jdataset = (jalview.datamodel.Alignment) getvObj2jv(dataset); int jremain = 0; if (jdataset == null) @@ -1574,12 +1624,12 @@ public class VamsasAppDatastore // TODO: test sequence merging - we preserve existing non vamsas // sequences but add in any new vamsas ones, and don't yet update any // sequence attributes - for (i = 0; i < iSize - ; i++) + for (i = 0; i < iSize; i++) { Sequence vdseq = dataset.getSequence(i); - jalview.io.vamsas.Datasetsequence dssync = new Datasetsequence(this, vdseq); - + jalview.io.vamsas.Datasetsequence dssync = new Datasetsequence( + this, vdseq); + jalview.datamodel.SequenceI dsseq = (SequenceI) dssync.getJvobj(); if (dssync.isAddfromdoc()) { @@ -1602,8 +1652,8 @@ public class VamsasAppDatastore SequenceI[] seqs = new SequenceI[dsseqs.size()]; for (i = 0, iSize = dsseqs.size(); i < iSize; i++) { - seqs[i] = (SequenceI) dsseqs.elementAt(i); - dsseqs.setElementAt(null, i); + seqs[i] = dsseqs.get(i); + dsseqs.set(i, null); } jdataset = new jalview.datamodel.Alignment(seqs); Cache.log.debug("New vamsas dataset imported into jalview."); @@ -1635,7 +1685,7 @@ public class VamsasAppDatastore if (dseta.getAnnotationElementCount() == 0) { new jalview.io.vamsas.Sequencefeature(this, dseta, dsSeq); - + } else { @@ -1648,8 +1698,11 @@ public class VamsasAppDatastore .warn("Ignoring dataset annotation with annotationElements. Not yet supported in jalview."); } } - } else { - Cache.log.warn("Ignoring multiply referenced dataset sequence annotation for binding to datsaet sequence features."); + } + else + { + Cache.log + .warn("Ignoring multiply referenced dataset sequence annotation for binding to datsaet sequence features."); } } } @@ -1662,7 +1715,7 @@ public class VamsasAppDatastore uk.ac.vamsas.objects.core.Alignment alignment = dataset .getAlignment(al); // TODO check this handles multiple views properly - AlignViewport av = findViewport(alignment); + AlignmentViewport av = findViewport(alignment); jalview.datamodel.AlignmentI jal = null; if (av != null) @@ -1672,7 +1725,7 @@ public class VamsasAppDatastore jal = (av.hasHiddenRows()) ? av.getAlignment() .getHiddenSequences().getFullAlignment() : av .getAlignment(); - } + } iSize = alignment.getAlignmentSequenceCount(); boolean refreshal = false; Vector newasAnnots = new Vector(); @@ -1693,8 +1746,7 @@ public class VamsasAppDatastore AlignmentSequence valseq = alignment.getAlignmentSequence(i); jalview.datamodel.Sequence alseq = (jalview.datamodel.Sequence) getvObj2jv(valseq); if (syncFromAlignmentSequence(valseq, valGapchar, gapChar, - dsseqs) - && alseq != null) + dsseqs) && alseq != null) { // updated to sequence from the document @@ -1762,8 +1814,8 @@ public class VamsasAppDatastore SequenceI[] seqs = new SequenceI[dsseqs.size()]; for (i = 0, iSize = dsseqs.size(); i < iSize; i++) { - seqs[i] = (SequenceI) dsseqs.elementAt(i); - dsseqs.setElementAt(null, i); + seqs[i] = dsseqs.get(i); + dsseqs.set(i, null); } jal = new jalview.datamodel.Alignment(seqs); Cache.log.debug("New vamsas alignment imported into jalview " @@ -1820,7 +1872,8 @@ public class VamsasAppDatastore else { jan = getjAlignmentAnnotation(jal, an[j]); - // TODO: ensure we add the alignment annotation before the automatic annotation rows + // TODO: ensure we add the alignment annotation before the + // automatic annotation rows jal.addAnnotation(jan); bindjvvobj(jan, an[j]); refreshal = true; @@ -1839,8 +1892,10 @@ public class VamsasAppDatastore .toString()); av = alignFrame.getViewport(); newAlignmentViews.addElement(av); - String title = alignment.getProvenance().getEntry( - alignment.getProvenance().getEntryCount() - 1) + String title = alignment + .getProvenance() + .getEntry( + alignment.getProvenance().getEntryCount() - 1) .getAction(); if (alignment.getPropertyCount() > 0) { @@ -1934,10 +1989,10 @@ public class VamsasAppDatastore return newAlignmentViews.size(); } - public AlignViewport findViewport(Alignment alignment) + public AlignmentViewport findViewport(Alignment alignment) { - AlignViewport av = null; - AlignViewport[] avs = Desktop + AlignmentViewport av = null; + AlignmentViewport[] avs = Desktop .getViewports((String) getvObj2jv(alignment)); if (avs != null) { @@ -1980,8 +2035,7 @@ public class VamsasAppDatastore // may not quite cope with this (without binding an array of annotations to // a vamsas alignment annotation) // summary flags saying what we found over the set of annotation rows. - boolean[] AeContent = new boolean[] - { false, false, false, false, false }; + boolean[] AeContent = new boolean[] { false, false, false, false, false }; int[] rangeMap = getMapping(annotation); jalview.datamodel.Annotation[][] anot = new jalview.datamodel.Annotation[][] { new jalview.datamodel.Annotation[rangeMap.length], @@ -2031,16 +2085,14 @@ public class VamsasAppDatastore { if (glyphs[g] .getDict() - .equals( - uk.ac.vamsas.objects.utils.GlyphDictionary.PROTEIN_SS_3STATE)) + .equals(uk.ac.vamsas.objects.utils.GlyphDictionary.PROTEIN_SS_3STATE)) { ss = glyphs[g].getContent(); AeContent[HASSECSTR] = true; } else if (glyphs[g] .getDict() - .equals( - uk.ac.vamsas.objects.utils.GlyphDictionary.PROTEIN_HD_HYDRO)) + .equals(uk.ac.vamsas.objects.utils.GlyphDictionary.PROTEIN_HD_HYDRO)) { Cache.log.debug("ignoring hydrophobicity glyph marker."); AeContent[HASHPHOB] = true; @@ -2079,14 +2131,14 @@ public class VamsasAppDatastore if (colour == null) { anot[row][pos] = new jalview.datamodel.Annotation( - (dc != null) ? dc : "", desc, (ss != null) ? ss - .charAt(0) : ' ', val); + (dc != null) ? dc : "", desc, + (ss != null) ? ss.charAt(0) : ' ', val); } else { anot[row][pos] = new jalview.datamodel.Annotation( - (dc != null) ? dc : "", desc, (ss != null) ? ss - .charAt(0) : ' ', val, colour); + (dc != null) ? dc : "", desc, + (ss != null) ? ss.charAt(0) : ' ', val, colour); } } else @@ -2118,24 +2170,21 @@ public class VamsasAppDatastore anot[1][i].description = anot[1][i].description + " (after)"; } } - return new Object[] - { AeContent, rangeMap, anot[0], anot[1] }; + return new Object[] { AeContent, rangeMap, anot[0], anot[1] }; } else { // no annotations to parse. Just return an empty annotationElement[] // array. - return new Object[] - { AeContent, rangeMap, anot[0], anot[1] }; + return new Object[] { AeContent, rangeMap, anot[0], anot[1] }; } // return null; } /** * @param jal - * the jalview alignment to which the annotation will be - * attached (ideally - freshly updated from corresponding - * vamsas alignment) + * the jalview alignment to which the annotation will be attached + * (ideally - freshly updated from corresponding vamsas alignment) * @param annotation * @return unbound jalview alignment annotation object. */ @@ -2188,6 +2237,7 @@ public class VamsasAppDatastore Cache.log.warn("Failed to parse threshold property"); } if (val != null) + { if (gl == null) { gl = new GraphLine(val.floatValue(), "", java.awt.Color.black); @@ -2196,11 +2246,14 @@ public class VamsasAppDatastore { gl.value = val.floatValue(); } + } } else if (props[p].getName().equalsIgnoreCase(THRESHOLD + "Name")) { if (gl == null) + { gl = new GraphLine(0, "", java.awt.Color.black); + } gl.label = props[p].getContent(); } } @@ -2236,11 +2289,12 @@ public class VamsasAppDatastore // way its 'odd' - there is already an existing TODO about removing this // flag as being redundant /* - * if - * ((annotation.getClass().equals(uk.ac.vamsas.objects.core.AlignmentAnnotation.class) && - * ((uk.ac.vamsas.objects.core.AlignmentAnnotation)annotation).getGraph()) || - * (hasSequenceRef=true && - * ((uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation)annotation).getGraph())) { + * if((annotation.getClass().equals(uk.ac.vamsas.objects.core. + * AlignmentAnnotation.class) && + * ((uk.ac.vamsas.objects.core.AlignmentAnnotation)annotation).getGraph()) + * || (hasSequenceRef=true && + * ((uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation + * )annotation).getGraph())) { */ if (has[HASVALS]) { @@ -2380,7 +2434,6 @@ public class VamsasAppDatastore return null; } - /** * get real bounds of a RangeType's specification. start and end are an * inclusive range within which all segments and positions lie. TODO: refactor @@ -2397,7 +2450,8 @@ public class VamsasAppDatastore if (dseta.getSegCount() > 0 && dseta.getPosCount() > 0) { throw new Error( - "Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!"); + MessageManager + .getString("error.invalid_vamsas_rangetype_cannot_resolve_lists")); } if (dseta.getSegCount() > 0) { @@ -2420,8 +2474,7 @@ public class VamsasAppDatastore // could do a polarity for pos range too. and pass back indication of // discontinuities. int pos = dseta.getPos(0).getI(); - se = new int[] - { pos, pos }; + se = new int[] { pos, pos }; for (int p = 0, pSize = dseta.getPosCount(); p < pSize; p++) { pos = dseta.getPos(p).getI(); @@ -2456,7 +2509,8 @@ public class VamsasAppDatastore if (dseta.getSegCount() > 0 && dseta.getPosCount() > 0) { throw new Error( - "Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!"); + MessageManager + .getString("error.invalid_vamsas_rangetype_cannot_resolve_lists")); } if (dseta.getSegCount() > 0) { @@ -2497,12 +2551,10 @@ public class VamsasAppDatastore /** * * @param maprange - * where the from range is the local mapped range, and the to - * range is the 'mapped' range in the MapRangeType - * @param default - * unit for local - * @param default - * unit for mapped + * where the from range is the local mapped range, and the to range + * is the 'mapped' range in the MapRangeType + * @param default unit for local + * @param default unit for mapped * @return MapList */ private jalview.util.MapList parsemapType(MapType maprange, int localu, @@ -2524,15 +2576,15 @@ public class VamsasAppDatastore * initialise a range type object from a set of start/end inclusive intervals * * @param mrt - * @param range + * @param ranges */ - private void initRangeType(RangeType mrt, int[] range) + private void initRangeType(RangeType mrt, List ranges) { - for (int i = 0; i < range.length; i += 2) + for (int[] range : ranges) { Seg vSeg = new Seg(); - vSeg.setStart(range[i]); - vSeg.setEnd(range[i + 1]); + vSeg.setStart(range[0]); + vSeg.setEnd(range[1]); mrt.addSeg(vSeg); } } @@ -2567,8 +2619,8 @@ public class VamsasAppDatastore * * if (jprov != null) { entries = jprov.getEntries(); for (int i = 0; i < * entries.length; i++) { provEntry = new Entry(); try { date = new - * org.exolab.castor.types.Date(entries[i].getDate()); } catch (Exception ex) { - * ex.printStackTrace(); + * org.exolab.castor.types.Date(entries[i].getDate()); } catch (Exception ex) + * { ex.printStackTrace(); * * date = new org.exolab.castor.types.Date(entries[i].getDate()); } * provEntry.setDate(date); provEntry.setUser(entries[i].getUser()); @@ -2655,10 +2707,10 @@ public class VamsasAppDatastore return vobj2jv; } - public void storeSequenceMappings(AlignViewport viewport, String title) + public void storeSequenceMappings(AlignmentViewport viewport, String title) throws Exception { - AlignViewport av = viewport; + AlignmentViewport av = viewport; try { jalview.datamodel.AlignmentI jal = av.getAlignment(); @@ -2670,25 +2722,25 @@ public class VamsasAppDatastore Cache.log.warn("Creating new dataset for an alignment."); jal.setDataset(null); } - dataset = (DataSet) ((Alignment) getjv2vObj(viewport.getSequenceSetId())).getV_parent(); // jal.getDataset()); - if (dataset==null) + dataset = (DataSet) ((Alignment) getjv2vObj(viewport + .getSequenceSetId())).getV_parent(); // jal.getDataset()); + if (dataset == null) { dataset = (DataSet) getjv2vObj(jal.getDataset()); - Cache.log.error("Can't find the correct dataset for the alignment in this view. Creating new one."); + Cache.log + .error("Can't find the correct dataset for the alignment in this view. Creating new one."); } // Store any sequence mappings. - if (av.getAlignment().getCodonFrames() != null - && av.getAlignment().getCodonFrames().length > 0) + Set cframes = av.getAlignment().getCodonFrames(); + if (cframes != null) { - jalview.datamodel.AlignedCodonFrame[] cframes = av.getAlignment() - .getCodonFrames(); - for (int cf = 0; cf < cframes.length; cf++) + for (AlignedCodonFrame acf : cframes) { - if (cframes[cf].getdnaSeqs()!=null && cframes[cf].getdnaSeqs().length > 0) + if (acf.getdnaSeqs() != null && acf.getdnaSeqs().length > 0) { - jalview.datamodel.SequenceI[] dmps = cframes[cf].getdnaSeqs(); - jalview.datamodel.Mapping[] mps = cframes[cf].getProtMappings(); + jalview.datamodel.SequenceI[] dmps = acf.getdnaSeqs(); + jalview.datamodel.Mapping[] mps = acf.getProtMappings(); for (int smp = 0; smp < mps.length; smp++) { uk.ac.vamsas.objects.core.SequenceType mfrom = (SequenceType) getjv2vObj(dmps[smp]); @@ -2711,8 +2763,9 @@ public class VamsasAppDatastore } } catch (Exception e) { - throw new Exception("Couldn't store sequence mappings for " + title, - e); + throw new Exception(MessageManager.formatMessage( + "exception.couldnt_store_sequence_mappings", + new String[] { title }), e); } } @@ -2733,19 +2786,22 @@ public class VamsasAppDatastore } /** - * @param skipList the skipList to set + * @param skipList + * the skipList to set */ public void setSkipList(Hashtable skipList) { this.skipList = skipList; } + /** * registry for datastoreItems */ DatastoreRegistry dsReg = new DatastoreRegistry(); + public DatastoreRegistry getDatastoreRegisty() { - if (dsReg==null) + if (dsReg == null) { dsReg = new DatastoreRegistry(); }