- if ( _rerooting == REROOTING.BY_ALGORITHM ) {
- writeLogSubHeader();
- }
- }
-
- private final void writeLogSubHeader() {
- _log.append( ForesterUtil.LINE_SEPARATOR );
- _log.append( "Some information about duplication numbers in gene trees:" );
- _log.append( ForesterUtil.LINE_SEPARATOR );
- _log.append( "#" );
- _log.append( "\t" );
- _log.append( "re-rootings with minimal number of duplications" );
- _log.append( "/" );
- _log.append( "total root placements" );
- _log.append( "\t" );
- _log.append( "duplications range" );
- _log.append( "\t" );
- _log.append( "mininal duplication re-rootings with shortest tree heigth" );
- _log.append( ForesterUtil.LINE_SEPARATOR );
- }
-
- private final void writeStatsToLog( final int i, final GSDIR gsdir, final List<Integer> shortests ) {
- final BasicDescriptiveStatistics stats = gsdir.getDuplicationsSumStats();
- _log.append( i );
- _log.append( "\t" );
- _log.append( gsdir.getMinDuplicationsSumGeneTrees().size() );
- _log.append( "/" );
- _log.append( stats.getN() );
- _log.append( "\t" );
- _log.append( ( int ) stats.getMin() );
- _log.append( "-" );
- _log.append( ( int ) stats.getMax() );
- _log.append( "\t" );
- _log.append( shortests.size() );
- _log.append( ForesterUtil.LINE_SEPARATOR );
- }
-
- 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 );
- }
- }
- }