X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FVamsasAppDatastore.java;h=82e9fbabad07e34b57dc342c0a3d5e67cf1245be;hb=9d8d94660cfba31f6dd39cd6a8a25e3e88284277;hp=379982ade00bff0302da64259e741719b9d55ef7;hpb=6ab5d6082ba24bfa949ee3a44b100d7fed92c9ad;p=jalview.git diff --git a/src/jalview/io/VamsasAppDatastore.java b/src/jalview/io/VamsasAppDatastore.java index 379982a..82e9fba 100644 --- a/src/jalview/io/VamsasAppDatastore.java +++ b/src/jalview/io/VamsasAppDatastore.java @@ -59,17 +59,18 @@ public class VamsasAppDatastore public static final String JALVIEW_ANNOTATION_ROW = "JalviewAnnotation"; /** - * AlignmentAnnotation property to indicate that values should not be interpolated + * AlignmentAnnotation property to indicate that values should not be + * interpolated */ public static final String DISCRETE_ANNOTATION = "discrete"; + /** - * continuous property - optional to specify that annotation should be represented - * as a continous graph line + * continuous property - optional to specify that annotation should be + * represented as a continous graph line */ private static final String CONTINUOUS_ANNOTATION = "continuous"; - private static final String THRESHOLD = "threshold"; - + private static final String THRESHOLD = "threshold"; Entry provEntry = null; @@ -79,13 +80,16 @@ public class VamsasAppDatastore IdentityHashMap jv2vobj; + Hashtable alignRDHash; + public VamsasAppDatastore(IClientDocument cdoc, Hashtable vobj2jv, - IdentityHashMap jv2vobj, Entry provEntry) + IdentityHashMap jv2vobj, Entry provEntry, Hashtable alignRDHash) { this.cdoc = cdoc; this.vobj2jv = vobj2jv; this.jv2vobj = jv2vobj; this.provEntry = provEntry; + this.alignRDHash = alignRDHash; } /** @@ -175,9 +179,9 @@ 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 + * title for alignment */ public void storeVAMSAS(AlignViewport av, String aFtitle) { @@ -235,7 +239,7 @@ public class VamsasAppDatastore root.addDataSet(dataset); bindjvvobj(jal.getDataset(), dataset); dataset.setProvenance(dummyProvenance()); - dataset.getProvenance().addEntry(provEntry); + // dataset.getProvenance().addEntry(provEntry); nw = true; } else @@ -251,6 +255,7 @@ public class VamsasAppDatastore // acid sequences. String dict = jal.isNucleotide() ? uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_NA : uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_AA; + Vector dssmods = new Vector(); for (int i = 0; i < jal.getHeight(); i++) { SequenceI sq = jal.getSequenceAt(i).getDatasetSequence(); // only insert @@ -265,25 +270,61 @@ public class VamsasAppDatastore sq.setVamsasId(sequence.getVorbaId().getId()); sequence.setSequence(sq.getSequenceAsString()); sequence.setDictionary(dict); - sequence.setName(jal.getDataset().getSequenceAt(i).getName()); - sequence.setStart(jal.getDataset().getSequenceAt(i).getStart()); - sequence.setEnd(jal.getDataset().getSequenceAt(i).getEnd()); - sequence.setDescription(jal.getDataset().getSequenceAt(i) - .getDescription()); + sequence.setName(sq.getName()); + sequence.setStart(sq.getStart()); + sequence.setEnd(sq.getEnd()); + sequence.setDescription(sq.getDescription()); dataset.addSequence(sequence); + dssmods.addElement(dssmods); } else { - // verify principal attributes. and update any new - // features/references. - System.out.println("update dataset sequence object."); + boolean dsmod = false; + // verify and update principal attributes. + if (sq.getDescription() != null + && (sequence.getDescription() == null || !sequence + .getDescription().equals(sq.getDescription()))) + { + sequence.setDescription(sq.getDescription()); + dsmod = true; + } + if (sequence.getSequence() == null + || !sequence.getSequence().equals( + sq.getSequenceAsString())) + { + if (sequence.getStart() != sq.getStart() + || sequence.getEnd() != sq.getEnd()) + { + // update modified sequence. + sequence.setSequence(sq.getSequenceAsString()); + sequence.setStart(sq.getStart()); + sequence.setEnd(sq.getEnd()); + dsmod = true; + } + } + if (!dict.equals(sequence.getDictionary())) + { + sequence.setDictionary(dict); + dsmod = true; + } + if (!sequence.getName().equals(sq.getName())) + { + sequence.setName(sq.getName()); + dsmod = true; + } + if (dsmod) + { + dssmods.addElement(sequence); + } } + // add or update any new features/references on dataset sequence if (sq.getSequenceFeatures() != null) { int sfSize = sq.getSequenceFeatures().length; for (int sf = 0; sf < sfSize; sf++) { + // TODO: update/modifiable synchronizer jalview.datamodel.SequenceFeature feature = (jalview.datamodel.SequenceFeature) sq .getSequenceFeatures()[sf]; @@ -299,7 +340,7 @@ public class VamsasAppDatastore addProvenance(dsa.getProvenance(), "created"); // JBPNote - need // to update dsa.addSeqRef(sequence); // we have just created this annotation - // - so safe to use this + // - so safe to use this bindjvvobj(feature, dsa); dataset.addDataSetAnnotations(dsa); } @@ -323,21 +364,42 @@ public class VamsasAppDatastore } } + if (dssmods.size() > 0) + { + if (!nw) + { + Entry pentry = this.addProvenance(dataset.getProvenance(), + "updated sequences"); + // pentry.addInput(vInput); could write in which sequences were + // modified. + dssmods.removeAllElements(); + } + } // dataset.setProvenance(getVamsasProvenance(jal.getDataset().getProvenance())); // //////////////////////////////////////////// if (!av.getAlignment().isAligned()) - return; // TODO: trees could be written - but for the moment we just skip - + return; // TODO: trees could be written - but for the moment we just + // skip // //////////////////////////////////////////// // Save the Alignments - Alignment alignment = (Alignment) getjv2vObj(av); // this is so we can get - // the alignviewport - // back + Alignment alignment = (Alignment) getjv2vObj(av.getSequenceSetId()); // bind + // to + // the + // value + // used + // to + // associate + // different + // views + // to + // same + // alignment + if (alignment == null) { alignment = new Alignment(); - bindjvvobj(av, alignment); + bindjvvobj(av.getSequenceSetId(), alignment); if (alignment.getProvenance() == null) { alignment.setProvenance(new Provenance()); @@ -354,37 +416,76 @@ public class VamsasAppDatastore alignment.addProperty(title); } alignment.setGapChar(String.valueOf(av.getGapCharacter())); - AlignmentSequence alseq = null; for (int i = 0; i < jal.getHeight(); i++) { - alseq = new AlignmentSequence(); - // TODO: VAMSAS: translate lowercase symbols to annotation ? - alseq.setSequence(jal.getSequenceAt(i).getSequenceAsString()); - alseq.setName(jal.getSequenceAt(i).getName()); - alseq.setStart(jal.getSequenceAt(i).getStart()); - alseq.setEnd(jal.getSequenceAt(i).getEnd()); - if (getjv2vObj(jal.getSequenceAt(i).getDatasetSequence()) == null) - { - Cache.log - .warn("Serious. Unbound dataset sequence in alignment: " - + jal.getSequenceAt(i).getDatasetSequence()); - } - alseq.setRefid(getjv2vObj(jal.getSequenceAt(i) - .getDatasetSequence())); - alignment.addAlignmentSequence(alseq); - bindjvvobj(jal.getSequenceAt(i), alseq); + syncToAlignmentSequence(jal.getSequenceAt(i), alignment, null); } + alignRDHash.put(av.getSequenceSetId(), av.getUndoRedoHash()); } else { + // always prepare to clone the alignment + boolean alismod = av.isUndoRedoHashModified((long[]) alignRDHash + .get(av.getSequenceSetId())); // todo: verify and update mutable alignment props. - if (alignment.getModifiable() == null) // TODO: USE VAMSAS LIBRARY - // OBJECT LOCK METHODS + // TODO: Use isLocked methods + if (alignment.getModifiable() == null + || alignment.getModifiable().length() == 0) + // && !alignment.isDependedOn()) { - System.out.println("update alignment in document."); + boolean modified = false; + // check existing sequences in local and in document. + Vector docseqs = new Vector(alignment + .getAlignmentSequenceAsReference()); + for (int i = 0; i < jal.getHeight(); i++) + { + modified |= syncToAlignmentSequence(jal.getSequenceAt(i), + alignment, docseqs); + } + if (docseqs.size() > 0) + { + // removeValignmentSequences(alignment, docseqs); + docseqs.removeAllElements(); + System.out + .println("Sequence deletion from alignment is not implemented."); + + } + if (modified) + { + if (alismod) + { + // info in the undo + addProvenance(alignment.getProvenance(), "Edited"); // TODO: + // insert + // something + // sensible + // here again + } + else + { + // info in the undo + addProvenance(alignment.getProvenance(), "Attributes Edited"); // TODO: + // insert + // something + // sensible + // here + // again + } + } + if (alismod) + { + System.out.println("update alignment in document."); + } + else + { + System.out.println("alignment in document left unchanged."); + } } else { + // unbind alignment from view. + // create new binding and new alignment. + // mark trail on new alignment as being derived from old ? System.out .println("update edited alignment to new alignment in document."); } @@ -416,8 +517,7 @@ public class VamsasAppDatastore * if (valseqf.getProvenance() == null) { valseqf.setProvenance(new * Provenance()); } addProvenance(valseqf.getProvenance(), "created"); // * JBPNote - // need to // update bindjvvobj(features[i], valseqf); - * valseq.addAlignmentSequenceAnnotation(valseqf); } } - * } + * valseq.addAlignmentSequenceAnnotation(valseqf); } } } */ } } @@ -479,8 +579,8 @@ public class VamsasAppDatastore an.setDescription(aa[i].description); alignment.addAlignmentAnnotation(an); Seg vSeg = new Seg(); // TODO: refactor to have a default - // rangeAnnotationType initer/updater that - // takes a set of int ranges. + // rangeAnnotationType initer/updater that + // takes a set of int ranges. vSeg.setStart(1); vSeg.setInclusive(true); vSeg.setEnd(jal.getWidth()); @@ -494,7 +594,7 @@ public class VamsasAppDatastore if (aa[i].graph != AlignmentAnnotation.NO_GRAPH) { an.setGroup(Integer.toString(aa[i].graphGroup)); // // JBPNote - // - + // - // originally we // were going to // store @@ -550,23 +650,29 @@ public class VamsasAppDatastore // modifiable flag is supposed to be used. } setAnnotationType(an, aa[i]); - + if (aa[i].graph != jalview.datamodel.AlignmentAnnotation.NO_GRAPH) { an.setGraph(true); an.setGroup(Integer.toString(aa[i].graphGroup)); - if (aa[i].threshold!=null && aa[i].threshold.displayed) - an.addProperty(newProperty(THRESHOLD, "float", ""+aa[i].threshold.value)); - if (aa[i].threshold.label!=null) - an.addProperty(newProperty(THRESHOLD+"Name", "string", ""+aa[i].threshold.label)); + if (aa[i].threshold != null && aa[i].threshold.displayed) + { + an.addProperty(newProperty(THRESHOLD, "float", "" + + aa[i].threshold.value)); + if (aa[i].threshold.label != null) + { + an.addProperty(newProperty(THRESHOLD + "Name", + "string", "" + aa[i].threshold.label)); + } } - } - + + } + else { if (an.getModifiable() == null) // TODO: USE VAMSAS LIBRARY OBJECT - // LOCK METHODS) + // LOCK METHODS) { // verify annotation - update (perhaps) Cache.log @@ -618,6 +724,227 @@ public class VamsasAppDatastore } + /** + * remove docseqs from the given alignment marking provenance appropriately + * and removing any references to the sequences. + * + * @param alignment + * @param docseqs + */ + private void removeValignmentSequences(Alignment alignment, Vector docseqs) + { + // delete these from document. This really needs to be a generic document + // API function derived by CASTOR. + Enumeration en = docseqs.elements(); + while (en.hasMoreElements()) + { + alignment.removeAlignmentSequence((AlignmentSequence) en + .nextElement()); + } + Entry pe = addProvenance(alignment.getProvenance(), "Removed " + + docseqs.size() + " sequences"); + en = alignment.enumerateAlignmentAnnotation(); + Vector toremove = new Vector(); + while (en.hasMoreElements()) + { + uk.ac.vamsas.objects.core.AlignmentAnnotation alan = (uk.ac.vamsas.objects.core.AlignmentAnnotation) en + .nextElement(); + if (alan.getSeqrefsCount() > 0) + { + int p = 0; + Vector storem = new Vector(); + Enumeration sr = alan.enumerateSeqrefs(); + while (sr.hasMoreElements()) + { + Object alsr = sr.nextElement(); + if (docseqs.contains(alsr)) + { + storem.addElement(alsr); + } + } + // remove references to the deleted sequences + sr = storem.elements(); + while (sr.hasMoreElements()) + { + alan.removeSeqrefs(sr.nextElement()); + } + + if (alan.getSeqrefsCount() == 0) + { + // should then delete alan from dataset + toremove.addElement(alan); + } + } + } + // remove any annotation that used to be associated to a specific bunch of + // sequences + en = toremove.elements(); + while (en.hasMoreElements()) + { + alignment + .removeAlignmentAnnotation((uk.ac.vamsas.objects.core.AlignmentAnnotation) en + .nextElement()); + } + // TODO: search through alignment annotations to remove any references to + // this alignment sequence + } + + /** + * sync a jalview alignment seuqence into a vamsas alignment assumes all lock + * transformation/bindings have been sorted out before hand. creates/syncs the + * vamsas alignment sequence for jvalsq and adds it to the alignment if + * necessary. unbounddocseq is a duplicate of the vamsas alignment sequences + * and these are removed after being processed w.r.t a bound jvalsq + * + */ + private boolean syncToAlignmentSequence(SequenceI jvalsq, + Alignment alignment, Vector unbounddocseq) + { + boolean modal = false; + // todo: islocked method here + boolean up2doc = false; + AlignmentSequence alseq = (AlignmentSequence) getjv2vObj(jvalsq); + if (alseq == null) + { + alseq = new AlignmentSequence(); + up2doc = true; + } + else + { + if (unbounddocseq != null) + { + unbounddocseq.removeElement(alseq); + } + } + // boolean locked = (alignment.getModifiable()==null || + // alignment.getModifiable().length()>0); + // TODO: VAMSAS: translate lowercase symbols to annotation ? + if (up2doc || !alseq.getSequence().equals(jvalsq.getSequenceAsString())) + { + alseq.setSequence(jvalsq.getSequenceAsString()); + alseq.setStart(jvalsq.getStart()); + alseq.setEnd(jvalsq.getEnd()); + modal = true; + } + if (up2doc || !alseq.getName().equals(jvalsq.getName())) + { + modal = true; + alseq.setName(jvalsq.getName()); + } + if (jvalsq.getDescription() != null + && (alseq.getDescription() == null || !jvalsq.getDescription() + .equals(alseq.getDescription()))) + { + modal = true; + alseq.setDescription(jvalsq.getDescription()); + } + if (getjv2vObj(jvalsq.getDatasetSequence()) == null) + { + Cache.log + .warn("Serious Implementation error - Unbound dataset sequence in alignment: " + + jvalsq.getDatasetSequence()); + } + alseq.setRefid(getjv2vObj(jvalsq.getDatasetSequence())); + if (up2doc) + { + + alignment.addAlignmentSequence(alseq); + bindjvvobj(jvalsq, alseq); + } + return up2doc || modal; + } + + /** + * locally sync a jalview alignment seuqence from a vamsas alignment assumes + * all lock transformation/bindings have been sorted out before hand. + * creates/syncs the jvalsq from the alignment sequence + */ + private boolean syncFromAlignmentSequence(AlignmentSequence valseq, + char valGapchar, char gapChar, Vector dsseqs) + + { + boolean modal = false; + // todo: islocked method here + boolean upFromdoc = false; + jalview.datamodel.SequenceI alseq = (SequenceI) getvObj2jv(valseq); + if (alseq == null) + { + upFromdoc = true; + } + if (alseq != null) + { + + // boolean locked = (alignment.getModifiable()==null || + // alignment.getModifiable().length()>0); + // TODO: VAMSAS: translate lowercase symbols to annotation ? + if (upFromdoc + || !valseq.getSequence().equals(alseq.getSequenceAsString())) + { + // this might go *horribly* wrong + alseq.setSequence(new String(valseq.getSequence()).replace( + valGapchar, gapChar)); + alseq.setStart((int) valseq.getStart()); + alseq.setEnd((int) valseq.getEnd()); + modal = true; + } + if (!valseq.getName().equals(alseq.getName())) + { + modal = true; + alseq.setName(valseq.getName()); + } + if (alseq.getDescription() == null + || (valseq.getDescription() == null || alseq.getDescription() + .equals(valseq.getDescription()))) + { + alseq.setDescription(valseq.getDescription()); + modal = true; + } + if (modal && Cache.log.isDebugEnabled()) + { + Cache.log.debug("Updating apparently edited sequence " + + alseq.getName()); + } + } + else + { + alseq = new jalview.datamodel.Sequence(valseq.getName(), valseq + .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 + // AlignemntSequence + // reference + // isn't + // a + // simple + // SequenceI + } + else + { + Cache.log + .error("Invalid dataset sequence id (null) for alignment sequence " + + valseq.getVorbaId()); + } + bindjvvobj(alseq, valseq); + alseq.setVamsasId(valseq.getVorbaId().getId()); + dsseqs.add(alseq); + } + Vobject datsetseq = (Vobject) valseq.getRefid(); + if (datsetseq != null) + { + if (datsetseq != alseq.getDatasetSequence()) + { + modal = true; + } + alseq.setDatasetSequence((SequenceI) getvObj2jv(datsetseq)); // exceptions + } + return upFromdoc || modal; + } + private void initRangeAnnotationType(RangeAnnotation an, AlignmentAnnotation alan, int[] gapMap) { @@ -706,11 +1033,13 @@ public class VamsasAppDatastore // the Jalview // specific // bits. - if (alan.getThreshold()!=null && alan.getThreshold().displayed) + if (alan.getThreshold() != null && alan.getThreshold().displayed) { - an.addProperty(newProperty(THRESHOLD, "float", ""+alan.getThreshold().value)); - if (alan.getThreshold().label!=null) - an.addProperty(newProperty(THRESHOLD+"Name", "string", ""+alan.getThreshold().label)); + an.addProperty(newProperty(THRESHOLD, "float", "" + + alan.getThreshold().value)); + if (alan.getThreshold().label != null) + an.addProperty(newProperty(THRESHOLD + "Name", "string", "" + + alan.getThreshold().label)); } ((DataSet) sref.getV_parent()).addDataSetAnnotations(an); bindjvvobj(alan, an); @@ -719,7 +1048,7 @@ public class VamsasAppDatastore { // update reference sequence Annotation if (an.getModifiable() == null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK - // METHODS) + // METHODS) { // verify existing alignment sequence annotation is up to date System.out.println("update dataset sequence annotation."); @@ -773,7 +1102,7 @@ public class VamsasAppDatastore * something extracted from another program, etc) */ an.setType(JALVIEW_ANNOTATION_ROW); // TODO: better fix - // this rough guess ;) + // this rough guess ;) alsref.addAlignmentSequenceAnnotation(an); bindjvvobj(alan, an); // These properties are directly supported by the @@ -787,7 +1116,7 @@ public class VamsasAppDatastore { // update reference sequence Annotation if (an.getModifiable() == null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK - // METHODS) + // METHODS) { // verify existing alignment sequence annotation is up to date System.out.println("update alignment sequence annotation."); @@ -803,41 +1132,46 @@ public class VamsasAppDatastore /** * set vamsas annotation object type from jalview annotation + * * @param an * @param alan */ - private void setAnnotationType(RangeAnnotation an, AlignmentAnnotation alan) + private void setAnnotationType(RangeAnnotation an, + AlignmentAnnotation alan) { if (an instanceof AlignmentSequenceAnnotation) { if (alan.graph != AlignmentAnnotation.NO_GRAPH) { - ((AlignmentSequenceAnnotation)an).setGraph(true); - } else + ((AlignmentSequenceAnnotation) an).setGraph(true); + } + else { - ((AlignmentSequenceAnnotation)an).setGraph(false); + ((AlignmentSequenceAnnotation) an).setGraph(false); } } if (an instanceof uk.ac.vamsas.objects.core.AlignmentAnnotation) { if (alan.graph != AlignmentAnnotation.NO_GRAPH) { - ((uk.ac.vamsas.objects.core.AlignmentAnnotation)an).setGraph(true); - } else + ((uk.ac.vamsas.objects.core.AlignmentAnnotation) an).setGraph(true); + } + else { - ((uk.ac.vamsas.objects.core.AlignmentAnnotation)an).setGraph(false); + ((uk.ac.vamsas.objects.core.AlignmentAnnotation) an) + .setGraph(false); } } switch (alan.graph) { - case AlignmentAnnotation.BAR_GRAPH: - an.addProperty(newProperty(DISCRETE_ANNOTATION, "boolean","true")); - break; - case AlignmentAnnotation.LINE_GRAPH: - an.addProperty(newProperty(CONTINUOUS_ANNOTATION, "boolean","true")); - break; - default: - // don't add any kind of discrete or continous property info. + case AlignmentAnnotation.BAR_GRAPH: + an.addProperty(newProperty(DISCRETE_ANNOTATION, "boolean", "true")); + break; + case AlignmentAnnotation.LINE_GRAPH: + an.addProperty(newProperty(CONTINUOUS_ANNOTATION, "boolean", "true")); + break; + default: + // don't add any kind of discrete or continous property info. } } @@ -861,9 +1195,10 @@ public class VamsasAppDatastore * correctly create a RangeAnnotation from a jalview sequence feature * * @param dsa - * (typically DataSetAnnotations or AlignmentSequenceAnnotation) + * (typically DataSetAnnotations or + * AlignmentSequenceAnnotation) * @param feature - * (the feature to be mapped from) + * (the feature to be mapped from) * @return */ private RangeAnnotation getDSAnnotationFromJalview(RangeAnnotation dsa, @@ -909,7 +1244,7 @@ public class VamsasAppDatastore * * @param visSeg * @param ensureDirection - * when true - always ensure start is less than end. + * when true - always ensure start is less than end. * @return int[] { start, end, direction} where direction==1 for range running * from end to start. */ @@ -1037,6 +1372,7 @@ public class VamsasAppDatastore new jalview.io.vamsas.Dbref(this, dbref[db], vdseq, dsseq); } + dsseq.updatePDBIds(); } } @@ -1064,7 +1400,7 @@ public class VamsasAppDatastore { SequenceI dsSeq = (SequenceI) getvObj2jv((Vobject) dseta .getSeqRef(0)); // TODO: deal with group dataset - // annotations + // annotations if (dsSeq == null) { jalview.bin.Cache.log @@ -1107,7 +1443,8 @@ public class VamsasAppDatastore { uk.ac.vamsas.objects.core.Alignment alignment = dataset .getAlignment(al); - AlignViewport av = (AlignViewport) getvObj2jv(alignment); + AlignViewport av = findViewport(alignment); + jalview.datamodel.AlignmentI jal = null; if (av != null) { @@ -1115,9 +1452,10 @@ public class VamsasAppDatastore } iSize = alignment.getAlignmentSequenceCount(); boolean newal = (jal == null) ? true : false; + boolean refreshal = false; Vector newasAnnots = new Vector(); char gapChar = ' '; // default for new alignments read in from the - // document + // document if (jal != null) { dsseqs = jal.getSequences(); // for merge/update @@ -1131,51 +1469,15 @@ public class VamsasAppDatastore for (i = 0; i < iSize; i++) { AlignmentSequence valseq = alignment.getAlignmentSequence(i); - jalview.datamodel.SequenceI alseq = (SequenceI) getvObj2jv(valseq); - if (alseq != null) - { - // TODO: upperCase/LowerCase situation here ? do we allow it ? - // if (!alseq.getSequence().equals(valseq.getSequence())) { - // throw new Error("Broken! - mismatch of dataset sequence and - // jalview internal dataset sequence."); - if (Cache.log.isDebugEnabled()) - { - Cache.log.debug("Updating apparently edited sequence " - + alseq.getName()); - } - // this might go *horribly* wrong - alseq.setSequence(new String(valseq.getSequence()).replace( - valGapchar, gapChar)); - jremain--; - } - else + jalview.datamodel.Sequence alseq = (jalview.datamodel.Sequence) getvObj2jv(valseq); + if (syncFromAlignmentSequence(valseq, valGapchar, gapChar, + dsseqs) + && alseq != null) { - alseq = new jalview.datamodel.Sequence(valseq.getName(), - valseq.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 - // AlignemntSequence - // reference - // isn't - // a - // simple - // SequenceI - } - else - { - Cache.log - .error("Invalid dataset sequence id (null) for alignment sequence " - + valseq.getVorbaId()); - } - bindjvvobj(alseq, valseq); - alseq.setVamsasId(valseq.getVorbaId().getId()); - dsseqs.add(alseq); + // updated to sequence from the document + jremain--; + refreshal = true; } if (valseq.getAlignmentSequenceAnnotationCount() > 0) { @@ -1184,27 +1486,27 @@ public class VamsasAppDatastore for (int a = 0; a < vasannot.length; a++) { jalview.datamodel.AlignmentAnnotation asa = (jalview.datamodel.AlignmentAnnotation) getvObj2jv(vasannot[a]); // TODO: - // 1:many - // jalview - // alignment - // sequence - // annotations + // 1:many + // jalview + // alignment + // sequence + // annotations if (asa == null) { int se[] = getBounds(vasannot[a]); asa = getjAlignmentAnnotation(jal, vasannot[a]); asa.setSequenceRef(alseq); asa.createSequenceMapping(alseq, se[0], false); // TODO: - // verify - // that - // positions - // in - // alseqAnnotation - // correspond - // to - // ungapped - // residue - // positions. + // verify + // that + // positions + // in + // alseqAnnotation + // correspond + // to + // ungapped + // residue + // positions. alseq.addAlignmentAnnotation(asa); bindjvvobj(asa, vasannot[a]); newasAnnots.add(asa); @@ -1213,9 +1515,9 @@ public class VamsasAppDatastore { // update existing annotation - can do this in place if (vasannot[a].getModifiable() == null) // TODO: USE - // VAMSAS LIBRARY - // OBJECT LOCK - // METHODS) + // VAMSAS LIBRARY + // OBJECT LOCK + // METHODS) { Cache.log .info("UNIMPLEMENTED: not recovering user modifiable sequence alignment annotation"); @@ -1281,8 +1583,8 @@ public class VamsasAppDatastore Cache.log .debug("update from vamsas alignment annotation to existing jalview alignment annotation."); if (an[j].getModifiable() == null) // TODO: USE VAMSAS - // LIBRARY OBJECT LOCK - // METHODS) + // LIBRARY OBJECT LOCK + // METHODS) { // TODO: user defined annotation is totally mutable... - so // load it up or throw away if locally edited. @@ -1317,8 +1619,7 @@ public class VamsasAppDatastore { for (int p = 0, pe = alignment.getPropertyCount(); p < pe; p++) { - if (alignment.getProperty(p).getName().equals( - "title")) + if (alignment.getProperty(p).getName().equals("title")) { title = alignment.getProperty(p).getContent(); } @@ -1328,14 +1629,12 @@ public class VamsasAppDatastore // alignment using its provenance. if (Cache.log.isDebugEnabled()) { - title = title + "(" - + alignment.getVorbaId() + ")"; - + title = title + "(" + alignment.getVorbaId() + ")"; + } - jalview.gui.Desktop.addInternalFrame(alignFrame, title - , + jalview.gui.Desktop.addInternalFrame(alignFrame, title, AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); - bindjvvobj(av, alignment); + bindjvvobj(av.getSequenceSetId(), alignment); } else { @@ -1343,6 +1642,10 @@ public class VamsasAppDatastore // TODO: fix this so we retrieve the alignFrame handing av // *directly* alignFrame = getAlignFrameFor(av); + if (refreshal) + { + av.alignmentChanged(alignFrame.alignPanel); + } } // LOAD TREES // ///////////////////////////////////// @@ -1355,17 +1658,28 @@ public class VamsasAppDatastore this, alignFrame, alignment.getTree(t)); TreePanel tp = null; if (vstree.isValidTree()) - { - tp = alignFrame - .ShowNewickTree(vstree.getNewickTree(), vstree - .getTitle(), vstree.getInputData(), 600, - 500, t * 20 + 50, t * 20 + 50); + { + tp = alignFrame.ShowNewickTree(vstree.getNewickTree(), + vstree.getTitle(), vstree.getInputData(), 600, + 500, t * 20 + 50, t * 20 + 50); + } - if (tp!=null) + if (tp != null) + { bindjvvobj(tp, alignment.getTree(t)); + try + { + vstree.UpdateSequenceTreeMap(tp); + } catch (RuntimeException e) + { + Cache.log.warn("update of labels failed.", e); + } + } else { - Cache.log.warn("Cannot create tree for tree "+t+" in document ("+alignment.getTree(t).getVorbaId()); + Cache.log.warn("Cannot create tree for tree " + t + + " in document (" + + alignment.getTree(t).getVorbaId()); } } @@ -1390,6 +1704,45 @@ public class VamsasAppDatastore } } + public AlignViewport findViewport(Alignment alignment) + { + AlignViewport av = null; + AlignViewport[] avs = findViewportForSequenceSetId((String) getvObj2jv(alignment)); + if (avs != null) + { + av = avs[0]; + } + return av; + } + + private AlignViewport[] findViewportForSequenceSetId(String sequenceSetId) + { + Vector viewp = new Vector(); + if (Desktop.desktop != null) + { + javax.swing.JInternalFrame[] frames = Desktop.instance.getAllFrames(); + + for (int t = 0; t < frames.length; t++) + { + if (frames[t] instanceof AlignFrame) + { + if (((AlignFrame) frames[t]).getViewport().getSequenceSetId() + .equals(sequenceSetId)) + { + viewp.addElement(((AlignFrame) frames[t]).getViewport()); + } + } + } + if (viewp.size() > 0) + { + AlignViewport[] vp = new AlignViewport[viewp.size()]; + viewp.copyInto(vp); + return vp; + } + } + return null; + } + // bitfields - should be a template in j1.5 private static int HASSECSTR = 0; @@ -1431,7 +1784,7 @@ public class VamsasAppDatastore { new jalview.datamodel.Annotation[rangeMap.length], new jalview.datamodel.Annotation[rangeMap.length] }; boolean mergeable = true; // false if 'after positions cant be placed on - // same annotation row as positions. + // same annotation row as positions. if (annotation.getAnnotationElementCount() > 0) { @@ -1439,7 +1792,7 @@ public class VamsasAppDatastore for (int aa = 0; aa < ae.length; aa++) { int pos = (int) ae[aa].getPosition() - 1; // pos counts from 1 to - // (|seg.start-seg.end|+1) + // (|seg.start-seg.end|+1) if (pos >= 0 && pos < rangeMap.length) { int row = ae[aa].getAfter() ? 1 : 0; @@ -1464,9 +1817,9 @@ public class VamsasAppDatastore } } String dc = null; // ae[aa].getDisplayCharacter()==null ? "dc" : - // ae[aa].getDisplayCharacter(); + // ae[aa].getDisplayCharacter(); String ss = null; // ae[aa].getSecondaryStructure()==null ? "ss" : - // ae[aa].getSecondaryStructure(); + // ae[aa].getSecondaryStructure(); java.awt.Color colour = null; if (ae[aa].getGlyphCount() > 0) { @@ -1502,8 +1855,9 @@ public class VamsasAppDatastore } else { - Cache.log.debug("IMPLEMENTATION TODO: Ignoring unknown glyph type " - + glyphs[g].getDict()); + Cache.log + .debug("IMPLEMENTATION TODO: Ignoring unknown glyph type " + + glyphs[g].getDict()); } } } @@ -1548,7 +1902,7 @@ public class VamsasAppDatastore anot[0][i] = anot[1][i]; anot[0][i].description = anot[0][i].description + " (after)"; AeContent[HASDESCSTR] = true; // we have valid description string - // data + // data anot[1][i] = null; } } @@ -1576,8 +1930,9 @@ public class VamsasAppDatastore /** * @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. */ @@ -1600,46 +1955,48 @@ public class VamsasAppDatastore Object[] parsedRangeAnnotation = parseRangeAnnotation(annotation); String a_label = annotation.getLabel(); String a_descr = annotation.getDescription(); - GraphLine gl=null; - int type=0; - boolean interp=true; // cleared if annotation is DISCRETE + GraphLine gl = null; + int type = 0; + boolean interp = true; // cleared if annotation is DISCRETE // set type and other attributes from properties if (annotation.getPropertyCount() > 0) { // look for special jalview properties - uk.ac.vamsas.objects.core.Property[] props = annotation - .getProperty(); + uk.ac.vamsas.objects.core.Property[] props = annotation.getProperty(); for (int p = 0; p < props.length; p++) { if (props[p].getName().equalsIgnoreCase(DISCRETE_ANNOTATION)) { type = AlignmentAnnotation.BAR_GRAPH; - interp=false; - } else if - (props[p].getName().equalsIgnoreCase(CONTINUOUS_ANNOTATION)) { + interp = false; + } + else if (props[p].getName().equalsIgnoreCase(CONTINUOUS_ANNOTATION)) + { type = AlignmentAnnotation.LINE_GRAPH; - } else if - (props[p].getName().equalsIgnoreCase(THRESHOLD)) + } + else if (props[p].getName().equalsIgnoreCase(THRESHOLD)) { - Float val=null; - try { + Float val = null; + try + { val = new Float(props[p].getContent()); - }catch (Exception e) + } catch (Exception e) { Cache.log.warn("Failed to parse threshold property"); } - if (val!=null) - if (gl==null) - { - gl = new GraphLine(val.floatValue(), "", java.awt.Color.black); - } else - { - gl.value = val.floatValue(); - } + if (val != null) + if (gl == null) + { + gl = new GraphLine(val.floatValue(), "", java.awt.Color.black); + } + else + { + gl.value = val.floatValue(); + } } - else if (props[p].getName().equalsIgnoreCase(THRESHOLD+"Name")) + else if (props[p].getName().equalsIgnoreCase(THRESHOLD + "Name")) { - if (gl==null) + if (gl == null) gl = new GraphLine(0, "", java.awt.Color.black); gl.label = props[p].getContent(); } @@ -1684,9 +2041,12 @@ public class VamsasAppDatastore */ if (has[HASVALS]) { - if (type==0) + if (type == 0) { - type = jalview.datamodel.AlignmentAnnotation.BAR_GRAPH; // default type of value annotation + type = jalview.datamodel.AlignmentAnnotation.BAR_GRAPH; // default + // type of + // value + // annotation if (has[HASHPHOB]) { // no hints - so we ensure HPHOB display is like this. @@ -1746,17 +2106,19 @@ public class VamsasAppDatastore if (!has[HASDC]) { if (!interp) - { - if (arow[i].description!=null && arow[i].description.length()<3) + { + if (arow[i].description != null + && arow[i].description.length() < 3) { // copy over the description as the display char. arow[i].displayCharacter = new String(arow[i].description); } - } else - { - // mark the position as a point used for the interpolation. + } + else + { + // mark the position as a point used for the interpolation. arow[i].displayCharacter = arow[i].value + ""; - } + } } } } @@ -1765,10 +2127,12 @@ public class VamsasAppDatastore } else { - if (annotation.getAnnotationElementCount()==0) + if (annotation.getAnnotationElementCount() == 0) { // empty annotation array - // TODO: alignment 'features' compare rangeType spec to alignment width - if it is not complete, then mark regions on the annotation row. + // TODO: alignment 'features' compare rangeType spec to alignment + // width - if it is not complete, then mark regions on the annotation + // row. } jan = new jalview.datamodel.AlignmentAnnotation(a_label, a_descr, arow); @@ -1779,8 +2143,10 @@ public class VamsasAppDatastore Cache.log.warn("Ignoring " + annotation.getLinkCount() + "links added to AlignmentAnnotation."); } - if (annotation.getModifiable() == null) // TODO: USE VAMSAS LIBRARY OBJECT - // LOCK METHODS) + if (annotation.getModifiable() == null + || annotation.getModifiable().length() == 0) // TODO: USE VAMSAS + // LIBRARY OBJECT + // LOCK METHODS) { jan.editable = true; } @@ -1789,7 +2155,13 @@ public class VamsasAppDatastore if (annotation.getGroup() != null && annotation.getGroup().length() > 0) { - jan.graphGroup = Integer.parseInt(annotation.getGroup()); + jan.graphGroup = Integer.parseInt(annotation.getGroup()); // TODO: + // group + // similarly + // named + // annotation + // together + // ? } } catch (Exception e) { @@ -1936,12 +2308,12 @@ 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 + * 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 + * unit for local * @param default - * unit for mapped + * unit for mapped * @return MapList */ private jalview.util.MapList parsemapType(MapType maprange, int localu, @@ -2067,9 +2439,11 @@ public class VamsasAppDatastore return prov; } - void addProvenance(Provenance p, String action) + Entry addProvenance(Provenance p, String action) { - p.addEntry(dummyPEntry(action)); + Entry dentry = dummyPEntry(action); + p.addEntry(dentry); + return dentry; } public Entry getProvEntry() @@ -2132,7 +2506,7 @@ public class VamsasAppDatastore { Cache.log .warn("NO Vamsas Binding for local sequence! NOT CREATING MAPPING FOR " - + mfrom.getName() + + dmps[smp].getDisplayId(true) + " to " + mps[smp].getTo().getName()); }