X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fsdi%2FGSDI.java;h=4caeb72778c089a753e1fa353ffbf6197319dd7b;hb=a29d5642b2f9a3db526f35ca5971c08700963503;hp=f9cc14ea35799ccbcb66a9f4dcbb3f28ae2c0c78;hpb=03001eb3d298d53e97e4194787fa21bcbc43c5d8;p=jalview.git diff --git a/forester/java/src/org/forester/sdi/GSDI.java b/forester/java/src/org/forester/sdi/GSDI.java index f9cc14e..4caeb72 100644 --- a/forester/java/src/org/forester/sdi/GSDI.java +++ b/forester/java/src/org/forester/sdi/GSDI.java @@ -21,7 +21,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA // // Contact: phylosoft @ gmail . com -// WWW: www.phylosoft.org/forester +// WWW: https://sites.google.com/site/cmzmasek/home/software/forester package org.forester.sdi; @@ -59,9 +59,11 @@ public final class GSDI implements GSDII { final boolean strip_gene_tree, final boolean strip_species_tree ) throws SDIException { _most_parsimonious_duplication_model = most_parsimonious_duplication_model; + if ( gene_tree.getRoot().getNumberOfDescendants() == 3 ) { + gene_tree.reRoot( gene_tree.getRoot().getChildNode( 2 ) ); + } final NodesLinkingResult nodes_linking_result = linkNodesOfG( gene_tree, species_tree, - null, strip_gene_tree, strip_species_tree ); _stripped_gene_tree_nodes = nodes_linking_result.getStrippedGeneTreeNodes(); @@ -141,14 +143,20 @@ public final class GSDI implements GSDII { * the species tree must be labeled in preorder. *
* @return
+ * @throws SDIException
*
*/
final static GSDIsummaryResult geneTreePostOrderTraversal( final Phylogeny gene_tree,
- final boolean most_parsimonious_duplication_model ) {
+ final boolean most_parsimonious_duplication_model )
+ 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 ) {
@@ -166,6 +174,48 @@ public final class GSDI implements GSDII {
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,
+ final boolean strip_species_tree ) throws SDIException {
+ final TaxonomyComparisonBase tax_comp_base = SDIutil.determineTaxonomyComparisonBase( gene_tree );
+ if ( tax_comp_base == null ) {
+ throw new RuntimeException( "failed to establish taxonomy linking base (taxonomy linking base is null)" );
+ }
+ return linkNodesOfG( gene_tree, species_tree, tax_comp_base, strip_gene_tree, strip_species_tree );
+ }
+
/**
* This allows for linking of internal nodes of the species tree (as opposed
* to just external nodes, as in the method it overrides.
@@ -178,15 +228,13 @@ public final class GSDI implements GSDII {
final TaxonomyComparisonBase tax_comp_base,
final boolean strip_gene_tree,
final boolean strip_species_tree ) throws SDIException {
+ if ( tax_comp_base == null ) {
+ throw new IllegalArgumentException( "taxonomy linking base is null" );
+ }
final Map