From b9084958e22938eb21e285905dba1658db299286 Mon Sep 17 00:00:00 2001 From: selewis Date: Wed, 14 Sep 2016 22:44:43 -0700 Subject: [PATCH] make sure annotations from experiments are using non-obsolete terms sped up sorting of matrix term-column headings restored older macify --- pom.xml | 4 +- resources/org/paint/resources/VERSION | 2 +- .../paint/gui/matrix/AnnotMatrixModel.java | 27 ++- .../paint/gui/matrix/TermCountComparator.java | 31 ++- src/org/paint/gui/menu/TreeMenu.java | 2 +- src/org/paint/gui/tracking/EvidencePanel.java | 31 --- src/org/paint/gui/tree/TreePanel.java | 211 +++++++++--------- src/org/paint/main/PaintManager.java | 2 +- 8 files changed, 148 insertions(+), 162 deletions(-) diff --git a/pom.xml b/pom.xml index 75dd0d8..7410b73 100644 --- a/pom.xml +++ b/pom.xml @@ -147,9 +147,9 @@ 1.5.0 - org.simplericity.macify + macify macify - 1.6 + 1.1 org.bbop diff --git a/resources/org/paint/resources/VERSION b/resources/org/paint/resources/VERSION index d527e14..249d0f0 100755 --- a/resources/org/paint/resources/VERSION +++ b/resources/org/paint/resources/VERSION @@ -1 +1 @@ -v2.23 \ No newline at end of file +v2.24 \ No newline at end of file diff --git a/src/org/paint/gui/matrix/AnnotMatrixModel.java b/src/org/paint/gui/matrix/AnnotMatrixModel.java index 4f5f5c9..1535681 100644 --- a/src/org/paint/gui/matrix/AnnotMatrixModel.java +++ b/src/org/paint/gui/matrix/AnnotMatrixModel.java @@ -162,15 +162,36 @@ private void sortTerms(List nodes, List temp_list) { * Then sort by the number of genes annotated to each term * The more genes annotated the higher in the list the term will be */ - Collections.sort(cellular_list, new TermCountComparator(nodes)); - Collections.sort(temp_list, new TermCountComparator(nodes)); + SortByCount(nodes, cellular_list); + SortByCount(nodes, temp_list); + /* - * But then insert the related terms immediately after their child + * But then insert the related terms immediately afterwards */ boolean odd_column = true; odd_column = groupParentTerms(cellular_list, odd_column); groupParentTerms(temp_list, odd_column); } + + private void SortByCount(List nodes, List terms) { + Map> term2node = new HashMap<>(); + for (Bioentity node : nodes) { + for (String term : terms) { + GeneAnnotation assoc = AnnotationUtil.isAnnotatedToTerm(node.getAnnotations(), term); + if (assoc != null && AnnotationUtil.isExpAnnotation(assoc)) { + List annotated_nodes = term2node.get(term); + if (annotated_nodes == null) { + annotated_nodes = new ArrayList(); + term2node.put(term, annotated_nodes); + } + if (!annotated_nodes.contains(node)) { + annotated_nodes.add(node); + } + } + } + } + Collections.sort(terms, new TermCountComparator(term2node)); + } private boolean groupParentTerms(List orig_termlist, boolean odd_column) { while (orig_termlist.size() > 0) { diff --git a/src/org/paint/gui/matrix/TermCountComparator.java b/src/org/paint/gui/matrix/TermCountComparator.java index fa68e11..1b0c587 100644 --- a/src/org/paint/gui/matrix/TermCountComparator.java +++ b/src/org/paint/gui/matrix/TermCountComparator.java @@ -1,11 +1,11 @@ package org.paint.gui.matrix; import java.util.Comparator; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.bbop.phylo.annotate.AnnotationUtil; -import org.bbop.phylo.util.OWLutil; -import org.paint.displaymodel.DisplayBioentity; import owltools.gaf.Bioentity; import owltools.gaf.GeneAnnotation; @@ -17,24 +17,23 @@ public class TermCountComparator implements Comparator { private static final int GREATER_THAN = 1; private static final int EQUAL_TO = 0; - private List nodes; - - public TermCountComparator (List nodes2) { - this.nodes = nodes2; + private Map> term2nodes; + + public TermCountComparator (Map> term2nodes) { + this.term2nodes = term2nodes; } - + public int compare(String term_a, String term_b) { int count_a = 0; int count_b = 0; - - if (nodes != null) { - for (Bioentity node : nodes) { - GeneAnnotation assoc_a = AnnotationUtil.isAnnotatedToTerm(node.getAnnotations(), term_a); - GeneAnnotation assoc_b = AnnotationUtil.isAnnotatedToTerm(node.getAnnotations(), term_b); - count_a += assoc_a != null && AnnotationUtil.isExpAnnotation(assoc_a) ? 1 : 0; - count_b += assoc_b != null && AnnotationUtil.isExpAnnotation(assoc_b) ? 1 : 0; - } - } + + if (term2nodes.get(term_a) != null) { + count_a = term2nodes.get(term_a).size(); + } + if (term2nodes.get(term_b) != null) { + count_b = term2nodes.get(term_b).size(); + } + if (count_b > count_a) return GREATER_THAN; else if (count_b < count_a) diff --git a/src/org/paint/gui/menu/TreeMenu.java b/src/org/paint/gui/menu/TreeMenu.java index 133c447..bcdabb6 100644 --- a/src/org/paint/gui/menu/TreeMenu.java +++ b/src/org/paint/gui/menu/TreeMenu.java @@ -170,7 +170,7 @@ public void actionPerformed(ActionEvent e) { case TREE_COLLAPSE_NONEXP_NODES: PaintConfig.inst().collapse_no_exp = ((JCheckBoxMenuItem) e.getSource()).isSelected(); if (PaintConfig.inst().collapse_no_exp) { - tree.collapseNonExperimental(true); + tree.collapseNonExperimental(); } else { tree.expandAllNodes(); } diff --git a/src/org/paint/gui/tracking/EvidencePanel.java b/src/org/paint/gui/tracking/EvidencePanel.java index 7bfd87c..e714008 100644 --- a/src/org/paint/gui/tracking/EvidencePanel.java +++ b/src/org/paint/gui/tracking/EvidencePanel.java @@ -296,37 +296,6 @@ public void run() { } } - // private class CommentThread extends Thread { - // private JTextArea text_area; - // private String comment; - // - // public CommentThread (JTextArea text_area) { - // this.text_area = text_area; - // comment = getLoggedComment(); - // } - // - // public void run() { - // if (SwingUtilities.isEventDispatchThread()) { - // text_area.setText(comment); - // } else { - // try { - //// SwingUtilities.invokeAndWait(new Runnable() { - // while (true) { - //// public void run() { - // comment = text_area.getText(); - // Logger.updateNotes(comment); - // Thread.sleep(1000); - //// }; - // } - // } catch (InterruptedException ex) { - // log.error(ex.toString()); - //// } catch (InvocationTargetException ex) { - //// log.error(ex.toString()); - // } - // } - // } - // } - // @Override public void newFamilyData(FamilyChangeEvent e) { comment_set = false; diff --git a/src/org/paint/gui/tree/TreePanel.java b/src/org/paint/gui/tree/TreePanel.java index eb2aac9..c628d98 100644 --- a/src/org/paint/gui/tree/TreePanel.java +++ b/src/org/paint/gui/tree/TreePanel.java @@ -110,7 +110,7 @@ public class TreePanel extends JPanel private double tree_distance_scaling = -1; protected static Logger logger = Logger.getLogger(TreePanel.class.getName()); - + protected static final String TOOLTIP_FOREGROUND = "ToolTip.foreground"; public static final String POPUP_MENU_COLLAPSE = "Collapse node"; @@ -134,7 +134,7 @@ public class TreePanel extends JPanel private DisplayTree tree; -// private static Logger log = Logger.getLogger(TreePanel.class); + // private static Logger log = Logger.getLogger(TreePanel.class); /** * Constructor declaration @@ -162,7 +162,6 @@ public void setTreeModel(DisplayTree tree) { // set the dang rectangle now! boolean use_distances = PaintConfig.inst().use_distances; updateNodePositions(tree.getRoot(), this.getGraphics(), PaintManager.inst().getRowHeight(), use_distances); -// setNeedPositionUpdate(false); } public DisplayTree getTreeModel() { @@ -193,7 +192,7 @@ public List getAllNodes() { public void scaleTree(double scale){ if (this.getDistanceScaling() != scale) { this.setDistance(scale); - setNeedPositionUpdate(true); + setNeedPositionUpdate(); PaintConfig.inst().tree_distance_scaling = scale; } } @@ -201,14 +200,14 @@ public void scaleTree(double scale){ public void speciesOrder() { if (tree != null) { tree.speciesOrder(); - setNeedPositionUpdate(true); + setNeedPositionUpdate(); } } public void descendentCountLadder(boolean most_leaves_at_top) { if (tree != null) { tree.descendentCountLadder(most_leaves_at_top); - setNeedPositionUpdate(true); + setNeedPositionUpdate(); } } @@ -232,27 +231,27 @@ public void getLeafDescendants(Bioentity node, List leafList){ } public void rescaleTree() { - setNeedPositionUpdate(false); + setNeedPositionUpdate(); } public void expandAllNodes() { if (tree != null) { tree.expandAllNodes(); - setNeedPositionUpdate(true); + setNeedPositionUpdate(); } } - public void collapseNonExperimental(boolean notify) { + public void collapseNonExperimental() { if (tree != null) { tree.collapseNonExperimental(); - setNeedPositionUpdate(notify); + setNeedPositionUpdate(); } } public void resetRootToMain() { if (tree != null) { if (tree.resetRootToMain()) - setNeedPositionUpdate(true); + setNeedPositionUpdate(); } } @@ -280,7 +279,7 @@ public Bioentity getBottomLeafNode(Bioentity node) { public void handlePruning(DisplayBioentity node) { boolean shift = tree.handlePruning(node); if (shift) { - setNeedPositionUpdate(true); + setNeedPositionUpdate(); } } @@ -384,16 +383,14 @@ private void updateNodePositions(Bioentity current_root, Graphics g, int row_hei need_update = false; } - protected void setNeedPositionUpdate(boolean notify) { + protected void setNeedPositionUpdate() { // Method to set number of leaves in tree need_update = true; revalidate(); repaint(); - if (notify) { - NodeReorderEvent event = new NodeReorderEvent(this); - event.setNodes(getTerminusNodes()); - EventManager.inst().fireNodeReorderEvent(event); - } + NodeReorderEvent event = new NodeReorderEvent(this); + event.setNodes(getTerminusNodes()); + EventManager.inst().fireNodeReorderEvent(event); } /** @@ -427,12 +424,12 @@ private Rectangle calcTreeSize(Graphics g) { } private Rectangle getTreeSize(Graphics g) { -// if (tree != null) { -// if (need_update) { -// tree.nodesReordered(); -// updateNodePositions(getCurrentRoot(), g, PaintManager.inst().getRowHeight(), PaintConfig.inst().use_distances); -// } -// } + // if (tree != null) { + // if (need_update) { + // tree.nodesReordered(); + // updateNodePositions(getCurrentRoot(), g, PaintManager.inst().getRowHeight(), PaintConfig.inst().use_distances); + // } + // } return tree_rect; } @@ -770,7 +767,7 @@ private class InternalRerootActionListener implements ActionListener{ */ public void actionPerformed(ActionEvent e) { tree.nodeReroot(node); - setNeedPositionUpdate(true); + setNeedPositionUpdate(); } } @@ -800,7 +797,7 @@ private class CollapseExpandNodeActionListener implements ActionListener{ */ public void actionPerformed(ActionEvent e){ tree.handleCollapseExpand(node); - setNeedPositionUpdate(true); + setNeedPositionUpdate(); } } @@ -1086,89 +1083,89 @@ public boolean pointInNode(Point p) { * * @see */ - protected DisplayBioentity getClicked(Point p){ + protected DisplayBioentity getClicked(Point p){ DisplayBioentity current_root = (DisplayBioentity) getCurrentRoot(); return getClicked(current_root, p); - } - - public DisplayBioentity getClickedInNodeArea(Point p) { - DisplayBioentity current_root = (DisplayBioentity) getCurrentRoot(); - return getClickedInNodeArea(current_root, p); - } - - /** - * Method declaration - * - * - * @param dsn - * @param p - * - * @return - * - * @see - */ - private DisplayBioentity getClicked(DisplayBioentity dsn, Point p){ - if (null == dsn || dsn.getScreenRectangle() == null){ - return null; - } - if (dsn.getScreenRectangle().contains(p)){ - return dsn; - } - List children = dsn.getChildren(); - - if (null == children){ - return null; - } - if (dsn.isTerminus()){ - return null; - } - for (int i = 0; i < children.size(); i++){ - DisplayBioentity gnHit = null; - DisplayBioentity child = (DisplayBioentity) children.get(i); - gnHit = getClicked(child, p); - if (null != gnHit){ - return gnHit; - } - } - return null; - } - - public DisplayBioentity getClickedInNodeArea(DisplayBioentity dsn, Point p) { - if (null == dsn || dsn.getScreenRectangle() == null){ - return null; - } - if (dsn.getScreenRectangle().contains(p)){ - return dsn; - } - - List children = dsn.getChildren(); - - if (children != null && !dsn.isTerminus()){ - DisplayBioentity dsnHit = null; - for (int i = 0; i < children.size(); i++){ - DisplayBioentity child = (DisplayBioentity) children.get(i); - dsnHit = getClickedInNodeArea(child, p); - if (null != dsnHit){ - return dsnHit; - } - } - } - return null; - } - - /** - * Method declaration - * - * - * @param dsn - * - * @return - * - * @see - */ - protected String getToolTipInfo(DisplayBioentity node){ - return node.getNodeLabel(); - } + } + + public DisplayBioentity getClickedInNodeArea(Point p) { + DisplayBioentity current_root = (DisplayBioentity) getCurrentRoot(); + return getClickedInNodeArea(current_root, p); + } + + /** + * Method declaration + * + * + * @param dsn + * @param p + * + * @return + * + * @see + */ + private DisplayBioentity getClicked(DisplayBioentity dsn, Point p){ + if (null == dsn || dsn.getScreenRectangle() == null){ + return null; + } + if (dsn.getScreenRectangle().contains(p)){ + return dsn; + } + List children = dsn.getChildren(); + + if (null == children){ + return null; + } + if (dsn.isTerminus()){ + return null; + } + for (int i = 0; i < children.size(); i++){ + DisplayBioentity gnHit = null; + DisplayBioentity child = (DisplayBioentity) children.get(i); + gnHit = getClicked(child, p); + if (null != gnHit){ + return gnHit; + } + } + return null; + } + + public DisplayBioentity getClickedInNodeArea(DisplayBioentity dsn, Point p) { + if (null == dsn || dsn.getScreenRectangle() == null){ + return null; + } + if (dsn.getScreenRectangle().contains(p)){ + return dsn; + } + + List children = dsn.getChildren(); + + if (children != null && !dsn.isTerminus()){ + DisplayBioentity dsnHit = null; + for (int i = 0; i < children.size(); i++){ + DisplayBioentity child = (DisplayBioentity) children.get(i); + dsnHit = getClickedInNodeArea(child, p); + if (null != dsnHit){ + return dsnHit; + } + } + } + return null; + } + + /** + * Method declaration + * + * + * @param dsn + * + * @return + * + * @see + */ + protected String getToolTipInfo(DisplayBioentity node){ + return node.getNodeLabel(); + } public boolean ensureExpansion(List genes) { List nodes_to_make_visible = new ArrayList<>(); diff --git a/src/org/paint/main/PaintManager.java b/src/org/paint/main/PaintManager.java index ee37b99..de480f2 100644 --- a/src/org/paint/main/PaintManager.java +++ b/src/org/paint/main/PaintManager.java @@ -211,7 +211,7 @@ private void openFamily(String family_name, boolean existing) { fireProgressChange("Collapsing branches lacking experimental data", progress, ProgressEvent.Status.START); progress += progress_increment; - tree_pane.collapseNonExperimental(false); + tree_pane.collapseNonExperimental(); } fireProgressChange("Notifying displays of new family", progress, ProgressEvent.Status.START);