+ /**
+ * 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.
+ */
+ public boolean alignmentWillBeSkipped(AlignmentViewport av)
+ {
+ return (!av.getAlignment().isAligned());
+ }
+
+ private void addToSkipList(AlignmentViewport av)
+ {
+ if (skipList == null)
+ {
+ skipList = new Hashtable();
+ }
+ skipList.put(av.getSequenceSetId(), av);
+ }
+
+ /**
+ * 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)
+ {
+ Console.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, List<SequenceI> 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 && Console.isDebugEnabled())
+ {
+ Console.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 (valseq.getDescription() != null)
+ {
+ alseq.setDescription(valseq.getDescription());
+ }
+ else
+ {
+ // inherit description line from dataset.
+ if (alseq.getDatasetSequence().getDescription() != null)
+ {
+ alseq.setDescription(
+ alseq.getDatasetSequence().getDescription());
+ }
+ }
+ // if
+ // AlignemntSequence
+ // reference
+ // isn't
+ // a
+ // simple
+ // SequenceI
+ }
+ else
+ {
+ Console.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;