X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fsdi%2FGSDIR.java;h=651383d424183139b07d68dd4d4e5e3c9779be6e;hb=c0439ed8b088887ffea2faf11bc7897333287cb3;hp=6b170d99159f2f450982b298842479ae7fa8f212;hpb=49d24119c8c55614fb78fba64333c02d3b4c52ae;p=jalview.git diff --git a/forester/java/src/org/forester/sdi/GSDIR.java b/forester/java/src/org/forester/sdi/GSDIR.java index 6b170d9..651383d 100644 --- a/forester/java/src/org/forester/sdi/GSDIR.java +++ b/forester/java/src/org/forester/sdi/GSDIR.java @@ -52,7 +52,8 @@ public class GSDIR implements GSDII { public GSDIR( final Phylogeny gene_tree, final Phylogeny species_tree, final boolean strip_gene_tree, - final boolean strip_species_tree ) throws SDIException { + final boolean strip_species_tree, + final boolean transfer_taxonomy ) throws SDIException { final NodesLinkingResult nodes_linking_result = GSDI.linkNodesOfG( gene_tree, species_tree, strip_gene_tree, @@ -72,7 +73,7 @@ public class GSDIR implements GSDII { } if ( gene_tree.getRoot().getNumberOfDescendants() == 2 ) { gene_tree_branches_post_order.add( new PhylogenyBranch( gene_tree.getRoot().getChildNode1(), gene_tree - .getRoot().getChildNode2() ) ); + .getRoot().getChildNode2() ) ); } int min_duplications_sum = Integer.MAX_VALUE; int speciations_sum = 0; @@ -80,7 +81,6 @@ public class GSDIR implements GSDII { for( final PhylogenyBranch branch : gene_tree_branches_post_order ) { reRoot( branch, gene_tree ); PhylogenyMethods.preOrderReId( species_tree ); - final GSDIsummaryResult gsdi_result = GSDI.geneTreePostOrderTraversal( gene_tree, true, min_duplications_sum ); @@ -91,6 +91,9 @@ public class GSDIR implements GSDII { min_duplications_sum = gsdi_result.getDuplicationsSum(); speciations_sum = gsdi_result.getSpeciationsSum(); _min_duplications_sum_gene_tree = gene_tree.copy(); + if ( transfer_taxonomy ) { + transferTaxonomy( _min_duplications_sum_gene_tree ); + } } else if ( gsdi_result.getDuplicationsSum() == min_duplications_sum ) { final List l = new ArrayList(); @@ -99,6 +102,9 @@ public class GSDIR implements GSDII { final int index = getIndexesOfShortestTree( l ).get( 0 ); if ( index == 1 ) { _min_duplications_sum_gene_tree = gene_tree.copy(); + if ( transfer_taxonomy ) { + transferTaxonomy( _min_duplications_sum_gene_tree ); + } } } _duplications_sum_stats.addValue( gsdi_result.getDuplicationsSum() ); @@ -182,7 +188,7 @@ public class GSDIR implements GSDII { /** * Places the root of this Phylogeny on Branch b. The new root is always * placed on the middle of the branch b. - * + * */ static final void reRoot( final PhylogenyBranch b, final Phylogeny phy ) { final PhylogenyNode n1 = b.getFirstNode(); @@ -202,10 +208,16 @@ public class GSDIR implements GSDII { // else if ( ( n1.getParent() != null ) && n1.getParent().isRoot() // && ( ( n1.getParent().getChildNode1() == n2 ) || ( n1.getParent().getChildNode2() == n2 ) ) ) { // phy.reRoot( n1 ); - // + // // } else { throw new IllegalArgumentException( "reRoot( Branch b ): b is not a branch." ); } } + + private final static void transferTaxonomy( final Phylogeny gt ) { + for( final PhylogenyNodeIterator it = gt.iteratorPostorder(); it.hasNext(); ) { + GSDI.transferTaxonomy( it.next() ); + } + } }