2 package org.forester.clade_analysis;
6 import org.forester.io.parsers.PhylogenyParser;
7 import org.forester.io.parsers.util.ParserUtils;
8 import org.forester.phylogeny.Phylogeny;
9 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
10 import org.forester.phylogeny.factories.PhylogenyFactory;
11 import org.forester.util.ForesterUtil;
13 public class CladeAnalysisTest {
15 private final static String PATH_TO_TEST_DATA = System.getProperty( "user.dir" ) + ForesterUtil.getFileSeparator()
16 + "test_data" + ForesterUtil.getFileSeparator();
18 public static void main( final String[] args ) {
19 boolean failed = false;
20 if ( !testCladeAnalysis1() ) {
21 System.out.println( "Clade analysis 1 failed" );
24 if ( !testCladeAnalysis2() ) {
25 System.out.println( "Clade analysis 2 failed" );
29 System.out.println( "OK" );
33 public static boolean test() {
34 if ( !testCladeAnalysis1() ) {
37 if ( !testCladeAnalysis2() ) {
43 private static boolean testCladeAnalysis1() {
45 final File intreefile1 = new File( PATH_TO_TEST_DATA + "clade_analysis_test_1.xml" );
46 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
47 final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( intreefile1, true );
48 final Phylogeny p1 = factory.create( intreefile1, pp )[ 0 ];
49 Result res = Analysis.execute( p1, "A.1.1.1", "." );
50 if ( !res.getGreatestCommonPrefix().equals( "A.1" ) ) {
53 if ( !res.getGreatestCommonPrefixDown().equals( "A.1.1" ) ) {
56 if ( !res.getGreatestCommonPrefixUp().equals( "A.1.2.1" ) ) {
59 if ( res.getLeastEncompassingCladeSize() != 4 ) {
62 if ( res.getTreeSize() != 25 ) {
65 if ( res.getWarnings().size() != 0 ) {
68 res = Analysis.execute( p1, "A.1.1.2", "." );
69 if ( !res.getGreatestCommonPrefix().equals( "A.1" ) ) {
72 if ( !res.getGreatestCommonPrefixDown().equals( "A.1.1" ) ) {
75 if ( !res.getGreatestCommonPrefixUp().equals( "A.1.2.1" ) ) {
78 if ( res.getLeastEncompassingCladeSize() != 4 ) {
81 if ( res.getTreeSize() != 25 ) {
84 if ( res.getWarnings().size() != 0 ) {
87 res = Analysis.execute( p1, "A.1.1.3", "." );
88 if ( !res.getGreatestCommonPrefix().equals( "A.1" ) ) {
91 if ( !res.getGreatestCommonPrefixDown().equals( "A.1.1" ) ) {
94 if ( !res.getGreatestCommonPrefixUp().equals( "A.1.2.1" ) ) {
97 if ( res.getLeastEncompassingCladeSize() != 4 ) {
100 if ( res.getTreeSize() != 25 ) {
103 if ( res.getWarnings().size() != 0 ) {
106 res = Analysis.execute( p1, "A.1.1.4", "." );
107 if ( !res.getGreatestCommonPrefix().equals( "A.1.1" ) ) {
110 if ( !res.getGreatestCommonPrefixDown().equals( "A.1.1" ) ) {
113 if ( !res.getGreatestCommonPrefixUp().equals( "A.1.1" ) ) {
116 if ( res.getLeastEncompassingCladeSize() != 3 ) {
119 if ( res.getTreeSize() != 25 ) {
122 if ( res.getWarnings().size() != 0 ) {
125 res = Analysis.execute( p1, "A.1.2.1", "." );
126 if ( !res.getGreatestCommonPrefix().equals( "A" ) ) {
129 if ( !res.getGreatestCommonPrefixDown().equals( "A.1.1" ) ) {
132 if ( !res.getGreatestCommonPrefixUp().equals( "A" ) ) {
135 if ( res.getLeastEncompassingCladeSize() != 17 ) {
138 if ( res.getTreeSize() != 25 ) {
141 if ( res.getWarnings().size() != 0 ) {
144 res = Analysis.execute( p1, "A.2.1.1", "." );
145 if ( !res.getGreatestCommonPrefix().equals( "A" ) ) {
148 if ( !res.getGreatestCommonPrefixDown().equals( "A.2.1.2" ) ) {
151 if ( !res.getGreatestCommonPrefixUp().equals( "A" ) ) {
154 if ( res.getLeastEncompassingCladeSize() != 17 ) {
157 if ( res.getTreeSize() != 25 ) {
160 if ( res.getWarnings().size() != 0 ) {
163 res = Analysis.execute( p1, "A.2.1.2", "." );
164 if ( !res.getGreatestCommonPrefix().equals( "A" ) ) {
167 if ( !res.getGreatestCommonPrefixDown().equals( "A.2.1.1" ) ) {
170 if ( !res.getGreatestCommonPrefixUp().equals( "A" ) ) {
173 if ( res.getLeastEncompassingCladeSize() != 17 ) {
176 if ( res.getTreeSize() != 25 ) {
179 if ( res.getWarnings().size() != 0 ) {
182 res = Analysis.execute( p1, "A.3.1.1", "." );
183 if ( !res.getGreatestCommonPrefix().equals( "A.3" ) ) {
186 if ( !res.getGreatestCommonPrefixDown().equals( "A.3.1.2" ) ) {
189 if ( !res.getGreatestCommonPrefixUp().equals( "A.3.2.1" ) ) {
192 if ( res.getLeastEncompassingCladeSize() != 2 ) {
195 if ( res.getTreeSize() != 25 ) {
198 if ( res.getWarnings().size() != 0 ) {
201 res = Analysis.execute( p1, "A.3.1.2", "." );
202 if ( !res.getGreatestCommonPrefix().equals( "A.3" ) ) {
205 if ( !res.getGreatestCommonPrefixDown().equals( "A.3.1.1" ) ) {
208 if ( !res.getGreatestCommonPrefixUp().equals( "A.3.2.1" ) ) {
211 if ( res.getLeastEncompassingCladeSize() != 2 ) {
214 if ( res.getTreeSize() != 25 ) {
217 if ( res.getWarnings().size() != 0 ) {
220 res = Analysis.execute( p1, "A.3.2.1", "." );
221 if ( !res.getGreatestCommonPrefix().equals( "A.3" ) ) {
224 if ( !res.getGreatestCommonPrefixDown().equals( "A.3.1" ) ) {
227 if ( !res.getGreatestCommonPrefixUp().equals( "A.3.3.1" ) ) {
230 if ( res.getLeastEncompassingCladeSize() != 3 ) {
233 if ( res.getTreeSize() != 25 ) {
236 if ( res.getWarnings().size() != 0 ) {
239 res = Analysis.execute( p1, "A.3.3.1", "." );
240 if ( !res.getGreatestCommonPrefix().equals( "A" ) ) {
243 if ( !res.getGreatestCommonPrefixDown().equals( "A.3" ) ) {
246 if ( !res.getGreatestCommonPrefixUp().equals( "A" ) ) {
249 if ( res.getLeastEncompassingCladeSize() != 10 ) {
252 if ( res.getTreeSize() != 25 ) {
255 if ( res.getWarnings().size() != 0 ) {
258 res = Analysis.execute( p1, "A.4.1.1", "." );
259 if ( !res.getGreatestCommonPrefix().equals( "A.4.1" ) ) {
262 if ( !res.getGreatestCommonPrefixDown().equals( "A.4.1.1.a" ) ) {
265 if ( !res.getGreatestCommonPrefixUp().equals( "A.4.1.2" ) ) {
268 if ( res.getLeastEncompassingCladeSize() != 3 ) {
271 if ( res.getTreeSize() != 25 ) {
274 if ( res.getWarnings().size() != 0 ) {
277 res = Analysis.execute( p1, "A.4.1.1.a", "." );
278 if ( !res.getGreatestCommonPrefix().equals( "A.4.1" ) ) {
281 if ( !res.getGreatestCommonPrefixDown().equals( "A.4.1.1" ) ) {
284 if ( !res.getGreatestCommonPrefixUp().equals( "A.4.1.2" ) ) {
287 if ( res.getLeastEncompassingCladeSize() != 3 ) {
290 if ( res.getTreeSize() != 25 ) {
293 if ( res.getWarnings().size() != 0 ) {
296 res = Analysis.execute( p1, "A.4.1.2", "." );
297 res = Analysis.execute( p1, "A.4.1.2.a", "." );
298 res = Analysis.execute( p1, "A.5.1.1", "." );
299 if ( !res.getGreatestCommonPrefix().equals( "A" ) ) {
302 if ( !res.getGreatestCommonPrefixDown().equals( "A.5.1.2" ) ) {
305 if ( !res.getGreatestCommonPrefixUp().equals( "A" ) ) {
308 if ( res.getLeastEncompassingCladeSize() != 10 ) {
311 if ( res.getTreeSize() != 25 ) {
314 if ( res.getWarnings().size() != 0 ) {
317 res = Analysis.execute( p1, "A.5.1.2", "." );
318 if ( !res.getGreatestCommonPrefix().equals( "A" ) ) {
321 if ( !res.getGreatestCommonPrefixDown().equals( "A.5.1.1" ) ) {
324 if ( !res.getGreatestCommonPrefixUp().equals( "A" ) ) {
327 if ( res.getLeastEncompassingCladeSize() != 10 ) {
330 if ( res.getTreeSize() != 25 ) {
333 if ( res.getWarnings().size() != 0 ) {
336 res = Analysis.execute( p1, "A.6.3.12", "." );
337 if ( !res.getGreatestCommonPrefix().equals( "A" ) ) {
340 if ( !res.getGreatestCommonPrefixDown().equals( "A" ) ) {
343 if ( !res.getGreatestCommonPrefixUp().equals( "A" ) ) {
346 if ( res.getLeastEncompassingCladeSize() != 17 ) {
349 if ( res.getTreeSize() != 25 ) {
352 if ( res.getWarnings().size() != 0 ) {
355 res = Analysis.execute( p1, "B.1.1.1", "." );
356 if ( !res.getGreatestCommonPrefix().equals( "" ) ) {
359 if ( !res.getGreatestCommonPrefixDown().equals( "B.1.234.3" ) ) {
362 if ( !res.getGreatestCommonPrefixUp().equals( "" ) ) {
365 if ( res.getLeastEncompassingCladeSize() != 25 ) {
368 if ( res.getTreeSize() != 25 ) {
371 if ( res.getWarnings().size() != 2 ) {
374 res = Analysis.execute( p1, "B.1.234.3", "." );
375 if ( !res.getGreatestCommonPrefix().equals( "" ) ) {
378 if ( !res.getGreatestCommonPrefixDown().equals( "B.1.1.1" ) ) {
381 if ( !res.getGreatestCommonPrefixUp().equals( "" ) ) {
384 if ( res.getLeastEncompassingCladeSize() != 25 ) {
387 if ( res.getTreeSize() != 25 ) {
390 if ( res.getWarnings().size() != 2 ) {
393 res = Analysis.execute( p1, "C.1.1.1", "." );
394 if ( !res.getGreatestCommonPrefix().equals( "C.1" ) ) {
397 if ( !res.getGreatestCommonPrefixDown().equals( "C.1.1.2" ) ) {
400 if ( !res.getGreatestCommonPrefixUp().equals( "C.1.2.1" ) ) {
403 if ( res.getLeastEncompassingCladeSize() != 2 ) {
406 if ( res.getTreeSize() != 25 ) {
409 if ( res.getWarnings().size() != 0 ) {
412 res = Analysis.execute( p1, "C.1.1.2", "." );
413 if ( !res.getGreatestCommonPrefix().equals( "C.1" ) ) {
416 if ( !res.getGreatestCommonPrefixDown().equals( "C.1.1.1" ) ) {
419 if ( !res.getGreatestCommonPrefixUp().equals( "C.1.2.1" ) ) {
422 if ( res.getLeastEncompassingCladeSize() != 2 ) {
425 if ( res.getTreeSize() != 25 ) {
428 if ( res.getWarnings().size() != 0 ) {
431 res = Analysis.execute( p1, "C.1.2.1", "." );
432 if ( !res.getGreatestCommonPrefix().equals( "C" ) ) {
435 if ( !res.getGreatestCommonPrefixDown().equals( "C.1.1" ) ) {
438 if ( !res.getGreatestCommonPrefixUp().equals( "C.2.1" ) ) {
441 if ( res.getLeastEncompassingCladeSize() != 3 ) {
444 if ( res.getTreeSize() != 25 ) {
447 if ( res.getWarnings().size() != 0 ) {
450 res = Analysis.execute( p1, "C.2.1", "." );
451 if ( !res.getGreatestCommonPrefix().equals( "C" ) ) {
454 if ( !res.getGreatestCommonPrefixDown().equals( "C.1" ) ) {
457 if ( !res.getGreatestCommonPrefixUp().equals( "C.3" ) ) {
460 if ( res.getLeastEncompassingCladeSize() != 4 ) {
463 if ( res.getTreeSize() != 25 ) {
466 if ( res.getWarnings().size() != 0 ) {
469 res = Analysis.execute( p1, "C.3", "." );
470 if ( !res.getGreatestCommonPrefix().equals( "" ) ) {
473 if ( !res.getGreatestCommonPrefixDown().equals( "C" ) ) {
476 if ( !res.getGreatestCommonPrefixUp().equals( "QE.1.1.1.2.1" ) ) {
479 if ( res.getLeastEncompassingCladeSize() != 5 ) {
482 if ( res.getTreeSize() != 25 ) {
485 if ( res.getWarnings().size() != 1 ) {
488 res = Analysis.execute( p1, "QE.1.1.1.2.1", "." );
489 if ( !res.getGreatestCommonPrefix().equals( "" ) ) {
492 if ( !res.getGreatestCommonPrefixDown().equals( "C" ) ) {
495 if ( !res.getGreatestCommonPrefixUp().equals( "" ) ) {
498 if ( res.getLeastEncompassingCladeSize() != 25 ) {
501 if ( res.getTreeSize() != 25 ) {
504 if ( res.getWarnings().size() != 2 ) {
508 catch ( final Exception e ) {
509 e.printStackTrace( System.out );
515 private static boolean testCladeAnalysis2() {
517 final File intreefile1 = new File( PATH_TO_TEST_DATA + "clade_analysis_test_2.xml" );
518 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
519 final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( intreefile1, true );
520 final Phylogeny p1 = factory.create( intreefile1, pp )[ 0 ];
521 Result res = Analysis.execute( p1, "6_DQ278891", null );
522 if ( !res.getGreatestCommonPrefix().equals( "6_" ) ) {
525 if ( !res.getGreatestCommonPrefixDown().equals( "6_DQ278893" ) ) {
528 if ( !res.getGreatestCommonPrefixUp().equals( "6_JX183550" ) ) {
531 if ( res.getLeastEncompassingCladeSize() != 2 ) {
534 if ( res.getTreeSize() != 219 ) {
537 if ( res.getWarnings().size() != 0 ) {
540 res = Analysis.execute( p1, "6xa_EU408330", null );
541 if ( !res.getGreatestCommonPrefix().equals( "6xa_EU40833" ) ) {
544 if ( !res.getGreatestCommonPrefixDown().equals( "6xa_EU408331" ) ) {
547 if ( !res.getGreatestCommonPrefixUp().equals( "6xa_EU408332" ) ) {
550 if ( res.getLeastEncompassingCladeSize() != 2 ) {
553 if ( res.getTreeSize() != 219 ) {
556 if ( res.getWarnings().size() != 0 ) {
559 res = Analysis.execute( p1, "7a_EF108306", null );
560 if ( !res.getGreatestCommonPrefix().equals( "" ) ) {
563 if ( !res.getGreatestCommonPrefixDown().equals( "2" ) ) {
566 if ( !res.getGreatestCommonPrefixUp().equals( "" ) ) {
569 if ( res.getLeastEncompassingCladeSize() != 219 ) {
572 if ( res.getTreeSize() != 219 ) {
575 if ( res.getWarnings().size() != 2 ) {
579 catch ( final Exception e ) {
580 e.printStackTrace( System.out );