2 // FORESTER -- software libraries and applications
\r
3 // for evolutionary biology research and applications.
\r
5 // Copyright (C) 2008-2013 Christian M. Zmasek
\r
6 // All rights reserved
\r
8 // This library is free software; you can redistribute it and/or
\r
9 // modify it under the terms of the GNU Lesser General Public
\r
10 // License as published by the Free Software Foundation; either
\r
11 // version 2.1 of the License, or (at your option) any later version.
\r
13 // This library is distributed in the hope that it will be useful,
\r
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
16 // Lesser General Public License for more details.
\r
18 // You should have received a copy of the GNU Lesser General Public
\r
19 // License along with this library; if not, write to the Free Software
\r
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
22 // Contact: phylosoft @ gmail . com
\r
23 // WWW: www.phylosoft.org
\r
25 package org.forester.sdi;
\r
27 import java.util.ArrayList;
\r
28 import java.util.List;
\r
30 import org.forester.phylogeny.Phylogeny;
\r
31 import org.forester.phylogeny.PhylogenyBranch;
\r
32 import org.forester.phylogeny.PhylogenyMethods;
\r
33 import org.forester.phylogeny.PhylogenyNode;
\r
34 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
\r
35 import org.forester.util.BasicDescriptiveStatistics;
\r
37 public class GSDIR extends GSDI {
\r
39 private int _min_duplications_sum;
\r
40 private final BasicDescriptiveStatistics _duplications_sum_stats;
\r
41 private final List<Phylogeny> _min_duplications_sum_gene_trees;
\r
43 public GSDIR( final Phylogeny gene_tree,
\r
44 final Phylogeny species_tree,
\r
45 final boolean strip_gene_tree,
\r
46 final boolean strip_species_tree ) throws SDIException {
\r
47 super( gene_tree.copy(), species_tree, strip_gene_tree );
\r
48 linkNodesOfG( null, strip_gene_tree, strip_species_tree );
\r
49 final List<PhylogenyBranch> gene_tree_branches_post_order = new ArrayList<PhylogenyBranch>();
\r
50 for( final PhylogenyNodeIterator it = _gene_tree.iteratorPostorder(); it.hasNext(); ) {
\r
51 final PhylogenyNode n = it.next();
\r
52 if ( !n.isRoot() && !( n.getParent().isRoot() && n.isFirstChildNode() ) ) {
\r
53 gene_tree_branches_post_order.add( new PhylogenyBranch( n, n.getParent() ) );
\r
56 _min_duplications_sum = Integer.MAX_VALUE;
\r
57 _min_duplications_sum_gene_trees = new ArrayList<Phylogeny>();
\r
58 _duplications_sum_stats = new BasicDescriptiveStatistics();
\r
59 for( final PhylogenyBranch branch : gene_tree_branches_post_order ) {
\r
60 _duplications_sum = 0;
\r
61 _speciations_sum = 0;
\r
62 _gene_tree.reRoot( branch );
\r
63 PhylogenyMethods.preOrderReId( getSpeciesTree() );
\r
64 //TEST, remove later
\r
65 // for( final PhylogenyNodeIterator it = _gene_tree.iteratorPostorder(); it.hasNext(); ) {
\r
66 // final PhylogenyNode g = it.next();
\r
67 // if ( g.isInternal() ) {
\r
68 // g.setLink( null );
\r
71 geneTreePostOrderTraversal();
\r
72 if ( _duplications_sum < _min_duplications_sum ) {
\r
73 _min_duplications_sum = _duplications_sum;
\r
74 _min_duplications_sum_gene_trees.clear();
\r
75 _min_duplications_sum_gene_trees.add( getGeneTree().copy() );
\r
77 else if ( _duplications_sum == _min_duplications_sum ) {
\r
78 _min_duplications_sum_gene_trees.add( getGeneTree().copy() );
\r
80 _duplications_sum_stats.addValue( _duplications_sum );
\r
84 public int getMinDuplicationsSum() {
\r
85 return _min_duplications_sum;
\r
88 public List<Phylogeny> getMinDuplicationsSumGeneTrees() {
\r
89 return _min_duplications_sum_gene_trees;
\r
92 public BasicDescriptiveStatistics getDuplicationsSumStats() {
\r
93 return _duplications_sum_stats;
\r