import org.forester.io.writers.PhylogenyWriter;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.PhylogenyMethods;
+import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
import org.forester.phylogeny.PhylogenyNode;
import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
import org.forester.phylogeny.factories.PhylogenyFactory;
}
if ( order_subtrees ) {
for( final Phylogeny phy : phys ) {
- phy.orderAppearance( true );
+ PhylogenyMethods.orderAppearance( phy.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.TAXONOMY );
}
}
try {
import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.PhylogenyMethods;
+import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
import org.forester.phylogeny.PhylogenyNode;
import org.forester.phylogeny.data.Sequence;
import org.forester.phylogeny.data.SequenceRelation;
showWhole();
}
else if ( e.getSource() == _order ) {
- tp.getPhylogeny().orderAppearance( _order_of_appearance );
+ DESCENDANT_SORT_PRIORITY pri = DESCENDANT_SORT_PRIORITY.TAXONOMY;
+ if ( ( !isShowTaxonomyScientificNames() && !isShowTaxonomyCode() && !isShowTaxonomyCommonNames() ) ) {
+ if ( ( isShowSequenceAcc() || isShowGeneNames() || isShowGeneSymbols() ) ) {
+ pri = DESCENDANT_SORT_PRIORITY.SEQUENCE;
+ }
+ else if ( isShowNodeNames() ) {
+ pri = DESCENDANT_SORT_PRIORITY.NODE_NAME;
+ }
+ }
+ PhylogenyMethods.orderAppearance( tp.getPhylogeny().getRoot(), _order_of_appearance, true, pri );
_order_of_appearance = !_order_of_appearance;
displayedPhylogenyMightHaveChanged( false );
}
_node_popup_menu_items[ i ].setEnabled( isCanReroot() );
}
else if ( title.equals( Configuration.clickto_options[ Configuration.collapse_uncollapse ][ 0 ] ) ) {
- _node_popup_menu_items[ i ].setEnabled( isCanCollapse() );
+ _node_popup_menu_items[ i ].setEnabled( ( isCanCollapse() && !node.isExternal() ) );
}
else if ( title.equals( Configuration.clickto_options[ Configuration.color_subtree ][ 0 ] ) ) {
_node_popup_menu_items[ i ].setEnabled( isCanColorSubtree() );
else if ( title.equals( Configuration.clickto_options[ Configuration.subtree ][ 0 ] ) ) {
_node_popup_menu_items[ i ].setEnabled( isCanSubtree( node ) );
}
+ else if ( title.equals( Configuration.clickto_options[ Configuration.swap ][ 0 ] ) ) {
+ _node_popup_menu_items[ i ].setEnabled( node.getNumberOfDescendants() == 2 );
+ }
+ else if ( title.equals( Configuration.clickto_options[ Configuration.sort_descendents ][ 0 ] ) ) {
+ _node_popup_menu_items[ i ].setEnabled( node.getNumberOfDescendants() > 1 );
+ }
_node_popup_menu_items[ i ].addActionListener( this );
_node_popup_menu.add( _node_popup_menu_items[ i ] );
}
}
final void swap( final PhylogenyNode node ) {
+ if ( node.isExternal() || ( node.getNumberOfDescendants() < 2 ) ) {
+ return;
+ }
+ if ( node.getNumberOfDescendants() > 2 ) {
+ JOptionPane.showMessageDialog( this,
+ "Cannot swap descendants of nodes with more than 2 descendants",
+ "Cannot swap descendants",
+ JOptionPane.ERROR_MESSAGE );
+ return;
+ }
if ( !node.isExternal() ) {
- _phylogeny.swapChildren( node );
+ node.swapChildren();
setNodeInPreorderToNull();
}
repaint();
final boolean limit_to_five,
final PhylogenyMethods.TAXONOMY_EXTRACTION taxonomy_extraction ) {
if ( ( name.indexOf( "_" ) > 0 )
- && ( name.length() < 25 )
- && ( name.lastIndexOf( "_" ) == name.indexOf( "_" ) )
+ && ( name.length() < 31 )
+ // && ( name.lastIndexOf( "_" ) == name.indexOf( "_" ) )
&& ( name.indexOf( "|" ) < 0 )
&& ( name.indexOf( "." ) < 0 )
&& ( ( taxonomy_extraction != PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ) || ( name
final String[] s = name.split( "[_/]" );
if ( s.length > 1 ) {
String str = s[ 1 ];
- if ( limit_to_five ) {
- if ( str.length() > 5 ) {
- str = str.substring( 0, 5 );
- }
- else if ( ( str.length() < 5 ) && ( str.startsWith( "RAT" ) || str.startsWith( "PIG" ) ) ) {
+ if ( !limit_to_five || ( str.length() < 6 ) ) {
+ if ( ( str.length() < 5 ) && ( str.startsWith( "RAT" ) || str.startsWith( "PIG" ) ) ) {
str = str.substring( 0, 3 );
}
+ final Matcher uc_letters_and_numbers = NHXParser.UC_LETTERS_NUMBERS_PATTERN.matcher( str );
+ if ( !uc_letters_and_numbers.matches() ) {
+ return null;
+ }
+ final Matcher numbers_only = NHXParser.NUMBERS_ONLY_PATTERN.matcher( str );
+ if ( numbers_only.matches() ) {
+ return null;
+ }
+ return str;
}
- final Matcher letters_and_numbers = NHXParser.UC_LETTERS_NUMBERS_PATTERN.matcher( str );
- if ( !letters_and_numbers.matches() ) {
- return null;
- }
- final Matcher numbers_only = NHXParser.NUMBERS_ONLY_PATTERN.matcher( str );
- if ( numbers_only.matches() ) {
- return null;
- }
- return str;
}
}
return null;
PhylogenyNode.setNodeCount( max + 1 );
}
- /**
- * Arranges the order of childern for each node of this Phylogeny in such a
- * way that either the branch with more children is on top (right) or on
- * bottom (left), dependent on the value of boolean order.
- *
- * @param order
- * decides in which direction to order
- */
- public void orderAppearance( final boolean order ) throws RuntimeException {
- if ( !isTree() ) {
- throw new FailedConditionCheckException( "Attempt to order appearance on phylogeny which is not tree-like." );
- }
- if ( isEmpty() ) {
- return;
- }
- orderAppearanceHelper( getRoot(), order );
- }
-
- // Helper method for "orderAppearance(boolean)".
- // Traverses this Phylogeny recusively.
- private void orderAppearanceHelper( final PhylogenyNode n, final boolean order ) {
- if ( n.isExternal() ) {
- return;
- }
- else {
- PhylogenyNode temp = null;
- // FIXME
- if ( ( n.getNumberOfDescendants() == 2 )
- && ( n.getChildNode1().getNumberOfExternalNodes() != n.getChildNode2().getNumberOfExternalNodes() )
- && ( ( n.getChildNode1().getNumberOfExternalNodes() < n.getChildNode2().getNumberOfExternalNodes() ) == order ) ) {
- temp = n.getChildNode1();
- n.setChild1( n.getChildNode2() );
- n.setChild2( temp );
- }
- for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
- orderAppearanceHelper( n.getChildNode( i ), order );
- }
- }
- }
-
public void preOrderReId() {
if ( isEmpty() ) {
return;
_type = type;
}
- /**
- * Swaps the the two childern of a PhylogenyNode node of this Phylogeny.
- * <p>
- * (Last modified: 06/13/01)
- *
- * @param node
- * a PhylogenyNode of this Phylogeny
- */
- public void swapChildren( final PhylogenyNode node ) throws RuntimeException {
- if ( !isTree() ) {
- throw new FailedConditionCheckException( "Attempt to swap children on phylogeny which is not tree-like." );
- }
- if ( isEmpty() || node.isExternal() || ( node.getNumberOfDescendants() < 2 ) ) {
- return;
- }
- final PhylogenyNode first = node.getFirstChildNode();
- for( int i = 1; i < node.getNumberOfDescendants(); ++i ) {
- node.setChildNode( i - 1, node.getChildNode( i ) );
- }
- node.setChildNode( node.getNumberOfDescendants() - 1, first );
- } // swapChildren( PhylogenyNode )
-
public String toNewHampshire() {
return toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE );
}
return nodes_to_delete.size();
}
+ /**
+ * Arranges the order of childern for each node of this Phylogeny in such a
+ * way that either the branch with more children is on top (right) or on
+ * bottom (left), dependent on the value of boolean order.
+ *
+ * @param order
+ * decides in which direction to order
+ * @param pri
+ */
+ public static void orderAppearance( final PhylogenyNode n,
+ final boolean order,
+ final boolean order_ext_alphabetically,
+ final DESCENDANT_SORT_PRIORITY pri ) {
+ if ( n.isExternal() ) {
+ return;
+ }
+ else {
+ PhylogenyNode temp = null;
+ if ( ( n.getNumberOfDescendants() == 2 )
+ && ( n.getChildNode1().getNumberOfExternalNodes() != n.getChildNode2().getNumberOfExternalNodes() )
+ && ( ( n.getChildNode1().getNumberOfExternalNodes() < n.getChildNode2().getNumberOfExternalNodes() ) == order ) ) {
+ temp = n.getChildNode1();
+ n.setChild1( n.getChildNode2() );
+ n.setChild2( temp );
+ }
+ else if ( order_ext_alphabetically ) {
+ // boolean all_ext = true;
+ // for( PhylogenyNode i : n.getDescendants() ) {
+ // if ( !i.isExternal() ) {
+ // all_ext = false;
+ // break;
+ // }
+ // }
+ // if ( all_ext ) {
+ PhylogenyMethods.sortNodeDescendents( n, pri );
+ // }
+ }
+ for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
+ orderAppearance( n.getChildNode( i ), order, order_ext_alphabetically, pri );
+ }
+ }
+ }
+
public static enum PhylogenyNodeField {
CLADE_NAME,
TAXONOMY_CODE,
}
/**
+ * Swaps the the two childern of a PhylogenyNode node of this Phylogeny.
+ */
+ public void swapChildren() throws RuntimeException {
+ if ( isExternal() ) {
+ throw new RuntimeException( "attempt to swap descendants of external node" );
+ }
+ if ( getNumberOfDescendants() != 2 ) {
+ throw new RuntimeException( "attempt to swap descendants of node with " + getNumberOfDescendants()
+ + " descendants" );
+ }
+ final PhylogenyNode a = getChildNode( 0 );
+ final PhylogenyNode b = getChildNode( 1 );
+ setChildNode( 0, b );
+ setChildNode( 1, a );
+ }
+
+ /**
* Converts this PhylogenyNode to a New Hampshire X (NHX) String
* representation.
*/
if ( !b.getName().equals( "n10_ECOLI1/1-2" ) ) {
return false;
}
- if ( !PhylogenyMethods.getSpecies( b ).equals( "ECOLI" ) ) {
+ if ( !PhylogenyMethods.getSpecies( b ).equals( "" ) ) {
return false;
}
final PhylogenyNode c = PhylogenyNode
if ( !c.getName().equals( "n10_RATAF12/1000-2000" ) ) {
return false;
}
- if ( !PhylogenyMethods.getSpecies( c ).equals( "RATAF" ) ) {
+ if ( !PhylogenyMethods.getSpecies( c ).equals( "" ) ) {
+ return false;
+ }
+ final PhylogenyNode c1 = PhylogenyNode
+ .createInstanceFromNhxString( "n10_BOVIN_1/1000-2000",
+ PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ if ( !c1.getName().equals( "n10_BOVIN_1/1000-2000" ) ) {
+ return false;
+ }
+ if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
+ return false;
+ }
+ final PhylogenyNode c2 = PhylogenyNode
+ .createInstanceFromNhxString( "n10_Bovin_1/1000-2000",
+ PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ if ( !c2.getName().equals( "n10_Bovin_1/1000-2000" ) ) {
+ return false;
+ }
+ if ( !PhylogenyMethods.getSpecies( c2 ).equals( "" ) ) {
return false;
}
final PhylogenyNode d = PhylogenyNode
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.PhylogenyMethods;
+import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
import org.forester.phylogeny.PhylogenyNode;
import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
if ( strip_evaluator_phylogenies ) {
unstripped_evaluator_phylogeny = evaluator_phylogeny.copy();
SupportCount.strip( seq_names_to_keep, evaluator_phylogeny );
- evaluator_phylogeny.orderAppearance( true ); // This is for
+ PhylogenyMethods.orderAppearance( evaluator_phylogeny.getRoot(),
+ true,
+ true,
+ DESCENDANT_SORT_PRIORITY.TAXONOMY ); // This is for
// easer
// comparison if
// phylos are saved
true,
similarity_threshold );
if ( ( similarity_threshold < 0.0 ) || ( s >= similarity_threshold ) ) {
- unstripped_evaluator_phylogeny.orderAppearance( true );
+ PhylogenyMethods.orderAppearance( unstripped_evaluator_phylogeny.getRoot(),
+ true,
+ true,
+ DESCENDANT_SORT_PRIORITY.TAXONOMY );
evaluator_phylogenies_above_threshold.add( unstripped_evaluator_phylogeny );
}
if ( verbose ) {