X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2Fvamsas%2FTree.java;h=5ea97fbe12f9bcd30763a300098f701d90046d26;hb=a9177efb4097815d9a8031aa22700c61a7d6260a;hp=1866336dd9eece0633c3d0e0c442be2bb51bb8e0;hpb=12e7f97678ce85b0238f987d5f4eaf18512a0b94;p=jalview.git
diff --git a/src/jalview/io/vamsas/Tree.java b/src/jalview/io/vamsas/Tree.java
index 1866336..5ea97fb 100644
--- a/src/jalview/io/vamsas/Tree.java
+++ b/src/jalview/io/vamsas/Tree.java
@@ -1,31 +1,28 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
- * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ 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.vamsas;
-import java.io.IOException;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.Vector;
-
-import jalview.analysis.NJTree;
-import jalview.analysis.SequenceIdMatcher;
-import jalview.bin.Cache;
+import jalview.analysis.TreeBuilder;
+import jalview.analysis.TreeModel;
+import jalview.bin.Console;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.AlignmentView;
import jalview.datamodel.BinaryNode;
@@ -33,11 +30,17 @@ import jalview.datamodel.SeqCigar;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceI;
import jalview.datamodel.SequenceNode;
-import jalview.gui.AlignFrame;
-import jalview.gui.AlignViewport;
import jalview.gui.TreePanel;
import jalview.io.NewickFile;
import jalview.io.VamsasAppDatastore;
+import jalview.viewmodel.AlignmentViewport;
+
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Vector;
+
import uk.ac.vamsas.client.Vobject;
import uk.ac.vamsas.objects.core.AlignmentSequence;
import uk.ac.vamsas.objects.core.Entry;
@@ -98,10 +101,13 @@ public class Tree extends DatastoreItem
tree = (uk.ac.vamsas.objects.core.Tree) vobj;
doSync();
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see jalview.io.vamsas.DatastoreItem#addFromDocument()
*/
+ @Override
public void addFromDocument()
{
tree = (uk.ac.vamsas.objects.core.Tree) vobj; // vtree;
@@ -122,23 +128,29 @@ public class Tree extends DatastoreItem
}
} catch (Exception e)
{
- Cache.log.warn("Problems parsing treefile '"
+ Console.warn("Problems parsing treefile '"
+ tree.getNewick(0).getContent() + "'", e);
}
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jalview.io.vamsas.DatastoreItem#conflict()
*/
+ @Override
public void conflict()
{
- Cache.log
- .info("Update (with conflict) from vamsas document to alignment associated tree not implemented yet.");
+ Console.info(
+ "Update (with conflict) from vamsas document to alignment associated tree not implemented yet.");
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jalview.io.vamsas.DatastoreItem#update()
*/
+ @Override
public void updateToDoc()
{
if (isModifiable(tree.getModifiable()))
@@ -150,38 +162,33 @@ public class Tree extends DatastoreItem
else
{
// handle conflict
- log.info("TODO: Add the locally modified tree in Jalview as a new tree in document, leaving locked tree unchanged.");
+ log.info(
+ "TODO: Add the locally modified tree in Jalview as a new tree in document, leaving locked tree unchanged.");
}
}
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see jalview.io.vamsas.DatastoreItem#updateFromDoc()
*/
+ @Override
public void updateFromDoc()
{
- // should probably just open a new tree panel in the same place as the old one
+ // should probably just open a new tree panel in the same place as the old
+ // one
// TODO: Tree.updateFromDoc
/*
- TreePanel tp = (TreePanel) jvobj; // getvObj2jv(tree);
-
- // make a new tree
- Object[] idata = recoverInputData(tree.getProvenance());
- try
- {
- if (idata != null && idata[0] != null)
- {
- inputData = (AlignmentView) idata[0];
- }
- ntree = getNtree();
- title = tree.getNewick(0).getTitle();
- if (title == null || title.length() == 0)
- {
- title = tree.getTitle(); // hack!!!!
- }
- } catch (Exception e)
- {
- Cache.log.warn("Problems parsing treefile '"
- + tree.getNewick(0).getContent() + "'", e);
- }*/
+ * TreePanel tp = (TreePanel) jvobj; // getvObj2jv(tree);
+ *
+ * // make a new tree Object[] idata =
+ * recoverInputData(tree.getProvenance()); try { if (idata != null &&
+ * idata[0] != null) { inputData = (AlignmentView) idata[0]; } ntree =
+ * getNtree(); title = tree.getNewick(0).getTitle(); if (title == null ||
+ * title.length() == 0) { title = tree.getTitle(); // hack!!!! } } catch
+ * (Exception e) { Cache.warn("Problems parsing treefile '" +
+ * tree.getNewick(0).getContent() + "'", e); }
+ */
log.debug("Update the local tree in jalview from the document.");
if (isModifiable(tree.getModifiable()))
@@ -207,22 +214,24 @@ public class Tree extends DatastoreItem
*/
private Provenance makeTreeProvenance(AlignmentI jal, TreePanel tp)
{
- Cache.log.debug("Making Tree provenance for " + tp.getTitle());
+ Console.debug("Making Tree provenance for " + tp.getTitle());
Provenance prov = new Provenance();
prov.addEntry(new Entry());
prov.getEntry(0).setAction("imported " + tp.getTitle());
prov.getEntry(0).setUser(provEntry.getUser());
prov.getEntry(0).setApp(provEntry.getApp());
prov.getEntry(0).setDate(provEntry.getDate());
- if (tp.getTree().hasOriginalSequenceData())
+
+ AlignmentView originalData = tp.getTree().getOriginalData();
+ if (originalData != null)
{
Input vInput = new Input();
// LATER: check to see if tree input data is contained in this alignment -
// or just correctly resolve the tree's seqData to the correct alignment
// in
// the document.
- Vector alsqrefs = getjv2vObjs(findAlignmentSequences(jal, tp
- .getTree().seqData.getSequences()));
+ Vector alsqrefs = getjv2vObjs(findAlignmentSequences(jal,
+ tp.getTree().getOriginalData().getSequences()));
Object[] alsqs = new Object[alsqrefs.size()];
alsqrefs.copyInto(alsqs);
vInput.setObjRef(alsqs);
@@ -234,12 +243,13 @@ public class Tree extends DatastoreItem
prov.getEntry(0).addParam(new Param());
prov.getEntry(0).getParam(0).setName("treeType");
prov.getEntry(0).getParam(0).setType("utf8");
- prov.getEntry(0).getParam(0).setContent("NJ"); // TODO: type of tree is a
- // general parameter
- int ranges[] = tp.getTree().seqData.getVisibleContigs();
+ prov.getEntry(0).getParam(0)
+ .setContent(TreeBuilder.NEIGHBOUR_JOINING);
+ // TODO: type of tree is a general parameter
+ int ranges[] = originalData.getVisibleContigs();
// VisibleContigs are with respect to alignment coordinates. Still need
// offsets
- int start = tp.getTree().seqData.getAlignmentOrigin();
+ int start = tp.getTree().getOriginalData().getAlignmentOrigin();
for (int r = 0; r < ranges.length; r += 2)
{
Seg visSeg = new Seg();
@@ -249,7 +259,7 @@ public class Tree extends DatastoreItem
vInput.addSeg(visSeg);
}
}
- Cache.log.debug("Finished Tree provenance for " + tp.getTitle());
+ Console.debug("Finished Tree provenance for " + tp.getTitle());
return prov;
}
@@ -261,31 +271,35 @@ public class Tree extends DatastoreItem
* @return vector of alignment sequences in order of SeqCigar array (but
* missing unfound seqcigars)
*/
- private Vector findAlignmentSequences(AlignmentI jal, SeqCigar[] sequences)
+ private Vector findAlignmentSequences(AlignmentI jal,
+ SeqCigar[] sequences)
{
SeqCigar[] tseqs = new SeqCigar[sequences.length];
System.arraycopy(sequences, 0, tseqs, 0, sequences.length);
- Vector alsq = new Vector();
- Enumeration as = jal.getSequences().elements();
- while (as.hasMoreElements())
+ Vector alsq = new Vector<>();
+ List jalsqs = jal.getSequences();
+ synchronized (jalsqs)
{
- SequenceI asq = (SequenceI) as.nextElement();
- for (int t = 0; t < sequences.length; t++)
+ for (SequenceI asq : jalsqs)
{
- if (tseqs[t] != null
- && (tseqs[t].getRefSeq() == asq || tseqs[t].getRefSeq() == asq
- .getDatasetSequence()))
- // && tseqs[t].getStart()>=asq.getStart() &&
- // tseqs[t].getEnd()<=asq.getEnd())
+ for (int t = 0; t < sequences.length; t++)
{
- tseqs[t] = null;
- alsq.add(asq);
+ if (tseqs[t] != null && (tseqs[t].getRefSeq() == asq
+ || tseqs[t].getRefSeq() == asq.getDatasetSequence()))
+ // && tseqs[t].getStart()>=asq.getStart() &&
+ // tseqs[t].getEnd()<=asq.getEnd())
+ {
+ tseqs[t] = null;
+ alsq.add(asq);
+ }
}
}
}
if (alsq.size() < sequences.length)
- Cache.log
- .warn("Not recovered all alignment sequences for given set of input sequence CIGARS");
+ {
+ Console.warn(
+ "Not recovered all alignment sequences for given set of input sequence CIGARS");
+ }
return alsq;
}
@@ -294,20 +308,22 @@ public class Tree extends DatastoreItem
* Update jalview newick representation with TreeNode map
*
* @param tp
- * the treepanel that this tree is bound to.
+ * the treepanel that this tree is bound to.
*/
public void UpdateSequenceTreeMap(TreePanel tp)
{
if (tp == null || tree == null)
+ {
return;
- Vector leaves = new Vector();
+ }
+
if (tp.getTree() == null)
{
- Cache.log.warn("Not updating SequenceTreeMap for "
- + tree.getVorbaId());
+ Console.warn("Not updating SequenceTreeMap for " + tree.getVorbaId());
return;
}
- tp.getTree().findLeaves(tp.getTree().getTopNode(), leaves);
+ Vector leaves = tp.getTree()
+ .findLeaves(tp.getTree().getTopNode());
Treenode[] tn = tree.getTreenode(); // todo: select nodes for this
// particular tree
int sz = tn.length;
@@ -342,15 +358,14 @@ public class Tree extends DatastoreItem
}
if (jvseq instanceof SequenceI)
{
- leaf.setElement(jvseq);
+ leaf.setElement((SequenceI) jvseq);
leaf.setPlaceholder(false);
}
else
{
leaf.setPlaceholder(true);
- leaf
- .setElement(new Sequence(leaf.getName(),
- "THISISAPLACEHLDER"));
+ leaf.setElement(
+ new Sequence(leaf.getName(), "THISISAPLACEHLDER"));
}
}
}
@@ -360,14 +375,14 @@ public class Tree extends DatastoreItem
/**
* construct treenode mappings for mapped sequences
*
- * @param ntree
+ * @param treeModel
* @param newick
* @return
*/
- public Treenode[] makeTreeNodes(NJTree ntree, Newick newick)
+ public Treenode[] makeTreeNodes(TreeModel treeModel, Newick newick)
{
- Vector leaves = new Vector();
- ntree.findLeaves(ntree.getTopNode(), leaves);
+ Vector leaves = treeModel
+ .findLeaves(treeModel.getTopNode());
Vector tnv = new Vector();
Enumeration l = leaves.elements();
Hashtable nodespecs = new Hashtable();
@@ -379,8 +394,7 @@ public class Tree extends DatastoreItem
{
if (!((jalview.datamodel.SequenceNode) tnode).isPlaceholder())
{
- Object assocseq = ((jalview.datamodel.SequenceNode) tnode)
- .element();
+ Object assocseq = ((BinaryNode) tnode).element();
if (assocseq instanceof SequenceI)
{
Vobject vobj = this.getjv2vObj(assocseq);
@@ -401,11 +415,12 @@ public class Tree extends DatastoreItem
}
else
{
- System.err.println("WARNING: Unassociated treeNode "
- + tnode.element().toString()
- + " "
- + ((tnode.getName() != null) ? " label "
- + tnode.getName() : ""));
+ jalview.bin.Console
+ .errPrintln("WARNING: Unassociated treeNode "
+ + tnode.element().toString() + " "
+ + ((tnode.getName() != null)
+ ? " label " + tnode.getName()
+ : ""));
}
}
}
@@ -417,8 +432,7 @@ public class Tree extends DatastoreItem
tnv.copyInto(tn);
return tn;
}
- return new Treenode[]
- {};
+ return new Treenode[] {};
}
private String makeNodeSpec(Hashtable nodespecs,
@@ -428,7 +442,7 @@ public class Tree extends DatastoreItem
Integer nindx = (Integer) nodespecs.get(nname);
if (nindx == null)
{
- nindx = new Integer(1);
+ nindx = Integer.valueOf(1);
}
nname = nindx.toString() + " " + nname;
return nname;
@@ -439,7 +453,7 @@ public class Tree extends DatastoreItem
*
* @param nodespec
* @param leaves
- * as returned from NJTree.findLeaves( .., ..) ..
+ * as returned from NJTree.findLeaves( .., ..) ..
* @return
*/
private jalview.datamodel.BinaryNode findNodeSpec(String nodespec,
@@ -450,10 +464,10 @@ public class Tree extends DatastoreItem
String oval = nodespec.substring(0, nodespec.indexOf(' '));
try
{
- occurence = new Integer(oval).intValue();
+ occurence = Integer.valueOf(oval).intValue();
} catch (Exception e)
{
- System.err.println("Invalid nodespec '" + nodespec + "'");
+ jalview.bin.Console.errPrintln("Invalid nodespec '" + nodespec + "'");
return null;
}
jalview.datamodel.BinaryNode bn = null;
@@ -469,7 +483,9 @@ public class Tree extends DatastoreItem
--occurence;
}
else
+ {
bn = null;
+ }
}
return bn;
}
@@ -479,13 +495,14 @@ public class Tree extends DatastoreItem
* add jalview object to vamsas document
*
*/
+ @Override
public void addToDocument()
{
tree = new uk.ac.vamsas.objects.core.Tree();
bindjvvobj(tp, tree);
tree.setTitle(tp.getTitle());
Newick newick = new Newick();
- newick.setContent(tp.getTree().toString());
+ newick.setContent(tp.getTree().print());
newick.setTitle(tp.getTitle());
tree.addNewick(newick);
tree.setProvenance(makeTreeProvenance(jal, tp));
@@ -505,7 +522,7 @@ public class Tree extends DatastoreItem
*/
public Object[] recoverInputData(Provenance tp)
{
- AlignViewport javport = null;
+ AlignmentViewport javport = null;
jalview.datamodel.AlignmentI jal = null;
jalview.datamodel.CigarArray view = null;
for (int pe = 0; pe < tp.getEntryCount(); pe++)
@@ -514,17 +531,16 @@ public class Tree extends DatastoreItem
{
if (tp.getEntry(pe).getInputCount() > 1)
{
- Cache.log
- .warn("Ignoring additional input spec in provenance entry "
- + tp.getEntry(pe).toString());
+ Console.warn("Ignoring additional input spec in provenance entry "
+ + tp.getEntry(pe).toString());
}
// LATER: deal sensibly with multiple inputs
Input vInput = tp.getEntry(pe).getInput(0);
// is this the whole alignment or a specific set of sequences ?
if (vInput.getObjRefCount() == 0)
{
- if (tree.getV_parent() != null
- && tree.getV_parent() instanceof uk.ac.vamsas.objects.core.Alignment)
+ if (tree.getV_parent() != null && tree
+ .getV_parent() instanceof uk.ac.vamsas.objects.core.Alignment)
{
javport = getViewport(tree.getV_parent());
jal = javport.getAlignment();
@@ -534,26 +550,27 @@ public class Tree extends DatastoreItem
else
{
// Explicit reference - to alignment, sequences or what.
- if (vInput.getObjRefCount() == 1
- && vInput.getObjRef(0) instanceof uk.ac.vamsas.objects.core.Alignment)
+ if (vInput.getObjRefCount() == 1 && vInput.getObjRef(
+ 0) instanceof uk.ac.vamsas.objects.core.Alignment)
{
// recover an AlignmentView for the input data
javport = getViewport((Vobject) vInput.getObjRef(0));
jal = javport.getAlignment();
view = javport.getAlignment().getCompactAlignment();
}
- else if (vInput.getObjRef(0) instanceof uk.ac.vamsas.objects.core.AlignmentSequence)
+ else if (vInput.getObjRef(
+ 0) instanceof uk.ac.vamsas.objects.core.AlignmentSequence)
{
// recover an AlignmentView for the input data
- javport = getViewport(((Vobject) vInput.getObjRef(0))
- .getV_parent());
+ javport = getViewport(
+ ((Vobject) vInput.getObjRef(0)).getV_parent());
jal = javport.getAlignment();
jalview.datamodel.SequenceI[] seqs = new jalview.datamodel.SequenceI[vInput
.getObjRefCount()];
for (int i = 0, iSize = vInput.getObjRefCount(); i < iSize; i++)
{
- SequenceI seq = (SequenceI) getvObj2jv((Vobject) vInput
- .getObjRef(i));
+ SequenceI seq = (SequenceI) getvObj2jv(
+ (Vobject) vInput.getObjRef(i));
seqs[i] = seq;
}
view = new jalview.datamodel.Alignment(seqs)
@@ -570,7 +587,7 @@ public class Tree extends DatastoreItem
// bidirection alignments yet.
if (to < se[1])
{
- Cache.log.warn("Ignoring invalid segment in InputData spec.");
+ Console.warn("Ignoring invalid segment in InputData spec.");
}
else
{
@@ -590,16 +607,15 @@ public class Tree extends DatastoreItem
// off by
// one for to
}
- return new Object[]
- { new AlignmentView(view), jal };
+ return new Object[] { new AlignmentView(view), jal };
}
}
- Cache.log
- .debug("Returning null for input data recovery from provenance.");
+ Console.debug(
+ "Returning null for input data recovery from provenance.");
return null;
}
- private AlignViewport getViewport(Vobject v_parent)
+ private AlignmentViewport getViewport(Vobject v_parent)
{
if (v_parent instanceof uk.ac.vamsas.objects.core.Alignment)
{
@@ -640,7 +656,7 @@ public class Tree extends DatastoreItem
return true;
} catch (Exception e)
{
- Cache.log.debug("Failed to parse newick tree string", e);
+ Console.debug("Failed to parse newick tree string", e);
}
return false;
}