improving GSDI, under construction...
[jalview.git] / forester / java / src / org / forester / sdi / GSDI.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // All rights reserved
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org/forester
25
26 package org.forester.sdi;
27
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.HashSet;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.Set;
34 import java.util.SortedSet;
35 import java.util.TreeSet;
36
37 import org.forester.phylogeny.Phylogeny;
38 import org.forester.phylogeny.PhylogenyNode;
39 import org.forester.phylogeny.data.Event;
40 import org.forester.phylogeny.data.Taxonomy;
41 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
42 import org.forester.util.ForesterUtil;
43
44 /*
45  * Implements our algorithm for speciation - duplication inference (SDI). <p>
46  * The initialization is accomplished by: </p> <ul> <li>method
47  * "linkExtNodesOfG()" of class SDI: setting the links for the external nodes of
48  * the gene tree <li>"preorderReID(int)" from class Phylogeny: numbering of
49  * nodes of the species tree in preorder <li>the optional stripping of the
50  * species tree is accomplished by method "stripTree(Phylogeny,Phylogeny)" of
51  * class Phylogeny </ul> <p> The recursion part is accomplished by this class'
52  * method "geneTreePostOrderTraversal(PhylogenyNode)". <p> Requires JDK 1.5 or
53  * greater.
54  * 
55  * @see SDI#linkNodesOfG()
56  * 
57  * @see Phylogeny#preorderReID(int)
58  * 
59  * @see
60  * PhylogenyMethods#taxonomyBasedDeletionOfExternalNodes(Phylogeny,Phylogeny)
61  * 
62  * @see #geneTreePostOrderTraversal(PhylogenyNode)
63  * 
64  * @author Christian M. Zmasek
65  */
66 public final class GSDI extends SDI {
67
68     private final HashMap<PhylogenyNode, Integer> _transversal_counts;
69     private final boolean                         _most_parsimonious_duplication_model;
70     private final boolean                         _strip_gene_tree;
71     private final boolean                         _strip_species_tree;
72     private int                                   _speciation_or_duplication_events_sum;
73     private int                                   _speciations_sum;
74     private final List<PhylogenyNode>             _stripped_gene_tree_nodes;
75     private final List<PhylogenyNode>             _stripped_species_tree_nodes;
76     private final SortedSet<PhylogenyNode>        _mapped_species_tree_nodes;
77
78     /**
79      * Constructor which sets the gene tree and the species tree to be compared.
80      * species_tree is the species tree to which the gene tree gene_tree will be
81      * compared to - with method "infer(boolean)". Both Trees must be completely
82      * binary and rooted. The actual inference is accomplished with method
83      * "infer(boolean)". The mapping cost L can then be calculated with method
84      * "computeMappingCost()".
85      * <p>
86      * 
87      * @see #infer(boolean)
88      * @see SDI#computeMappingCostL()
89      * @param gene_tree
90      *            reference to a rooted gene tree to which assign duplication vs
91      *            speciation, must have species names in the species name fields
92      *            for all external nodes
93      * @param species_tree
94      *            reference to a rooted binary species tree which might get
95      *            stripped in the process, must have species names in the
96      *            species name fields for all external nodes
97      * 
98      * @param most_parsimonious_duplication_model
99      *            set to true to assign nodes as speciations which would
100      *            otherwise be assiged as unknown because of polytomies in the
101      *            species tree.
102      * @throws SdiException 
103      * 
104      */
105     public GSDI( final Phylogeny gene_tree,
106                  final Phylogeny species_tree,
107                  final boolean most_parsimonious_duplication_model,
108                  final boolean strip_gene_tree,
109                  final boolean strip_species_tree ) throws SdiException {
110         super( gene_tree, species_tree );
111         _speciation_or_duplication_events_sum = 0;
112         _speciations_sum = 0;
113         _most_parsimonious_duplication_model = most_parsimonious_duplication_model;
114         _transversal_counts = new HashMap<PhylogenyNode, Integer>();
115         _duplications_sum = 0;
116         _strip_gene_tree = strip_gene_tree;
117         _strip_species_tree = strip_species_tree;
118         _stripped_gene_tree_nodes = new ArrayList<PhylogenyNode>();
119         _stripped_species_tree_nodes = new ArrayList<PhylogenyNode>();
120         _mapped_species_tree_nodes = new TreeSet<PhylogenyNode>();
121         getSpeciesTree().preOrderReId();
122         linkNodesOfG();
123         geneTreePostOrderTraversal( getGeneTree().getRoot() );
124     }
125
126     GSDI( final Phylogeny gene_tree, final Phylogeny species_tree, final boolean most_parsimonious_duplication_model )
127             throws SdiException {
128         this( gene_tree, species_tree, most_parsimonious_duplication_model, false, false );
129     }
130
131     private final Event createDuplicationEvent() {
132         final Event event = Event.createSingleDuplicationEvent();
133         ++_duplications_sum;
134         return event;
135     }
136
137     private final Event createSingleSpeciationOrDuplicationEvent() {
138         final Event event = Event.createSingleSpeciationOrDuplicationEvent();
139         ++_speciation_or_duplication_events_sum;
140         return event;
141     }
142
143     private final Event createSpeciationEvent() {
144         final Event event = Event.createSingleSpeciationEvent();
145         ++_speciations_sum;
146         return event;
147     }
148
149     // s is the node on the species tree g maps to.
150     private final void determineEvent( final PhylogenyNode s, final PhylogenyNode g ) {
151         Event event = null;
152         // Determine how many children map to same node as parent.
153         int sum_g_childs_mapping_to_s = 0;
154         for( final PhylogenyNodeIterator iter = g.iterateChildNodesForward(); iter.hasNext(); ) {
155             if ( iter.next().getLink() == s ) {
156                 ++sum_g_childs_mapping_to_s;
157             }
158         }
159         // Determine the sum of traversals.
160         int traversals_sum = 0;
161         int max_traversals = 0;
162         PhylogenyNode max_traversals_node = null;
163         if ( !s.isExternal() ) {
164             for( final PhylogenyNodeIterator iter = s.iterateChildNodesForward(); iter.hasNext(); ) {
165                 final PhylogenyNode current_node = iter.next();
166                 final int traversals = getTraversalCount( current_node );
167                 traversals_sum += traversals;
168                 if ( traversals > max_traversals ) {
169                     max_traversals = traversals;
170                     max_traversals_node = current_node;
171                 }
172             }
173         }
174         // System.out.println( " sum=" + traversals_sum );
175         // System.out.println( " max=" + max_traversals );
176         // System.out.println( " m=" + sum_g_childs_mapping_to_s );
177         if ( sum_g_childs_mapping_to_s > 0 ) {
178             if ( traversals_sum == 2 ) {
179                 event = createDuplicationEvent();
180             }
181             else if ( traversals_sum > 2 ) {
182                 if ( max_traversals <= 1 ) {
183                     if ( _most_parsimonious_duplication_model ) {
184                         event = createSpeciationEvent();
185                     }
186                     else {
187                         event = createSingleSpeciationOrDuplicationEvent();
188                     }
189                 }
190                 else {
191                     event = createDuplicationEvent();
192                     _transversal_counts.put( max_traversals_node, 1 );
193                 }
194             }
195             else {
196                 event = createDuplicationEvent();
197             }
198         }
199         else {
200             event = createSpeciationEvent();
201         }
202         g.getNodeData().setEvent( event );
203     }
204
205     /**
206      * Traverses the subtree of PhylogenyNode g in postorder, calculating the
207      * mapping function M, and determines which nodes represent speciation
208      * events and which ones duplication events.
209      * <p>
210      * Preconditions: Mapping M for external nodes must have been calculated and
211      * the species tree must be labeled in preorder.
212      * <p>
213      * 
214      * @param g
215      *            starting node of a gene tree - normally the root
216      */
217     final void geneTreePostOrderTraversal( final PhylogenyNode g ) {
218         if ( !g.isExternal() ) {
219             for( final PhylogenyNodeIterator iter = g.iterateChildNodesForward(); iter.hasNext(); ) {
220                 geneTreePostOrderTraversal( iter.next() );
221             }
222             final PhylogenyNode[] linked_nodes = new PhylogenyNode[ g.getNumberOfDescendants() ];
223             for( int i = 0; i < linked_nodes.length; ++i ) {
224                 if ( g.getChildNode( i ).getLink() == null ) {
225                     System.out.println( "link is null for " + g.getChildNode( i ) );
226                     System.exit( -1 );
227                 }
228                 linked_nodes[ i ] = g.getChildNode( i ).getLink();
229             }
230             final int[] min_max = obtainMinMaxIdIndices( linked_nodes );
231             int min_i = min_max[ 0 ];
232             int max_i = min_max[ 1 ];
233             // initTransversalCounts();
234             while ( linked_nodes[ min_i ] != linked_nodes[ max_i ] ) {
235                 increaseTraversalCount( linked_nodes[ max_i ] );
236                 linked_nodes[ max_i ] = linked_nodes[ max_i ].getParent();
237                 final int[] min_max_ = obtainMinMaxIdIndices( linked_nodes );
238                 min_i = min_max_[ 0 ];
239                 max_i = min_max_[ 1 ];
240             }
241             final PhylogenyNode s = linked_nodes[ max_i ];
242             g.setLink( s );
243             // Determines whether dup. or spec.
244             determineEvent( s, g );
245             // _transversal_counts.clear();
246         }
247     }
248
249     public final int getSpeciationOrDuplicationEventsSum() {
250         return _speciation_or_duplication_events_sum;
251     }
252
253     public final int getSpeciationsSum() {
254         return _speciations_sum;
255     }
256
257     private final int getTraversalCount( final PhylogenyNode node ) {
258         if ( _transversal_counts.containsKey( node ) ) {
259             return _transversal_counts.get( node );
260         }
261         return 0;
262     }
263
264     private final void increaseTraversalCount( final PhylogenyNode node ) {
265         if ( _transversal_counts.containsKey( node ) ) {
266             _transversal_counts.put( node, _transversal_counts.get( node ) + 1 );
267         }
268         else {
269             _transversal_counts.put( node, 1 );
270         }
271         // System.out.println( "count for node " + node.getID() + " is now "
272         // + getTraversalCount( node ) );
273     }
274
275     /**
276      * This allows for linking of internal nodes of the species tree (as opposed
277      * to just external nodes, as in the method it overrides.
278      * @throws SdiException 
279      * 
280      */
281     @Override
282     //    final void linkNodesOfG() {
283     //        final HashMap<Taxonomy, PhylogenyNode> speciestree_ext_nodes = createTaxonomyToNodeMap();
284     //        if ( _strip_gene_tree ) {
285     //            stripGeneTree( speciestree_ext_nodes );
286     //            if ( ( _gene_tree == null ) || ( _gene_tree.getNumberOfExternalNodes() < 2 ) ) {
287     //                throw new IllegalArgumentException( "species tree does not contain any"
288     //                        + " nodes matching species in the gene tree" );
289     //            }
290     //        }
291     //        // Retrieve the reference to the PhylogenyNode with a matching species.
292     //        for( final PhylogenyNodeIterator iter = _gene_tree.iteratorExternalForward(); iter.hasNext(); ) {
293     //            final PhylogenyNode g = iter.next();
294     //            if ( !g.getNodeData().isHasTaxonomy() ) {
295     //                throw new IllegalArgumentException( "gene tree node " + g + " has no taxonomic data" );
296     //            }
297     //            final PhylogenyNode s = speciestree_ext_nodes.get( g.getNodeData().getTaxonomy() );
298     //            if ( s == null ) {
299     //                throw new IllegalArgumentException( "species " + g.getNodeData().getTaxonomy()
300     //                        + " not present in species tree" );
301     //            }
302     //            g.setLink( s );
303     //        }
304     //    }
305     final void linkNodesOfG() throws SdiException {
306         final Map<String, PhylogenyNode> species_to_node_map = new HashMap<String, PhylogenyNode>();
307         final Set<PhylogenyNode> species_tree_ext_nodes = new HashSet<PhylogenyNode>();
308         final TaxonomyComparisonBase tax_comp_base = determineTaxonomyComparisonBase( _gene_tree );
309         System.out.println( "comp base is: " + tax_comp_base );
310         // Stringyfied taxonomy is the key, node is the value.
311         for( final PhylogenyNodeIterator iter = _species_tree.iteratorExternalForward(); iter.hasNext(); ) {
312             final PhylogenyNode s = iter.next();
313             species_tree_ext_nodes.add( s );
314             final String tax_str = taxonomyToString( s, tax_comp_base );
315             if ( !ForesterUtil.isEmpty( tax_str ) ) {
316                 if ( species_to_node_map.containsKey( tax_str ) ) {
317                     throw new SdiException( "taxonomy \"" + s + "\" is not unique in species tree" );
318                 }
319                 species_to_node_map.put( tax_str, s );
320             }
321         }
322         // Retrieve the reference to the node with a matching stringyfied taxonomy.
323         for( final PhylogenyNodeIterator iter = _gene_tree.iteratorExternalForward(); iter.hasNext(); ) {
324             final PhylogenyNode g = iter.next();
325             if ( !g.getNodeData().isHasTaxonomy() ) {
326                 if ( _strip_gene_tree ) {
327                     _stripped_gene_tree_nodes.add( g );
328                 }
329                 else {
330                     throw new SdiException( "gene tree node \"" + g + "\" has no taxonomic data" );
331                 }
332             }
333             else {
334                 final String tax_str = taxonomyToString( g, tax_comp_base );
335                 if ( ForesterUtil.isEmpty( tax_str ) ) {
336                     if ( _strip_gene_tree ) {
337                         _stripped_gene_tree_nodes.add( g );
338                     }
339                     else {
340                         throw new SdiException( "gene tree node \"" + g + "\" has no appropriate taxonomic data" );
341                     }
342                 }
343                 else {
344                     final PhylogenyNode s = species_to_node_map.get( tax_str );
345                     if ( s == null ) {
346                         if ( _strip_gene_tree ) {
347                             _stripped_gene_tree_nodes.add( g );
348                         }
349                         else {
350                             throw new SdiException( "taxonomy \"" + g.getNodeData().getTaxonomy()
351                                     + "\" not present in species tree" );
352                         }
353                     }
354                     else {
355                         g.setLink( s );
356                         _mapped_species_tree_nodes.add( s );
357                         System.out.println( "setting link of " + g + " to " + s );
358                     }
359                 }
360             }
361         } // for loop
362         if ( _strip_gene_tree ) {
363             for( final PhylogenyNode g : _stripped_gene_tree_nodes ) {
364                 _gene_tree.deleteSubtree( g, true );
365             }
366         }
367         if ( _strip_species_tree ) {
368             for( final PhylogenyNode s : species_tree_ext_nodes ) {
369                 if ( !_mapped_species_tree_nodes.contains( s ) ) {
370                     _species_tree.deleteSubtree( s, true );
371                 }
372             }
373         }
374     }
375
376     public SortedSet<PhylogenyNode> getMappedExternalSpeciesTreeNodes() {
377         return _mapped_species_tree_nodes;
378     }
379
380     //    final private HashMap<Taxonomy, PhylogenyNode> createTaxonomyToNodeMap() {
381     //        final HashMap<Taxonomy, PhylogenyNode> speciestree_ext_nodes = new HashMap<Taxonomy, PhylogenyNode>();
382     //        for( final PhylogenyNodeIterator iter = _species_tree.iteratorLevelOrder(); iter.hasNext(); ) {
383     //            final PhylogenyNode n = iter.next();
384     //            if ( n.getNodeData().isHasTaxonomy() ) {
385     //                if ( speciestree_ext_nodes.containsKey( n.getNodeData().getTaxonomy() ) ) {
386     //                    throw new IllegalArgumentException( "taxonomy [" + n.getNodeData().getTaxonomy()
387     //                            + "] is not unique in species phylogeny" );
388     //                }
389     //                speciestree_ext_nodes.put( n.getNodeData().getTaxonomy(), n );
390     //            }
391     //        }
392     //        return speciestree_ext_nodes;
393     //    }
394     //    private final void stripGeneTree( final HashMap<Taxonomy, PhylogenyNode> speciestree_ext_nodes ) {
395     //        //  final Set<PhylogenyNode> to_delete = new HashSet<PhylogenyNode>();
396     //        for( final PhylogenyNodeIterator iter = _gene_tree.iteratorExternalForward(); iter.hasNext(); ) {
397     //            final PhylogenyNode g = iter.next();
398     //            if ( !g.getNodeData().isHasTaxonomy() ) {
399     //                throw new IllegalArgumentException( "gene tree node " + g + " has no taxonomic data" );
400     //            }
401     //            if ( !speciestree_ext_nodes.containsKey( g.getNodeData().getTaxonomy() ) ) {
402     //                _stripped_gene_tree_nodes.add( g );
403     //            }
404     //        }
405     //        for( final PhylogenyNode n : _stripped_gene_tree_nodes ) {
406     //            _gene_tree.deleteSubtree( n, true );
407     //        }
408     //    }
409     //    private final void stripGeneTree2( final HashMap<Taxonomy, PhylogenyNode> speciestree_ext_nodes ) {
410     //        //  final Set<PhylogenyNode> to_delete = new HashSet<PhylogenyNode>();
411     //        for( final PhylogenyNodeIterator iter = _gene_tree.iteratorExternalForward(); iter.hasNext(); ) {
412     //            final PhylogenyNode g = iter.next();
413     //            if ( !g.getNodeData().isHasTaxonomy() ) {
414     //                _stripped_gene_tree_nodes.add( g );
415     //            }
416     //            else {
417     //                if ( !speciestree_ext_nodes.containsKey( g.getNodeData().getTaxonomy() ) ) {
418     //                    _stripped_gene_tree_nodes.add( g );
419     //                }
420     //            }
421     //        }
422     //        for( final PhylogenyNode n : _stripped_gene_tree_nodes ) {
423     //            _gene_tree.deleteSubtree( n, true );
424     //        }
425     //    }
426     public static TaxonomyComparisonBase determineTaxonomyComparisonBase( final Phylogeny gene_tree ) {
427         int with_id_count = 0;
428         int with_code_count = 0;
429         int with_sn_count = 0;
430         int max = 0;
431         for( final PhylogenyNodeIterator iter = gene_tree.iteratorExternalForward(); iter.hasNext(); ) {
432             final PhylogenyNode g = iter.next();
433             if ( g.getNodeData().isHasTaxonomy() ) {
434                 final Taxonomy tax = g.getNodeData().getTaxonomy();
435                 if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) ) {
436                     if ( ++with_id_count > max ) {
437                         max = with_id_count;
438                     }
439                 }
440                 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
441                     if ( ++with_code_count > max ) {
442                         max = with_code_count;
443                     }
444                 }
445                 if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
446                     if ( ++with_sn_count > max ) {
447                         max = with_sn_count;
448                     }
449                 }
450             }
451         }
452         if ( max == 0 ) {
453             throw new IllegalArgumentException( "gene tree has no taxonomic data" );
454         }
455         else if ( max == 1 ) {
456             throw new IllegalArgumentException( "gene tree has only one node with taxonomic data" );
457         }
458         else if ( max == with_sn_count ) {
459             return SDI.TaxonomyComparisonBase.SCIENTIFIC_NAME;
460         }
461         else if ( max == with_id_count ) {
462             return SDI.TaxonomyComparisonBase.ID;
463         }
464         else {
465             return SDI.TaxonomyComparisonBase.CODE;
466         }
467     }
468
469     public List<PhylogenyNode> getStrippedExternalGeneTreeNodes() {
470         return _stripped_gene_tree_nodes;
471     }
472
473     @Override
474     public final String toString() {
475         final StringBuffer sb = new StringBuffer();
476         sb.append( "Most parsimonious duplication model: " + _most_parsimonious_duplication_model );
477         sb.append( ForesterUtil.getLineSeparator() );
478         sb.append( "Speciations sum                    : " + getSpeciationsSum() );
479         sb.append( ForesterUtil.getLineSeparator() );
480         sb.append( "Duplications sum                   : " + getDuplicationsSum() );
481         sb.append( ForesterUtil.getLineSeparator() );
482         if ( !_most_parsimonious_duplication_model ) {
483             sb.append( "Speciation or duplications sum     : " + getSpeciationOrDuplicationEventsSum() );
484             sb.append( ForesterUtil.getLineSeparator() );
485         }
486         sb.append( "mapping cost L                     : " + computeMappingCostL() );
487         return sb.toString();
488     }
489
490     static final int[] obtainMinMaxIdIndices( final PhylogenyNode[] linked_nodes ) {
491         int max_i = 0;
492         int min_i = 0;
493         int max_i_id = -Integer.MAX_VALUE;
494         int min_i_id = Integer.MAX_VALUE;
495         for( int i = 0; i < linked_nodes.length; ++i ) {
496             final int id_i = linked_nodes[ i ].getId();
497             if ( id_i > max_i_id ) {
498                 max_i = i;
499                 max_i_id = linked_nodes[ max_i ].getId();
500             }
501             if ( id_i < min_i_id ) {
502                 min_i = i;
503                 min_i_id = linked_nodes[ min_i ].getId();
504             }
505         }
506         return new int[] { min_i, max_i };
507     }
508     /**
509      * Updates the mapping function M after the root of the gene tree has been
510      * moved by one branch. It calculates M for the root of the gene tree and
511      * one of its two children.
512      * <p>
513      * To be used ONLY by method "SDIunrooted.fastInfer(Phylogeny,Phylogeny)".
514      * <p>
515      * (Last modfied: )
516      * 
517      * @param prev_root_was_dup
518      *            true if the previous root was a duplication, false otherwise
519      * @param prev_root_c1
520      *            child 1 of the previous root
521      * @param prev_root_c2
522      *            child 2 of the previous root
523      * @return number of duplications which have been assigned in gene tree
524      */
525     // int updateM( final boolean prev_root_was_dup,
526     // final PhylogenyNode prev_root_c1, final PhylogenyNode prev_root_c2 ) {
527     // final PhylogenyNode root = getGeneTree().getRoot();
528     // if ( ( root.getChildNode1() == prev_root_c1 )
529     // || ( root.getChildNode2() == prev_root_c1 ) ) {
530     // calculateMforNode( prev_root_c1 );
531     // }
532     // else {
533     // calculateMforNode( prev_root_c2 );
534     // }
535     // Event event = null;
536     // if ( prev_root_was_dup ) {
537     // event = Event.createSingleDuplicationEvent();
538     // }
539     // else {
540     // event = Event.createSingleSpeciationEvent();
541     // }
542     // root.getPhylogenyNodeData().setEvent( event );
543     // calculateMforNode( root );
544     // return getDuplications();
545     // } // updateM( boolean, PhylogenyNode, PhylogenyNode )
546     // Helper method for updateM( boolean, PhylogenyNode, PhylogenyNode )
547     // Calculates M for PhylogenyNode n, given that M for the two children
548     // of n has been calculated.
549     // (Last modified: 10/02/01)
550     // private void calculateMforNode( final PhylogenyNode n ) {
551     // if ( !n.isExternal() ) {
552     // boolean was_duplication = n.isDuplication();
553     // PhylogenyNode a = n.getChildNode1().getLink(), b = n
554     // .getChildNode2().getLink();
555     // while ( a != b ) {
556     // if ( a.getID() > b.getID() ) {
557     // a = a.getParent();
558     // }
559     // else {
560     // b = b.getParent();
561     // }
562     // }
563     // n.setLink( a );
564     // Event event = null;
565     // if ( ( a == n.getChildNode1().getLink() )
566     // || ( a == n.getChildNode2().getLink() ) ) {
567     // event = Event.createSingleDuplicationEvent();
568     // if ( !was_duplication ) {
569     // increaseDuplications();
570     // }
571     // }
572     // else {
573     // event = Event.createSingleSpeciationEvent();
574     // if ( was_duplication ) {
575     // decreaseDuplications();
576     // }
577     // }
578     // n.getPhylogenyNodeData().setEvent( event );
579     // }
580     // } // calculateMforNode( PhylogenyNode )
581 }