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