import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
import org.forester.io.parsers.phyloxml.PhyloXmlParser;
import org.forester.io.parsers.util.ParserUtils;
+import org.forester.io.writers.PhylogenyWriter;
+import org.forester.phylogeny.Phylogeny;
import org.forester.rio.RIO;
import org.forester.rio.RIO.REROOTING;
import org.forester.rio.RIOException;
public class rio {
- final static private String PRG_NAME = "rio";
- final static private String PRG_VERSION = "4.000 beta 7";
- final static private String PRG_DATE = "2013.01.08";
- final static private String E_MAIL = "phyloxml@gmail.com";
- final static private String WWW = "https://sites.google.com/site/cmzmasek/home/software/forester";
- final static private String HELP_OPTION_1 = "help";
- final static private String HELP_OPTION_2 = "h";
- final static private String GT_FIRST = "f";
- final static private String GT_LAST = "l";
- final static private String REROOTING_OPT = "r";
- final static private String OUTGROUP = "o";
- final static private String USE_SDIR = "b";
+ final static private String PRG_NAME = "rio";
+ final static private String PRG_VERSION = "4.000 beta 8";
+ final static private String PRG_DATE = "2013.01.11";
+ final static private String E_MAIL = "phyloxml@gmail.com";
+ final static private String WWW = "https://sites.google.com/site/cmzmasek/home/software/forester";
+ final static private String HELP_OPTION_1 = "help";
+ final static private String HELP_OPTION_2 = "h";
+ final static private String GT_FIRST = "f";
+ final static private String GT_LAST = "l";
+ final static private String REROOTING_OPT = "r";
+ final static private String OUTGROUP = "o";
+ final static private String RETURN_SPECIES_TREE = "s";
+ final static private String RETURN_BEST_GENE_TREE = "g";
+ final static private String USE_SDIR = "b";
public static void main( final String[] args ) {
ForesterUtil.printProgramInformation( PRG_NAME,
if ( cla.isOptionSet( HELP_OPTION_1 ) || cla.isOptionSet( HELP_OPTION_2 ) || ( args.length == 0 ) ) {
printHelp();
}
- if ( ( args.length < 3 ) || ( args.length > 9 ) ) {
+ if ( ( args.length < 3 ) || ( args.length > 11 ) ) {
System.out.println();
System.out.println( "error: incorrect number of arguments" );
System.out.println();
allowed_options.add( REROOTING_OPT );
allowed_options.add( OUTGROUP );
allowed_options.add( USE_SDIR );
+ allowed_options.add( RETURN_SPECIES_TREE );
+ allowed_options.add( RETURN_BEST_GENE_TREE );
final String dissallowed_options = cla.validateAllowedOptionsAsString( allowed_options );
if ( dissallowed_options.length() > 0 ) {
ForesterUtil.fatalError( "unknown option(s): " + dissallowed_options );
ForesterUtil.fatalError( "attempt to set range (0-based) of gene to analyze to: from " + gt_first + " to "
+ gt_last );
}
+ File return_species_tree = null;
+ if ( !sdir && cla.isOptionSet( RETURN_SPECIES_TREE ) ) {
+ if ( !cla.isOptionHasAValue( RETURN_SPECIES_TREE ) ) {
+ ForesterUtil.fatalError( "no value for -" + RETURN_SPECIES_TREE );
+ }
+ final String s = cla.getOptionValueAsCleanString( RETURN_SPECIES_TREE );
+ return_species_tree = new File( s );
+ if ( return_species_tree.exists() ) {
+ ForesterUtil.fatalError( "\"" + return_species_tree + "\" already exists" );
+ }
+ }
+ File return_gene_tree = null;
+ if ( !sdir && cla.isOptionSet( RETURN_BEST_GENE_TREE ) ) {
+ if ( !cla.isOptionHasAValue( RETURN_BEST_GENE_TREE ) ) {
+ ForesterUtil.fatalError( "no value for -" + RETURN_BEST_GENE_TREE );
+ }
+ final String s = cla.getOptionValueAsCleanString( RETURN_BEST_GENE_TREE );
+ return_gene_tree = new File( s );
+ if ( return_gene_tree.exists() ) {
+ ForesterUtil.fatalError( "\"" + return_gene_tree + "\" already exists" );
+ }
+ }
ForesterUtil.fatalErrorIfFileNotReadable( gene_trees_file );
ForesterUtil.fatalErrorIfFileNotReadable( species_tree_file );
if ( orthology_outtable.exists() ) {
else {
System.out.println( "Non binary species tree : disallowed" );
}
+ if ( return_species_tree != null ) {
+ System.out.println( "Write used species tree to: " + return_species_tree );
+ }
+ if ( return_gene_tree != null ) {
+ System.out.println( "Write best gene tree to : " + return_gene_tree );
+ }
time = System.currentTimeMillis();
final ALGORITHM algorithm;
if ( sdir ) {
PRG_DATE,
ForesterUtil.getForesterLibraryInformation() );
}
+ if ( return_species_tree != null ) {
+ writeTree( rio.getSpeciesTree(), return_species_tree, "Wrote (stripped) species tree to" );
+ }
+ if ( return_gene_tree != null ) {
+ writeTree( rio.getMinDuplicationsGeneTree(),
+ return_gene_tree,
+ "Wrote (one) minimal duplication gene tree to" );
+ }
final java.text.DecimalFormat df = new java.text.DecimalFormat( "0.#" );
System.out.println( "Mean number of duplications : " + df.format( stats.arithmeticMean() ) + " (sd: "
+ df.format( stats.sampleStandardDeviation() ) + ") ("
System.out.println( " or 'outgroup' (default: by minizming duplications)" );
System.out.println( " -" + OUTGROUP
+ "=<outgroup> : for rooting by outgroup, name of outgroup (external gene tree node)" );
+ System.out
+ .println( " -" + RETURN_SPECIES_TREE + "=<outfile> : to write the (stripped) species tree to file" );
+ System.out.println( " -" + RETURN_BEST_GENE_TREE
+ + "=<outfile> : to write (one) minimal duplication gene tree to file" );
System.out.println( " -" + USE_SDIR
+ " : to use SDIR instead of GSDIR (faster, but non-binary species trees are" );
System.out.println( " disallowed, as are most options)" );
w.close();
System.out.println( "Wrote table to \"" + table_outfile + "\"" );
}
+
+ private static void writeTree( final Phylogeny p, final File f, final String comment ) throws IOException {
+ final PhylogenyWriter writer = new PhylogenyWriter();
+ writer.toPhyloXML( f, p, 0 );
+ System.out.println( comment + " \"" + f + "\"" );
+ }
}
}
}
if ( ( nodes != null ) && ( nodes.size() > 0 ) ) {
- main_panel.getCurrentTreePanel().setFoundNodes( new HashSet<Integer>() );
+ main_panel.getCurrentTreePanel().setFoundNodes( new HashSet<Long>() );
for( final PhylogenyNode node : nodes ) {
main_panel.getCurrentTreePanel().getFoundNodes().add( node.getId() );
}
private void annotateSequences() {
if ( getCurrentTreePanel() != null ) {
- final Set<Integer> nodes = getCurrentTreePanel().getFoundNodes();
+ final Set<Long> nodes = getCurrentTreePanel().getFoundNodes();
if ( ( nodes == null ) || nodes.isEmpty() ) {
JOptionPane
.showMessageDialog( this,
desc = desc.replaceAll( "\\s+", " " );
}
if ( !ForesterUtil.isEmpty( ref ) || !ForesterUtil.isEmpty( desc ) ) {
- for( final Integer id : nodes ) {
+ for( final Long id : nodes ) {
final PhylogenyNode n = phy.getNode( id );
ForesterUtil.ensurePresenceOfSequence( n );
final Annotation ann = ForesterUtil.isEmpty( ref ) ? new Annotation()
private TreeColorSet _colorset;
private TreeFontSet _fontset;
private Phylogeny _cut_or_copied_tree;
- private Set<Integer> _copied_and_pasted_nodes;
+ private Set<Long> _copied_and_pasted_nodes;
private Hashtable<String, BufferedImage> _image_map;
private static Map<String, String> _lineage_to_rank_map;
return _control_panel;
}
- public Set<Integer> getCopiedAndPastedNodes() {
+ public Set<Long> getCopiedAndPastedNodes() {
return _copied_and_pasted_nodes;
}
repaint();
}
- public void setCopiedAndPastedNodes( final Set<Integer> node_ids ) {
+ public void setCopiedAndPastedNodes( final Set<Long> node_ids ) {
_copied_and_pasted_nodes = node_ids;
}
public final class TreePanel extends JPanel implements ActionListener, MouseWheelListener, Printable {
- private static final float PI = ( float ) ( Math.PI );
- private static final double TWO_PI = 2 * Math.PI;
- private static final float ONEHALF_PI = ( float ) ( 1.5 * Math.PI );
- private static final float HALF_PI = ( float ) ( Math.PI / 2.0 );
- private static final float ANGLE_ROTATION_UNIT = ( float ) ( Math.PI / 32 );
- private static final short OV_BORDER = 10;
- final static Cursor CUT_CURSOR = Cursor.getPredefinedCursor( Cursor.CROSSHAIR_CURSOR );
- final static Cursor MOVE_CURSOR = Cursor.getPredefinedCursor( Cursor.MOVE_CURSOR );
- final static Cursor ARROW_CURSOR = Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR );
- final static Cursor HAND_CURSOR = Cursor.getPredefinedCursor( Cursor.HAND_CURSOR );
- final static Cursor WAIT_CURSOR = Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR );
- private final static long serialVersionUID = -978349745916505029L;
- private final static int EURO_D = 10;
- private final static String NODE_POPMENU_NODE_CLIENT_PROPERTY = "node";
- private final static int MIN_ROOT_LENGTH = 3;
- private final static int MAX_SUBTREES = 100;
- private final static int MAX_NODE_FRAMES = 10;
- private final static int MOVE = 20;
- private final static NumberFormat FORMATTER_CONFIDENCE;
- private final static NumberFormat FORMATTER_BRANCH_LENGTH;
- private final static int WIGGLE = 2;
- private final static int LIMIT_FOR_HQ_RENDERING = 1000;
- private final static int CONFIDENCE_LEFT_MARGIN = 4;
- private final RenderingHints _rendering_hints = new RenderingHints( RenderingHints.KEY_RENDERING,
- RenderingHints.VALUE_RENDER_DEFAULT );
- private File _treefile = null;
- private Configuration _configuration = null;
- private final NodeFrame[] _node_frames = new NodeFrame[ TreePanel.MAX_NODE_FRAMES ];
- private int _node_frame_index = 0;
- private Phylogeny _phylogeny = null;
- private final Phylogeny[] _sub_phylogenies = new Phylogeny[ TreePanel.MAX_SUBTREES ];
- private final PhylogenyNode[] _sub_phylogenies_temp_roots = new PhylogenyNode[ TreePanel.MAX_SUBTREES ];
- private int _subtree_index = 0;
- private MainPanel _main_panel = null;
- private Set<Integer> _found_nodes = null;
- private PhylogenyNode _highlight_node = null;
- private JPopupMenu _node_popup_menu = null;
- private JMenuItem _node_popup_menu_items[] = null;
- private int _longest_ext_node_info = 0;
- private float _x_correction_factor = 0.0f;
- private float _ov_x_correction_factor = 0.0f;
- private float _x_distance = 0.0f;
- private float _y_distance = 0.0f;
- private PHYLOGENY_GRAPHICS_TYPE _graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
- private double _domain_structure_width = Constants.DOMAIN_STRUCTURE_DEFAULT_WIDTH;
- private int _domain_structure_e_value_thr_exp = Constants.DOMAIN_STRUCTURE_E_VALUE_THR_DEFAULT_EXP;
- private float _last_drag_point_x = 0;
- private float _last_drag_point_y = 0;
- private ControlPanel _control_panel = null;
- private int _external_node_index = 0;
- private final Polygon _polygon = new Polygon();
- private final StringBuilder _sb = new StringBuilder();
- private JColorChooser _color_chooser = null;
- private double _scale_distance = 0.0;
- private String _scale_label = null;
- private final CubicCurve2D _cubic_curve = new CubicCurve2D.Float();
- private final QuadCurve2D _quad_curve = new QuadCurve2D.Float();
- private final Line2D _line = new Line2D.Float();
- private final Ellipse2D _ellipse = new Ellipse2D.Float();
- private final Rectangle2D _rectangle = new Rectangle2D.Float();
- private Options _options = null;
- private float _ov_max_width = 0;
- private float _ov_max_height = 0;
- private int _ov_x_position = 0;
- private int _ov_y_position = 0;
- private int _ov_y_start = 0;
- private float _ov_y_distance = 0;
- private float _ov_x_distance = 0;
- private boolean _ov_on = false;
- private double _urt_starting_angle = ( float ) ( Math.PI / 2 );
- private float _urt_factor = 1;
- private float _urt_factor_ov = 1;
- private final boolean _phy_has_branch_lengths;
- private final Rectangle2D _ov_rectangle = new Rectangle2D.Float();
- private boolean _in_ov_rect = false;
- private boolean _in_ov = false;
- private final Rectangle _ov_virtual_rectangle = new Rectangle();
- final private static double _180_OVER_PI = 180.0 / Math.PI;
- private static final float ROUNDED_D = 8;
- private int _circ_max_depth;
- private PhylogenyNode _root;
- final private Arc2D _arc = new Arc2D.Double();
- final private HashMap<Integer, Double> _urt_nodeid_angle_map = new HashMap<Integer, Double>();
- final private HashMap<Integer, Integer> _urt_nodeid_index_map = new HashMap<Integer, Integer>();
- final private Set<Integer> _collapsed_external_nodeid_set = new HashSet<Integer>();
- HashMap<Integer, Short> _nodeid_dist_to_leaf = new HashMap<Integer, Short>();
- private AffineTransform _at;
- private double _max_distance_to_root = -1;
- private int _dynamic_hiding_factor = 0;
- private boolean _edited = false;
- private Popup _node_desc_popup;
- private JTextArea _rollover_popup;
- private final StringBuffer _popup_buffer = new StringBuffer();
- final private static Font POPUP_FONT = new Font( Configuration
- .getDefaultFontFamilyName(),
- Font.PLAIN,
- 12 );
- private Sequence _query_sequence = null;
- private final FontRenderContext _frc = new FontRenderContext( null,
- false,
- false );
+ private static final float PI = ( float ) ( Math.PI );
+ private static final double TWO_PI = 2 * Math.PI;
+ private static final float ONEHALF_PI = ( float ) ( 1.5 * Math.PI );
+ private static final float HALF_PI = ( float ) ( Math.PI / 2.0 );
+ private static final float ANGLE_ROTATION_UNIT = ( float ) ( Math.PI / 32 );
+ private static final short OV_BORDER = 10;
+ final static Cursor CUT_CURSOR = Cursor.getPredefinedCursor( Cursor.CROSSHAIR_CURSOR );
+ final static Cursor MOVE_CURSOR = Cursor.getPredefinedCursor( Cursor.MOVE_CURSOR );
+ final static Cursor ARROW_CURSOR = Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR );
+ final static Cursor HAND_CURSOR = Cursor.getPredefinedCursor( Cursor.HAND_CURSOR );
+ final static Cursor WAIT_CURSOR = Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR );
+ private final static long serialVersionUID = -978349745916505029L;
+ private final static int EURO_D = 10;
+ private final static String NODE_POPMENU_NODE_CLIENT_PROPERTY = "node";
+ private final static int MIN_ROOT_LENGTH = 3;
+ private final static int MAX_SUBTREES = 100;
+ private final static int MAX_NODE_FRAMES = 10;
+ private final static int MOVE = 20;
+ private final static NumberFormat FORMATTER_CONFIDENCE;
+ private final static NumberFormat FORMATTER_BRANCH_LENGTH;
+ private final static int WIGGLE = 2;
+ private final static int LIMIT_FOR_HQ_RENDERING = 1000;
+ private final static int CONFIDENCE_LEFT_MARGIN = 4;
+ private final RenderingHints _rendering_hints = new RenderingHints( RenderingHints.KEY_RENDERING,
+ RenderingHints.VALUE_RENDER_DEFAULT );
+ private File _treefile = null;
+ private Configuration _configuration = null;
+ private final NodeFrame[] _node_frames = new NodeFrame[ TreePanel.MAX_NODE_FRAMES ];
+ private int _node_frame_index = 0;
+ private Phylogeny _phylogeny = null;
+ private final Phylogeny[] _sub_phylogenies = new Phylogeny[ TreePanel.MAX_SUBTREES ];
+ private final PhylogenyNode[] _sub_phylogenies_temp_roots = new PhylogenyNode[ TreePanel.MAX_SUBTREES ];
+ private int _subtree_index = 0;
+ private MainPanel _main_panel = null;
+ private Set<Long> _found_nodes = null;
+ private PhylogenyNode _highlight_node = null;
+ private JPopupMenu _node_popup_menu = null;
+ private JMenuItem _node_popup_menu_items[] = null;
+ private int _longest_ext_node_info = 0;
+ private float _x_correction_factor = 0.0f;
+ private float _ov_x_correction_factor = 0.0f;
+ private float _x_distance = 0.0f;
+ private float _y_distance = 0.0f;
+ private PHYLOGENY_GRAPHICS_TYPE _graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
+ private double _domain_structure_width = Constants.DOMAIN_STRUCTURE_DEFAULT_WIDTH;
+ private int _domain_structure_e_value_thr_exp = Constants.DOMAIN_STRUCTURE_E_VALUE_THR_DEFAULT_EXP;
+ private float _last_drag_point_x = 0;
+ private float _last_drag_point_y = 0;
+ private ControlPanel _control_panel = null;
+ private int _external_node_index = 0;
+ private final Polygon _polygon = new Polygon();
+ private final StringBuilder _sb = new StringBuilder();
+ private JColorChooser _color_chooser = null;
+ private double _scale_distance = 0.0;
+ private String _scale_label = null;
+ private final CubicCurve2D _cubic_curve = new CubicCurve2D.Float();
+ private final QuadCurve2D _quad_curve = new QuadCurve2D.Float();
+ private final Line2D _line = new Line2D.Float();
+ private final Ellipse2D _ellipse = new Ellipse2D.Float();
+ private final Rectangle2D _rectangle = new Rectangle2D.Float();
+ private Options _options = null;
+ private float _ov_max_width = 0;
+ private float _ov_max_height = 0;
+ private int _ov_x_position = 0;
+ private int _ov_y_position = 0;
+ private int _ov_y_start = 0;
+ private float _ov_y_distance = 0;
+ private float _ov_x_distance = 0;
+ private boolean _ov_on = false;
+ private double _urt_starting_angle = ( float ) ( Math.PI / 2 );
+ private float _urt_factor = 1;
+ private float _urt_factor_ov = 1;
+ private final boolean _phy_has_branch_lengths;
+ private final Rectangle2D _ov_rectangle = new Rectangle2D.Float();
+ private boolean _in_ov_rect = false;
+ private boolean _in_ov = false;
+ private final Rectangle _ov_virtual_rectangle = new Rectangle();
+ final private static double _180_OVER_PI = 180.0 / Math.PI;
+ private static final float ROUNDED_D = 8;
+ private int _circ_max_depth;
+ private PhylogenyNode _root;
+ final private Arc2D _arc = new Arc2D.Double();
+ final private HashMap<Long, Double> _urt_nodeid_angle_map = new HashMap<Long, Double>();
+ final private HashMap<Long, Integer> _urt_nodeid_index_map = new HashMap<Long, Integer>();
+ final private Set<Long> _collapsed_external_nodeid_set = new HashSet<Long>();
+ HashMap<Long, Short> _nodeid_dist_to_leaf = new HashMap<Long, Short>();
+ private AffineTransform _at;
+ private double _max_distance_to_root = -1;
+ private int _dynamic_hiding_factor = 0;
+ private boolean _edited = false;
+ private Popup _node_desc_popup;
+ private JTextArea _rollover_popup;
+ private final StringBuffer _popup_buffer = new StringBuffer();
+ final private static Font POPUP_FONT = new Font( Configuration.getDefaultFontFamilyName(),
+ Font.PLAIN,
+ 12 );
+ private Sequence _query_sequence = null;
+ private final FontRenderContext _frc = new FontRenderContext( null,
+ false,
+ false );
// expression values menu:
- private DescriptiveStatistics _statistics_for_vector_data;
- private PhylogenyNode[] _nodes_in_preorder = null;
- private StringBuilder _current_external_nodes_data_buffer = new StringBuilder();
- private int _current_external_nodes_data_buffer_change_counter = 0;
- private Set<Integer> _current_external_nodes = null;
+ private DescriptiveStatistics _statistics_for_vector_data;
+ private PhylogenyNode[] _nodes_in_preorder = null;
+ private StringBuilder _current_external_nodes_data_buffer = new StringBuilder();
+ private int _current_external_nodes_data_buffer_change_counter = 0;
+ private Set<Long> _current_external_nodes = null;
// private Image offscreenImage;
// private Graphics offscreenGraphics;
// private Dimension offscreenDimension;
return _domain_structure_e_value_thr_exp;
}
- final Set<Integer> getFoundNodes() {
+ final Set<Long> getFoundNodes() {
return _found_nodes;
}
if ( ( e.getModifiers() & InputEvent.SHIFT_MASK ) != 0 ) {
// Yes, so add to _found_nodes
if ( getFoundNodes() == null ) {
- setFoundNodes( new HashSet<Integer>() );
+ setFoundNodes( new HashSet<Long>() );
}
getFoundNodes().add( node.getId() );
// Check if control key is down
}
final void resetNodeIdToDistToLeafMap() {
- _nodeid_dist_to_leaf = new HashMap<Integer, Short>();
+ _nodeid_dist_to_leaf = new HashMap<Long, Short>();
}
final void resetPreferredSize() {
getControlPanel().getSearchResetButton().setEnabled( true );
getControlPanel().getSearchResetButton().setVisible( true );
if ( getFoundNodes() == null ) {
- setFoundNodes( new HashSet<Integer>() );
+ setFoundNodes( new HashSet<Long>() );
}
getFoundNodes().add( node.getId() );
getControlPanel().setSearchFoundCountsOnLabel( getFoundNodes().size() );
_current_external_nodes_data_buffer = sb;
}
- final void setFoundNodes( final Set<Integer> found_nodes ) {
+ final void setFoundNodes( final Set<Long> found_nodes ) {
_found_nodes = found_nodes;
}
repaint();
}
- final private void addToCurrentExternalNodes( final int i ) {
+ final private void addToCurrentExternalNodes( final long i ) {
if ( _current_external_nodes == null ) {
- _current_external_nodes = new HashSet<Integer>();
+ _current_external_nodes = new HashSet<Long>();
}
_current_external_nodes.add( i );
}
setNodeInPreorderToNull();
setCutOrCopiedTree( _phylogeny.copy( node ) );
final List<PhylogenyNode> nodes = PhylogenyMethods.getAllDescendants( node );
- final Set<Integer> node_ids = new HashSet<Integer>( nodes.size() );
+ final Set<Long> node_ids = new HashSet<Long>( nodes.size() );
for( final PhylogenyNode n : nodes ) {
node_ids.add( n.getId() );
}
JOptionPane.ERROR_MESSAGE );
}
- final private Set<Integer> getCopiedAndPastedNodes() {
+ final private Set<Long> getCopiedAndPastedNodes() {
return getMainPanel().getCopiedAndPastedNodes();
}
- final private Set<Integer> getCurrentExternalNodes() {
+ final private Set<Long> getCurrentExternalNodes() {
return _current_external_nodes;
}
}
}
if ( getCopiedAndPastedNodes() == null ) {
- setCopiedAndPastedNodes( new HashSet<Integer>() );
+ setCopiedAndPastedNodes( new HashSet<Long>() );
}
final List<PhylogenyNode> nodes = PhylogenyMethods.obtainAllNodesAsList( buffer_phy );
- final Set<Integer> node_ids = new HashSet<Integer>( nodes.size() );
+ final Set<Long> node_ids = new HashSet<Long>( nodes.size() );
for( final PhylogenyNode n : nodes ) {
node_ids.add( n.getId() );
}
return sb;
}
- final private void setCopiedAndPastedNodes( final Set<Integer> nodeIds ) {
+ final private void setCopiedAndPastedNodes( final Set<Long> nodeIds ) {
getMainPanel().setCopiedAndPastedNodes( nodeIds );
}
private Confidence _confidence;
private Identifier _identifier;
private boolean _rerootable;
- private HashMap<Integer, PhylogenyNode> _id_to_node_map;
+ private HashMap<Long, PhylogenyNode> _id_to_node_map;
private List<PhylogenyNode> _external_nodes_set;
private Collection<Sequence> _sequenceRelationQueries;
private Collection<SequenceRelation.SEQUENCE_RELATION_TYPE> _relevant_sequence_relation_types;
* Finds the PhylogenyNode of this Phylogeny which has a matching ID number.
* @return PhylogenyNode with matching ID, null if not found
*/
- public PhylogenyNode getNode( final int id ) throws NoSuchElementException {
+ public PhylogenyNode getNode( final long id ) throws NoSuchElementException {
if ( isEmpty() ) {
throw new NoSuchElementException( "attempt to get node in an empty phylogeny" );
}
return;
}
_id_to_node_map = null;
- int max = 0;
+ long max = 0;
for( final PhylogenyNodeIterator it = iteratorPreorder(); it.hasNext(); ) {
final PhylogenyNode node = it.next();
if ( node.isRoot() ) {
* @param id
* ID (int) of PhylogenyNode of this Phylogeny
*/
- public void reRoot( final int id ) {
+ public void reRoot( final long id ) {
reRoot( getNode( id ) );
}
_identifier = identifier;
}
- public void setIdToNodeMap( final HashMap<Integer, PhylogenyNode> idhash ) {
+ public void setIdToNodeMap( final HashMap<Long, PhylogenyNode> idhash ) {
_id_to_node_map = idhash;
}
return;
} // unRoot()
- private HashMap<Integer, PhylogenyNode> getIdToNodeMap() {
+ private HashMap<Long, PhylogenyNode> getIdToNodeMap() {
return _id_to_node_map;
}
if ( isEmpty() ) {
return;
}
- setIdToNodeMap( new HashMap<Integer, PhylogenyNode>() );
+ setIdToNodeMap( new HashMap<Long, PhylogenyNode>() );
for( final PhylogenyNodeIterator iter = iteratorPreorder(); iter.hasNext(); ) {
final PhylogenyNode node = iter.next();
getIdToNodeMap().put( node.getId(), node );
public static final HashMap<String, PhylogenyNode> createNameToExtNodeMap( final Phylogeny phy ) {
final HashMap<String, PhylogenyNode> nodes = new HashMap<String, PhylogenyNode>();
- for( final PhylogenyNodeIterator iter = phy.iteratorExternalForward(); iter.hasNext(); ) {
- final PhylogenyNode n = iter.next();
+ List<PhylogenyNode> ext = phy.getExternalNodes();
+ for( PhylogenyNode n : ext ) {
nodes.put( n.getName(), n );
}
+ // for( final PhylogenyNodeIterator iter = phy.iteratorExternalForward(); iter.hasNext(); ) {
+ // final PhylogenyNode n = iter.next();
+ // nodes.put( n.getName(), n );
+ // }
return nodes;
}
public static List<PhylogenyNode> getAllDescendants( final PhylogenyNode node ) {
final List<PhylogenyNode> descs = new ArrayList<PhylogenyNode>();
- final Set<Integer> encountered = new HashSet<Integer>();
+ final Set<Long> encountered = new HashSet<Long>();
if ( !node.isExternal() ) {
final List<PhylogenyNode> exts = node.getAllExternalDescendants();
for( PhylogenyNode current : exts ) {
return;
}
phy.setIdToNodeMap( null );
- int i = PhylogenyNode.getNodeCount();
+ long i = PhylogenyNode.getNodeCount();
for( final PhylogenyNodeIterator it = phy.iteratorPreorder(); it.hasNext(); ) {
it.next().setId( i++ );
}
public enum NH_CONVERSION_SUPPORT_VALUE_STYLE {
NONE, IN_SQUARE_BRACKETS, AS_INTERNAL_NODE_NAMES;
}
- private static int _node_count = 0;
+ private static long NODE_COUNT = 0;
private byte _indicator;
- private int _id;
+ private long _id;
private int _sum_ext_nodes;
private float _x;
private float _y;
/**
* Returns the ID (int) of this PhylogenyNode.
*/
- final public int getId() {
+ final public long getId() {
return _id;
}
* should not be set to values lower than getNodeCount() -- which this method
* does not allow.
*/
- synchronized final protected void setId( final int i ) {
+ synchronized final protected void setId( final long i ) {
if ( i < getNodeCount() ) {
throw new IllegalArgumentException( "attempt to set node id to a value less than total node count (thus violating the uniqueness of node ids)" );
}
* Decreases the total number of all Nodes created so far by one.
*/
final static synchronized void decreaseNodeCount() {
- --PhylogenyNode._node_count;
+ --NODE_COUNT;
}
/**
* Returns the total number of all Nodes created so far.
*
- * @return total number of Nodes (int)
+ * @return total number of Nodes (long)
*/
- synchronized final public static int getNodeCount() {
- return PhylogenyNode._node_count;
+ synchronized final public static long getNodeCount() {
+ return NODE_COUNT;
}
/**
* Increases the total number of all Nodes created so far by one.
*/
synchronized final private static void increaseNodeCount() {
- ++PhylogenyNode._node_count;
+ ++NODE_COUNT;
}
/**
- * Sets the total number of all Nodes created so far to i (int).
+ * Sets the total number of all Nodes created so far to i.
*/
- synchronized final static void setNodeCount( final int i ) {
- PhylogenyNode._node_count = i;
+ synchronized final static void setNodeCount( final long i ) {
+ PhylogenyNode.NODE_COUNT = i;
}
public static PhylogenyNode createInstanceFromNhxString( final String nhx ) throws NHXFormatException,
private final boolean _produce_log;
private final boolean _verbose;
private final REROOTING _rerooting;
+ private final Phylogeny _species_tree;
+ private Phylogeny _min_dub_gene_tree;
- private RIO( final Phylogeny[] gene_trees,
+ private RIO( final IteratingPhylogenyParser p,
final Phylogeny species_tree,
final ALGORITHM algorithm,
final REROOTING rerooting,
final boolean produce_log,
final boolean verbose ) throws IOException, SDIException, RIOException {
if ( ( last == DEFAULT_RANGE ) && ( first >= 0 ) ) {
- last = gene_trees.length - 1;
+ last = END_OF_GT;
}
else if ( ( first == DEFAULT_RANGE ) && ( last >= 0 ) ) {
first = 0;
}
removeSingleDescendentsNodes( species_tree, verbose );
- checkPreconditions( gene_trees, species_tree, rerooting, outgroup, first, last );
+ p.reset();
+ checkPreconditions( p, species_tree, rerooting, outgroup, first, last );
_produce_log = produce_log;
_verbose = verbose;
_rerooting = rerooting;
_analyzed_gene_trees = null;
_removed_gene_tree_nodes = null;
_duplications_stats = new BasicDescriptiveStatistics();
- inferOrthologs( gene_trees, species_tree, algorithm, outgroup, first, last );
+ p.reset();
+ inferOrthologs( p, species_tree, algorithm, outgroup, first, last );
+ _species_tree = species_tree;
}
- private RIO( final IteratingPhylogenyParser p,
+ private RIO( final Phylogeny[] gene_trees,
final Phylogeny species_tree,
final ALGORITHM algorithm,
final REROOTING rerooting,
final boolean produce_log,
final boolean verbose ) throws IOException, SDIException, RIOException {
if ( ( last == DEFAULT_RANGE ) && ( first >= 0 ) ) {
- last = END_OF_GT;
+ last = gene_trees.length - 1;
}
else if ( ( first == DEFAULT_RANGE ) && ( last >= 0 ) ) {
first = 0;
}
removeSingleDescendentsNodes( species_tree, verbose );
- p.reset();
- checkPreconditions( p, species_tree, rerooting, outgroup, first, last );
+ checkPreconditions( gene_trees, species_tree, rerooting, outgroup, first, last );
_produce_log = produce_log;
_verbose = verbose;
_rerooting = rerooting;
_analyzed_gene_trees = null;
_removed_gene_tree_nodes = null;
_duplications_stats = new BasicDescriptiveStatistics();
- p.reset();
- inferOrthologs( p, species_tree, algorithm, outgroup, first, last );
+ inferOrthologs( gene_trees, species_tree, algorithm, outgroup, first, last );
+ _species_tree = species_tree;
}
public final Phylogeny[] getAnalyzedGeneTrees() {
return _ext_nodes;
}
+ public final TaxonomyComparisonBase getGSDIRtaxCompBase() {
+ return _gsdir_tax_comp_base;
+ }
+
/**
* Returns the numbers of number of int nodes in gene trees analyzed (after
* stripping).
return _int_nodes;
}
- public final TaxonomyComparisonBase getGSDIRtaxCompBase() {
- return _gsdir_tax_comp_base;
- }
-
public final StringBuilder getLog() {
return _log;
}
+ final public Phylogeny getMinDuplicationsGeneTree() {
+ return _min_dub_gene_tree;
+ }
+
+ public final IntMatrix getOrthologTable() {
+ return _m;
+ }
+
public final List<PhylogenyNode> getRemovedGeneTreeNodes() {
return _removed_gene_tree_nodes;
}
- private final void inferOrthologs( final Phylogeny[] gene_trees,
- final Phylogeny species_tree,
- final ALGORITHM algorithm,
- final String outgroup,
- final int first,
- final int last ) throws SDIException, RIOException, FileNotFoundException,
- IOException {
- if ( algorithm == ALGORITHM.SDIR ) {
- // Removes from species_tree all species not found in gene_tree.
- PhylogenyMethods.taxonomyBasedDeletionOfExternalNodes( gene_trees[ 0 ], species_tree );
- if ( species_tree.isEmpty() ) {
- throw new RIOException( "failed to establish species based mapping between gene and species trees" );
- }
- }
- final Phylogeny[] my_gene_trees;
- if ( ( first >= 0 ) && ( last >= first ) && ( last < gene_trees.length ) ) {
- my_gene_trees = new Phylogeny[ ( 1 + last ) - first ];
- int c = 0;
- for( int i = first; i <= last; ++i ) {
- my_gene_trees[ c++ ] = gene_trees[ i ];
- }
- }
- else {
- my_gene_trees = gene_trees;
- }
- if ( log() ) {
- preLog( gene_trees.length, species_tree, algorithm, outgroup );
- }
- if ( _verbose && ( my_gene_trees.length >= 4 ) ) {
- System.out.println();
- }
- _analyzed_gene_trees = new Phylogeny[ my_gene_trees.length ];
- int gene_tree_ext_nodes = 0;
- for( int i = 0; i < my_gene_trees.length; ++i ) {
- final Phylogeny gt = my_gene_trees[ i ];
- if ( _verbose && ( my_gene_trees.length > 4 ) ) {
- ForesterUtil.updateProgress( ( ( double ) i ) / my_gene_trees.length );
- }
- if ( i == 0 ) {
- gene_tree_ext_nodes = gt.getNumberOfExternalNodes();
- }
- else if ( gene_tree_ext_nodes != gt.getNumberOfExternalNodes() ) {
- throw new RIOException( "gene tree #" + i + " has a different number of external nodes ("
- + gt.getNumberOfExternalNodes() + ") than the preceding gene tree(s) (" + gene_tree_ext_nodes
- + ")" );
- }
- if ( algorithm == ALGORITHM.SDIR ) {
- // Removes from gene_tree all species not found in species_tree.
- PhylogenyMethods.taxonomyBasedDeletionOfExternalNodes( species_tree, gt );
- if ( gt.isEmpty() ) {
- throw new RIOException( "failed to establish species based mapping between gene and species trees" );
- }
- }
- _analyzed_gene_trees[ i ] = performOrthologInference( gt, species_tree, algorithm, outgroup, i );
- }
- if ( log() ) {
- postLog( species_tree, first, last );
- }
- if ( _verbose && ( my_gene_trees.length > 4 ) ) {
- System.out.println();
- System.out.println();
- }
+ public final Phylogeny getSpeciesTree() {
+ return _species_tree;
}
private final void inferOrthologs( final IteratingPhylogenyParser parser,
}
}
+ private final void inferOrthologs( final Phylogeny[] gene_trees,
+ final Phylogeny species_tree,
+ final ALGORITHM algorithm,
+ final String outgroup,
+ final int first,
+ final int last ) throws SDIException, RIOException, FileNotFoundException,
+ IOException {
+ if ( algorithm == ALGORITHM.SDIR ) {
+ // Removes from species_tree all species not found in gene_tree.
+ PhylogenyMethods.taxonomyBasedDeletionOfExternalNodes( gene_trees[ 0 ], species_tree );
+ if ( species_tree.isEmpty() ) {
+ throw new RIOException( "failed to establish species based mapping between gene and species trees" );
+ }
+ }
+ final Phylogeny[] my_gene_trees;
+ if ( ( first >= 0 ) && ( last >= first ) && ( last < gene_trees.length ) ) {
+ my_gene_trees = new Phylogeny[ ( 1 + last ) - first ];
+ int c = 0;
+ for( int i = first; i <= last; ++i ) {
+ my_gene_trees[ c++ ] = gene_trees[ i ];
+ }
+ }
+ else {
+ my_gene_trees = gene_trees;
+ }
+ if ( log() ) {
+ preLog( gene_trees.length, species_tree, algorithm, outgroup );
+ }
+ if ( _verbose && ( my_gene_trees.length >= 4 ) ) {
+ System.out.println();
+ }
+ _analyzed_gene_trees = new Phylogeny[ my_gene_trees.length ];
+ int gene_tree_ext_nodes = 0;
+ for( int i = 0; i < my_gene_trees.length; ++i ) {
+ final Phylogeny gt = my_gene_trees[ i ];
+ if ( _verbose && ( my_gene_trees.length > 4 ) ) {
+ ForesterUtil.updateProgress( ( ( double ) i ) / my_gene_trees.length );
+ }
+ if ( i == 0 ) {
+ gene_tree_ext_nodes = gt.getNumberOfExternalNodes();
+ }
+ else if ( gene_tree_ext_nodes != gt.getNumberOfExternalNodes() ) {
+ throw new RIOException( "gene tree #" + i + " has a different number of external nodes ("
+ + gt.getNumberOfExternalNodes() + ") than the preceding gene tree(s) (" + gene_tree_ext_nodes
+ + ")" );
+ }
+ if ( algorithm == ALGORITHM.SDIR ) {
+ // Removes from gene_tree all species not found in species_tree.
+ PhylogenyMethods.taxonomyBasedDeletionOfExternalNodes( species_tree, gt );
+ if ( gt.isEmpty() ) {
+ throw new RIOException( "failed to establish species based mapping between gene and species trees" );
+ }
+ }
+ _analyzed_gene_trees[ i ] = performOrthologInference( gt, species_tree, algorithm, outgroup, i );
+ }
+ if ( log() ) {
+ postLog( species_tree, first, last );
+ }
+ if ( _verbose && ( my_gene_trees.length > 4 ) ) {
+ System.out.println();
+ System.out.println();
+ }
+ }
+
private final boolean log() {
return _produce_log;
}
final String outgroup,
final int i ) throws SDIException, RIOException {
final Phylogeny assigned_tree;
+ final int dups;
if ( _rerooting == REROOTING.BY_ALGORITHM ) {
final GSDIR gsdir = new GSDIR( gene_tree, species_tree, true, i == 0 );
assigned_tree = gsdir.getMinDuplicationsSumGeneTree();
if ( i == 0 ) {
_gsdir_tax_comp_base = gsdir.getTaxCompBase();
}
- _duplications_stats.addValue( gsdir.getMinDuplicationsSum() );
+ dups = gsdir.getMinDuplicationsSum();
}
else {
if ( _rerooting == REROOTING.MIDPOINT ) {
if ( i == 0 ) {
_gsdir_tax_comp_base = gsdi.getTaxCompBase();
}
- _duplications_stats.addValue( gsdi.getDuplicationsSum() );
+ dups = gsdi.getDuplicationsSum();
+ }
+ if ( ( i == 0 ) || ( dups < _duplications_stats.getMin() ) ) {
+ _min_dub_gene_tree = assigned_tree;
}
+ _duplications_stats.addValue( dups );
return assigned_tree;
}
log( "Re-rooting : " + rs );
}
- public final IntMatrix getOrthologTable() {
- return _m;
- }
-
- private final static void calculateOrthologTable( final Phylogeny g, final boolean sort, final int counter )
- throws RIOException {
- final List<String> labels = new ArrayList<String>();
- final Set<String> labels_set = new HashSet<String>();
- if ( counter == 0 ) {
- for( final PhylogenyNode n : g.getExternalNodes() ) {
- final String label = obtainLabel( labels_set, n );
- labels_set.add( label );
- labels.add( label );
- }
- if ( sort ) {
- Collections.sort( labels );
- }
- _m = new IntMatrix( labels );
- }
- updateCounts( _m, counter, g );
- }
-
- private final static String obtainLabel( final Set<String> labels_set, final PhylogenyNode n ) throws RIOException {
- String label;
- if ( n.getNodeData().isHasSequence() && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
- label = n.getNodeData().getSequence().getName();
- }
- else if ( n.getNodeData().isHasSequence() && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getSymbol() ) ) {
- label = n.getNodeData().getSequence().getSymbol();
- }
- else if ( !ForesterUtil.isEmpty( n.getName() ) ) {
- label = n.getName();
- }
- else {
- throw new RIOException( "node " + n + " has no appropriate label" );
- }
- if ( labels_set.contains( label ) ) {
- throw new RIOException( "label " + label + " is not unique" );
- }
- return label;
- }
-
- private final static void updateCounts( final IntMatrix m, final int counter, final Phylogeny g )
- throws RIOException {
- PhylogenyMethods.preOrderReId( g );
- final HashMap<String, PhylogenyNode> map = PhylogenyMethods.createNameToExtNodeMap( g );
- for( int x = 0; x < m.size(); ++x ) {
- final String mx = m.getLabel( x );
- final PhylogenyNode nx = map.get( mx );
- if ( nx == null ) {
- throw new RIOException( "node \"" + mx + "\" not present in gene tree #" + counter );
- }
- String my;
- PhylogenyNode ny;
- for( int y = 0; y < m.size(); ++y ) {
- my = m.getLabel( y );
- ny = map.get( my );
- if ( ny == null ) {
- throw new RIOException( "node \"" + my + "\" not present in gene tree #" + counter );
- }
- if ( !PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( nx, ny ).isDuplication() ) {
- m.inreaseByOne( x, y );
- }
- }
- }
- }
-
public final static IntMatrix calculateOrthologTable( final Phylogeny[] analyzed_gene_trees, final boolean sort )
throws RIOException {
final List<String> labels = new ArrayList<String>();
return new RIO( gene_trees, species_tree, algorithm, rerooting, outgroup, first, last, produce_log, verbose );
}
- public final static RIO executeAnalysis( final IteratingPhylogenyParser p,
- final File species_tree_file,
+ public final static RIO executeAnalysis( final File gene_trees_file,
+ final Phylogeny species_tree,
final ALGORITHM algorithm,
final REROOTING rerooting,
final String outgroup,
- final int first,
- final int last,
final boolean produce_log,
final boolean verbose ) throws IOException, SDIException, RIOException {
- final Phylogeny g0 = p.next();
- if ( ( g0 == null ) || g0.isEmpty() || ( g0.getNumberOfExternalNodes() < 2 ) ) {
- throw new RIOException( "input file does not seem to contain any gene trees" );
- }
- final Phylogeny species_tree = SDIutil.parseSpeciesTree( g0,
- species_tree_file,
- false,
- true,
- TAXONOMY_EXTRACTION.NO );
- p.reset();
- return new RIO( p, species_tree, algorithm, rerooting, outgroup, first, last, produce_log, verbose );
+ return new RIO( parseGeneTrees( gene_trees_file ),
+ species_tree,
+ algorithm,
+ rerooting,
+ outgroup,
+ DEFAULT_RANGE,
+ DEFAULT_RANGE,
+ produce_log,
+ verbose );
}
public final static RIO executeAnalysis( final File gene_trees_file,
final ALGORITHM algorithm,
final REROOTING rerooting,
final String outgroup,
+ final int first,
+ final int last,
final boolean produce_log,
final boolean verbose ) throws IOException, SDIException, RIOException {
return new RIO( parseGeneTrees( gene_trees_file ),
algorithm,
rerooting,
outgroup,
- DEFAULT_RANGE,
- DEFAULT_RANGE,
+ first,
+ last,
produce_log,
verbose );
}
public final static RIO executeAnalysis( final IteratingPhylogenyParser p,
+ final File species_tree_file,
+ final ALGORITHM algorithm,
+ final REROOTING rerooting,
+ final String outgroup,
+ final int first,
+ final int last,
+ final boolean produce_log,
+ final boolean verbose ) throws IOException, SDIException, RIOException {
+ final Phylogeny g0 = p.next();
+ if ( ( g0 == null ) || g0.isEmpty() || ( g0.getNumberOfExternalNodes() < 2 ) ) {
+ throw new RIOException( "input file does not seem to contain any gene trees" );
+ }
+ final Phylogeny species_tree = SDIutil.parseSpeciesTree( g0,
+ species_tree_file,
+ false,
+ true,
+ TAXONOMY_EXTRACTION.NO );
+ p.reset();
+ return new RIO( p, species_tree, algorithm, rerooting, outgroup, first, last, produce_log, verbose );
+ }
+
+ public final static RIO executeAnalysis( final IteratingPhylogenyParser p,
final Phylogeny species_tree,
final ALGORITHM algorithm,
final REROOTING rerooting,
verbose );
}
- public final static RIO executeAnalysis( final File gene_trees_file,
+ public final static RIO executeAnalysis( final IteratingPhylogenyParser p,
final Phylogeny species_tree,
final ALGORITHM algorithm,
final REROOTING rerooting,
final int last,
final boolean produce_log,
final boolean verbose ) throws IOException, SDIException, RIOException {
- return new RIO( parseGeneTrees( gene_trees_file ),
- species_tree,
- algorithm,
- rerooting,
- outgroup,
- first,
- last,
- produce_log,
- verbose );
+ return new RIO( p, species_tree, algorithm, rerooting, outgroup, first, last, produce_log, verbose );
}
public final static RIO executeAnalysis( final Phylogeny[] gene_trees, final Phylogeny species_tree )
return new RIO( gene_trees, species_tree, algorithm, rerooting, outgroup, first, last, produce_log, verbose );
}
- public final static RIO executeAnalysis( final IteratingPhylogenyParser p,
- final Phylogeny species_tree,
- final ALGORITHM algorithm,
- final REROOTING rerooting,
- final String outgroup,
- final int first,
- final int last,
- final boolean produce_log,
- final boolean verbose ) throws IOException, SDIException, RIOException {
- return new RIO( p, species_tree, algorithm, rerooting, outgroup, first, last, produce_log, verbose );
+ private final static void calculateOrthologTable( final Phylogeny g, final boolean sort, final int counter )
+ throws RIOException {
+ if ( counter == 0 ) {
+ final List<String> labels = new ArrayList<String>();
+ final Set<String> labels_set = new HashSet<String>();
+ for( final PhylogenyNode n : g.getExternalNodes() ) {
+ final String label = obtainLabel( labels_set, n );
+ labels_set.add( label );
+ labels.add( label );
+ }
+ if ( sort ) {
+ Collections.sort( labels );
+ }
+ _m = new IntMatrix( labels );
+ }
+ updateCounts( _m, counter, g );
}
- private final static void checkPreconditions( final Phylogeny[] gene_trees,
+ private final static void checkPreconditions( final IteratingPhylogenyParser p,
final Phylogeny species_tree,
final REROOTING rerooting,
final String outgroup,
final int first,
- final int last ) throws RIOException {
+ final int last ) throws RIOException, IOException {
+ final Phylogeny g0 = p.next();
+ if ( ( g0 == null ) || g0.isEmpty() ) {
+ throw new RIOException( "input file does not seem to contain any gene trees" );
+ }
+ if ( g0.getNumberOfExternalNodes() < 2 ) {
+ throw new RIOException( "input file does not seem to contain any useable gene trees" );
+ }
if ( !species_tree.isRooted() ) {
throw new RIOException( "species tree is not rooted" );
}
if ( !( ( last == DEFAULT_RANGE ) && ( first == DEFAULT_RANGE ) )
- && ( ( last < first ) || ( last >= gene_trees.length ) || ( last < 0 ) || ( first < 0 ) ) ) {
+ && ( ( last < first ) || ( last < 0 ) || ( first < 0 ) ) ) {
throw new RIOException( "attempt to set range (0-based) of gene to analyze to: from " + first + " to "
- + last + " (out of " + gene_trees.length + ")" );
+ + last );
}
if ( ( rerooting == REROOTING.OUTGROUP ) && ForesterUtil.isEmpty( outgroup ) ) {
throw new RIOException( "outgroup not set for midpoint rooting" );
if ( ( rerooting != REROOTING.OUTGROUP ) && !ForesterUtil.isEmpty( outgroup ) ) {
throw new RIOException( "outgroup only used for midpoint rooting" );
}
- if ( ( rerooting == REROOTING.MIDPOINT )
- && ( PhylogenyMethods.calculateMaxDistanceToRoot( gene_trees[ 0 ] ) <= 0 ) ) {
+ if ( ( rerooting == REROOTING.MIDPOINT ) && ( PhylogenyMethods.calculateMaxDistanceToRoot( g0 ) <= 0 ) ) {
throw new RIOException( "attempt to use midpoint rooting on gene trees which seem to have no (positive) branch lengths (cladograms)" );
}
if ( rerooting == REROOTING.OUTGROUP ) {
try {
- gene_trees[ 0 ].getNode( outgroup );
+ g0.getNode( outgroup );
}
catch ( final IllegalArgumentException e ) {
throw new RIOException( "cannot perform re-rooting by outgroup: " + e.getLocalizedMessage() );
}
}
- private final static void checkPreconditions( final IteratingPhylogenyParser p,
+ private final static void checkPreconditions( final Phylogeny[] gene_trees,
final Phylogeny species_tree,
final REROOTING rerooting,
final String outgroup,
final int first,
- final int last ) throws RIOException, IOException {
- final Phylogeny g0 = p.next();
- if ( ( g0 == null ) || g0.isEmpty() ) {
- throw new RIOException( "input file does not seem to contain any gene trees" );
- }
- if ( g0.getNumberOfExternalNodes() < 2 ) {
- throw new RIOException( "input file does not seem to contain any useable gene trees" );
- }
+ final int last ) throws RIOException {
if ( !species_tree.isRooted() ) {
throw new RIOException( "species tree is not rooted" );
}
if ( !( ( last == DEFAULT_RANGE ) && ( first == DEFAULT_RANGE ) )
- && ( ( last < first ) || ( last < 0 ) || ( first < 0 ) ) ) {
+ && ( ( last < first ) || ( last >= gene_trees.length ) || ( last < 0 ) || ( first < 0 ) ) ) {
throw new RIOException( "attempt to set range (0-based) of gene to analyze to: from " + first + " to "
- + last );
+ + last + " (out of " + gene_trees.length + ")" );
}
if ( ( rerooting == REROOTING.OUTGROUP ) && ForesterUtil.isEmpty( outgroup ) ) {
throw new RIOException( "outgroup not set for midpoint rooting" );
if ( ( rerooting != REROOTING.OUTGROUP ) && !ForesterUtil.isEmpty( outgroup ) ) {
throw new RIOException( "outgroup only used for midpoint rooting" );
}
- if ( ( rerooting == REROOTING.MIDPOINT ) && ( PhylogenyMethods.calculateMaxDistanceToRoot( g0 ) <= 0 ) ) {
+ if ( ( rerooting == REROOTING.MIDPOINT )
+ && ( PhylogenyMethods.calculateMaxDistanceToRoot( gene_trees[ 0 ] ) <= 0 ) ) {
throw new RIOException( "attempt to use midpoint rooting on gene trees which seem to have no (positive) branch lengths (cladograms)" );
}
if ( rerooting == REROOTING.OUTGROUP ) {
try {
- g0.getNode( outgroup );
+ gene_trees[ 0 ].getNode( outgroup );
}
catch ( final IllegalArgumentException e ) {
throw new RIOException( "cannot perform re-rooting by outgroup: " + e.getLocalizedMessage() );
}
}
+ private final static String obtainLabel( final Set<String> labels_set, final PhylogenyNode n ) throws RIOException {
+ String label;
+ if ( n.getNodeData().isHasSequence() && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
+ label = n.getNodeData().getSequence().getName();
+ }
+ else if ( n.getNodeData().isHasSequence() && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getSymbol() ) ) {
+ label = n.getNodeData().getSequence().getSymbol();
+ }
+ else if ( !ForesterUtil.isEmpty( n.getName() ) ) {
+ label = n.getName();
+ }
+ else {
+ throw new RIOException( "node " + n + " has no appropriate label" );
+ }
+ if ( labels_set.contains( label ) ) {
+ throw new RIOException( "label " + label + " is not unique" );
+ }
+ return label;
+ }
+
private final static Phylogeny[] parseGeneTrees( final File gene_trees_file ) throws FileNotFoundException,
IOException {
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
}
}
+ private final static void updateCounts( final IntMatrix m, final int counter, final Phylogeny g )
+ throws RIOException {
+ PhylogenyMethods.preOrderReId( g );
+ final HashMap<String, PhylogenyNode> map = PhylogenyMethods.createNameToExtNodeMap( g );
+ for( int x = 0; x < m.size(); ++x ) {
+ final String mx = m.getLabel( x );
+ final PhylogenyNode nx = map.get( mx );
+ if ( nx == null ) {
+ throw new RIOException( "node \"" + mx + "\" not present in gene tree #" + counter );
+ }
+ String my;
+ PhylogenyNode ny;
+ for( int y = 0; y < m.size(); ++y ) {
+ my = m.getLabel( y );
+ ny = map.get( my );
+ if ( ny == null ) {
+ throw new RIOException( "node \"" + my + "\" not present in gene tree #" + counter );
+ }
+ if ( !PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( nx, ny ).isDuplication() ) {
+ m.inreaseByOne( x, y );
+ }
+ }
+ }
+ }
+
public enum REROOTING {
NONE, BY_ALGORITHM, MIDPOINT, OUTGROUP;
}
return res;
}
+ final static GSDIsummaryResult geneTreePostOrderTraversal( final Phylogeny gene_tree,
+ final boolean most_parsimonious_duplication_model,
+ final int min_duplications ) throws SDIException {
+ final GSDIsummaryResult res = new GSDIsummaryResult();
+ for( final PhylogenyNodeIterator it = gene_tree.iteratorPostorder(); it.hasNext(); ) {
+ final PhylogenyNode g = it.next();
+ if ( g.isInternal() ) {
+ if ( g.getNumberOfDescendants() != 2 ) {
+ throw new SDIException( "gene tree contains internal node with " + g.getNumberOfDescendants()
+ + " descendents" );
+ }
+ PhylogenyNode s1 = g.getChildNode1().getLink();
+ PhylogenyNode s2 = g.getChildNode2().getLink();
+ while ( s1 != s2 ) {
+ if ( s1.getId() > s2.getId() ) {
+ s1 = s1.getParent();
+ }
+ else {
+ s2 = s2.getParent();
+ }
+ }
+ g.setLink( s1 );
+ determineEvent( s1, g, most_parsimonious_duplication_model, res );
+ if ( res.getDuplicationsSum() > min_duplications ) {
+ return null;
+ }
+ }
+ }
+ return res;
+ }
+
final static NodesLinkingResult linkNodesOfG( final Phylogeny gene_tree,
final Phylogeny species_tree,
final boolean strip_gene_tree,
// g.setLink( null );\r
// }\r
// }\r
- final GSDIsummaryResult gsdi_result = GSDI.geneTreePostOrderTraversal( gene_tree, true );\r
+ final GSDIsummaryResult gsdi_result = GSDI.geneTreePostOrderTraversal( gene_tree,\r
+ true,\r
+ min_duplications_sum );\r
+ if ( gsdi_result == null ) {\r
+ continue;\r
+ }\r
if ( gsdi_result.getDuplicationsSum() < min_duplications_sum ) {\r
min_duplications_sum = gsdi_result.getDuplicationsSum();\r
speciations_sum = gsdi_result.getSpeciationsSum();\r
branches.add( new PhylogenyBranch( t.getRoot().getChildNode1(), t.getRoot().getChildNode2() ) );
return branches;
}
- final Set<Integer> one = new HashSet<Integer>();
- final Set<Integer> two = new HashSet<Integer>();
+ final Set<Long> one = new HashSet<Long>();
+ final Set<Long> two = new HashSet<Long>();
PhylogenyNode node = t.getRoot();
while ( !node.isRoot() || !two.contains( node.getId() ) ) {
if ( !node.isExternal() && !two.contains( node.getId() ) ) {
try {
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
- final int count = PhylogenyNode.getNodeCount();
+ final long count = PhylogenyNode.getNodeCount();
p.levelOrderReID();
if ( p.getNode( "r" ).getId() != count ) {
return false;
phylogeny.reRoot( phylogeny.getNode( child0_name ) );
evaluator_phylogeny.reRoot( evaluator_phylogeny.getNode( child0_name ) );
}
- final Map<Integer, ArrayList<String>> phylogeny_external_names_per_node = SupportCount
+ final Map<Long, ArrayList<String>> phylogeny_external_names_per_node = SupportCount
.extractExternalNamesPerNode( phylogeny );
return ( SupportCount.compare( phylogeny,
evaluator_phylogeny,
*/
private static double compare( final Phylogeny phylogeny,
final Phylogeny evaluator_phylogeny,
- final Map<Integer, ArrayList<String>> phylogeny_external_names_per_node,
+ final Map<Long, ArrayList<String>> phylogeny_external_names_per_node,
final boolean update_support_in_phylogeny,
final double similarity_threshold ) {
int matching_branches = 0;
for( final Object element : evaluator_phylogeny_it.next().getAllExternalDescendants() ) {
c1.add( ( ( PhylogenyNode ) element ).getName() );
}
- for( final Integer id : phylogeny_external_names_per_node.keySet() ) {
+ for( final Long id : phylogeny_external_names_per_node.keySet() ) {
final List<String> c2 = phylogeny_external_names_per_node.get( id );
if ( ( c2.size() == c1.size() ) && c2.containsAll( c1 ) ) {
if ( c2.size() > 1 ) {
}
final String child0_name = phylogeny.getFirstExternalNode().getName();
phylogeny.reRoot( phylogeny.getNode( child0_name ) );
- final Map<Integer, ArrayList<String>> phylogeny_external_names_per_node = SupportCount
+ final Map<Long, ArrayList<String>> phylogeny_external_names_per_node = SupportCount
.extractExternalNamesPerNode( phylogeny );
if ( verbose ) {
System.out.println();
return evaluator_phylogenies_above_threshold;
}
- private static Map<Integer, ArrayList<String>> extractExternalNamesPerNode( final Phylogeny phylogeny )
+ private static Map<Long, ArrayList<String>> extractExternalNamesPerNode( final Phylogeny phylogeny )
throws NoSuchElementException {
- final HashMap<Integer, ArrayList<String>> phylogeny_external_names_per_node = new HashMap<Integer, ArrayList<String>>();
+ final HashMap<Long, ArrayList<String>> phylogeny_external_names_per_node = new HashMap<Long, ArrayList<String>>();
for( final PhylogenyNodeIterator it = phylogeny.iteratorPostorder(); it.hasNext(); ) {
final PhylogenyNode n = it.next();
final List<PhylogenyNode> l = n.getAllExternalDescendants();
final ArrayList<String> c = new ArrayList<String>();
- phylogeny_external_names_per_node.put( new Integer( n.getId() ), c );
+ phylogeny_external_names_per_node.put( new Long( n.getId() ), c );
for( final PhylogenyNode phylogenyNode : l ) {
c.add( phylogenyNode.getName() );
}