32a725b35ad56bb77bac158ec2255116db03b631
[jalview.git] / forester / java / src / org / forester / sdi / TestGSDI.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.io.IOException;
29
30 import org.forester.archaeopteryx.Archaeopteryx;
31 import org.forester.development.DevelopmentTools;
32 import org.forester.io.parsers.nhx.NHXParser;
33 import org.forester.phylogeny.Phylogeny;
34 import org.forester.phylogeny.PhylogenyMethods;
35 import org.forester.phylogeny.data.Event;
36 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
37 import org.forester.phylogeny.factories.PhylogenyFactory;
38
39 public final class TestGSDI {
40
41     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
42         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
43         p.setRooted( true );
44         return p;
45     }
46
47     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
48         return PhylogenyMethods.getInstance().obtainLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
49     }
50
51     public static boolean test() {
52         if ( !TestGSDI.testGSDI_general() ) {
53             return false;
54         }
55         if ( !TestGSDI.testGSDI_against_binary_gene_tree() ) {
56             return false;
57         }
58         return true;
59     }
60
61     private static boolean testGSDI_against_binary_gene_tree() {
62         try {
63             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
64             final String multi_species_2_str = "(((((([&&NHX:S=1],[&&NHX:S=2]),"
65                     + "([&&NHX:S=3],[&&NHX:S=4],[&&NHX:S=5])),"
66                     + "([&&NHX:S=6],[&&NHX:S=7],[&&NHX:S=8],[&&NHX:S=9])),"
67                     + "([&&NHX:S=10],[&&NHX:S=11])),"
68                     + "([&&NHX:S=12],[&&NHX:S=13],[&&NHX:S=14])),"
69                     + "([&&NHX:S=15],([&&NHX:S=16],[&&NHX:S=17]),([&&NHX:S=18],[&&NHX:S=19],[&&NHX:S=20]),([&&NHX:S=21],[&&NHX:S=22],[&&NHX:S=23],[&&NHX:S=24])));";
70             final String gene_2_1_str = "(((((([&&NHX:S=1],[&&NHX:S=2])1_2,([&&NHX:S=3],[&&NHX:S=4])),"
71                     + "([&&NHX:S=6],[&&NHX:S=7])6_7_8_9)1_9,([&&NHX:S=10],[&&NHX:S=11])),"
72                     + "([&&NHX:S=12],[&&NHX:S=13])12_13_14)1_14,"
73                     + "([&&NHX:S=15],([&&NHX:S=21],[&&NHX:S=24])21_22_23_24)15_24);";
74             final Phylogeny multi_species_2 = factory.create( multi_species_2_str, new NHXParser() )[ 0 ];
75             final Phylogeny gene_2_1 = factory.create( gene_2_1_str, new NHXParser() )[ 0 ];
76             multi_species_2.setRooted( true );
77             gene_2_1.setRooted( true );
78             final GSDI sdi = new GSDI( gene_2_1, multi_species_2, false );
79             if ( sdi.getSpeciationOrDuplicationEventsSum() != 0 ) {
80                 return false;
81             }
82             if ( sdi.getDuplicationsSum() != 0 ) {
83                 return false;
84             }
85         }
86         catch ( final Exception e ) {
87             e.printStackTrace( System.out );
88             return false;
89         }
90         return true;
91     }
92
93     private static boolean testGSDI_general() {
94         try {
95             final PhylogenyMethods pm = PhylogenyMethods.getInstance();
96             final String s2_ = "((" + "([&&NHX:S=a1],[&&NHX:S=a2],[&&NHX:S=a3],[&&NHX:S=a4]),"
97                     + "([&&NHX:S=b1],[&&NHX:S=b2],[&&NHX:S=b3],[&&NHX:S=b4]),"
98                     + "([&&NHX:S=c1],[&&NHX:S=c2],[&&NHX:S=c3],[&&NHX:S=c4]),"
99                     + "([&&NHX:S=d1],[&&NHX:S=d2],[&&NHX:S=d3],[&&NHX:S=d4])),("
100                     + "([&&NHX:S=e1],[&&NHX:S=e2],[&&NHX:S=e3],[&&NHX:S=e4]),"
101                     + "([&&NHX:S=f1],[&&NHX:S=f2],[&&NHX:S=f3],[&&NHX:S=f4]),"
102                     + "([&&NHX:S=g1],[&&NHX:S=g2],[&&NHX:S=g3],[&&NHX:S=g4]),"
103                     + "([&&NHX:S=h1],[&&NHX:S=h2],[&&NHX:S=h3],[&&NHX:S=h4])),("
104                     + "([&&NHX:S=i1],[&&NHX:S=i2],[&&NHX:S=i3],[&&NHX:S=i4]),"
105                     + "([&&NHX:S=j1],[&&NHX:S=j2],[&&NHX:S=j3],[&&NHX:S=j4]),"
106                     + "([&&NHX:S=k1],[&&NHX:S=k2],[&&NHX:S=k3],[&&NHX:S=k4]),"
107                     + "([&&NHX:S=l1],[&&NHX:S=l2],[&&NHX:S=l3],[&&NHX:S=l4])),("
108                     + "([&&NHX:S=m1],[&&NHX:S=m2],[&&NHX:S=m3],[&&NHX:S=m4]),"
109                     + "([&&NHX:S=n1],[&&NHX:S=n2],[&&NHX:S=n3],[&&NHX:S=n4]),"
110                     + "([&&NHX:S=o1],[&&NHX:S=o2],[&&NHX:S=o3],[&&NHX:S=o4]),"
111                     + "([&&NHX:S=p1],[&&NHX:S=p2],[&&NHX:S=p3],[&&NHX:S=p4])"
112                     + "),[&&NHX:S=x],[&&NHX:S=y],[&&NHX:S=z])";
113             final Phylogeny s2 = ParserBasedPhylogenyFactory.getInstance().create( s2_, new NHXParser() )[ 0 ];
114             s2.setRooted( true );
115             final String s1_ = "((([&&NHX:S=A2],[&&NHX:S=A1]),[&&NHX:S=B],[&&NHX:S=C]),[&&NHX:S=D])";
116             final Phylogeny s1 = ParserBasedPhylogenyFactory.getInstance().create( s1_, new NHXParser() )[ 0 ];
117             s1.setRooted( true );
118             final Phylogeny g1 = TestGSDI
119                     .createPhylogeny( "((((B[&&NHX:S=B],A1[&&NHX:S=A1]),C[&&NHX:S=C]),A2[&&NHX:S=A2]),D[&&NHX:S=D])" );
120             final GSDI sdi1 = new GSDI( g1, s1, false );
121             // Archaeopteryx.createApplication( g1 );
122             // Archaeopteryx.createApplication( s1 );
123             if ( sdi1.getDuplicationsSum() != 1 ) {
124                 return false;
125             }
126             if ( !pm.obtainLCA( g1.getNode( "B" ), g1.getNode( "A1" ) ).getNodeData().getEvent().isSpeciation() ) {
127                 return false;
128             }
129             if ( !pm.obtainLCA( g1.getNode( "C" ), g1.getNode( "A1" ) ).getNodeData().getEvent()
130                     .isSpeciationOrDuplication() ) {
131                 return false;
132             }
133             if ( !( pm.obtainLCA( g1.getNode( "A2" ), g1.getNode( "A1" ) ).getNodeData().getEvent().isDuplication() ) ) {
134                 return false;
135             }
136             if ( !pm.obtainLCA( g1.getNode( "D" ), g1.getNode( "A1" ) ).getNodeData().getEvent().isSpeciation() ) {
137                 return false;
138             }
139             final Phylogeny g2 = TestGSDI
140                     .createPhylogeny( "((((A2[&&NHX:S=A2],A1[&&NHX:S=A1]),B[&&NHX:S=B]),C[&&NHX:S=C]),D[&&NHX:S=D])" );
141             final GSDI sdi2 = new GSDI( g2, s1, false );
142             if ( sdi2.getDuplicationsSum() != 0 ) {
143                 return false;
144             }
145             if ( !pm.obtainLCA( g2.getNode( "A1" ), g2.getNode( "A2" ) ).getNodeData().getEvent().isSpeciation() ) {
146                 return false;
147             }
148             if ( !pm.obtainLCA( g2.getNode( "A1" ), g2.getNode( "B" ) ).getNodeData().getEvent().isSpeciation() ) {
149                 return false;
150             }
151             if ( !pm.obtainLCA( g2.getNode( "A1" ), g2.getNode( "C" ) ).getNodeData().getEvent()
152                     .isSpeciationOrDuplication() ) {
153                 return false;
154             }
155             if ( !pm.obtainLCA( g2.getNode( "A1" ), g2.getNode( "D" ) ).getNodeData().getEvent().isSpeciation() ) {
156                 return false;
157             }
158             final Phylogeny g3 = TestGSDI
159                     .createPhylogeny( "((((A2[&&NHX:S=A2],A1[&&NHX:S=A1]),C[&&NHX:S=C]),B[&&NHX:S=B]),D[&&NHX:S=D])" );
160             final GSDI sdi3 = new GSDI( g3, s1, false );
161             if ( sdi3.getDuplicationsSum() != 0 ) {
162                 return false;
163             }
164             if ( !pm.obtainLCA( g3.getNode( "A1" ), g3.getNode( "A2" ) ).getNodeData().getEvent().isSpeciation() ) {
165                 return false;
166             }
167             if ( !pm.obtainLCA( g3.getNode( "A1" ), g3.getNode( "C" ) ).getNodeData().getEvent().isSpeciation() ) {
168                 return false;
169             }
170             if ( !pm.obtainLCA( g3.getNode( "A1" ), g3.getNode( "B" ) ).getNodeData().getEvent()
171                     .isSpeciationOrDuplication() ) {
172                 return false;
173             }
174             if ( !pm.obtainLCA( g3.getNode( "A1" ), g3.getNode( "D" ) ).getNodeData().getEvent().isSpeciation() ) {
175                 return false;
176             }
177             final Phylogeny g4 = TestGSDI
178                     .createPhylogeny( "(((B[&&NHX:S=B],C1[&&NHX:S=C]),C2[&&NHX:S=C]),D[&&NHX:S=D])" );
179             final GSDI sdi4 = new GSDI( g4, s1, false );
180             if ( sdi4.getDuplicationsSum() != 1 ) {
181                 return false;
182             }
183             if ( !pm.obtainLCA( g4.getNode( "B" ), g4.getNode( "C1" ) ).getNodeData().getEvent().isSpeciation() ) {
184                 return false;
185             }
186             if ( !pm.obtainLCA( g4.getNode( "B" ), g4.getNode( "C2" ) ).getNodeData().getEvent().isDuplication() ) {
187                 return false;
188             }
189             if ( !pm.obtainLCA( g4.getNode( "B" ), g4.getNode( "D" ) ).getNodeData().getEvent().isSpeciation() ) {
190                 return false;
191             }
192             final Phylogeny g5 = TestGSDI
193                     .createPhylogeny( "(((D1[&&NHX:S=D],A1[&&NHX:S=A1]),B[&&NHX:S=B]),((D2[&&NHX:S=D],D3[&&NHX:S=D]),C[&&NHX:S=C]))" );
194             final GSDI sdi5 = new GSDI( g5, s1, false );
195             if ( sdi5.getDuplicationsSum() != 3 ) {
196                 return false;
197             }
198             if ( !pm.obtainLCA( g5.getNode( "D1" ), g5.getNode( "A1" ) ).getNodeData().getEvent().isSpeciation() ) {
199                 return false;
200             }
201             if ( !pm.obtainLCA( g5.getNode( "D1" ), g5.getNode( "B" ) ).getNodeData().getEvent().isDuplication() ) {
202                 return false;
203             }
204             if ( !pm.obtainLCA( g5.getNode( "D1" ), g5.getNode( "D2" ) ).getNodeData().getEvent().isDuplication() ) {
205                 return false;
206             }
207             if ( !pm.obtainLCA( g5.getNode( "D2" ), g5.getNode( "D3" ) ).getNodeData().getEvent().isDuplication() ) {
208                 return false;
209             }
210             if ( !pm.obtainLCA( g5.getNode( "C" ), g5.getNode( "D3" ) ).getNodeData().getEvent().isSpeciation() ) {
211                 return false;
212             }
213             final Phylogeny species7 = TestGSDI.createPhylogeny( "(((((((([&&NHX:S=a1],[&&NHX:S=a2]),"
214                     + "([&&NHX:S=b1],[&&NHX:S=b2])),[&&NHX:S=x]),(([&&NHX:S=m1],[&&NHX:S=m2]),"
215                     + "([&&NHX:S=n1],[&&NHX:S=n2]))),(([&&NHX:S=i1],[&&NHX:S=i2]),"
216                     + "([&&NHX:S=j1],[&&NHX:S=j2]))),(([&&NHX:S=e1],[&&NHX:S=e2]),"
217                     + "([&&NHX:S=f1],[&&NHX:S=f2]))),[&&NHX:S=y]),[&&NHX:S=z])" );
218             final Phylogeny gene7_2 = TestGSDI
219                     .createPhylogeny( "(((((((((a1[&&NHX:S=a1],a2[&&NHX:S=a2]),b1[&&NHX:S=b1]),x[&&NHX:S=x]),m1[&&NHX:S=m1]),i1[&&NHX:S=i1]),j2[&&NHX:S=j2]),e1[&&NHX:S=e1]),y[&&NHX:S=y]),z[&&NHX:S=z])" );
220             gene7_2.setRooted( true );
221             final GSDI sdi7_2 = new GSDI( gene7_2, species7, false );
222             if ( sdi7_2.getDuplicationsSum() != 1 ) {
223                 return false;
224             }
225             if ( !TestGSDI.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
226                 return false;
227             }
228             if ( !TestGSDI.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
229                 return false;
230             }
231             if ( !TestGSDI.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
232                 return false;
233             }
234             if ( !TestGSDI.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
235                 return false;
236             }
237             if ( !TestGSDI.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
238                 return false;
239             }
240             if ( !TestGSDI.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
241                 return false;
242             }
243             if ( !TestGSDI.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
244                 return false;
245             }
246             if ( !TestGSDI.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
247                 return false;
248             }
249             if ( !TestGSDI.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
250                 return false;
251             }
252             final Phylogeny g2_0 = TestGSDI.createPhylogeny( "(m1[&&NHX:S=m1],m3[&&NHX:S=m3])" );
253             final GSDI sdi2_0 = new GSDI( g2_0, s2, false );
254             if ( sdi2_0.getDuplicationsSum() != 0 ) {
255                 return false;
256             }
257             if ( sdi2_0.getSpeciationOrDuplicationEventsSum() != 0 ) {
258                 return false;
259             }
260             if ( sdi2_0.getSpeciationsSum() != 1 ) {
261                 return false;
262             }
263             if ( !pm.obtainLCA( g2_0.getNode( "m1" ), g2_0.getNode( "m3" ) ).getNodeData().getEvent().isSpeciation() ) {
264                 return false;
265             }
266             final Phylogeny g2_1 = TestGSDI.createPhylogeny( "(e2[&&NHX:S=e2],h2[&&NHX:S=h2])" );
267             final GSDI sdi2_1 = new GSDI( g2_1, s2, false );
268             if ( sdi2_1.getDuplicationsSum() != 0 ) {
269                 return false;
270             }
271             if ( sdi2_1.getSpeciationOrDuplicationEventsSum() != 0 ) {
272                 return false;
273             }
274             if ( sdi2_1.getSpeciationsSum() != 1 ) {
275                 return false;
276             }
277             if ( !pm.obtainLCA( g2_1.getNode( "e2" ), g2_1.getNode( "h2" ) ).getNodeData().getEvent().isSpeciation() ) {
278                 return false;
279             }
280             final Phylogeny g2_2 = TestGSDI.createPhylogeny( "(e2[&&NHX:S=e2],p4[&&NHX:S=p4])" );
281             final GSDI sdi2_2 = new GSDI( g2_2, s2, false );
282             if ( sdi2_2.getDuplicationsSum() != 0 ) {
283                 return false;
284             }
285             if ( sdi2_2.getSpeciationOrDuplicationEventsSum() != 0 ) {
286                 return false;
287             }
288             if ( sdi2_2.getSpeciationsSum() != 1 ) {
289                 return false;
290             }
291             if ( !pm.obtainLCA( g2_2.getNode( "e2" ), g2_2.getNode( "p4" ) ).getNodeData().getEvent().isSpeciation() ) {
292                 return false;
293             }
294             final Phylogeny g2_3 = TestGSDI.createPhylogeny( "(e2a[&&NHX:S=e2],e2b[&&NHX:S=e2])" );
295             final GSDI sdi2_3 = new GSDI( g2_3, s2, false );
296             if ( sdi2_3.getDuplicationsSum() != 1 ) {
297                 return false;
298             }
299             if ( sdi2_3.getSpeciationOrDuplicationEventsSum() != 0 ) {
300                 return false;
301             }
302             if ( sdi2_3.getSpeciationsSum() != 0 ) {
303                 return false;
304             }
305             if ( !pm.obtainLCA( g2_3.getNode( "e2a" ), g2_3.getNode( "e2b" ) ).getNodeData().getEvent().isDuplication() ) {
306                 return false;
307             }
308             final Phylogeny g2_4 = TestGSDI.createPhylogeny( "((j1[&&NHX:S=j1],j4[&&NHX:S=j4]),i3[&&NHX:S=i3])" );
309             final GSDI sdi2_4 = new GSDI( g2_4, s2, false );
310             if ( sdi2_4.getDuplicationsSum() != 0 ) {
311                 return false;
312             }
313             if ( sdi2_4.getSpeciationOrDuplicationEventsSum() != 0 ) {
314                 return false;
315             }
316             if ( sdi2_4.getSpeciationsSum() != 2 ) {
317                 return false;
318             }
319             if ( !pm.obtainLCA( g2_4.getNode( "j1" ), g2_4.getNode( "j4" ) ).getNodeData().getEvent().isSpeciation() ) {
320                 return false;
321             }
322             if ( !pm.obtainLCA( g2_4.getNode( "j1" ), g2_4.getNode( "i3" ) ).getNodeData().getEvent().isSpeciation() ) {
323                 return false;
324             }
325             final Phylogeny g2_5 = TestGSDI.createPhylogeny( "((j1[&&NHX:S=j1],j4[&&NHX:S=j4]),f3[&&NHX:S=f3])" );
326             final GSDI sdi2_5 = new GSDI( g2_5, s2, false );
327             if ( sdi2_5.getDuplicationsSum() != 0 ) {
328                 return false;
329             }
330             if ( sdi2_5.getSpeciationOrDuplicationEventsSum() != 0 ) {
331                 return false;
332             }
333             if ( sdi2_5.getSpeciationsSum() != 2 ) {
334                 return false;
335             }
336             if ( !pm.obtainLCA( g2_5.getNode( "j1" ), g2_5.getNode( "j4" ) ).getNodeData().getEvent().isSpeciation() ) {
337                 return false;
338             }
339             if ( !pm.obtainLCA( g2_5.getNode( "j1" ), g2_5.getNode( "f3" ) ).getNodeData().getEvent().isSpeciation() ) {
340                 return false;
341             }
342             final Phylogeny g2_6 = TestGSDI.createPhylogeny( "((j3[&&NHX:S=j3],i4[&&NHX:S=i4]),f3[&&NHX:S=f3])" );
343             final GSDI sdi2_6 = new GSDI( g2_6, s2, false );
344             if ( sdi2_6.getDuplicationsSum() != 0 ) {
345                 return false;
346             }
347             if ( sdi2_6.getSpeciationOrDuplicationEventsSum() != 0 ) {
348                 return false;
349             }
350             if ( sdi2_6.getSpeciationsSum() != 2 ) {
351                 return false;
352             }
353             if ( !pm.obtainLCA( g2_6.getNode( "j3" ), g2_6.getNode( "i4" ) ).getNodeData().getEvent().isSpeciation() ) {
354                 return false;
355             }
356             if ( !pm.obtainLCA( g2_6.getNode( "j3" ), g2_6.getNode( "f3" ) ).getNodeData().getEvent().isSpeciation() ) {
357                 return false;
358             }
359             final Phylogeny g2_7 = TestGSDI.createPhylogeny( "((j1[&&NHX:S=j1],k1[&&NHX:S=k1]),i1[&&NHX:S=i1])" );
360             final GSDI sdi2_7 = new GSDI( g2_7, s2, false );
361             if ( sdi2_7.getDuplicationsSum() != 0 ) {
362                 return false;
363             }
364             if ( sdi2_7.getSpeciationOrDuplicationEventsSum() != 1 ) {
365                 return false;
366             }
367             if ( sdi2_7.getSpeciationsSum() != 1 ) {
368                 return false;
369             }
370             if ( !pm.obtainLCA( g2_7.getNode( "j1" ), g2_7.getNode( "k1" ) ).getNodeData().getEvent().isSpeciation() ) {
371                 return false;
372             }
373             if ( !pm.obtainLCA( g2_7.getNode( "j1" ), g2_7.getNode( "i1" ) ).getNodeData().getEvent()
374                     .isSpeciationOrDuplication() ) {
375                 return false;
376             }
377             final Phylogeny g2_8 = TestGSDI.createPhylogeny( "(j1[&&NHX:S=j1],(k1[&&NHX:S=k1],i1[&&NHX:S=i1]))" );
378             final GSDI sdi2_8 = new GSDI( g2_8, s2, false );
379             if ( sdi2_8.getDuplicationsSum() != 0 ) {
380                 return false;
381             }
382             if ( sdi2_8.getSpeciationOrDuplicationEventsSum() != 1 ) {
383                 return false;
384             }
385             if ( sdi2_8.getSpeciationsSum() != 1 ) {
386                 return false;
387             }
388             if ( !pm.obtainLCA( g2_8.getNode( "j1" ), g2_8.getNode( "k1" ) ).getNodeData().getEvent()
389                     .isSpeciationOrDuplication() ) {
390                 return false;
391             }
392             if ( !pm.obtainLCA( g2_8.getNode( "k1" ), g2_8.getNode( "i1" ) ).getNodeData().getEvent().isSpeciation() ) {
393                 return false;
394             }
395             final Phylogeny g2_9 = TestGSDI.createPhylogeny( "((j1[&&NHX:S=j1],k4[&&NHX:S=k4]),f2[&&NHX:S=f2])" );
396             final GSDI sdi2_9 = new GSDI( g2_9, s2, false );
397             if ( sdi2_9.getDuplicationsSum() != 0 ) {
398                 return false;
399             }
400             if ( sdi2_9.getSpeciationOrDuplicationEventsSum() != 0 ) {
401                 return false;
402             }
403             if ( sdi2_9.getSpeciationsSum() != 2 ) {
404                 return false;
405             }
406             if ( !TestGSDI.getEvent( g2_9, "j1", "k4" ).isSpeciation() ) {
407                 return false;
408             }
409             if ( !TestGSDI.getEvent( g2_9, "j1", "f2" ).isSpeciation() ) {
410                 return false;
411             }
412             final Phylogeny g2_10 = TestGSDI.createPhylogeny( "((m1[&&NHX:S=m1],k4[&&NHX:S=k4]),f2[&&NHX:S=f2])" );
413             final GSDI sdi2_10 = new GSDI( g2_10, s2, false );
414             if ( sdi2_10.getDuplicationsSum() != 0 ) {
415                 return false;
416             }
417             if ( sdi2_10.getSpeciationOrDuplicationEventsSum() != 1 ) {
418                 return false;
419             }
420             if ( sdi2_10.getSpeciationsSum() != 1 ) {
421                 return false;
422             }
423             if ( !TestGSDI.getEvent( g2_10, "m1", "k4" ).isSpeciation() ) {
424                 return false;
425             }
426             if ( !TestGSDI.getEvent( g2_10, "m1", "f2" ).isSpeciationOrDuplication() ) {
427                 return false;
428             }
429             final Phylogeny g2_11 = TestGSDI.createPhylogeny( "((m1[&&NHX:S=m1],k4[&&NHX:S=k4]),x[&&NHX:S=x])" );
430             final GSDI sdi2_11 = new GSDI( g2_11, s2, false );
431             if ( sdi2_11.getDuplicationsSum() != 0 ) {
432                 return false;
433             }
434             if ( sdi2_11.getSpeciationOrDuplicationEventsSum() != 1 ) {
435                 return false;
436             }
437             if ( sdi2_11.getSpeciationsSum() != 1 ) {
438                 return false;
439             }
440             if ( !TestGSDI.getEvent( g2_11, "m1", "k4" ).isSpeciation() ) {
441                 return false;
442             }
443             if ( !TestGSDI.getEvent( g2_11, "m1", "x" ).isSpeciationOrDuplication() ) {
444                 return false;
445             }
446             final Phylogeny g2_12 = TestGSDI.createPhylogeny( "(m1[&&NHX:S=m1],(k4[&&NHX:S=k4],x[&&NHX:S=x]))" );
447             final GSDI sdi2_12 = new GSDI( g2_12, s2, false );
448             if ( sdi2_12.getDuplicationsSum() != 0 ) {
449                 return false;
450             }
451             if ( sdi2_12.getSpeciationOrDuplicationEventsSum() != 1 ) {
452                 return false;
453             }
454             if ( sdi2_12.getSpeciationsSum() != 1 ) {
455                 return false;
456             }
457             if ( !TestGSDI.getEvent( g2_12, "x", "k4" ).isSpeciation() ) {
458                 return false;
459             }
460             if ( !TestGSDI.getEvent( g2_12, "m1", "x" ).isSpeciationOrDuplication() ) {
461                 return false;
462             }
463             final Phylogeny g2_13 = TestGSDI.createPhylogeny( "(x[&&NHX:S=x],(y[&&NHX:S=y],z[&&NHX:S=z]))" );
464             final GSDI sdi2_13 = new GSDI( g2_13, s2, false );
465             if ( sdi2_13.getDuplicationsSum() != 0 ) {
466                 return false;
467             }
468             if ( sdi2_13.getSpeciationOrDuplicationEventsSum() != 1 ) {
469                 return false;
470             }
471             if ( sdi2_13.getSpeciationsSum() != 1 ) {
472                 return false;
473             }
474             if ( !TestGSDI.getEvent( g2_13, "y", "z" ).isSpeciation() ) {
475                 return false;
476             }
477             if ( !TestGSDI.getEvent( g2_13, "x", "z" ).isSpeciationOrDuplication() ) {
478                 return false;
479             }
480             final Phylogeny g2_14 = TestGSDI.createPhylogeny( "(a1_1[&&NHX:S=a1],(b1[&&NHX:S=b1],a1[&&NHX:S=a1]))" );
481             final GSDI sdi2_14 = new GSDI( g2_14, s2, false );
482             if ( sdi2_14.getDuplicationsSum() != 1 ) {
483                 return false;
484             }
485             if ( sdi2_14.getSpeciationOrDuplicationEventsSum() != 0 ) {
486                 return false;
487             }
488             if ( sdi2_14.getSpeciationsSum() != 1 ) {
489                 return false;
490             }
491             if ( !TestGSDI.getEvent( g2_14, "b1", "a1" ).isSpeciation() ) {
492                 return false;
493             }
494             if ( !TestGSDI.getEvent( g2_14, "b1", "a1_1" ).isDuplication() ) {
495                 return false;
496             }
497             final Phylogeny g2_15 = TestGSDI.createPhylogeny( "(a2[&&NHX:S=a2],(b1[&&NHX:S=b1],a1[&&NHX:S=a1]))" );
498             final GSDI sdi2_15 = new GSDI( g2_15, s2, false );
499             if ( sdi2_15.getDuplicationsSum() != 1 ) {
500                 return false;
501             }
502             if ( sdi2_15.getSpeciationOrDuplicationEventsSum() != 0 ) {
503                 return false;
504             }
505             if ( sdi2_15.getSpeciationsSum() != 1 ) {
506                 return false;
507             }
508             if ( !TestGSDI.getEvent( g2_15, "b1", "a1" ).isSpeciation() ) {
509                 return false;
510             }
511             if ( !TestGSDI.getEvent( g2_15, "b1", "a2" ).isDuplication() ) {
512                 return false;
513             }
514             final Phylogeny g2_16 = TestGSDI.createPhylogeny( "(n2[&&NHX:S=n2],(j3[&&NHX:S=j3],n1[&&NHX:S=n1]))" );
515             final GSDI sdi2_16 = new GSDI( g2_16, s2, false );
516             if ( sdi2_16.getDuplicationsSum() != 1 ) {
517                 return false;
518             }
519             if ( sdi2_16.getSpeciationOrDuplicationEventsSum() != 0 ) {
520                 return false;
521             }
522             if ( sdi2_16.getSpeciationsSum() != 1 ) {
523                 return false;
524             }
525             if ( !TestGSDI.getEvent( g2_16, "j3", "n1" ).isSpeciation() ) {
526                 return false;
527             }
528             if ( !TestGSDI.getEvent( g2_16, "j3", "n2" ).isDuplication() ) {
529                 return false;
530             }
531             final Phylogeny g2_17 = TestGSDI.createPhylogeny( "(p4[&&NHX:S=p4],(j3[&&NHX:S=j3],n1[&&NHX:S=n1]))" );
532             final GSDI sdi2_17 = new GSDI( g2_17, s2, false );
533             if ( sdi2_17.getDuplicationsSum() != 1 ) {
534                 return false;
535             }
536             if ( sdi2_17.getSpeciationOrDuplicationEventsSum() != 0 ) {
537                 return false;
538             }
539             if ( sdi2_17.getSpeciationsSum() != 1 ) {
540                 return false;
541             }
542             if ( !TestGSDI.getEvent( g2_17, "j3", "n1" ).isSpeciation() ) {
543                 return false;
544             }
545             if ( !TestGSDI.getEvent( g2_17, "j3", "p4" ).isDuplication() ) {
546                 return false;
547             }
548             final Phylogeny g2_18 = TestGSDI
549                     .createPhylogeny( "((n11[&&NHX:S=n1],n12[&&NHX:S=n1]),(n13[&&NHX:S=n1],n14[&&NHX:S=n1]))" );
550             final GSDI sdi2_18 = new GSDI( g2_18, s2, false );
551             if ( sdi2_18.getDuplicationsSum() != 3 ) {
552                 return false;
553             }
554             if ( sdi2_18.getSpeciationOrDuplicationEventsSum() != 0 ) {
555                 return false;
556             }
557             if ( sdi2_18.getSpeciationsSum() != 0 ) {
558                 return false;
559             }
560             if ( !TestGSDI.getEvent( g2_18, "n11", "n12" ).isDuplication() ) {
561                 return false;
562             }
563             if ( !TestGSDI.getEvent( g2_18, "n13", "n14" ).isDuplication() ) {
564                 return false;
565             }
566             if ( !TestGSDI.getEvent( g2_18, "n11", "n13" ).isDuplication() ) {
567                 return false;
568             }
569             final Phylogeny g2_19 = TestGSDI
570                     .createPhylogeny( "((n11[&&NHX:S=n1],n21[&&NHX:S=n2]),(n12[&&NHX:S=n1],n22[&&NHX:S=n2]))" );
571             final GSDI sdi2_19 = new GSDI( g2_19, s2, false );
572             if ( sdi2_19.getDuplicationsSum() != 1 ) {
573                 return false;
574             }
575             if ( sdi2_19.getSpeciationOrDuplicationEventsSum() != 0 ) {
576                 return false;
577             }
578             if ( sdi2_19.getSpeciationsSum() != 2 ) {
579                 return false;
580             }
581             if ( !TestGSDI.getEvent( g2_19, "n11", "n21" ).isSpeciation() ) {
582                 return false;
583             }
584             if ( !TestGSDI.getEvent( g2_19, "n12", "n22" ).isSpeciation() ) {
585                 return false;
586             }
587             if ( !TestGSDI.getEvent( g2_19, "n11", "n12" ).isDuplication() ) {
588                 return false;
589             }
590             final Phylogeny g2_20 = TestGSDI
591                     .createPhylogeny( "((n11[&&NHX:S=n1],n2[&&NHX:S=n2]),(n12[&&NHX:S=n1],n3[&&NHX:S=n3]))" );
592             final GSDI sdi2_20 = new GSDI( g2_20, s2, false );
593             if ( sdi2_20.getDuplicationsSum() != 1 ) {
594                 return false;
595             }
596             if ( sdi2_20.getSpeciationOrDuplicationEventsSum() != 0 ) {
597                 return false;
598             }
599             if ( sdi2_20.getSpeciationsSum() != 2 ) {
600                 return false;
601             }
602             if ( !TestGSDI.getEvent( g2_20, "n11", "n2" ).isSpeciation() ) {
603                 return false;
604             }
605             if ( !TestGSDI.getEvent( g2_20, "n12", "n3" ).isSpeciation() ) {
606                 return false;
607             }
608             if ( !TestGSDI.getEvent( g2_20, "n11", "n12" ).isDuplication() ) {
609                 return false;
610             }
611             final Phylogeny g2_21 = TestGSDI
612                     .createPhylogeny( "((n1[&&NHX:S=n1],n2[&&NHX:S=n2]),(n3[&&NHX:S=n3],a1[&&NHX:S=a1]))" );
613             final GSDI sdi2_21 = new GSDI( g2_21, s2, false );
614             if ( sdi2_21.getDuplicationsSum() != 1 ) {
615                 return false;
616             }
617             if ( sdi2_21.getSpeciationOrDuplicationEventsSum() != 0 ) {
618                 return false;
619             }
620             if ( sdi2_21.getSpeciationsSum() != 2 ) {
621                 return false;
622             }
623             if ( !TestGSDI.getEvent( g2_21, "n1", "n2" ).isSpeciation() ) {
624                 return false;
625             }
626             if ( !TestGSDI.getEvent( g2_21, "n3", "a1" ).isSpeciation() ) {
627                 return false;
628             }
629             if ( !TestGSDI.getEvent( g2_21, "n2", "a1" ).isDuplication() ) {
630                 return false;
631             }
632             final Phylogeny g2_22 = TestGSDI
633                     .createPhylogeny( "((n1[&&NHX:S=n1],n2[&&NHX:S=n2]),(n3[&&NHX:S=n3],n4[&&NHX:S=n4]))" );
634             final GSDI sdi2_22 = new GSDI( g2_22, s2, false );
635             //Archaeopteryx.createApplication( g2_22 );
636             //Archaeopteryx.createApplication( s2 );
637             if ( sdi2_22.getDuplicationsSum() != 0 ) {
638                 return false;
639             }
640             if ( sdi2_22.getSpeciationOrDuplicationEventsSum() != 1 ) {
641                 return false;
642             }
643             if ( sdi2_22.getSpeciationsSum() != 2 ) {
644                 return false;
645             }
646             if ( !TestGSDI.getEvent( g2_22, "n1", "n2" ).isSpeciation() ) {
647                 return false;
648             }
649             if ( !TestGSDI.getEvent( g2_22, "n3", "n4" ).isSpeciation() ) {
650                 return false;
651             }
652             if ( !TestGSDI.getEvent( g2_22, "n1", "n3" ).isSpeciationOrDuplication() ) {
653                 return false;
654             }
655             final Phylogeny g2_23 = TestGSDI
656                     .createPhylogeny( "((a1[&&NHX:S=a1],b1[&&NHX:S=b1]),(c1[&&NHX:S=c1],d1[&&NHX:S=d1]))" );
657             final GSDI sdi2_23 = new GSDI( g2_23, s2, false );
658             if ( sdi2_23.getDuplicationsSum() != 0 ) {
659                 return false;
660             }
661             if ( sdi2_23.getSpeciationOrDuplicationEventsSum() != 1 ) {
662                 return false;
663             }
664             if ( sdi2_23.getSpeciationsSum() != 2 ) {
665                 return false;
666             }
667             if ( !TestGSDI.getEvent( g2_23, "a1", "b1" ).isSpeciation() ) {
668                 return false;
669             }
670             if ( !TestGSDI.getEvent( g2_23, "c1", "d1" ).isSpeciation() ) {
671                 return false;
672             }
673             if ( !TestGSDI.getEvent( g2_23, "a1", "c1" ).isSpeciationOrDuplication() ) {
674                 return false;
675             }
676             final Phylogeny g2_24 = TestGSDI
677                     .createPhylogeny( "((a1[&&NHX:S=a1],e1[&&NHX:S=e1]),(i1[&&NHX:S=i1],m1[&&NHX:S=m1]))" );
678             final GSDI sdi2_24 = new GSDI( g2_24, s2, false );
679             if ( sdi2_24.getDuplicationsSum() != 0 ) {
680                 return false;
681             }
682             if ( sdi2_24.getSpeciationOrDuplicationEventsSum() != 1 ) {
683                 return false;
684             }
685             if ( sdi2_24.getSpeciationsSum() != 2 ) {
686                 return false;
687             }
688             if ( !TestGSDI.getEvent( g2_24, "a1", "e1" ).isSpeciation() ) {
689                 return false;
690             }
691             if ( !TestGSDI.getEvent( g2_24, "i1", "m1" ).isSpeciation() ) {
692                 return false;
693             }
694             if ( !TestGSDI.getEvent( g2_24, "a1", "i1" ).isSpeciationOrDuplication() ) {
695                 return false;
696             }
697             final Phylogeny g2_25 = TestGSDI
698                     .createPhylogeny( "((a1[&&NHX:S=a1],a4[&&NHX:S=a4]),(b1[&&NHX:S=b1],c1[&&NHX:S=c1]))" );
699             final GSDI sdi2_25 = new GSDI( g2_25, s2, false );
700             if ( sdi2_25.getDuplicationsSum() != 0 ) {
701                 return false;
702             }
703             if ( sdi2_25.getSpeciationOrDuplicationEventsSum() != 1 ) {
704                 return false;
705             }
706             if ( sdi2_25.getSpeciationsSum() != 2 ) {
707                 return false;
708             }
709             if ( !TestGSDI.getEvent( g2_25, "a1", "a4" ).isSpeciation() ) {
710                 return false;
711             }
712             if ( !TestGSDI.getEvent( g2_25, "b1", "c1" ).isSpeciation() ) {
713                 return false;
714             }
715             if ( !TestGSDI.getEvent( g2_25, "a1", "b1" ).isSpeciationOrDuplication() ) {
716                 return false;
717             }
718             final Phylogeny g2_26 = TestGSDI
719                     .createPhylogeny( "(((a1[&&NHX:S=a1],a4[&&NHX:S=a4]),b1[&&NHX:S=b1]),e1[&&NHX:S=e1])" );
720             final GSDI sdi2_26 = new GSDI( g2_26, s2, false );
721             if ( sdi2_26.getDuplicationsSum() != 0 ) {
722                 return false;
723             }
724             if ( sdi2_26.getSpeciationOrDuplicationEventsSum() != 0 ) {
725                 return false;
726             }
727             if ( sdi2_26.getSpeciationsSum() != 3 ) {
728                 return false;
729             }
730             if ( !TestGSDI.getEvent( g2_26, "a1", "a4" ).isSpeciation() ) {
731                 return false;
732             }
733             if ( !TestGSDI.getEvent( g2_26, "a1", "b1" ).isSpeciation() ) {
734                 return false;
735             }
736             if ( !TestGSDI.getEvent( g2_26, "a1", "e1" ).isSpeciation() ) {
737                 return false;
738             }
739             final Phylogeny g2_27 = TestGSDI
740                     .createPhylogeny( "(((a1[&&NHX:S=a1],a4[&&NHX:S=a4]),b1[&&NHX:S=b1]),c1[&&NHX:S=c1])" );
741             final GSDI sdi2_27 = new GSDI( g2_27, s2, false );
742             if ( sdi2_27.getDuplicationsSum() != 0 ) {
743                 return false;
744             }
745             if ( sdi2_27.getSpeciationOrDuplicationEventsSum() != 1 ) {
746                 return false;
747             }
748             if ( sdi2_27.getSpeciationsSum() != 2 ) {
749                 return false;
750             }
751             if ( !TestGSDI.getEvent( g2_27, "a1", "a4" ).isSpeciation() ) {
752                 return false;
753             }
754             if ( !TestGSDI.getEvent( g2_27, "a1", "b1" ).isSpeciation() ) {
755                 return false;
756             }
757             if ( !TestGSDI.getEvent( g2_27, "a1", "c1" ).isSpeciationOrDuplication() ) {
758                 return false;
759             }
760             final Phylogeny g2_28 = TestGSDI
761                     .createPhylogeny( "(((a1[&&NHX:S=a1],b1[&&NHX:S=b1]),c1[&&NHX:S=c1]),e1[&&NHX:S=e1])" );
762             final GSDI sdi2_28 = new GSDI( g2_28, s2, false );
763             if ( sdi2_28.getDuplicationsSum() != 0 ) {
764                 return false;
765             }
766             if ( sdi2_28.getSpeciationOrDuplicationEventsSum() != 1 ) {
767                 return false;
768             }
769             if ( sdi2_28.getSpeciationsSum() != 2 ) {
770                 return false;
771             }
772             if ( !TestGSDI.getEvent( g2_28, "a1", "b1" ).isSpeciation() ) {
773                 return false;
774             }
775             if ( !TestGSDI.getEvent( g2_28, "a1", "c1" ).isSpeciationOrDuplication() ) {
776                 return false;
777             }
778             if ( !TestGSDI.getEvent( g2_28, "a1", "e1" ).isSpeciation() ) {
779                 return false;
780             }
781             final Phylogeny g2_29 = TestGSDI
782                     .createPhylogeny( "(((a1[&&NHX:S=a1],b1[&&NHX:S=b1]),c1[&&NHX:S=c1]),d1[&&NHX:S=d1])" );
783             final GSDI sdi2_29 = new GSDI( g2_29, s2, false );
784             if ( sdi2_29.getDuplicationsSum() != 0 ) {
785                 return false;
786             }
787             if ( sdi2_29.getSpeciationOrDuplicationEventsSum() != 2 ) {
788                 return false;
789             }
790             if ( sdi2_29.getSpeciationsSum() != 1 ) {
791                 return false;
792             }
793             if ( !TestGSDI.getEvent( g2_29, "a1", "b1" ).isSpeciation() ) {
794                 return false;
795             }
796             if ( !TestGSDI.getEvent( g2_29, "a1", "c1" ).isSpeciationOrDuplication() ) {
797                 return false;
798             }
799             if ( !TestGSDI.getEvent( g2_29, "a1", "d1" ).isSpeciationOrDuplication() ) {
800                 return false;
801             }
802             final Phylogeny g2_30 = TestGSDI
803                     .createPhylogeny( "(((a1[&&NHX:S=a1],b1[&&NHX:S=b1]),c1[&&NHX:S=c1]),a2[&&NHX:S=a2])" );
804             final GSDI sdi2_30 = new GSDI( g2_30, s2, false );
805             if ( sdi2_30.getDuplicationsSum() != 1 ) {
806                 return false;
807             }
808             if ( sdi2_30.getSpeciationOrDuplicationEventsSum() != 1 ) {
809                 return false;
810             }
811             if ( sdi2_30.getSpeciationsSum() != 1 ) {
812                 return false;
813             }
814             if ( !TestGSDI.getEvent( g2_30, "a1", "b1" ).isSpeciation() ) {
815                 return false;
816             }
817             if ( !TestGSDI.getEvent( g2_30, "a1", "c1" ).isSpeciationOrDuplication() ) {
818                 return false;
819             }
820             if ( !TestGSDI.getEvent( g2_30, "a1", "a2" ).isDuplication() ) {
821                 return false;
822             }
823             final Phylogeny g2_31 = TestGSDI
824                     .createPhylogeny( "(((a1[&&NHX:S=a1],b1[&&NHX:S=b1]),c1[&&NHX:S=c1]),c2[&&NHX:S=c2])" );
825             final GSDI sdi2_31 = new GSDI( g2_31, s2, false );
826             if ( sdi2_31.getDuplicationsSum() != 1 ) {
827                 return false;
828             }
829             if ( sdi2_31.getSpeciationOrDuplicationEventsSum() != 1 ) {
830                 return false;
831             }
832             if ( sdi2_31.getSpeciationsSum() != 1 ) {
833                 return false;
834             }
835             if ( !TestGSDI.getEvent( g2_31, "a1", "b1" ).isSpeciation() ) {
836                 return false;
837             }
838             if ( !TestGSDI.getEvent( g2_31, "a1", "c1" ).isSpeciationOrDuplication() ) {
839                 return false;
840             }
841             if ( !TestGSDI.getEvent( g2_31, "a1", "c2" ).isDuplication() ) {
842                 return false;
843             }
844             final Phylogeny g2_32 = TestGSDI
845                     .createPhylogeny( "((((((((((a1[&&NHX:S=a1],a2[&&NHX:S=a2]),b1[&&NHX:S=b1]),c1[&&NHX:S=c1]),d1[&&NHX:S=d1]),x[&&NHX:S=x]),p1[&&NHX:S=p1]),i1[&&NHX:S=i1]),e1[&&NHX:S=e1]),y[&&NHX:S=y]),z[&&NHX:S=z])" );
846             final GSDI sdi2_32 = new GSDI( g2_32, s2, false );
847             if ( sdi2_32.getDuplicationsSum() != 0 ) {
848                 return false;
849             }
850             if ( sdi2_32.getSpeciationOrDuplicationEventsSum() != 7 ) {
851                 return false;
852             }
853             if ( sdi2_32.getSpeciationsSum() != 3 ) {
854                 return false;
855             }
856             if ( !TestGSDI.getEvent( g2_32, "a1", "a2" ).isSpeciation() ) {
857                 return false;
858             }
859             if ( !TestGSDI.getEvent( g2_32, "a1", "b1" ).isSpeciation() ) {
860                 return false;
861             }
862             if ( !TestGSDI.getEvent( g2_32, "a1", "c1" ).isSpeciationOrDuplication() ) {
863                 return false;
864             }
865             if ( !TestGSDI.getEvent( g2_32, "a1", "d1" ).isSpeciationOrDuplication() ) {
866                 return false;
867             }
868             if ( !TestGSDI.getEvent( g2_32, "a1", "x" ).isSpeciation() ) {
869                 return false;
870             }
871             if ( !TestGSDI.getEvent( g2_32, "a1", "p1" ).isSpeciationOrDuplication() ) {
872                 return false;
873             }
874             if ( !TestGSDI.getEvent( g2_32, "a1", "i1" ).isSpeciationOrDuplication() ) {
875                 return false;
876             }
877             if ( !TestGSDI.getEvent( g2_32, "a1", "e1" ).isSpeciationOrDuplication() ) {
878                 return false;
879             }
880             if ( !TestGSDI.getEvent( g2_32, "a1", "y" ).isSpeciationOrDuplication() ) {
881                 return false;
882             }
883             if ( !TestGSDI.getEvent( g2_32, "a1", "z" ).isSpeciationOrDuplication() ) {
884                 return false;
885             }
886             //            //            //-
887             final Phylogeny g2_33_d = TestGSDI
888                     .createPhylogeny( "((((((((((((a1[&&NHX:S=a1],a2[&&NHX:S=a2])[&&NHX:D=N],b1[&&NHX:S=b1])[&&NHX:D=N],c1[&&NHX:S=c1])[&&NHX:D=?],d1[&&NHX:S=d1])[&&NHX:D=?],x[&&NHX:S=x])[&&NHX:D=N],p1[&&NHX:S=p1])[&&NHX:D=?],i1[&&NHX:S=i1])[&&NHX:D=?],k2[&&NHX:S=k2])[&&NHX:D=Y],e1[&&NHX:S=e1])[&&NHX:D=Y],y[&&NHX:S=y])[&&NHX:D=Y],z[&&NHX:S=z])[&&NHX:D=?],(((((((((((a1[&&NHX:S=a1],a2[&&NHX:S=a2])[&&NHX:D=N],b1[&&NHX:S=b1])[&&NHX:D=N],c1[&&NHX:S=c1])[&&NHX:D=?],d1[&&NHX:S=d1])[&&NHX:D=?],x[&&NHX:S=x])[&&NHX:D=N],p1[&&NHX:S=p1])[&&NHX:D=?],i1[&&NHX:S=i1])[&&NHX:D=?],k2[&&NHX:S=k2])[&&NHX:D=Y],e1[&&NHX:S=e1])[&&NHX:D=Y],y[&&NHX:S=y])[&&NHX:D=Y],z[&&NHX:S=z])[&&NHX:D=?])" );
889             final GSDI sdi2_33_d = new GSDI( g2_33_d, s2, false );
890             Archaeopteryx.createApplication( g2_33_d );
891             //  Archaeopteryx.createApplication( s2 );
892             //-
893             final Phylogeny g2_33 = TestGSDI
894                     .createPhylogeny( "(((((((((((a1[&&NHX:S=a1],a2[&&NHX:S=a2]),b1[&&NHX:S=b1]),c1[&&NHX:S=c1]),d1[&&NHX:S=d1]),x[&&NHX:S=x]),p1[&&NHX:S=p1]),i1[&&NHX:S=i1]),k2[&&NHX:S=k2]),e1[&&NHX:S=e1]),y[&&NHX:S=y]),z[&&NHX:S=z])" );
895             final GSDI sdi2_33 = new GSDI( g2_33, s2, false );
896             Archaeopteryx.createApplication( g2_33 );
897             Archaeopteryx.createApplication( s2 );
898             if ( sdi2_33.getDuplicationsSum() != 1 ) {
899                 return false;
900             }
901             if ( sdi2_33.getSpeciationOrDuplicationEventsSum() != 7 ) {
902                 return false;
903             }
904             if ( sdi2_33.getSpeciationsSum() != 3 ) {
905                 return false;
906             }
907             if ( !TestGSDI.getEvent( g2_33, "a1", "a2" ).isSpeciation() ) {
908                 return false;
909             }
910             if ( !TestGSDI.getEvent( g2_33, "a1", "b1" ).isSpeciation() ) {
911                 return false;
912             }
913             if ( !TestGSDI.getEvent( g2_33, "a1", "c1" ).isSpeciationOrDuplication() ) {
914                 return false;
915             }
916             if ( !TestGSDI.getEvent( g2_33, "a1", "d1" ).isSpeciationOrDuplication() ) {
917                 return false;
918             }
919             if ( !TestGSDI.getEvent( g2_33, "a1", "x" ).isSpeciation() ) {
920                 return false;
921             }
922             if ( !TestGSDI.getEvent( g2_33, "a1", "p1" ).isSpeciationOrDuplication() ) {
923                 return false;
924             }
925             if ( !TestGSDI.getEvent( g2_33, "a1", "i1" ).isSpeciationOrDuplication() ) {
926                 return false;
927             }
928             if ( !TestGSDI.getEvent( g2_33, "a1", "k2" ).isDuplication() ) {
929                 return false;
930             }
931             if ( !TestGSDI.getEvent( g2_33, "a1", "e1" ).isSpeciationOrDuplication() ) {
932                 return false;
933             }
934             if ( !TestGSDI.getEvent( g2_33, "a1", "y" ).isSpeciationOrDuplication() ) {
935                 return false;
936             }
937             if ( !TestGSDI.getEvent( g2_33, "a1", "z" ).isSpeciationOrDuplication() ) {
938                 return false;
939             }
940             final Phylogeny g2_34 = TestGSDI
941                     .createPhylogeny( "(((n1_0[&&NHX:S=n1],n2_0[&&NHX:S=n2]),(n1_1[&&NHX:S=n1],n3_0[&&NHX:S=n3])),n4_0[&&NHX:S=n4])" );
942             final GSDI sdi2_34 = new GSDI( g2_34, s2, false );
943             if ( sdi2_34.getDuplicationsSum() != 1 ) {
944                 return false;
945             }
946             if ( sdi2_34.getSpeciationOrDuplicationEventsSum() != 1 ) {
947                 return false;
948             }
949             if ( sdi2_34.getSpeciationsSum() != 2 ) {
950                 return false;
951             }
952             if ( !TestGSDI.getEvent( g2_34, "n1_0", "n2_0" ).isSpeciation() ) {
953                 return false;
954             }
955             if ( !TestGSDI.getEvent( g2_34, "n1_1", "n3_0" ).isSpeciation() ) {
956                 return false;
957             }
958             if ( !TestGSDI.getEvent( g2_34, "n1_0", "n1_1" ).isDuplication() ) {
959                 return false;
960             }
961             if ( !TestGSDI.getEvent( g2_34, "n1_0", "n4_0" ).isSpeciationOrDuplication() ) {
962                 return false;
963             }
964             final Phylogeny g2_35 = TestGSDI
965                     .createPhylogeny( "((((n1_0[&&NHX:S=n1],n2_0[&&NHX:S=n2]),(n1_1[&&NHX:S=n1],n3_0[&&NHX:S=n3])),n4_0[&&NHX:S=n4]),a1_0[&&NHX:S=a1])" );
966             final GSDI sdi2_35 = new GSDI( g2_35, s2, false );
967             if ( sdi2_35.getDuplicationsSum() != 1 ) {
968                 return false;
969             }
970             if ( sdi2_35.getSpeciationOrDuplicationEventsSum() != 1 ) {
971                 return false;
972             }
973             if ( sdi2_35.getSpeciationsSum() != 3 ) {
974                 return false;
975             }
976             if ( !TestGSDI.getEvent( g2_35, "n1_0", "n2_0" ).isSpeciation() ) {
977                 return false;
978             }
979             if ( !TestGSDI.getEvent( g2_35, "n1_1", "n3_0" ).isSpeciation() ) {
980                 return false;
981             }
982             if ( !TestGSDI.getEvent( g2_35, "n1_0", "n1_1" ).isDuplication() ) {
983                 return false;
984             }
985             if ( !TestGSDI.getEvent( g2_35, "n1_0", "n4_0" ).isSpeciationOrDuplication() ) {
986                 return false;
987             }
988             if ( !TestGSDI.getEvent( g2_35, "n1_0", "a1_0" ).isSpeciation() ) {
989                 return false;
990             }
991             final Phylogeny g2_36 = TestGSDI
992                     .createPhylogeny( "(((a1_0[&&NHX:S=a1],b1_0[&&NHX:S=b1]),(a1_1[&&NHX:S=a1],c1_0[&&NHX:S=c1])),d1_0[&&NHX:S=d1])" );
993             final GSDI sdi2_36 = new GSDI( g2_36, s2, false );
994             if ( sdi2_36.getDuplicationsSum() != 1 ) {
995                 return false;
996             }
997             if ( sdi2_36.getSpeciationOrDuplicationEventsSum() != 1 ) {
998                 return false;
999             }
1000             if ( sdi2_36.getSpeciationsSum() != 2 ) {
1001                 return false;
1002             }
1003             if ( !TestGSDI.getEvent( g2_36, "a1_0", "b1_0" ).isSpeciation() ) {
1004                 return false;
1005             }
1006             if ( !TestGSDI.getEvent( g2_36, "a1_1", "c1_0" ).isSpeciation() ) {
1007                 return false;
1008             }
1009             if ( !TestGSDI.getEvent( g2_36, "a1_0", "c1_0" ).isDuplication() ) {
1010                 return false;
1011             }
1012             if ( !TestGSDI.getEvent( g2_36, "a1_0", "d1_0" ).isSpeciationOrDuplication() ) {
1013                 return false;
1014             }
1015             final Phylogeny g2_37 = TestGSDI
1016                     .createPhylogeny( "(((a1_0[&&NHX:S=a1],b1_0[&&NHX:S=b1]),(a2_0[&&NHX:S=a2],c1_0[&&NHX:S=c1])),d1_0[&&NHX:S=d1])" );
1017             final GSDI sdi2_37 = new GSDI( g2_37, s2, false );
1018             if ( sdi2_37.getDuplicationsSum() != 1 ) {
1019                 return false;
1020             }
1021             if ( sdi2_37.getSpeciationOrDuplicationEventsSum() != 1 ) {
1022                 return false;
1023             }
1024             if ( sdi2_37.getSpeciationsSum() != 2 ) {
1025                 return false;
1026             }
1027             if ( !TestGSDI.getEvent( g2_37, "a1_0", "b1_0" ).isSpeciation() ) {
1028                 return false;
1029             }
1030             if ( !TestGSDI.getEvent( g2_37, "a2_0", "c1_0" ).isSpeciation() ) {
1031                 return false;
1032             }
1033             if ( !TestGSDI.getEvent( g2_37, "a1_0", "c1_0" ).isDuplication() ) {
1034                 return false;
1035             }
1036             if ( !TestGSDI.getEvent( g2_37, "a1_0", "d1_0" ).isSpeciationOrDuplication() ) {
1037                 return false;
1038             }
1039             final Phylogeny g2_38 = TestGSDI
1040                     .createPhylogeny( "(((([&&NHX:S=n1],[&&NHX:S=n1]),([&&NHX:S=n1],[&&NHX:S=n1])),[&&NHX:S=n1]),[&&NHX:S=n1])" );
1041             final GSDI sdi2_38 = new GSDI( g2_38, s2, false );
1042             if ( sdi2_38.getDuplicationsSum() != 5 ) {
1043                 return false;
1044             }
1045             if ( sdi2_38.getSpeciationOrDuplicationEventsSum() != 0 ) {
1046                 return false;
1047             }
1048             if ( sdi2_38.getSpeciationsSum() != 0 ) {
1049                 return false;
1050             }
1051             final Phylogeny g2_100 = TestGSDI
1052                     .createPhylogeny( "(((e1[&&NHX:S=e1],f2[&&NHX:S=f2]),(d3[&&NHX:S=d3],g4[&&NHX:S=g4])),(((a1[&&NHX:S=a1],h2[&&NHX:S=h2]),c3[&&NHX:S=c3]),(i4[&&NHX:S=i4],b1[&&NHX:S=b1])))" );
1053             final GSDI sdi2_100 = new GSDI( g2_100, s2, false );
1054             if ( sdi2_100.getDuplicationsSum() != 4 ) {
1055                 return false;
1056             }
1057             if ( sdi2_100.getSpeciationOrDuplicationEventsSum() != 0 ) {
1058                 return false;
1059             }
1060             if ( sdi2_100.getSpeciationsSum() != 4 ) {
1061                 return false;
1062             }
1063             if ( !TestGSDI.getEvent( g2_100, "e1", "f2" ).isSpeciation() ) {
1064                 return false;
1065             }
1066             if ( !TestGSDI.getEvent( g2_100, "d3", "g4" ).isSpeciation() ) {
1067                 return false;
1068             }
1069             if ( !TestGSDI.getEvent( g2_100, "e1", "d3" ).isDuplication() ) {
1070                 return false;
1071             }
1072             if ( !TestGSDI.getEvent( g2_100, "a1", "h2" ).isSpeciation() ) {
1073                 return false;
1074             }
1075             if ( !TestGSDI.getEvent( g2_100, "a1", "c3" ).isDuplication() ) {
1076                 return false;
1077             }
1078             if ( !TestGSDI.getEvent( g2_100, "i4", "b1" ).isSpeciation() ) {
1079                 return false;
1080             }
1081             if ( !TestGSDI.getEvent( g2_100, "a1", "i4" ).isDuplication() ) {
1082                 return false;
1083             }
1084             if ( !TestGSDI.getEvent( g2_100, "e1", "a1" ).isDuplication() ) {
1085                 return false;
1086             }
1087             final Phylogeny g2_101 = TestGSDI
1088                     .createPhylogeny( "(((e1[&&NHX:S=e1],f2[&&NHX:S=f2]),(d3[&&NHX:S=d3],g4[&&NHX:S=g4])),(((a1[&&NHX:S=a1],b2[&&NHX:S=b2]),c3[&&NHX:S=c3]),(i4[&&NHX:S=i4],j1[&&NHX:S=j1])))" );
1089             final GSDI sdi2_101 = new GSDI( g2_101, s2, false );
1090             if ( sdi2_101.getDuplicationsSum() != 2 ) {
1091                 return false;
1092             }
1093             if ( sdi2_101.getSpeciationOrDuplicationEventsSum() != 1 ) {
1094                 return false;
1095             }
1096             if ( sdi2_101.getSpeciationsSum() != 5 ) {
1097                 return false;
1098             }
1099             if ( !TestGSDI.getEvent( g2_101, "e1", "f2" ).isSpeciation() ) {
1100                 return false;
1101             }
1102             if ( !TestGSDI.getEvent( g2_101, "d3", "g4" ).isSpeciation() ) {
1103                 return false;
1104             }
1105             if ( !TestGSDI.getEvent( g2_101, "e1", "d3" ).isDuplication() ) {
1106                 return false;
1107             }
1108             if ( !TestGSDI.getEvent( g2_101, "a1", "b2" ).isSpeciation() ) {
1109                 return false;
1110             }
1111             if ( !TestGSDI.getEvent( g2_101, "a1", "c3" ).isSpeciationOrDuplication() ) {
1112                 return false;
1113             }
1114             if ( !TestGSDI.getEvent( g2_101, "i4", "j1" ).isSpeciation() ) {
1115                 return false;
1116             }
1117             if ( !TestGSDI.getEvent( g2_101, "a1", "i4" ).isSpeciation() ) {
1118                 return false;
1119             }
1120             if ( !TestGSDI.getEvent( g2_101, "e1", "a1" ).isDuplication() ) {
1121                 return false;
1122             }
1123             final Phylogeny s_7_4 = DevelopmentTools.createBalancedPhylogeny( 7, 4 );
1124             DevelopmentTools.numberSpeciesInOrder( s_7_4 );
1125             final Phylogeny g_7_4_1 = TestGSDI
1126                     .createPhylogeny( "(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((("
1127                             + "1[&&NHX:S=1],2[&&NHX:S=2]),3[&&NHX:S=3]),4[&&NHX:S=4]),5[&&NHX:S=5]),"
1128                             + "6[&&NHX:S=6]),7[&&NHX:S=7]),8[&&NHX:S=8]),9[&&NHX:S=9]),10[&&NHX:S=10]),11[&&NHX:S=11]),"
1129                             + "12[&&NHX:S=12]),13[&&NHX:S=13]),14[&&NHX:S=14]),15[&&NHX:S=15]),16[&&NHX:S=16]),17[&&NHX:S=17]),"
1130                             + "18[&&NHX:S=18]),19[&&NHX:S=19]),20[&&NHX:S=20]),21[&&NHX:S=21]),22[&&NHX:S=22]),23[&&NHX:S=23]),"
1131                             + "24[&&NHX:S=24]),25[&&NHX:S=25]),26[&&NHX:S=26]),27[&&NHX:S=27]),28[&&NHX:S=28]),29[&&NHX:S=29]),"
1132                             + "30[&&NHX:S=30]),31[&&NHX:S=31]),32[&&NHX:S=32]),33[&&NHX:S=33]),34[&&NHX:S=34]),35[&&NHX:S=35]),"
1133                             + "36[&&NHX:S=36]),37[&&NHX:S=37]),38[&&NHX:S=38]),39[&&NHX:S=39]),40[&&NHX:S=40]),41[&&NHX:S=41]),"
1134                             + "42[&&NHX:S=42]),43[&&NHX:S=43]),44[&&NHX:S=44]),45[&&NHX:S=45]),46[&&NHX:S=46]),47[&&NHX:S=47]),"
1135                             + "48[&&NHX:S=48]),49[&&NHX:S=49]),50[&&NHX:S=50]),51[&&NHX:S=51]),52[&&NHX:S=52]),53[&&NHX:S=53]),"
1136                             + "54[&&NHX:S=54]),55[&&NHX:S=55]),56[&&NHX:S=56]),57[&&NHX:S=57]),58[&&NHX:S=58]),59[&&NHX:S=59]),"
1137                             + "60[&&NHX:S=60]),61[&&NHX:S=61]),62[&&NHX:S=62]),63[&&NHX:S=63]),64[&&NHX:S=64]),65[&&NHX:S=65])" );
1138             final GSDI sdi7_4_1 = new GSDI( g_7_4_1, s_7_4, false );
1139             if ( sdi7_4_1.getDuplicationsSum() != 54 ) {
1140                 return false;
1141             }
1142             if ( sdi7_4_1.getSpeciationOrDuplicationEventsSum() != 6 ) {
1143                 return false;
1144             }
1145             if ( sdi7_4_1.getSpeciationsSum() != 4 ) {
1146                 return false;
1147             }
1148             if ( !TestGSDI.getEvent( g_7_4_1, "1", "2" ).isSpeciation() ) {
1149                 return false;
1150             }
1151             if ( !TestGSDI.getEvent( g_7_4_1, "1", "3" ).isSpeciationOrDuplication() ) {
1152                 return false;
1153             }
1154             if ( !TestGSDI.getEvent( g_7_4_1, "1", "4" ).isSpeciationOrDuplication() ) {
1155                 return false;
1156             }
1157             if ( !TestGSDI.getEvent( g_7_4_1, "1", "5" ).isSpeciation() ) {
1158                 return false;
1159             }
1160             if ( !TestGSDI.getEvent( g_7_4_1, "1", "6" ).isDuplication() ) {
1161                 return false;
1162             }
1163             if ( !TestGSDI.getEvent( g_7_4_1, "1", "9" ).isSpeciationOrDuplication() ) {
1164                 return false;
1165             }
1166             if ( !TestGSDI.getEvent( g_7_4_1, "1", "13" ).isSpeciationOrDuplication() ) {
1167                 return false;
1168             }
1169             if ( !TestGSDI.getEvent( g_7_4_1, "1", "17" ).isSpeciation() ) {
1170                 return false;
1171             }
1172             if ( !TestGSDI.getEvent( g_7_4_1, "1", "33" ).isSpeciationOrDuplication() ) {
1173                 return false;
1174             }
1175             if ( !TestGSDI.getEvent( g_7_4_1, "1", "49" ).isSpeciationOrDuplication() ) {
1176                 return false;
1177             }
1178             if ( !TestGSDI.getEvent( g_7_4_1, "1", "65" ).isSpeciation() ) {
1179                 return false;
1180             }
1181             final Phylogeny g_7_4_2 = TestGSDI
1182                     .createPhylogeny( "((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((("
1183                             + "1[&&NHX:S=1],2[&&NHX:S=2]),3[&&NHX:S=3]),4[&&NHX:S=4]),5[&&NHX:S=5]),"
1184                             + "6[&&NHX:S=6]),7[&&NHX:S=7]),8[&&NHX:S=8]),9[&&NHX:S=9]),10[&&NHX:S=10]),11[&&NHX:S=11]),"
1185                             + "12[&&NHX:S=12]),13[&&NHX:S=13]),14[&&NHX:S=14]),15[&&NHX:S=15]),16[&&NHX:S=16]),17[&&NHX:S=17]),"
1186                             + "18[&&NHX:S=18]),19[&&NHX:S=19]),20[&&NHX:S=20]),21[&&NHX:S=21]),22[&&NHX:S=22]),23[&&NHX:S=23]),"
1187                             + "24[&&NHX:S=24]),25[&&NHX:S=25]),26[&&NHX:S=26]),27[&&NHX:S=27]),28[&&NHX:S=28]),29[&&NHX:S=29]),"
1188                             + "30[&&NHX:S=30]),31[&&NHX:S=31]),32[&&NHX:S=32]),33[&&NHX:S=33]),34[&&NHX:S=34]),35[&&NHX:S=35]),"
1189                             + "36[&&NHX:S=36]),37[&&NHX:S=37]),38[&&NHX:S=38]),39[&&NHX:S=39]),40[&&NHX:S=40]),41[&&NHX:S=41]),"
1190                             + "42[&&NHX:S=42]),43[&&NHX:S=43]),44[&&NHX:S=44]),45[&&NHX:S=45]),46[&&NHX:S=46]),47[&&NHX:S=47]),"
1191                             + "48[&&NHX:S=48]),49[&&NHX:S=49]),50[&&NHX:S=50]),51[&&NHX:S=51]),52[&&NHX:S=52]),53[&&NHX:S=53]),"
1192                             + "54[&&NHX:S=54]),55[&&NHX:S=55]),56[&&NHX:S=56]),57[&&NHX:S=57]),58[&&NHX:S=58]),59[&&NHX:S=59]),"
1193                             + "60[&&NHX:S=60]),61[&&NHX:S=61]),62[&&NHX:S=62]),63[&&NHX:S=63]),64[&&NHX:S=64]),65[&&NHX:S=65]),"
1194                             + "66[&&NHX:S=66]),257[&&NHX:S=257]),258[&&NHX:S=258]),513[&&NHX:S=513]),514[&&NHX:S=514]),769[&&NHX:S=769]),770[&&NHX:S=770])" );
1195             final GSDI sdi7_4_2 = new GSDI( g_7_4_2, s_7_4, false );
1196             if ( sdi7_4_2.getDuplicationsSum() != 58 ) {
1197                 return false;
1198             }
1199             if ( sdi7_4_2.getSpeciationOrDuplicationEventsSum() != 8 ) {
1200                 return false;
1201             }
1202             if ( sdi7_4_2.getSpeciationsSum() != 5 ) {
1203                 return false;
1204             }
1205             //---------------------
1206             final String g2_0_ = "(([&&NHX:S=a1],[&&NHX:S=a2]),([&&NHX:S=o2],[&&NHX:S=o4]))";
1207             final Phylogeny g2_0p = TestGSDI.createPhylogeny( g2_0_ );
1208             g2_0.setRooted( true );
1209             final GSDI sdi2_0p = new GSDI( g2_0p, s2, false );
1210             if ( sdi2_0p.getDuplicationsSum() != 0 ) {
1211                 return false;
1212             }
1213         }
1214         catch ( final Exception e ) {
1215             e.printStackTrace( System.out );
1216             return false;
1217         }
1218         return true;
1219     }
1220
1221     public static void main( final String[] args ) {
1222         if ( !TestGSDI.testGSDI_against_binary_gene_tree() ) {
1223             System.out.println( "binary failed" );
1224         }
1225         if ( !TestGSDI.testGSDI_general() ) {
1226             System.out.println( "general failed" );
1227         }
1228         else {
1229             System.out.println( "general OK" );
1230         }
1231         //        boolean success = test();
1232         //        if ( success ) {
1233         //            System.out.println( "OK" );
1234         //        }
1235         //        else {
1236         //            System.out.println( "failed" );
1237         //        }
1238     }
1239 }