📄 treejuxtaposer.java
字号:
ATD.setKey(treeDrawers.size()); ATD.setLineThickness(linethickness); treeDrawers.add(ATD); ATD.setExpandLeaves(1, false);// ATD.setDimColors(true);// ATD.drawDirection = getLeftRight(); return ATD; } /** * Delete a tree from "trees", clean up all the data structures * constructed for tree comparisons. * * @author * @see AccordionDrawer.AccordionDrawer.close * @see AccordionDrawer.AccordionTreeDrawer.close * @see AccordionDrawer.GridCell.close * @see AccordionDrawer.Tree.close * @see AccordionDrawer.TreeEdge.close * @see AccordionDrawer.TreeNode.close * @see Parse.Newick.close * @see Tree2Tree.close * @see TreePairs.removeTree */ public void deleteTrees(int[] treeNums) { System.out.println("VM memory before operation: "+Runtime.getRuntime().freeMemory()) ; System.out.println("Total memory before operation: "+Runtime.getRuntime().totalMemory()) ; for (int i = treeNums.length-1; i >= 0; i--) { Tree currTree = (Tree)trees.get(treeNums[i]); AccordionTreeDrawer atd = (AccordionTreeDrawer)treeDrawers.get(treeNums[i]); if (atd.tree != currTree) { System.out.println("Error: mismatched tree/drawer in delete: " + currTree + " != " + atd.tree); continue; } Component c = atd.getCanvas(); TPs.removeTree(currTree); currTree.close(); trees.remove(currTree); atd.shutdown(); atd.cvsDispose(); treeDrawers.remove(atd); drawPanel.remove(c); treeCount--; } drawPanel.validate(); } public void postDeleteTrees() { addLeaves();// clearGroup(diffGroup); for (int i=0; i<groups.size(); i++) clearGroup(i); for (int i = 0; i < treeDrawers.size(); i++) { AccordionTreeDrawerFinal atdA = (AccordionTreeDrawerFinal)treeDrawers.get(i); for (int j = i+1; j < treeDrawers.size(); j++) { AccordionTreeDrawerFinal atdB = (AccordionTreeDrawerFinal)treeDrawers.get(j); doStructuralDiff(atdA, atdB, diffGroup); doStructuralDiff(atdB, atdA, diffGroup); } } System.gc(); System.out.println("VM memory after operation: "+Runtime.getRuntime().freeMemory()) ; System.out.println("Total memory after operation: "+Runtime.getRuntime().totalMemory()) ; changedMarks(); updateTitle(); requestRedrawAll(); } /** * Fetch a tree by its name. This is done by linear search as we * do not expect to have many trees in memory. * * @author Li Zhang */ public Tree getTreeByName(String name) { for(int i=0; i<trees.size(); i++) { Tree t = (Tree)trees.get(i); if(t.getName().equals(name)) return t; } return null; } protected void addAction(){ ui.addAction(); }// private void quitAction() protected void quitAction() { // add other actions if needed when the quit menu option is selected //System.exit(0); ui.quitAction(); } public void changedMarks() { Iterator tdIter = treeDrawers.iterator(); while (tdIter.hasNext()) { AccordionTreeDrawer atd = (AccordionTreeDrawer)tdIter.next(); atd.changedMarks(); //System.out.println("changedmarks, cache: "+atd.cacherange); } } public void requestRedrawAll() { Iterator tdIter = treeDrawers.iterator(); while (tdIter.hasNext()) { AccordionTreeDrawer atd = (AccordionTreeDrawer)tdIter.next(); atd.requestRedraw(); } } // resets the leaves and recreates the node hash set and search array public void addLeaves() { // hash set has constant time verification that a similarly named node has already been added // a tree set is also capable of doing this job, but requires rebalancing HashSet hn; if (trees.size() > 0) hn = new HashSet(((Tree)trees.get(0)).nodes.size() * 2); else hn = new HashSet(); int i; int floatNum = 0; for(i=0; i<trees.size(); i++) { Tree t = (Tree)trees.get(i); for(int j=0; j<t.nodes.size(); j++) { String n = ((TreeNode)t.nodes.get(j)).getName(); if(n.length()>0) hn.add(n); } } i=0; String s[] = new String[hn.size()]; Iterator it = hn.iterator(); while (it.hasNext()) { s[i] = (String) it.next(); i++; } Arrays.sort(s); // one sort instead of making s a treeset which would sort with every add searchFrame.initializeList(new ArrayList(Arrays.asList(s))); } public int addGroup(boolean thisTreeOnly) { int groupCount = groups.size(); RangeList g = new RangeList(groupCount); g.setEnabled(true); g.setThisTreeOnly(thisTreeOnly); System.out.println("adding group " + groupCount); groups.add(g); groupsByIndex.add(g); // permanent ordering return groupCount; } public void setGroupPriority(int group) {// System.out.println("priority change, group " + group + " " + foundGroup); Object g = groupsByIndex.get(group); if (group <= markGroup.length) { groups.remove(g); groups.add(1,g); // put it first of changeable ones // update keys/alpha for marked colors Iterator iter = groups.listIterator(1); int currKey = 0; while (currKey < markGroup.length) { RangeList currGroup = (RangeList)iter.next();// System.out.println("setting group " + currGroup.getColor().getAlpha() + " " + currGroup.hashCode() + " to key " + currKey); currGroup.setKey(currKey++); } } } public void clearDrawers() { Iterator atdIter = treeDrawers.iterator(); if( treeDrawers.size() > 1) while( atdIter.hasNext()) { AccordionTreeDrawerFinal a = (AccordionTreeDrawerFinal) atdIter.next(); if( a.baseBox != null && a == a.getBaseBox().getDrawer()) { if( a.getFlashBox() != null ) a.getFlashBox().undraw(); a.baseBox = null; a.setFlashBox(null); a.requestRedraw(); // too much drawing a.actionmodeReset(); } } } // deliberately don't have removeGroup method. if you don't want // it anymore, disable it. why? we want the index in the groups // vector to match the key in the rangelist. maybe there's a less // hardline way to do this?... // what sort of error checking should we do here if group is out // of bounds? be silent, return null where appropriate? print out // error message? throw an informative exception? ... public void setGroupColor(int group, Color c) { ((RangeList)groupsByIndex.get(group)).setColor(c); } public void setGroupEnable(int group, boolean on) { ((RangeList)groupsByIndex.get(group)).setEnabled(on); } private void ascendTreeMark(AccordionTreeDrawer atd, AccordionTreeDrawer currTree, TreeNode directlyMarked, TreeNode n, RangeList addToGroup) { // ascend currTree (from n, the bcn of directlymarked, to the root) until no more marking needs to be done TreeNode currIndirectNode = n.parent;// System.out.print(0); if (currIndirectNode == null) return;// System.out.print(1); TreeNode currDirectNode = TPs.getBestCorrNode(currTree.tree, currIndirectNode, atd.tree, edgeweightLevelUsed); if (currDirectNode == null) {return;}// System.out.print(2);// System.out.println("addedAlready: " + currChild.key + " " + currTree.getKey()); boolean addedAlready = addToGroup.isThisRangeInList(currIndirectNode.key, currIndirectNode.key, currTree);// System.out.println("fitsIntoDirect: " + currDirectNode.key + " " + atd.getKey()); boolean fitsIntoDirect = addToGroup.isThisRangeInList(currDirectNode.key, currDirectNode.key, atd);// System.out.println("added: " + addedAlready + " fits: " + fitsIntoDirect); while (!addedAlready && fitsIntoDirect)// while (!addToGroup.isThisRangeInList(currIndirectNode.key, currIndirectNode.key, currTree) &&// currDirectNode == directlyMarked) {// System.out.print('.'); //System.out.println("ascend mark for " + currIndirectNode); addToGroup.addRange(currIndirectNode.key, currIndirectNode.key, currTree); currIndirectNode = n.parent; if (currIndirectNode == null) break; currDirectNode = TPs.getBestCorrNode(atd.tree, currIndirectNode, currTree.tree, edgeweightLevelUsed); if (currDirectNode == null) break; addedAlready = addToGroup.isThisRangeInList(currIndirectNode.key, currIndirectNode.key, currTree); fitsIntoDirect = addToGroup.isThisRangeInList(currDirectNode.key, currDirectNode.key, atd); }// System.out.println(3); } private void descendTreeMark(AccordionTreeDrawer atd, AccordionTreeDrawer currTree, TreeNode directlyMarked, TreeNode n, RangeList addToGroup) { // descend currTree (from n to leaves recursively), until no more marking is needed for (int i = 0; i < n.numberChildren(); i++) { TreeNode currChild = n.getChild(i);// System.out.println("child " + i + " checking for descent: " + currChild); TreeNode currDirectNode = TPs.getBestCorrNode(currTree.tree, currChild, atd.tree, edgeweightLevelUsed); if (currDirectNode == null) {continue;}// System.out.println("addedAlready: " + currChild.key + " " + currTree.getKey()); boolean addedAlready = addToGroup.isThisRangeInList(currChild.key, currChild.key, currTree);// System.out.println("fitsIntoDirect: " + currDirectNode.key + " " + atd.getKey()); boolean fitsIntoDirect = addToGroup.isThisRangeInList(currDirectNode.key, currDirectNode.key, atd);// System.out.println("added: " + addedAlready + " fits: " + fitsIntoDirect); if (!addedAlready && fitsIntoDirect) {// System.out.println("adding on descent: " + currChild); addToGroup.addRange(currChild.key, currChild.key, currTree); descendTreeMark(atd, currTree, directlyMarked, currChild, addToGroup); } }// System.out.println("d" + n.numberChildren() + " " + n.key + " RangeList: " + addToGroup); } // add nodes indirectly marked in all trees public void addNodesToGroup(int min, int max, int group, AccordionTreeDrawer atd) { RangeList addToGroup = (RangeList)groupsByIndex.get(group); addToGroup.addRange(min, max, atd); //System.out.println("range now has " + ((RangeList)groupsByIndex.get(group)).ranges.size() + " elements"); //System.out.println("added min " + min + " max " + max + " group " + group + " tree " + atd.getKey()); // must add the nodes from all other trees as well Iterator iter = treeDrawers.iterator();// System.out.println("RangeList: " + addToGroup); while (iter.hasNext()) { AccordionTreeDrawer currTree = (AccordionTreeDrawer)iter.next(); if (currTree != atd) // ignore the directly marked tree { for (int i = min; i <= max; i++) // over all directly marked nodes {// System.out.println(i + "RangeList: " + addToGroup); TreeNode directlyMarked = atd.getNodeByKey(i); TreeNode n = TPs.getBestCorrNode(atd.tree, directlyMarked, currTree.tree, edgeweightLevelUsed); if (n != null) { // the key represents the current subtree selected; all children of the bcn of this subtree are added to the range // the subtree selected also needs to be walked to make sure all potential forest created with bcn's is handled if (!addToGroup.isThisRangeInList(n.key, n.key, currTree)) {// System.out.println("adding, checking on ascend/descend: " + n); addToGroup.addRange(n.key, n.key, currTree); // after getting the corresponding node, search up the tree until nothing is needed to be marked ascendTreeMark(atd, currTree, directlyMarked, n, addToGroup); // also descend the tree until all nodes are marked that need to be descendTreeMark(atd, currTree, directlyMarked, n, addToGroup); if(!stateFrame.LCAMark.isSelected()) addToGroup.addRange(n.key, n.key, currTree); else addToGroup.addRange(n.key, n.getMax(), currTree); } } } } } } public void removeNodesFromGroup(int min, int max, int group, AccordionTreeDrawer atd) { ((RangeList)groupsByIndex.get(group)).removeRange(min, max, atd); } public Color getGroupColor(int group) { return ((RangeList)groupsByIndex.get(group)).getColor(); } public void clearGroup(int group) { RangeList groupList = (RangeList)groupsByIndex.get(group); groupList.clear();// groupList.setColorTree(null); } public void unmarkGroup(int group) { // lcaNode.removeAll(lcaNode); RangeList groupList = (RangeList)groupsByIndex.get(group); RangeInTree rit; if(groupList.getNumRanges() != 0) { rit = groupList.getFirst(); for (int i=0; i<lcaNode.size(); i++) { if(((TreeNode)lcaNode.get(i)).getKey() == rit.getMin() ) {// System.out.println("lca node key: " + rit.getMin()); lcaNode.remove(i); } } } if(stateFrame.LCAMark.isSelected()) this.doLCAGeom(lcaGroup, (AccordionTreeDrawer)treeDrawers.get(0)); changedMarks(); clearGroup(group); } RangeList getGroup(int group) { return ((RangeList)groupsByIndex.get(group)); } void seedGroups(AccordionTreeDrawerFinal atd) { Iterator GroupIter = groups.iterator(); while (GroupIter.hasNext()) { RangeList group = (RangeList)((RangeList)GroupIter.next()).onlyThisAD(atd); if (true == group.getEnabled()) { Iterator RangeIter = group.getRanges().iterator(); int count=0; while (RangeIter.hasNext()) { // seed all ranges for now, add count restriction back later if necessary && count < 5) { RangeInTree r = (RangeInTree) RangeIter.next(); int min = r.getMin(), max = r.getMax(); TreeNode rootNode; do { rootNode = atd.getNodeByKey(min); atd.addToDrawQueue(rootNode); min = rootNode.rightmostLeaf.key+1; } while (min <= max); count++; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -