in progress
[jalview.git] / forester / java / src / org / forester / surfacing / TestSurfacing.java
1 // $Id:
2 //
3 // FORESTER -- software libraries and applications
4 // for evolutionary biology research and applications.
5 //
6 // Copyright (C) 2008-2009 Christian M. Zmasek
7 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
8 // All rights reserved
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 //
24 // Contact: phylosoft @ gmail . com
25 // WWW: www.phylosoft.org/forester
26
27 package org.forester.surfacing;
28
29 import java.io.File;
30 import java.util.ArrayList;
31 import java.util.HashMap;
32 import java.util.HashSet;
33 import java.util.Iterator;
34 import java.util.List;
35 import java.util.Map;
36 import java.util.Set;
37 import java.util.SortedSet;
38 import java.util.TreeSet;
39
40 import org.forester.evoinference.matrix.character.BasicCharacterStateMatrix;
41 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
42 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
43 import org.forester.evoinference.matrix.character.CharacterStateMatrix.GainLossStates;
44 import org.forester.io.parsers.HmmPfamOutputParser;
45 import org.forester.io.parsers.nexus.PaupLogParser;
46 import org.forester.io.parsers.nhx.NHXParser;
47 import org.forester.phylogeny.Phylogeny;
48 import org.forester.phylogeny.PhylogenyNode;
49 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
50 import org.forester.phylogeny.factories.PhylogenyFactory;
51 import org.forester.protein.BasicProtein;
52 import org.forester.protein.BinaryDomainCombination;
53 import org.forester.protein.BinaryDomainCombination.DomainCombinationType;
54 import org.forester.protein.Domain;
55 import org.forester.protein.DomainId;
56 import org.forester.protein.Protein;
57 import org.forester.protein.ProteinId;
58 import org.forester.species.BasicSpecies;
59 import org.forester.species.Species;
60 import org.forester.test.Test;
61 import org.forester.util.ForesterUtil;
62
63 @SuppressWarnings( "unused")
64 public class TestSurfacing {
65
66     private final static double ZERO_DIFF = 1.0E-9;
67
68     public static boolean isEqual( final double a, final double b ) {
69         return ( ( Math.abs( a - b ) ) < TestSurfacing.ZERO_DIFF );
70     }
71
72     private static StringBuffer mapToStringBuffer( final Map<PhylogenyNode, CharacterStateMatrix.BinaryStates> map ) {
73         final StringBuffer sb = new StringBuffer();
74         for( final PhylogenyNode key : map.keySet() ) {
75             if ( !key.isExternal() ) {
76                 sb.append( key.getName() );
77                 sb.append( " : " );
78                 sb.append( map.get( key ).toString() );
79                 sb.append( ForesterUtil.getLineSeparator() );
80             }
81         }
82         return sb;
83     }
84
85     public static boolean test( final File test_dir ) {
86         System.out.print( "  Domain id: " );
87         if ( !TestSurfacing.testDomainId() ) {
88             System.out.println( "failed." );
89             return false;
90         }
91         System.out.println( "OK." );
92         System.out.print( "  Protein id: " );
93         if ( !TestSurfacing.testProteinId() ) {
94             System.out.println( "failed." );
95             return false;
96         }
97         System.out.println( "OK." );
98         System.out.print( "  Species: " );
99         if ( !TestSurfacing.testSpecies() ) {
100             System.out.println( "failed." );
101             return false;
102         }
103         System.out.println( "OK." );
104         System.out.print( "  Basic domain: " );
105         if ( !TestSurfacing.testBasicDomain() ) {
106             System.out.println( "failed." );
107             return false;
108         }
109         System.out.println( "OK." );
110         System.out.print( "  Basic protein: " );
111         if ( !TestSurfacing.testBasicProtein() ) {
112             System.out.println( "failed." );
113             return false;
114         }
115         System.out.println( "OK." );
116         System.out.print( "  Combinable domains: " );
117         if ( !TestSurfacing.testCombinableDomains() ) {
118             System.out.println( "failed." );
119             return false;
120         }
121         System.out.println( "OK." );
122         System.out.print( "  Directed combinable domains: " );
123         if ( !TestSurfacing.testDirectedCombinableDomains() ) {
124             System.out.println( "failed." );
125             return false;
126         }
127         System.out.println( "OK." );
128         System.out.print( "  Genome wide specific combinable domains: " );
129         if ( !TestSurfacing.testGenomeWideCombinableDomains() ) {
130             System.out.println( "failed." );
131             return false;
132         }
133         System.out.println( "OK." );
134         System.out.print( "  Domain architecture based genome similarity calculator: " );
135         if ( !TestSurfacing.testDomainArchitectureBasedGenomeSimilarityCalculator() ) {
136             System.out.println( "failed." );
137             return false;
138         }
139         System.out.println( "OK." );
140         System.out.print( "  Hmmpfam output parser: " );
141         if ( !TestSurfacing.testHmmPfamOutputParser( test_dir ) ) {
142             System.out.println( "failed." );
143             return false;
144         }
145         System.out.println( "OK." );
146         System.out.print( "  Hmmpfam output parser with filter: " );
147         if ( !TestSurfacing.testHmmPfamOutputParserWithFilter( test_dir ) ) {
148             System.out.println( "failed." );
149             return false;
150         }
151         System.out.println( "OK." );
152         System.out.print( "  Combinations based pairwise similarity calculator: " );
153         if ( !TestSurfacing.testCombinationsBasedPairwiseSimilarityCalculator() ) {
154             System.out.println( "failed." );
155             return false;
156         }
157         System.out.println( "OK." );
158         System.out.print( "  Copy number based pairwise similarity calculator: " );
159         if ( !TestSurfacing.testCopyNumberBasedPairwiseSimilarityCalculator() ) {
160             return false;
161         }
162         System.out.println( "OK." );
163         System.out.print( "  Domain combination counting: " );
164         if ( !TestSurfacing.testDomainCombinationCounting( test_dir ) ) {
165             System.out.println( "failed." );
166             return false;
167         }
168         System.out.println( "OK." );
169         System.out.print( "  Basic domain similarity calculator: " );
170         if ( !TestSurfacing.testBasicDomainSimilarityCalculator() ) {
171             System.out.println( "failed." );
172             return false;
173         }
174         System.out.println( "OK." );
175         System.out.print( "  Basic domain similarity calculator not ignoring species specific domains: " );
176         if ( !TestSurfacing.testBasicDomainSimilarityCalculatorNotIgnoringSpeciesSpeficDomains() ) {
177             System.out.println( "failed." );
178             return false;
179         }
180         System.out.println( "OK." );
181         System.out.print( "  Basic domain similarity calculator removal of singles: " );
182         if ( !TestSurfacing.testBasicDomainSimilarityCalculatorRemovalOfSingles() ) {
183             System.out.println( "failed." );
184             return false;
185         }
186         System.out.println( "OK." );
187         System.out.print( "  Domain sorting: " );
188         if ( !TestSurfacing.testDomainSorting() ) {
189             System.out.println( "failed." );
190             return false;
191         }
192         System.out.println( "OK." );
193         System.out.print( "  Overlap removal: " );
194         if ( !TestSurfacing.testOverlapRemoval() ) {
195             System.out.println( "failed." );
196             return false;
197         }
198         System.out.println( "OK." );
199         System.out.print( "  Engulfing overlap removal: " );
200         if ( !TestSurfacing.testEngulfingOverlapRemoval() ) {
201             System.out.println( "failed." );
202             return false;
203         }
204         System.out.println( "OK." );
205         System.out.print( "  Binary domain combination: " );
206         if ( !TestSurfacing.testBinaryDomainCombination() ) {
207             System.out.println( "failed." );
208             return false;
209         }
210         System.out.println( "OK." );
211         System.out.print( "  Parsimony: " );
212         if ( !TestSurfacing.testParsimony() ) {
213             System.out.println( "failed." );
214             return false;
215         }
216         System.out.println( "OK." );
217         System.out.print( "  Directedness: " );
218         if ( !TestSurfacing.testDirectedness() ) {
219             System.out.println( "failed." );
220             return false;
221         }
222         System.out.println( "OK." );
223         System.out.print( "  Directedness and adjacency: " );
224         if ( !TestSurfacing.testDirectednessAndAdjacency() ) {
225             System.out.println( "failed." );
226             return false;
227         }
228         System.out.println( "OK." );
229         System.out.print( "  Dollo parsimony on secodary features: " );
230         if ( !TestSurfacing.testParsimonyOnSecondaryFeatures() ) {
231             System.out.println( "failed." );
232             return false;
233         }
234         System.out.println( "OK." );
235         System.out.print( "  Paup log parser: " );
236         if ( !TestSurfacing.testPaupLogParser( test_dir ) ) {
237             System.out.println( "failed." );
238             return false;
239         }
240         System.out.println( "OK." );
241         System.out.print( "  Binary state matrix to gain loss matrix: " );
242         if ( !TestSurfacing.testBinaryStateMatrixToGainLossMatrix( test_dir ) ) {
243             System.out.println( "failed." );
244             return false;
245         }
246         System.out.println( "OK." );
247         return true;
248     }
249
250     private static boolean testBasicDomain() {
251         try {
252             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
253             if ( !pd.getDomainId().getId().equals( "id" ) ) {
254                 return false;
255             }
256             if ( pd.getNumber() != 1 ) {
257                 return false;
258             }
259             if ( pd.getTotalCount() != 4 ) {
260                 return false;
261             }
262             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
263                 return false;
264             }
265             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
266             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
267             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
268             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
269             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
270             if ( !a1.equals( a1 ) ) {
271                 return false;
272             }
273             if ( !a1.equals( a1_copy ) ) {
274                 return false;
275             }
276             if ( !a1.equals( a1_equal ) ) {
277                 return false;
278             }
279             if ( !a1.equals( a2 ) ) {
280                 return false;
281             }
282             if ( a1.equals( a3 ) ) {
283                 return false;
284             }
285             if ( a1.compareTo( a1 ) != 0 ) {
286                 return false;
287             }
288             if ( a1.compareTo( a1_copy ) != 0 ) {
289                 return false;
290             }
291             if ( a1.compareTo( a1_equal ) != 0 ) {
292                 return false;
293             }
294             if ( a1.compareTo( a2 ) != 0 ) {
295                 return false;
296             }
297             if ( a1.compareTo( a3 ) != 0 ) {
298                 return false;
299             }
300         }
301         catch ( final Exception e ) {
302             e.printStackTrace( System.out );
303             return false;
304         }
305         return true;
306     }
307
308     private static boolean testBasicDomainSimilarityCalculator() {
309         // mouse : ABCDE
310         // rabbit: A.C.EF
311         // ciona : A....FGX
312         // nemve : ABCDEFG
313         //
314         // domain A:
315         // m r c n
316         // m 2/(2+3) 0 4/(4+2)
317         // r 1/(1+4) 3/(3+3)
318         // c 2/(2+5)
319         // n
320         //
321         // mean = ( 2/5 + 0 + 2/3 + 1/5 + 1/2 + 2/7 ) / 6
322         // min = 0.0
323         // max = 2/3
324         // n = 6
325         //
326         //
327         // domain B:
328         // m n
329         // m 4/(4+2)
330         // n
331         //
332         // mean = 2/3
333         // min = 2/3
334         // max = 2/3
335         // sd = 0.0
336         // n = 1
337         //
338         //
339         // domain C:
340         // m r n
341         // m - 2/(2+3) 4/(4+2)
342         // r - - 3/(3+3)
343         // n - - -
344         //
345         // mean = (2/5 + 2/3 + 1/2)/3 =
346         // min = 2/5
347         // max = 2/3
348         // sd = 0.0
349         // n = 3
350         try {
351             final Domain A = new BasicDomain( "A", 1, 2, ( short ) 1, ( short ) 1, 0.15, -12 );
352             final Domain B = new BasicDomain( "B", 1, 2, ( short ) 1, ( short ) 1, 0.2, -12 );
353             final Domain C = new BasicDomain( "C", 1, 2, ( short ) 1, ( short ) 1, 0.3, -12 );
354             final Domain D = new BasicDomain( "D", 1, 2, ( short ) 1, ( short ) 1, 0.5, -12 );
355             final Domain E = new BasicDomain( "E", 1, 2, ( short ) 1, ( short ) 1, 0.5, -12 );
356             final Domain F = new BasicDomain( "F", 1, 2, ( short ) 1, ( short ) 1, 0.01, -12 );
357             final Domain G = new BasicDomain( "G", 1, 2, ( short ) 1, ( short ) 1, 0.001, -12 );
358             final Domain X = new BasicDomain( "X", 1, 2, ( short ) 1, ( short ) 1, 0.0001, -12 );
359             if ( !TestSurfacing.isEqual( X.getPerSequenceScore(), -12 ) ) {
360                 return false;
361             }
362             final Protein mouse_1 = new BasicProtein( "1", "mouse", 0 );
363             final Protein rabbit_1 = new BasicProtein( "1", "rabbit", 0 );
364             final Protein ciona_1 = new BasicProtein( "1", "ciona", 0 );
365             final Protein nemve_1 = new BasicProtein( "1", "nemve", 0 );
366             mouse_1.addProteinDomain( A );
367             mouse_1.addProteinDomain( B );
368             mouse_1.addProteinDomain( C );
369             mouse_1.addProteinDomain( D );
370             mouse_1.addProteinDomain( E );
371             rabbit_1.addProteinDomain( A );
372             rabbit_1.addProteinDomain( C );
373             rabbit_1.addProteinDomain( E );
374             rabbit_1.addProteinDomain( F );
375             rabbit_1.addProteinDomain( F );
376             rabbit_1.addProteinDomain( F );
377             rabbit_1.addProteinDomain( F );
378             rabbit_1.addProteinDomain( F );
379             rabbit_1.addProteinDomain( F );
380             ciona_1.addProteinDomain( A );
381             ciona_1.addProteinDomain( A );
382             ciona_1.addProteinDomain( A );
383             ciona_1.addProteinDomain( A );
384             ciona_1.addProteinDomain( A );
385             ciona_1.addProteinDomain( F );
386             ciona_1.addProteinDomain( G );
387             ciona_1.addProteinDomain( X );
388             nemve_1.addProteinDomain( A );
389             nemve_1.addProteinDomain( B );
390             nemve_1.addProteinDomain( C );
391             nemve_1.addProteinDomain( D );
392             nemve_1.addProteinDomain( E );
393             nemve_1.addProteinDomain( F );
394             nemve_1.addProteinDomain( G );
395             final List<Protein> protein_list_mouse = new ArrayList<Protein>();
396             final List<Protein> protein_list_rabbit = new ArrayList<Protein>();
397             final List<Protein> protein_list_ciona = new ArrayList<Protein>();
398             final List<Protein> protein_list_nemve = new ArrayList<Protein>();
399             protein_list_mouse.add( mouse_1 );
400             protein_list_rabbit.add( rabbit_1 );
401             protein_list_ciona.add( ciona_1 );
402             protein_list_nemve.add( nemve_1 );
403             final List<GenomeWideCombinableDomains> cdc_list = new ArrayList<GenomeWideCombinableDomains>();
404             cdc_list.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_mouse,
405                                                                            true,
406                                                                            new BasicSpecies( "mouse" ) ) );
407             cdc_list.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_rabbit,
408                                                                            true,
409                                                                            new BasicSpecies( "rabbit" ) ) );
410             cdc_list.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_ciona,
411                                                                            true,
412                                                                            new BasicSpecies( "ciona" ) ) );
413             cdc_list.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_nemve,
414                                                                            true,
415                                                                            new BasicSpecies( "nemve" ) ) );
416             final DomainSimilarityCalculator calc = new BasicDomainSimilarityCalculator( DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID,
417                                                                                          false,
418                                                                                          false );
419             final SortedSet<DomainSimilarity> sims = calc
420                     .calculateSimilarities( new CombinationsBasedPairwiseDomainSimilarityCalculator(),
421                                             cdc_list,
422                                             true,
423                                             true );
424             final Iterator<DomainSimilarity> sims_it = sims.iterator();
425             final DomainSimilarity sa = sims_it.next();
426             if ( !sa.getDomainId().getId().equals( "A" ) ) {
427                 return false;
428             }
429             if ( sa.getSpeciesData().size() != 4 ) {
430                 return false;
431             }
432             if ( !sa.getSpecies().contains( new BasicSpecies( "ciona" ) ) ) {
433                 return false;
434             }
435             if ( !sa.getSpecies().contains( new BasicSpecies( "mouse" ) ) ) {
436                 return false;
437             }
438             if ( !sa.getSpecies().contains( new BasicSpecies( "nemve" ) ) ) {
439                 return false;
440             }
441             if ( !sa.getSpecies().contains( new BasicSpecies( "rabbit" ) ) ) {
442                 return false;
443             }
444             if ( !TestSurfacing.isEqual( sa.getMeanSimilarityScore(),
445                                          ( 2.0 / 5 + 0 + 2.0 / 3 + 1.0 / 5 + 1.0 / 2 + 2.0 / 7 ) / 6 ) ) {
446                 return false;
447             }
448             if ( !TestSurfacing.isEqual( sa.getStandardDeviationOfSimilarityScore(), ( 0.23410788192183737 ) ) ) {
449                 return false;
450             }
451             if ( !TestSurfacing.isEqual( sa.getMaximalSimilarityScore(), ( 2.0 / 3 ) ) ) {
452                 return false;
453             }
454             if ( !TestSurfacing.isEqual( sa.getMinimalSimilarityScore(), ( 0.0 ) ) ) {
455                 return false;
456             }
457             if ( sa.getN() != 6 ) {
458                 return false;
459             }
460             if ( sa.getMaximalDifference() != 7 ) {
461                 return false;
462             }
463             if ( sa.getMaximalDifferenceInCounts() != 3 ) {
464                 return false;
465             }
466             final DomainSimilarity sb = sims_it.next();
467             if ( !sb.getDomainId().getId().equals( "B" ) ) {
468                 return false;
469             }
470             if ( sb.getSpeciesData().size() != 2 ) {
471                 return false;
472             }
473             if ( !sb.getSpecies().contains( new BasicSpecies( "mouse" ) ) ) {
474                 return false;
475             }
476             if ( !sb.getSpecies().contains( new BasicSpecies( "nemve" ) ) ) {
477                 return false;
478             }
479             if ( !TestSurfacing.isEqual( sb.getMeanSimilarityScore(), 2.0 / 3 ) ) {
480                 return false;
481             }
482             if ( !TestSurfacing.isEqual( sb.getStandardDeviationOfSimilarityScore(), 0.0 ) ) {
483                 return false;
484             }
485             if ( !TestSurfacing.isEqual( sb.getMaximalSimilarityScore(), ( 2.0 / 3 ) ) ) {
486                 return false;
487             }
488             if ( !TestSurfacing.isEqual( sb.getMinimalSimilarityScore(), ( 2.0 / 3 ) ) ) {
489                 return false;
490             }
491             if ( sb.getN() != 1 ) {
492                 return false;
493             }
494             if ( sb.getMaximalDifference() != 2 ) {
495                 return false;
496             }
497             if ( sb.getMaximalDifferenceInCounts() != 2 ) {
498                 return false;
499             }
500             final DomainSimilarity sc = sims_it.next();
501             if ( !sc.getDomainId().getId().equals( "C" ) ) {
502                 return false;
503             }
504             if ( sc.getSpeciesData().size() != 3 ) {
505                 return false;
506             }
507             if ( !sc.getSpecies().contains( new BasicSpecies( "mouse" ) ) ) {
508                 return false;
509             }
510             if ( !sc.getSpecies().contains( new BasicSpecies( "rabbit" ) ) ) {
511                 return false;
512             }
513             if ( !sc.getSpecies().contains( new BasicSpecies( "nemve" ) ) ) {
514                 return false;
515             }
516             if ( !TestSurfacing.isEqual( sc.getMeanSimilarityScore(), ( 2.0 / 5 + 2.0 / 3 + 1.0 / 2 ) / 3 ) ) {
517                 return false;
518             }
519             if ( !TestSurfacing.isEqual( sc.getStandardDeviationOfSimilarityScore(), 0.13471506281091264 ) ) {
520                 return false;
521             }
522             if ( !TestSurfacing.isEqual( sc.getMaximalSimilarityScore(), ( 2.0 / 3 ) ) ) {
523                 return false;
524             }
525             if ( !TestSurfacing.isEqual( sc.getMinimalSimilarityScore(), ( 2.0 / 5 ) ) ) {
526                 return false;
527             }
528             if ( sc.getN() != 3 ) {
529                 return false;
530             }
531             if ( sc.getMaximalDifference() != 3 ) {
532                 return false;
533             }
534             if ( sc.getMaximalDifferenceInCounts() != 3 ) {
535                 return false;
536             }
537             // mouse : ....ABCDE.....
538             // rabbit: ....A.C.EFFF..
539             // ciona : AAAAA......FGX
540             // nemve : ....ABCDEFG...
541             //
542             // domain A:
543             // m r c n
544             // m 2/(2+3) 0 4/(4+2)
545             // r - 1/(1+5) 3/(3+3)
546             // c - 2/(2+6)
547             // n
548             //
549             // mean = ( 2/5 + 0 + 2/3 + 1/6 + 1/2 + 2/8 ) / 6
550             // min = 0.0
551             // max = 2/3
552             // n = 6
553             final List<GenomeWideCombinableDomains> cdc_list2 = new ArrayList<GenomeWideCombinableDomains>();
554             cdc_list2.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_mouse,
555                                                                             false,
556                                                                             new BasicSpecies( "mouse" ) ) );
557             cdc_list2.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_rabbit,
558                                                                             false,
559                                                                             new BasicSpecies( "rabbit" ) ) );
560             cdc_list2.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_ciona,
561                                                                             false,
562                                                                             new BasicSpecies( "ciona" ) ) );
563             cdc_list2.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_nemve,
564                                                                             false,
565                                                                             new BasicSpecies( "nemve" ) ) );
566             final DomainSimilarityCalculator calc2 = new BasicDomainSimilarityCalculator( DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID,
567                                                                                           false,
568                                                                                           false );
569             final SortedSet<DomainSimilarity> sims2 = calc2
570                     .calculateSimilarities( new CombinationsBasedPairwiseDomainSimilarityCalculator(),
571                                             cdc_list2,
572                                             false,
573                                             true );
574             final Iterator<DomainSimilarity> sims_it2 = sims2.iterator();
575             final DomainSimilarity sa2 = sims_it2.next();
576             if ( !sa2.getDomainId().getId().equals( "A" ) ) {
577                 return false;
578             }
579             if ( sa2.getSpeciesData().size() != 4 ) {
580                 return false;
581             }
582             if ( !sa2.getSpecies().contains( new BasicSpecies( "ciona" ) ) ) {
583                 return false;
584             }
585             if ( !sa2.getSpecies().contains( new BasicSpecies( "mouse" ) ) ) {
586                 return false;
587             }
588             if ( !sa2.getSpecies().contains( new BasicSpecies( "nemve" ) ) ) {
589                 return false;
590             }
591             if ( !sa2.getSpeciesData().keySet().contains( new BasicSpecies( "rabbit" ) ) ) {
592                 return false;
593             }
594             if ( !TestSurfacing.isEqual( sa2.getMeanSimilarityScore(),
595                                          ( 2.0 / 5 + 0 + 2.0 / 3 + 1.0 / 6 + 1.0 / 2 + 2.0 / 8 ) / 6 ) ) {
596                 return false;
597             }
598             if ( !TestSurfacing.isEqual( sa2.getStandardDeviationOfSimilarityScore(), ( 0.2404663678647683 ) ) ) {
599                 return false;
600             }
601             if ( !TestSurfacing.isEqual( sa2.getMaximalSimilarityScore(), ( 2.0 / 3 ) ) ) {
602                 return false;
603             }
604             if ( !TestSurfacing.isEqual( sa2.getMinimalSimilarityScore(), ( 0.0 ) ) ) {
605                 return false;
606             }
607             if ( sa2.getN() != 6 ) {
608                 return false;
609             }
610             if ( sa2.getMaximalDifference() != 8 ) {
611                 return false;
612             }
613             if ( sa2.getMaximalDifferenceInCounts() != 3 ) {
614                 return false;
615             }
616             final Protein ciona_2 = new BasicProtein( "2", "ciona", 0 );
617             ciona_2.addProteinDomain( A );
618             ciona_2.addProteinDomain( A );
619             ciona_2.addProteinDomain( A );
620             ciona_2.addProteinDomain( B );
621             ciona_2.addProteinDomain( B );
622             ciona_2.addProteinDomain( B );
623             ciona_2.addProteinDomain( F );
624             ciona_2.addProteinDomain( F );
625             ciona_2.addProteinDomain( F );
626             ciona_2.addProteinDomain( F );
627             ciona_2.addProteinDomain( G );
628             ciona_2.addProteinDomain( X );
629             final Protein ciona_3 = new BasicProtein( "3", "ciona", 0 );
630             ciona_3.addProteinDomain( A );
631             ciona_3.addProteinDomain( A );
632             ciona_3.addProteinDomain( A );
633             ciona_3.addProteinDomain( A );
634             ciona_3.addProteinDomain( B );
635             ciona_3.addProteinDomain( B );
636             ciona_3.addProteinDomain( X );
637             ciona_3.addProteinDomain( X );
638             protein_list_ciona.add( ciona_2 );
639             protein_list_ciona.add( ciona_3 );
640             final List<GenomeWideCombinableDomains> cdc_list3 = new ArrayList<GenomeWideCombinableDomains>();
641             cdc_list3.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_mouse,
642                                                                             true,
643                                                                             new BasicSpecies( "mouse" ) ) );
644             cdc_list3.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_rabbit,
645                                                                             true,
646                                                                             new BasicSpecies( "rabbit" ) ) );
647             cdc_list3.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_ciona,
648                                                                             true,
649                                                                             new BasicSpecies( "ciona" ) ) );
650             cdc_list3.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_nemve,
651                                                                             true,
652                                                                             new BasicSpecies( "nemve" ) ) );
653             final DomainSimilarityCalculator calc3 = new BasicDomainSimilarityCalculator( DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID,
654                                                                                           false,
655                                                                                           false );
656             final SortedSet<DomainSimilarity> sims3 = calc3
657                     .calculateSimilarities( new CombinationsBasedPairwiseDomainSimilarityCalculator(),
658                                             cdc_list3,
659                                             false,
660                                             true );
661             final Iterator<DomainSimilarity> sims_it3 = sims3.iterator();
662             final DomainSimilarity sa3 = sims_it3.next();
663             if ( !sa3.getDomainId().getId().equals( "A" ) ) {
664                 return false;
665             }
666             final SpeciesSpecificDomainSimilariyData ssdsd = sa3.getSpeciesData().get( new BasicSpecies( "ciona" ) );
667             if ( ssdsd.getCombinableDomainIdToCountsMap().size() != 4 ) {
668                 return false;
669             }
670             if ( ssdsd.getNumberOfProteinsExhibitingCombinationWith( new DomainId( "B" ) ) != 2 ) {
671                 return false;
672             }
673             if ( ssdsd.getNumberOfProteinsExhibitingCombinationWith( new DomainId( "F" ) ) != 2 ) {
674                 return false;
675             }
676             if ( ssdsd.getNumberOfProteinsExhibitingCombinationWith( new DomainId( "G" ) ) != 2 ) {
677                 return false;
678             }
679             if ( ssdsd.getNumberOfProteinsExhibitingCombinationWith( new DomainId( "X" ) ) != 3 ) {
680                 return false;
681             }
682             final List<GenomeWideCombinableDomains> cdc_list4 = new ArrayList<GenomeWideCombinableDomains>();
683             cdc_list4.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_mouse,
684                                                                             false,
685                                                                             new BasicSpecies( "mouse" ) ) );
686             cdc_list4.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_rabbit,
687                                                                             false,
688                                                                             new BasicSpecies( "rabbit" ) ) );
689             cdc_list4.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_ciona,
690                                                                             false,
691                                                                             new BasicSpecies( "ciona" ) ) );
692             ;
693             cdc_list4.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_nemve,
694                                                                             false,
695                                                                             new BasicSpecies( "nemve" ) ) );
696             final DomainSimilarityCalculator calc4 = new BasicDomainSimilarityCalculator( DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID,
697                                                                                           true,
698                                                                                           false );
699             final SortedSet<DomainSimilarity> sims4 = calc4
700                     .calculateSimilarities( new CombinationsBasedPairwiseDomainSimilarityCalculator(),
701                                             cdc_list4,
702                                             false,
703                                             true );
704             final Iterator<DomainSimilarity> sims_it4 = sims4.iterator();
705             final DomainSimilarity sa4 = sims_it4.next();
706             if ( !sa4.getDomainId().getId().equals( "A" ) ) {
707                 return false;
708             }
709             final SpeciesSpecificDomainSimilariyData ssdsd4 = sa4.getSpeciesData().get( new BasicSpecies( "ciona" ) );
710             if ( ssdsd4.getCombinableDomainIdToCountsMap().size() != 5 ) {
711                 return false;
712             }
713             if ( ssdsd4.getNumberOfProteinsExhibitingCombinationWith( new DomainId( "A" ) ) != 3 ) {
714                 return false;
715             }
716             if ( ssdsd4.getNumberOfProteinsExhibitingCombinationWith( new DomainId( "B" ) ) != 2 ) {
717                 return false;
718             }
719             if ( ssdsd4.getNumberOfProteinsExhibitingCombinationWith( new DomainId( "F" ) ) != 2 ) {
720                 return false;
721             }
722             if ( ssdsd4.getNumberOfProteinsExhibitingCombinationWith( new DomainId( "G" ) ) != 2 ) {
723                 return false;
724             }
725             if ( ssdsd4.getNumberOfProteinsExhibitingCombinationWith( new DomainId( "X" ) ) != 3 ) {
726                 return false;
727             }
728             final SortedSet<DomainSimilarity> sims4_d = calc4
729                     .calculateSimilarities( new DomainCountsBasedPairwiseSimilarityCalculator(), cdc_list4, false, true );
730             final Iterator<DomainSimilarity> sims_it4_d = sims4_d.iterator();
731             final DomainSimilarity sa4_d = sims_it4_d.next();
732             if ( !sa4_d.getDomainId().getId().equals( "A" ) ) {
733                 return false;
734             }
735             if ( sa4_d.getCombinableDomainIds( new BasicSpecies( "ciona" ) ).size() != 5 ) {
736                 return false;
737             }
738             if ( !TestSurfacing.isEqual( sa4_d.getMeanSimilarityScore(), ( 1 + 1 - 11.0 / 13 + 1 - 11.0 / 13 + 1 + 1
739                     + 1 - 11.0 / 13 ) / 6.0 ) ) {
740                 return false;
741             }
742             if ( !TestSurfacing.isEqual( sa4_d.getMaximalSimilarityScore(), 1.0 ) ) {
743                 return false;
744             }
745             if ( !TestSurfacing.isEqual( sa4_d.getMinimalSimilarityScore(), ( 1 - 11.0 / 13 ) ) ) {
746                 return false;
747             }
748             if ( sa4_d.getN() != 6 ) {
749                 return false;
750             }
751             final SortedSet<DomainSimilarity> sims4_p = calc4
752                     .calculateSimilarities( new ProteinCountsBasedPairwiseDomainSimilarityCalculator(),
753                                             cdc_list4,
754                                             false,
755                                             true );
756             final Iterator<DomainSimilarity> sims_it4_p = sims4_p.iterator();
757             final DomainSimilarity sa4_p = sims_it4_p.next();
758             if ( !sa4_p.getDomainId().getId().equals( "A" ) ) {
759                 return false;
760             }
761             if ( sa4_p.getCombinableDomainIds( new BasicSpecies( "ciona" ) ).size() != 5 ) {
762                 return false;
763             }
764             if ( !sa4_p.getCombinableDomainIds( new BasicSpecies( "ciona" ) ).contains( new DomainId( "A" ) ) ) {
765                 return false;
766             }
767             if ( !sa4_p.getCombinableDomainIds( new BasicSpecies( "ciona" ) ).contains( new DomainId( "B" ) ) ) {
768                 return false;
769             }
770             if ( !sa4_p.getCombinableDomainIds( new BasicSpecies( "ciona" ) ).contains( new DomainId( "F" ) ) ) {
771                 return false;
772             }
773             if ( !sa4_p.getCombinableDomainIds( new BasicSpecies( "ciona" ) ).contains( new DomainId( "G" ) ) ) {
774                 return false;
775             }
776             if ( !sa4_p.getCombinableDomainIds( new BasicSpecies( "ciona" ) ).contains( new DomainId( "X" ) ) ) {
777                 return false;
778             }
779             if ( !TestSurfacing.isEqual( sa4_p.getMeanSimilarityScore(),
780                                          ( 1 + 1 - 2.0 / 4 + 1 - 2.0 / 4 + 1 + 1 + 1 - 2.0 / 4 ) / 6.0 ) ) {
781                 return false;
782             }
783             if ( !TestSurfacing.isEqual( sa4_p.getMaximalSimilarityScore(), 1 ) ) {
784                 return false;
785             }
786             if ( !TestSurfacing.isEqual( sa4_p.getMinimalSimilarityScore(), ( 1 - 2.0 / 4 ) ) ) {
787                 return false;
788             }
789             if ( sa4_p.getN() != 6 ) {
790                 return false;
791             }
792             final List<GenomeWideCombinableDomains> cdc_list5 = new ArrayList<GenomeWideCombinableDomains>();
793             cdc_list5.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_mouse,
794                                                                             true,
795                                                                             new BasicSpecies( "mouse" ) ) );
796             cdc_list5.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_rabbit,
797                                                                             true,
798                                                                             new BasicSpecies( "rabbit" ) ) );
799             cdc_list5.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_ciona,
800                                                                             true,
801                                                                             new BasicSpecies( "ciona" ) ) );
802             cdc_list5.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_nemve,
803                                                                             true,
804                                                                             new BasicSpecies( "nemve" ) ) );
805             final SortedSet<DomainSimilarity> sims5_d = calc4
806                     .calculateSimilarities( new DomainCountsBasedPairwiseSimilarityCalculator(), cdc_list5, false, true );
807             final Iterator<DomainSimilarity> sims_it5_d = sims5_d.iterator();
808             final DomainSimilarity sa5_d = sims_it5_d.next();
809             if ( sa5_d.getSpecies().size() != 4 ) {
810                 return false;
811             }
812             if ( !sa5_d.getSpecies().last().equals( new BasicSpecies( "rabbit" ) ) ) {
813                 return false;
814             }
815             final SpeciesSpecificDomainSimilariyData ssdsd5 = sa5_d.getSpeciesData().get( new BasicSpecies( "ciona" ) );
816             if ( ssdsd5.getCombinableDomainIdToCountsMap().size() != 4 ) {
817                 return false;
818             }
819             if ( ssdsd5.getNumberOfProteinsExhibitingCombinationWith( new DomainId( "B" ) ) != 2 ) {
820                 return false;
821             }
822             if ( ssdsd5.getNumberOfProteinsExhibitingCombinationWith( new DomainId( "F" ) ) != 2 ) {
823                 return false;
824             }
825             if ( ssdsd5.getNumberOfProteinsExhibitingCombinationWith( new DomainId( "G" ) ) != 2 ) {
826                 return false;
827             }
828             if ( ssdsd5.getNumberOfProteinsExhibitingCombinationWith( new DomainId( "X" ) ) != 3 ) {
829                 return false;
830             }
831             if ( !sa5_d.getDomainId().getId().equals( "A" ) ) {
832                 return false;
833             }
834             final Species ciona = new BasicSpecies( "ciona" );
835             if ( sa5_d.getCombinableDomainIds( ciona ).size() != 4 ) {
836                 return false;
837             }
838             if ( sa5_d.getCombinableDomainIds( ciona ).contains( new DomainId( "A" ) ) ) {
839                 return false;
840             }
841             if ( !sa5_d.getCombinableDomainIds( ciona ).contains( new DomainId( "B" ) ) ) {
842                 return false;
843             }
844             if ( !sa5_d.getCombinableDomainIds( ciona ).contains( new DomainId( "F" ) ) ) {
845                 return false;
846             }
847             if ( !sa5_d.getCombinableDomainIds( ciona ).contains( new DomainId( "G" ) ) ) {
848                 return false;
849             }
850             if ( !sa5_d.getCombinableDomainIds( ciona ).contains( new DomainId( "X" ) ) ) {
851                 return false;
852             }
853             if ( !TestSurfacing.isEqual( sa5_d.getMeanSimilarityScore(), ( 1 + 1 - 11.0 / 13 + 1 - 11.0 / 13 + 1 + 1
854                     + 1 - 11.0 / 13 ) / 6.0 ) ) {
855                 return false;
856             }
857             if ( !TestSurfacing.isEqual( sa5_d.getMaximalSimilarityScore(), 1.0 ) ) {
858                 return false;
859             }
860             if ( !TestSurfacing.isEqual( sa5_d.getMinimalSimilarityScore(), ( 1 - 11.0 / 13 ) ) ) {
861                 return false;
862             }
863             if ( sa5_d.getN() != 6 ) {
864                 return false;
865             }
866             if ( sa5_d.getMaximalDifference() != sa5_d.getMaximalDifferenceInCounts() ) {
867                 return false;
868             }
869             if ( sa5_d.getMaximalDifference() != 11 ) {
870                 return false;
871             }
872             if ( sa5_d.getMaximalDifferenceInCounts() != 11 ) {
873                 return false;
874             }
875             final SortedSet<DomainSimilarity> sims5_p = calc4
876                     .calculateSimilarities( new ProteinCountsBasedPairwiseDomainSimilarityCalculator(),
877                                             cdc_list5,
878                                             false,
879                                             true );
880             final Iterator<DomainSimilarity> sims_it5_p = sims5_p.iterator();
881             final DomainSimilarity sa5_p = sims_it5_p.next();
882             if ( !sa5_p.getDomainId().getId().equals( "A" ) ) {
883                 return false;
884             }
885             if ( sa5_p.getCombinableDomainIds( ciona ).size() != 4 ) {
886                 return false;
887             }
888             if ( sa5_p.getCombinableDomainIds( ciona ).contains( new DomainId( "A" ) ) ) {
889                 return false;
890             }
891             if ( !sa5_p.getCombinableDomainIds( ciona ).contains( new DomainId( "B" ) ) ) {
892                 return false;
893             }
894             if ( !sa5_p.getCombinableDomainIds( ciona ).contains( new DomainId( "F" ) ) ) {
895                 return false;
896             }
897             if ( !sa5_p.getCombinableDomainIds( ciona ).contains( new DomainId( "G" ) ) ) {
898                 return false;
899             }
900             if ( !sa5_p.getCombinableDomainIds( ciona ).contains( new DomainId( "X" ) ) ) {
901                 return false;
902             }
903             if ( !TestSurfacing.isEqual( sa5_p.getMeanSimilarityScore(),
904                                          ( 1 + 1 - 2.0 / 4 + 1 - 2.0 / 4 + 1 + 1 + 1 - 2.0 / 4 ) / 6.0 ) ) {
905                 return false;
906             }
907             if ( !TestSurfacing.isEqual( sa5_p.getMaximalSimilarityScore(), 1 ) ) {
908                 return false;
909             }
910             if ( !TestSurfacing.isEqual( sa5_p.getMinimalSimilarityScore(), ( 1 - 2.0 / 4 ) ) ) {
911                 return false;
912             }
913             if ( sa5_p.getN() != 6 ) {
914                 return false;
915             }
916             if ( sa5_p.getMaximalDifference() != sa5_p.getMaximalDifferenceInCounts() ) {
917                 return false;
918             }
919             if ( sa5_p.getMaximalDifference() != 2 ) {
920                 return false;
921             }
922             if ( sa5_p.getMaximalDifferenceInCounts() != 2 ) {
923                 return false;
924             }
925             final List<GenomeWideCombinableDomains> cdc_list6 = new ArrayList<GenomeWideCombinableDomains>();
926             cdc_list6.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_mouse,
927                                                                             false,
928                                                                             new BasicSpecies( "mouse" ) ) );
929             cdc_list6.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_rabbit,
930                                                                             false,
931                                                                             new BasicSpecies( "rabbit" ) ) );
932             cdc_list6.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_ciona,
933                                                                             false,
934                                                                             new BasicSpecies( "ciona" ) ) );
935             cdc_list6.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_nemve,
936                                                                             false,
937                                                                             new BasicSpecies( "nemve" ) ) );
938             final SortedSet<DomainSimilarity> sims6_d = calc4
939                     .calculateSimilarities( new DomainCountsBasedPairwiseSimilarityCalculator(), cdc_list6, false, true );
940             final Iterator<DomainSimilarity> sims_it6_d = sims6_d.iterator();
941             final DomainSimilarity sa6_d = sims_it6_d.next();
942             if ( sa6_d.getSpecies().size() != 4 ) {
943                 return false;
944             }
945             if ( !sa6_d.getSpecies().last().equals( new BasicSpecies( "rabbit" ) ) ) {
946                 return false;
947             }
948             final SpeciesSpecificDomainSimilariyData ssdsd6 = sa6_d.getSpeciesData().get( new BasicSpecies( "ciona" ) );
949             if ( ssdsd6.getCombinableDomainIdToCountsMap().size() != 5 ) {
950                 return false;
951             }
952             if ( ssdsd6.getNumberOfProteinsExhibitingCombinationWith( new DomainId( "B" ) ) != 2 ) {
953                 return false;
954             }
955             if ( ssdsd6.getNumberOfProteinsExhibitingCombinationWith( new DomainId( "F" ) ) != 2 ) {
956                 return false;
957             }
958             if ( ssdsd6.getNumberOfProteinsExhibitingCombinationWith( new DomainId( "G" ) ) != 2 ) {
959                 return false;
960             }
961             if ( ssdsd6.getNumberOfProteinsExhibitingCombinationWith( new DomainId( "X" ) ) != 3 ) {
962                 return false;
963             }
964             if ( !sa5_d.getDomainId().getId().equals( "A" ) ) {
965                 return false;
966             }
967             final Species ciona6 = new BasicSpecies( "ciona" );
968             if ( sa6_d.getCombinableDomainIds( ciona6 ).size() != 5 ) {
969                 return false;
970             }
971             if ( !sa6_d.getCombinableDomainIds( ciona6 ).contains( new DomainId( "A" ) ) ) {
972                 return false;
973             }
974             if ( !sa6_d.getCombinableDomainIds( ciona6 ).contains( new DomainId( "B" ) ) ) {
975                 return false;
976             }
977             if ( !sa6_d.getCombinableDomainIds( ciona6 ).contains( new DomainId( "F" ) ) ) {
978                 return false;
979             }
980             if ( !sa6_d.getCombinableDomainIds( ciona6 ).contains( new DomainId( "G" ) ) ) {
981                 return false;
982             }
983             if ( !sa6_d.getCombinableDomainIds( ciona6 ).contains( new DomainId( "X" ) ) ) {
984                 return false;
985             }
986             if ( !TestSurfacing.isEqual( sa6_d.getMeanSimilarityScore(), ( 1 + 1 - 11.0 / 13 + 1 - 11.0 / 13 + 1 + 1
987                     + 1 - 11.0 / 13 ) / 6.0 ) ) {
988                 return false;
989             }
990             if ( !TestSurfacing.isEqual( sa6_d.getMaximalSimilarityScore(), 1.0 ) ) {
991                 return false;
992             }
993             if ( !TestSurfacing.isEqual( sa6_d.getMinimalSimilarityScore(), ( 1 - 11.0 / 13 ) ) ) {
994                 return false;
995             }
996             if ( sa6_d.getN() != 6 ) {
997                 return false;
998             }
999             if ( sa6_d.getMaximalDifference() != sa6_d.getMaximalDifferenceInCounts() ) {
1000                 return false;
1001             }
1002             if ( sa6_d.getMaximalDifference() != 11 ) {
1003                 return false;
1004             }
1005             if ( sa6_d.getMaximalDifferenceInCounts() != 11 ) {
1006                 return false;
1007             }
1008             final SortedSet<DomainSimilarity> sims6_p = calc4
1009                     .calculateSimilarities( new ProteinCountsBasedPairwiseDomainSimilarityCalculator(),
1010                                             cdc_list6,
1011                                             false,
1012                                             true );
1013             final Iterator<DomainSimilarity> sims_it6_p = sims6_p.iterator();
1014             final DomainSimilarity sa6_p = sims_it6_p.next();
1015             if ( !sa6_p.getDomainId().getId().equals( "A" ) ) {
1016                 return false;
1017             }
1018             if ( sa6_p.getCombinableDomainIds( ciona ).size() != 5 ) {
1019                 return false;
1020             }
1021             if ( !sa6_p.getCombinableDomainIds( ciona ).contains( new DomainId( "A" ) ) ) {
1022                 return false;
1023             }
1024             if ( !sa6_p.getCombinableDomainIds( ciona ).contains( new DomainId( "B" ) ) ) {
1025                 return false;
1026             }
1027             if ( !sa6_p.getCombinableDomainIds( ciona ).contains( new DomainId( "F" ) ) ) {
1028                 return false;
1029             }
1030             if ( !sa6_p.getCombinableDomainIds( ciona ).contains( new DomainId( "G" ) ) ) {
1031                 return false;
1032             }
1033             if ( !sa6_p.getCombinableDomainIds( ciona ).contains( new DomainId( "X" ) ) ) {
1034                 return false;
1035             }
1036             if ( !TestSurfacing.isEqual( sa6_p.getMeanSimilarityScore(),
1037                                          ( 1 + 1 - 2.0 / 4 + 1 - 2.0 / 4 + 1 + 1 + 1 - 2.0 / 4 ) / 6.0 ) ) {
1038                 return false;
1039             }
1040             if ( !TestSurfacing.isEqual( sa6_p.getMaximalSimilarityScore(), 1 ) ) {
1041                 return false;
1042             }
1043             if ( !TestSurfacing.isEqual( sa6_p.getMinimalSimilarityScore(), ( 1 - 2.0 / 4 ) ) ) {
1044                 return false;
1045             }
1046             if ( sa6_p.getN() != 6 ) {
1047                 return false;
1048             }
1049             if ( sa6_p.getMaximalDifference() != sa6_p.getMaximalDifferenceInCounts() ) {
1050                 return false;
1051             }
1052             if ( sa6_p.getMaximalDifference() != 2 ) {
1053                 return false;
1054             }
1055             if ( sa6_p.getMaximalDifferenceInCounts() != 2 ) {
1056                 return false;
1057             }
1058         }
1059         catch ( final Exception e ) {
1060             e.printStackTrace( System.out );
1061             return false;
1062         }
1063         return true;
1064     }
1065
1066     private static boolean testBasicDomainSimilarityCalculatorNotIgnoringSpeciesSpeficDomains() {
1067         try {
1068             final Domain A = new BasicDomain( "A", 1, 2, ( short ) 1, ( short ) 1, 0.15, -12 );
1069             final Domain B = new BasicDomain( "B", 1, 2, ( short ) 1, ( short ) 1, 0.2, -12 );
1070             final Domain D = new BasicDomain( "D", 1, 2, ( short ) 1, ( short ) 1, 0.5, -12 );
1071             final Domain E = new BasicDomain( "E", 1, 2, ( short ) 1, ( short ) 1, 0.5, -12 );
1072             final Domain F = new BasicDomain( "F", 1, 2, ( short ) 1, ( short ) 1, 0.01, -12 );
1073             final Domain G = new BasicDomain( "G", 1, 2, ( short ) 1, ( short ) 1, 0.001, -12 );
1074             final Domain X = new BasicDomain( "X", 1, 2, ( short ) 1, ( short ) 1, 0.0001, -12 );
1075             if ( !TestSurfacing.isEqual( X.getPerSequenceScore(), -12 ) ) {
1076                 return false;
1077             }
1078             final Protein mouse_1 = new BasicProtein( "1", "mouse", 0 );
1079             final Protein rabbit_1 = new BasicProtein( "1", "rabbit", 0 );
1080             final Protein ciona_1 = new BasicProtein( "1", "ciona", 0 );
1081             final Protein nemve_1 = new BasicProtein( "1", "nemve", 0 );
1082             mouse_1.addProteinDomain( A );
1083             mouse_1.addProteinDomain( D );
1084             mouse_1.addProteinDomain( E );
1085             rabbit_1.addProteinDomain( B );
1086             rabbit_1.addProteinDomain( E );
1087             rabbit_1.addProteinDomain( F );
1088             rabbit_1.addProteinDomain( F );
1089             rabbit_1.addProteinDomain( F );
1090             rabbit_1.addProteinDomain( F );
1091             rabbit_1.addProteinDomain( F );
1092             rabbit_1.addProteinDomain( F );
1093             ciona_1.addProteinDomain( F );
1094             ciona_1.addProteinDomain( G );
1095             ciona_1.addProteinDomain( X );
1096             nemve_1.addProteinDomain( D );
1097             nemve_1.addProteinDomain( E );
1098             nemve_1.addProteinDomain( F );
1099             nemve_1.addProteinDomain( G );
1100             final List<Protein> protein_list_mouse = new ArrayList<Protein>();
1101             final List<Protein> protein_list_rabbit = new ArrayList<Protein>();
1102             final List<Protein> protein_list_ciona = new ArrayList<Protein>();
1103             final List<Protein> protein_list_nemve = new ArrayList<Protein>();
1104             protein_list_mouse.add( mouse_1 );
1105             protein_list_rabbit.add( rabbit_1 );
1106             protein_list_ciona.add( ciona_1 );
1107             protein_list_nemve.add( nemve_1 );
1108             final List<GenomeWideCombinableDomains> cdc_list = new ArrayList<GenomeWideCombinableDomains>();
1109             cdc_list.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_mouse,
1110                                                                            true,
1111                                                                            new BasicSpecies( "mouse" ) ) );
1112             cdc_list.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_rabbit,
1113                                                                            true,
1114                                                                            new BasicSpecies( "rabbit" ) ) );
1115             cdc_list.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_ciona,
1116                                                                            true,
1117                                                                            new BasicSpecies( "ciona" ) ) );
1118             cdc_list.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_nemve,
1119                                                                            true,
1120                                                                            new BasicSpecies( "nemve" ) ) );
1121             final DomainSimilarityCalculator calc = new BasicDomainSimilarityCalculator( DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID,
1122                                                                                          false,
1123                                                                                          false );
1124             final SortedSet<DomainSimilarity> sims = calc
1125                     .calculateSimilarities( new CombinationsBasedPairwiseDomainSimilarityCalculator(),
1126                                             cdc_list,
1127                                             true,
1128                                             false );
1129             final Iterator<DomainSimilarity> sims_it = sims.iterator();
1130             final DomainSimilarity sa = sims_it.next();
1131             if ( !sa.getDomainId().getId().equals( "A" ) ) {
1132                 return false;
1133             }
1134             if ( sa.getSpeciesData().size() != 1 ) {
1135                 return false;
1136             }
1137             if ( !sa.getSpecies().contains( new BasicSpecies( "mouse" ) ) ) {
1138                 return false;
1139             }
1140             if ( !TestSurfacing.isEqual( sa.getMeanSimilarityScore(), 1.0 ) ) {
1141                 return false;
1142             }
1143             if ( !TestSurfacing.isEqual( sa.getStandardDeviationOfSimilarityScore(), 0.0 ) ) {
1144                 return false;
1145             }
1146             if ( !TestSurfacing.isEqual( sa.getMaximalSimilarityScore(), 1.0 ) ) {
1147                 return false;
1148             }
1149             if ( !TestSurfacing.isEqual( sa.getMinimalSimilarityScore(), 1.0 ) ) {
1150                 return false;
1151             }
1152             if ( sa.getN() != 0 ) {
1153                 return false;
1154             }
1155             if ( sa.getMaximalDifference() != 0 ) {
1156                 return false;
1157             }
1158             if ( sa.getMaximalDifferenceInCounts() != 0 ) {
1159                 return false;
1160             }
1161             final DomainSimilarity sb = sims_it.next();
1162             if ( !sb.getDomainId().getId().equals( "B" ) ) {
1163                 return false;
1164             }
1165             if ( sb.getSpeciesData().size() != 1 ) {
1166                 return false;
1167             }
1168             if ( !sb.getSpecies().contains( new BasicSpecies( "rabbit" ) ) ) {
1169                 return false;
1170             }
1171             final SortedSet<DomainSimilarity> sims2 = calc
1172                     .calculateSimilarities( new CombinationsBasedPairwiseDomainSimilarityCalculator(),
1173                                             cdc_list,
1174                                             true,
1175                                             true );
1176             final Iterator<DomainSimilarity> sims_it2 = sims2.iterator();
1177             final DomainSimilarity sa2 = sims_it2.next();
1178             if ( !sa2.getDomainId().getId().equals( "D" ) ) {
1179                 return false;
1180             }
1181             if ( sa2.getSpeciesData().size() != 2 ) {
1182                 return false;
1183             }
1184         }
1185         catch ( final Exception e ) {
1186             e.printStackTrace( System.out );
1187             return false;
1188         }
1189         return true;
1190     }
1191
1192     private static boolean testBasicDomainSimilarityCalculatorRemovalOfSingles() {
1193         try {
1194             final Domain A = new BasicDomain( "A", 1, 2, ( short ) 1, ( short ) 1, 0.15, -12 );
1195             final Domain B = new BasicDomain( "B", 1, 2, ( short ) 1, ( short ) 1, 0.2, -12 );
1196             final Protein mouse_1 = new BasicProtein( "1", "mouse", 0 );
1197             final Protein rabbit_1 = new BasicProtein( "1", "rabbit", 0 );
1198             final Protein ciona_1 = new BasicProtein( "1", "ciona", 0 );
1199             final Protein nemve_1 = new BasicProtein( "1", "nemve", 0 );
1200             mouse_1.addProteinDomain( A );
1201             rabbit_1.addProteinDomain( A );
1202             ciona_1.addProteinDomain( A );
1203             ciona_1.addProteinDomain( A );
1204             ciona_1.addProteinDomain( A );
1205             ciona_1.addProteinDomain( A );
1206             ciona_1.addProteinDomain( A );
1207             nemve_1.addProteinDomain( A );
1208             final List<Protein> protein_list_mouse = new ArrayList<Protein>();
1209             final List<Protein> protein_list_rabbit = new ArrayList<Protein>();
1210             final List<Protein> protein_list_ciona = new ArrayList<Protein>();
1211             final List<Protein> protein_list_nemve = new ArrayList<Protein>();
1212             protein_list_mouse.add( mouse_1 );
1213             protein_list_rabbit.add( rabbit_1 );
1214             protein_list_ciona.add( ciona_1 );
1215             protein_list_nemve.add( nemve_1 );
1216             final List<GenomeWideCombinableDomains> cdc_list = new ArrayList<GenomeWideCombinableDomains>();
1217             cdc_list.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_mouse,
1218                                                                            true,
1219                                                                            new BasicSpecies( "mouse" ) ) );
1220             cdc_list.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_rabbit,
1221                                                                            true,
1222                                                                            new BasicSpecies( "rabbit" ) ) );
1223             cdc_list.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_ciona,
1224                                                                            true,
1225                                                                            new BasicSpecies( "ciona" ) ) );
1226             cdc_list.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_nemve,
1227                                                                            true,
1228                                                                            new BasicSpecies( "nemve" ) ) );
1229             final DomainSimilarityCalculator calc = new BasicDomainSimilarityCalculator( DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID,
1230                                                                                          false,
1231                                                                                          false );
1232             final SortedSet<DomainSimilarity> sims = calc
1233                     .calculateSimilarities( new CombinationsBasedPairwiseDomainSimilarityCalculator(),
1234                                             cdc_list,
1235                                             false,
1236                                             true );
1237             if ( sims.size() != 1 ) {
1238                 return false;
1239             }
1240             final Iterator<DomainSimilarity> sims_it = sims.iterator();
1241             final DomainSimilarity sa = sims_it.next();
1242             if ( !sa.getDomainId().getId().equals( "A" ) ) {
1243                 return false;
1244             }
1245             if ( sa.getSpeciesData().size() != 4 ) {
1246                 return false;
1247             }
1248             if ( !sa.getSpecies().contains( new BasicSpecies( "ciona" ) ) ) {
1249                 return false;
1250             }
1251             if ( !sa.getSpecies().contains( new BasicSpecies( "mouse" ) ) ) {
1252                 return false;
1253             }
1254             if ( !sa.getSpecies().contains( new BasicSpecies( "nemve" ) ) ) {
1255                 return false;
1256             }
1257             if ( !sa.getSpecies().contains( new BasicSpecies( "rabbit" ) ) ) {
1258                 return false;
1259             }
1260             final SortedSet<DomainSimilarity> sims_ns = calc
1261                     .calculateSimilarities( new CombinationsBasedPairwiseDomainSimilarityCalculator(),
1262                                             cdc_list,
1263                                             true,
1264                                             true );
1265             if ( sims_ns.size() != 0 ) {
1266                 return false;
1267             }
1268             final Protein mouse_2 = new BasicProtein( "1", "mouse", 0 );
1269             final Protein rabbit_2 = new BasicProtein( "1", "rabbit", 0 );
1270             final Protein ciona_2 = new BasicProtein( "1", "ciona", 0 );
1271             final Protein nemve_2 = new BasicProtein( "1", "nemve", 0 );
1272             mouse_2.addProteinDomain( A );
1273             rabbit_2.addProteinDomain( A );
1274             ciona_2.addProteinDomain( A );
1275             ciona_2.addProteinDomain( A );
1276             ciona_2.addProteinDomain( B );
1277             ciona_2.addProteinDomain( A );
1278             ciona_2.addProteinDomain( A );
1279             ciona_2.addProteinDomain( A );
1280             nemve_2.addProteinDomain( A );
1281             final List<Protein> protein_list_mouse2 = new ArrayList<Protein>();
1282             final List<Protein> protein_list_rabbit2 = new ArrayList<Protein>();
1283             final List<Protein> protein_list_ciona2 = new ArrayList<Protein>();
1284             final List<Protein> protein_list_nemve2 = new ArrayList<Protein>();
1285             protein_list_mouse2.add( mouse_2 );
1286             protein_list_rabbit2.add( rabbit_2 );
1287             protein_list_ciona2.add( ciona_2 );
1288             protein_list_nemve2.add( nemve_2 );
1289             final List<GenomeWideCombinableDomains> cdc_list2 = new ArrayList<GenomeWideCombinableDomains>();
1290             cdc_list2.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_mouse2,
1291                                                                             true,
1292                                                                             new BasicSpecies( "mouse" ) ) );
1293             cdc_list2.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_rabbit2,
1294                                                                             true,
1295                                                                             new BasicSpecies( "rabbit" ) ) );
1296             cdc_list2.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_ciona2,
1297                                                                             true,
1298                                                                             new BasicSpecies( "ciona" ) ) );
1299             cdc_list2.add( BasicGenomeWideCombinableDomains.createInstance( protein_list_nemve2,
1300                                                                             true,
1301                                                                             new BasicSpecies( "nemve" ) ) );
1302             final SortedSet<DomainSimilarity> sims2 = calc
1303                     .calculateSimilarities( new CombinationsBasedPairwiseDomainSimilarityCalculator(),
1304                                             cdc_list2,
1305                                             true,
1306                                             true );
1307             if ( sims2.size() != 1 ) {
1308                 return false;
1309             }
1310         }
1311         catch ( final Exception e ) {
1312             e.printStackTrace( System.out );
1313             return false;
1314         }
1315         return true;
1316     }
1317
1318     private static boolean testBasicProtein() {
1319         try {
1320             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
1321             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1322             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
1323             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
1324             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
1325             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
1326             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
1327             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
1328             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
1329             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
1330             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
1331             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
1332             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
1333             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
1334             p.addProteinDomain( B15 );
1335             p.addProteinDomain( C50 );
1336             p.addProteinDomain( A60 );
1337             p.addProteinDomain( A30 );
1338             p.addProteinDomain( C70 );
1339             p.addProteinDomain( B35 );
1340             p.addProteinDomain( B40 );
1341             p.addProteinDomain( A0 );
1342             p.addProteinDomain( A10 );
1343             p.addProteinDomain( A20 );
1344             p.addProteinDomain( B25 );
1345             p.addProteinDomain( D80 );
1346             List<DomainId> domains_ids = new ArrayList<DomainId>();
1347             domains_ids.add( new DomainId( "A" ) );
1348             domains_ids.add( new DomainId( "B" ) );
1349             domains_ids.add( new DomainId( "C" ) );
1350             if ( !p.contains( domains_ids, false ) ) {
1351                 return false;
1352             }
1353             if ( !p.contains( domains_ids, true ) ) {
1354                 return false;
1355             }
1356             domains_ids.add( new DomainId( "X" ) );
1357             if ( p.contains( domains_ids, false ) ) {
1358                 return false;
1359             }
1360             if ( p.contains( domains_ids, true ) ) {
1361                 return false;
1362             }
1363             domains_ids = new ArrayList<DomainId>();
1364             domains_ids.add( new DomainId( "A" ) );
1365             domains_ids.add( new DomainId( "C" ) );
1366             domains_ids.add( new DomainId( "D" ) );
1367             if ( !p.contains( domains_ids, false ) ) {
1368                 return false;
1369             }
1370             if ( !p.contains( domains_ids, true ) ) {
1371                 return false;
1372             }
1373             domains_ids = new ArrayList<DomainId>();
1374             domains_ids.add( new DomainId( "A" ) );
1375             domains_ids.add( new DomainId( "D" ) );
1376             domains_ids.add( new DomainId( "C" ) );
1377             if ( !p.contains( domains_ids, false ) ) {
1378                 return false;
1379             }
1380             if ( p.contains( domains_ids, true ) ) {
1381                 return false;
1382             }
1383             domains_ids = new ArrayList<DomainId>();
1384             domains_ids.add( new DomainId( "A" ) );
1385             domains_ids.add( new DomainId( "A" ) );
1386             domains_ids.add( new DomainId( "B" ) );
1387             if ( !p.contains( domains_ids, false ) ) {
1388                 return false;
1389             }
1390             if ( !p.contains( domains_ids, true ) ) {
1391                 return false;
1392             }
1393             domains_ids = new ArrayList<DomainId>();
1394             domains_ids.add( new DomainId( "A" ) );
1395             domains_ids.add( new DomainId( "A" ) );
1396             domains_ids.add( new DomainId( "A" ) );
1397             domains_ids.add( new DomainId( "B" ) );
1398             domains_ids.add( new DomainId( "B" ) );
1399             if ( !p.contains( domains_ids, false ) ) {
1400                 return false;
1401             }
1402             if ( !p.contains( domains_ids, true ) ) {
1403                 return false;
1404             }
1405             domains_ids = new ArrayList<DomainId>();
1406             domains_ids.add( new DomainId( "A" ) );
1407             domains_ids.add( new DomainId( "A" ) );
1408             domains_ids.add( new DomainId( "A" ) );
1409             domains_ids.add( new DomainId( "A" ) );
1410             domains_ids.add( new DomainId( "B" ) );
1411             domains_ids.add( new DomainId( "B" ) );
1412             if ( !p.contains( domains_ids, false ) ) {
1413                 return false;
1414             }
1415             if ( !p.contains( domains_ids, true ) ) {
1416                 return false;
1417             }
1418             domains_ids = new ArrayList<DomainId>();
1419             domains_ids.add( new DomainId( "A" ) );
1420             domains_ids.add( new DomainId( "A" ) );
1421             domains_ids.add( new DomainId( "A" ) );
1422             domains_ids.add( new DomainId( "A" ) );
1423             domains_ids.add( new DomainId( "A" ) );
1424             domains_ids.add( new DomainId( "B" ) );
1425             domains_ids.add( new DomainId( "B" ) );
1426             if ( !p.contains( domains_ids, false ) ) {
1427                 return false;
1428             }
1429             if ( p.contains( domains_ids, true ) ) {
1430                 return false;
1431             }
1432             domains_ids = new ArrayList<DomainId>();
1433             domains_ids.add( new DomainId( "A" ) );
1434             domains_ids.add( new DomainId( "A" ) );
1435             domains_ids.add( new DomainId( "B" ) );
1436             domains_ids.add( new DomainId( "A" ) );
1437             domains_ids.add( new DomainId( "B" ) );
1438             domains_ids.add( new DomainId( "A" ) );
1439             domains_ids.add( new DomainId( "B" ) );
1440             domains_ids.add( new DomainId( "B" ) );
1441             domains_ids.add( new DomainId( "C" ) );
1442             domains_ids.add( new DomainId( "A" ) );
1443             domains_ids.add( new DomainId( "C" ) );
1444             domains_ids.add( new DomainId( "D" ) );
1445             if ( !p.contains( domains_ids, false ) ) {
1446                 return false;
1447             }
1448             if ( !p.contains( domains_ids, true ) ) {
1449                 return false;
1450             }
1451             domains_ids = new ArrayList<DomainId>();
1452             domains_ids.add( new DomainId( "A" ) );
1453             domains_ids.add( new DomainId( "B" ) );
1454             domains_ids.add( new DomainId( "A" ) );
1455             domains_ids.add( new DomainId( "B" ) );
1456             domains_ids.add( new DomainId( "A" ) );
1457             domains_ids.add( new DomainId( "B" ) );
1458             domains_ids.add( new DomainId( "B" ) );
1459             domains_ids.add( new DomainId( "A" ) );
1460             domains_ids.add( new DomainId( "C" ) );
1461             domains_ids.add( new DomainId( "D" ) );
1462             if ( !p.contains( domains_ids, false ) ) {
1463                 return false;
1464             }
1465             if ( !p.contains( domains_ids, true ) ) {
1466                 return false;
1467             }
1468             domains_ids = new ArrayList<DomainId>();
1469             domains_ids.add( new DomainId( "A" ) );
1470             domains_ids.add( new DomainId( "A" ) );
1471             domains_ids.add( new DomainId( "B" ) );
1472             domains_ids.add( new DomainId( "A" ) );
1473             domains_ids.add( new DomainId( "B" ) );
1474             domains_ids.add( new DomainId( "A" ) );
1475             domains_ids.add( new DomainId( "B" ) );
1476             domains_ids.add( new DomainId( "B" ) );
1477             domains_ids.add( new DomainId( "C" ) );
1478             domains_ids.add( new DomainId( "C" ) );
1479             domains_ids.add( new DomainId( "A" ) );
1480             domains_ids.add( new DomainId( "C" ) );
1481             domains_ids.add( new DomainId( "D" ) );
1482             if ( !p.contains( domains_ids, false ) ) {
1483                 return false;
1484             }
1485             if ( p.contains( domains_ids, true ) ) {
1486                 return false;
1487             }
1488             domains_ids = new ArrayList<DomainId>();
1489             domains_ids.add( new DomainId( "A" ) );
1490             domains_ids.add( new DomainId( "A" ) );
1491             domains_ids.add( new DomainId( "A" ) );
1492             domains_ids.add( new DomainId( "B" ) );
1493             domains_ids.add( new DomainId( "A" ) );
1494             domains_ids.add( new DomainId( "B" ) );
1495             domains_ids.add( new DomainId( "A" ) );
1496             domains_ids.add( new DomainId( "B" ) );
1497             domains_ids.add( new DomainId( "B" ) );
1498             domains_ids.add( new DomainId( "C" ) );
1499             domains_ids.add( new DomainId( "A" ) );
1500             domains_ids.add( new DomainId( "C" ) );
1501             domains_ids.add( new DomainId( "D" ) );
1502             if ( !p.contains( domains_ids, false ) ) {
1503                 return false;
1504             }
1505             if ( p.contains( domains_ids, true ) ) {
1506                 return false;
1507             }
1508             domains_ids = new ArrayList<DomainId>();
1509             domains_ids.add( new DomainId( "A" ) );
1510             domains_ids.add( new DomainId( "A" ) );
1511             domains_ids.add( new DomainId( "B" ) );
1512             domains_ids.add( new DomainId( "A" ) );
1513             domains_ids.add( new DomainId( "B" ) );
1514             domains_ids.add( new DomainId( "A" ) );
1515             domains_ids.add( new DomainId( "B" ) );
1516             domains_ids.add( new DomainId( "B" ) );
1517             domains_ids.add( new DomainId( "A" ) );
1518             domains_ids.add( new DomainId( "D" ) );
1519             if ( !p.contains( domains_ids, false ) ) {
1520                 return false;
1521             }
1522             if ( !p.contains( domains_ids, true ) ) {
1523                 return false;
1524             }
1525             domains_ids = new ArrayList<DomainId>();
1526             domains_ids.add( new DomainId( "A" ) );
1527             domains_ids.add( new DomainId( "A" ) );
1528             domains_ids.add( new DomainId( "B" ) );
1529             domains_ids.add( new DomainId( "A" ) );
1530             domains_ids.add( new DomainId( "B" ) );
1531             domains_ids.add( new DomainId( "A" ) );
1532             domains_ids.add( new DomainId( "B" ) );
1533             domains_ids.add( new DomainId( "B" ) );
1534             domains_ids.add( new DomainId( "C" ) );
1535             domains_ids.add( new DomainId( "A" ) );
1536             domains_ids.add( new DomainId( "C" ) );
1537             domains_ids.add( new DomainId( "D" ) );
1538             domains_ids.add( new DomainId( "X" ) );
1539             if ( p.contains( domains_ids, false ) ) {
1540                 return false;
1541             }
1542             if ( p.contains( domains_ids, true ) ) {
1543                 return false;
1544             }
1545             domains_ids = new ArrayList<DomainId>();
1546             domains_ids.add( new DomainId( "X" ) );
1547             domains_ids.add( new DomainId( "A" ) );
1548             domains_ids.add( new DomainId( "A" ) );
1549             domains_ids.add( new DomainId( "B" ) );
1550             domains_ids.add( new DomainId( "A" ) );
1551             domains_ids.add( new DomainId( "B" ) );
1552             domains_ids.add( new DomainId( "A" ) );
1553             domains_ids.add( new DomainId( "B" ) );
1554             domains_ids.add( new DomainId( "B" ) );
1555             domains_ids.add( new DomainId( "C" ) );
1556             domains_ids.add( new DomainId( "A" ) );
1557             domains_ids.add( new DomainId( "C" ) );
1558             domains_ids.add( new DomainId( "D" ) );
1559             if ( p.contains( domains_ids, false ) ) {
1560                 return false;
1561             }
1562             if ( p.contains( domains_ids, true ) ) {
1563                 return false;
1564             }
1565             domains_ids = new ArrayList<DomainId>();
1566             domains_ids.add( new DomainId( "A" ) );
1567             domains_ids.add( new DomainId( "A" ) );
1568             domains_ids.add( new DomainId( "B" ) );
1569             domains_ids.add( new DomainId( "A" ) );
1570             domains_ids.add( new DomainId( "B" ) );
1571             domains_ids.add( new DomainId( "B" ) );
1572             domains_ids.add( new DomainId( "A" ) );
1573             domains_ids.add( new DomainId( "B" ) );
1574             domains_ids.add( new DomainId( "C" ) );
1575             domains_ids.add( new DomainId( "A" ) );
1576             domains_ids.add( new DomainId( "C" ) );
1577             domains_ids.add( new DomainId( "D" ) );
1578             if ( !p.contains( domains_ids, false ) ) {
1579                 return false;
1580             }
1581             if ( p.contains( domains_ids, true ) ) {
1582                 return false;
1583             }
1584         }
1585         catch ( final Exception e ) {
1586             e.printStackTrace( System.out );
1587             return false;
1588         }
1589         return true;
1590     }
1591
1592     private static boolean testBinaryDomainCombination() {
1593         try {
1594             final BasicBinaryDomainCombination s0 = new BasicBinaryDomainCombination( "a", "a" );
1595             final BasicBinaryDomainCombination s1 = new BasicBinaryDomainCombination( "b", "a" );
1596             final BasicBinaryDomainCombination s2 = new BasicBinaryDomainCombination( "a", "b" );
1597             final BasicBinaryDomainCombination s3 = new BasicBinaryDomainCombination( "B", "A" );
1598             final BasicBinaryDomainCombination s4 = new BasicBinaryDomainCombination( "A", "B" );
1599             final BasicBinaryDomainCombination s5 = new BasicBinaryDomainCombination( "c", "a" );
1600             final BasicBinaryDomainCombination s6 = new BasicBinaryDomainCombination( "b", "c" );
1601             final BasicBinaryDomainCombination s7 = new BasicBinaryDomainCombination( "d", "a" );
1602             final BasicBinaryDomainCombination s8 = new BasicBinaryDomainCombination( "b", "d" );
1603             final BinaryDomainCombination s9 = BasicBinaryDomainCombination.createInstance( " z-z=a-aa " );
1604             if ( !s9.toString().equals( "a-aa=z-z" ) ) {
1605                 System.out.println( s9.toString() );
1606                 return false;
1607             }
1608             if ( !s0.equals( s0 ) ) {
1609                 return false;
1610             }
1611             if ( s0.equals( s1 ) ) {
1612                 return false;
1613             }
1614             if ( s1.equals( s0 ) ) {
1615                 return false;
1616             }
1617             if ( !s1.equals( s2 ) ) {
1618                 return false;
1619             }
1620             if ( !s2.equals( s1 ) ) {
1621                 return false;
1622             }
1623             if ( s2.equals( s3 ) ) {
1624                 return false;
1625             }
1626             if ( s2.equals( s3 ) ) {
1627                 return false;
1628             }
1629             if ( s2.equals( s4 ) ) {
1630                 return false;
1631             }
1632             final SortedSet<BasicBinaryDomainCombination> sorted = new TreeSet<BasicBinaryDomainCombination>();
1633             sorted.add( s0 );
1634             sorted.add( s1 );
1635             sorted.add( s2 );
1636             sorted.add( s3 );
1637             sorted.add( s3 );
1638             sorted.add( s3 );
1639             sorted.add( s4 );
1640             sorted.add( s5 );
1641             sorted.add( s6 );
1642             sorted.add( s7 );
1643             sorted.add( s7 );
1644             sorted.add( s8 );
1645             if ( sorted.size() != 6 ) {
1646                 return false;
1647             }
1648             final DirectedBinaryDomainCombination aa = new DirectedBinaryDomainCombination( "a", "a" );
1649             final DirectedBinaryDomainCombination ba = new DirectedBinaryDomainCombination( "b", "a" );
1650             final DirectedBinaryDomainCombination ab = new DirectedBinaryDomainCombination( "a", "b" );
1651             final DirectedBinaryDomainCombination bb = new DirectedBinaryDomainCombination( "b", "b" );
1652             if ( !aa.equals( aa ) ) {
1653                 return false;
1654             }
1655             if ( aa.equals( bb ) ) {
1656                 return false;
1657             }
1658             if ( ab.equals( ba ) ) {
1659                 return false;
1660             }
1661             if ( ba.equals( ab ) ) {
1662                 return false;
1663             }
1664             if ( !ab.equals( ab ) ) {
1665                 return false;
1666             }
1667             if ( ab.equals( aa ) ) {
1668                 return false;
1669             }
1670             if ( ab.equals( bb ) ) {
1671                 return false;
1672             }
1673         }
1674         catch ( final Exception e ) {
1675             e.printStackTrace( System.out );
1676             return false;
1677         }
1678         return true;
1679     }
1680
1681     private static boolean testBinaryStateMatrixToGainLossMatrix( final File test_dir ) {
1682         final BinaryStates I = BinaryStates.PRESENT;
1683         final BinaryStates O = BinaryStates.ABSENT;
1684         try {
1685             final CharacterStateMatrix<BinaryStates> binary_states_matrix_0 = new BasicCharacterStateMatrix<BinaryStates>( 7,
1686                                                                                                                            6 );
1687             binary_states_matrix_0.setIdentifier( 0, "A" );
1688             binary_states_matrix_0.setIdentifier( 1, "B" );
1689             binary_states_matrix_0.setIdentifier( 2, "C" );
1690             binary_states_matrix_0.setIdentifier( 3, "D" );
1691             binary_states_matrix_0.setIdentifier( 4, "1" );
1692             binary_states_matrix_0.setIdentifier( 5, "2" );
1693             binary_states_matrix_0.setIdentifier( 6, "3" );
1694             binary_states_matrix_0.setState( 0, 0, O );
1695             binary_states_matrix_0.setState( 1, 0, O );
1696             binary_states_matrix_0.setState( 2, 0, O );
1697             binary_states_matrix_0.setState( 3, 0, O );
1698             binary_states_matrix_0.setState( 4, 0, O );
1699             binary_states_matrix_0.setState( 5, 0, O );
1700             binary_states_matrix_0.setState( 6, 0, O );
1701             binary_states_matrix_0.setState( 0, 1, I );
1702             binary_states_matrix_0.setState( 1, 1, O );
1703             binary_states_matrix_0.setState( 2, 1, O );
1704             binary_states_matrix_0.setState( 3, 1, O );
1705             binary_states_matrix_0.setState( 4, 1, O );
1706             binary_states_matrix_0.setState( 5, 1, O );
1707             binary_states_matrix_0.setState( 6, 1, O );
1708             binary_states_matrix_0.setState( 0, 2, O );
1709             binary_states_matrix_0.setState( 1, 2, O );
1710             binary_states_matrix_0.setState( 2, 2, O );
1711             binary_states_matrix_0.setState( 3, 2, O );
1712             binary_states_matrix_0.setState( 4, 2, I );
1713             binary_states_matrix_0.setState( 5, 2, O );
1714             binary_states_matrix_0.setState( 6, 2, O );
1715             binary_states_matrix_0.setState( 0, 3, I );
1716             binary_states_matrix_0.setState( 1, 3, O );
1717             binary_states_matrix_0.setState( 2, 3, O );
1718             binary_states_matrix_0.setState( 3, 3, O );
1719             binary_states_matrix_0.setState( 4, 3, I );
1720             binary_states_matrix_0.setState( 5, 3, O );
1721             binary_states_matrix_0.setState( 6, 3, I );
1722             binary_states_matrix_0.setState( 0, 4, I );
1723             binary_states_matrix_0.setState( 1, 4, O );
1724             binary_states_matrix_0.setState( 2, 4, I );
1725             binary_states_matrix_0.setState( 3, 4, O );
1726             binary_states_matrix_0.setState( 4, 4, I );
1727             binary_states_matrix_0.setState( 5, 4, O );
1728             binary_states_matrix_0.setState( 6, 4, I );
1729             binary_states_matrix_0.setState( 0, 5, I );
1730             binary_states_matrix_0.setState( 1, 5, I );
1731             binary_states_matrix_0.setState( 2, 5, I );
1732             binary_states_matrix_0.setState( 3, 5, I );
1733             binary_states_matrix_0.setState( 4, 5, I );
1734             binary_states_matrix_0.setState( 5, 5, I );
1735             binary_states_matrix_0.setState( 6, 5, I );
1736             final String[] character_labels_0 = new String[ 6 ];
1737             character_labels_0[ 0 ] = "first";
1738             character_labels_0[ 1 ] = "second";
1739             character_labels_0[ 2 ] = "third";
1740             character_labels_0[ 3 ] = "forth";
1741             character_labels_0[ 4 ] = "fifth";
1742             character_labels_0[ 5 ] = "sixth";
1743             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1744             final Phylogeny phylogeny_0 = factory.create( "(((A,B)1,C)2,D)3", new NHXParser() )[ 0 ];
1745             final DomainParsimonyCalculator dom_pars = DomainParsimonyCalculator.createInstance( phylogeny_0 );
1746             dom_pars.executeOnGivenBinaryStatesMatrix( binary_states_matrix_0, character_labels_0 );
1747             final CharacterStateMatrix<GainLossStates> gl_matrix_0 = dom_pars.getGainLossMatrix();
1748             // final StringWriter sw = new StringWriter();
1749             //  gl_matrix_0.toWriter( sw );
1750             // System.out.println( sw.toString() );
1751             if ( dom_pars.getCost() != 13 ) {
1752                 return false;
1753             }
1754             if ( dom_pars.getTotalGains() != 5 ) {
1755                 return false;
1756             }
1757             if ( dom_pars.getTotalLosses() != 8 ) {
1758                 return false;
1759             }
1760             if ( dom_pars.getTotalUnchanged() != 29 ) {
1761                 return false;
1762             }
1763             if ( gl_matrix_0.getState( "A", 1 ) != GainLossStates.GAIN ) {
1764                 return false;
1765             }
1766             if ( gl_matrix_0.getState( "A", 4 ) != GainLossStates.UNCHANGED_PRESENT ) {
1767                 return false;
1768             }
1769             if ( gl_matrix_0.getState( "B", 4 ) != GainLossStates.LOSS ) {
1770                 return false;
1771             }
1772             if ( gl_matrix_0.getState( "C", 4 ) != GainLossStates.GAIN ) {
1773                 return false;
1774             }
1775             if ( gl_matrix_0.getState( "D", 4 ) != GainLossStates.LOSS ) {
1776                 return false;
1777             }
1778             if ( gl_matrix_0.getState( "1", 4 ) != GainLossStates.GAIN ) {
1779                 return false;
1780             }
1781             if ( gl_matrix_0.getState( "2", 4 ) != GainLossStates.LOSS ) {
1782                 return false;
1783             }
1784             if ( gl_matrix_0.getState( "3", 4 ) != GainLossStates.UNCHANGED_PRESENT ) {
1785                 return false;
1786             }
1787         }
1788         catch ( final Exception e ) {
1789             e.printStackTrace( System.out );
1790             return false;
1791         }
1792         return true;
1793     }
1794
1795     private static boolean testCombinableDomains() {
1796         try {
1797             final Domain key0 = new BasicDomain( "key0", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1798             final Domain a = new BasicDomain( "a", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1799             final Domain b = new BasicDomain( "b", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1800             final Domain c = new BasicDomain( "c", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1801             final CombinableDomains cd0 = new BasicCombinableDomains( key0.getDomainId(), new BasicSpecies( "eel" ) );
1802             cd0.addCombinableDomain( a.getDomainId() );
1803             cd0.addCombinableDomain( b.getDomainId() );
1804             cd0.addCombinableDomain( b.getDomainId() );
1805             cd0.addCombinableDomain( c.getDomainId() );
1806             cd0.addCombinableDomain( c.getDomainId() );
1807             cd0.addCombinableDomain( c.getDomainId() );
1808             if ( cd0.getNumberOfCombinableDomains() != 3 ) {
1809                 return false;
1810             }
1811             if ( cd0.getNumberOfProteinsExhibitingCombination( a.getDomainId() ) != 1 ) {
1812                 return false;
1813             }
1814             if ( cd0.getNumberOfProteinsExhibitingCombination( b.getDomainId() ) != 2 ) {
1815                 return false;
1816             }
1817             if ( cd0.getNumberOfProteinsExhibitingCombination( c.getDomainId() ) != 3 ) {
1818                 return false;
1819             }
1820             if ( cd0.getNumberOfProteinsExhibitingCombination( key0.getDomainId() ) != 0 ) {
1821                 return false;
1822             }
1823             if ( cd0.getAllDomains().size() != 4 ) {
1824                 return false;
1825             }
1826             if ( !cd0.getAllDomains().contains( a.getDomainId() ) ) {
1827                 return false;
1828             }
1829             if ( !cd0.getAllDomains().contains( b.getDomainId() ) ) {
1830                 return false;
1831             }
1832             if ( !cd0.getAllDomains().contains( c.getDomainId() ) ) {
1833                 return false;
1834             }
1835             if ( !cd0.getAllDomains().contains( key0.getDomainId() ) ) {
1836                 return false;
1837             }
1838             if ( cd0.toBinaryDomainCombinations().size() != 3 ) {
1839                 return false;
1840             }
1841             final BasicBinaryDomainCombination s0 = new BasicBinaryDomainCombination( "key0", "a" );
1842             final BasicBinaryDomainCombination s1 = new BasicBinaryDomainCombination( "b", "key0" );
1843             final BasicBinaryDomainCombination s2 = new BasicBinaryDomainCombination( "key0", "c" );
1844             final BasicBinaryDomainCombination s3 = new BasicBinaryDomainCombination( "key0", "cc" );
1845             final BasicBinaryDomainCombination s4 = new BasicBinaryDomainCombination( "c", "key0" );
1846             if ( !cd0.toBinaryDomainCombinations().contains( s0 ) ) {
1847                 return false;
1848             }
1849             if ( !cd0.toBinaryDomainCombinations().contains( s1 ) ) {
1850                 return false;
1851             }
1852             if ( !cd0.toBinaryDomainCombinations().contains( s2 ) ) {
1853                 return false;
1854             }
1855             if ( cd0.toBinaryDomainCombinations().contains( s3 ) ) {
1856                 return false;
1857             }
1858             if ( !cd0.toBinaryDomainCombinations().contains( s4 ) ) {
1859                 return false;
1860             }
1861             final Domain key1 = new BasicDomain( "key1", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1862             final Domain a1 = new BasicDomain( "a1", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1863             final Domain b1 = new BasicDomain( "b1", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1864             final Domain c1 = new BasicDomain( "c1", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1865             final CombinableDomains cd1 = new BasicCombinableDomains( key1.getDomainId(), new BasicSpecies( "eel" ) );
1866             cd1.addCombinableDomain( a1.getDomainId() );
1867             cd1.addCombinableDomain( b1.getDomainId() );
1868             cd1.addCombinableDomain( c1.getDomainId() );
1869             cd1.addCombinableDomain( key1.getDomainId() );
1870             if ( cd1.getNumberOfCombinableDomains() != 4 ) {
1871                 return false;
1872             }
1873             if ( cd1.getNumberOfProteinsExhibitingCombination( a1.getDomainId() ) != 1 ) {
1874                 return false;
1875             }
1876             if ( cd1.getNumberOfProteinsExhibitingCombination( b1.getDomainId() ) != 1 ) {
1877                 return false;
1878             }
1879             if ( cd1.getNumberOfProteinsExhibitingCombination( c1.getDomainId() ) != 1 ) {
1880                 return false;
1881             }
1882             if ( cd1.getNumberOfProteinsExhibitingCombination( key1.getDomainId() ) != 1 ) {
1883                 return false;
1884             }
1885             if ( cd1.getAllDomains().size() != 4 ) {
1886                 return false;
1887             }
1888             if ( cd1.toBinaryDomainCombinations().size() != 4 ) {
1889                 return false;
1890             }
1891             final BasicBinaryDomainCombination kk = new BasicBinaryDomainCombination( "key1", "key1" );
1892             if ( !cd1.toBinaryDomainCombinations().contains( kk ) ) {
1893                 return false;
1894             }
1895         }
1896         catch ( final Exception e ) {
1897             e.printStackTrace( System.out );
1898             return false;
1899         }
1900         return true;
1901     }
1902
1903     private static boolean testCombinationsBasedPairwiseSimilarityCalculator() {
1904         try {
1905             final Domain a = new BasicDomain( "A", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1906             final Domain b = new BasicDomain( "B", 2, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1907             final Domain c = new BasicDomain( "C", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1908             final Domain one_key = new BasicDomain( "bcl2", 4, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1909             final Domain two_key = new BasicDomain( "bcl2", 5, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1910             final CombinableDomains one = new BasicCombinableDomains( one_key.getDomainId(), new BasicSpecies( "mouse" ) );
1911             final CombinableDomains two = new BasicCombinableDomains( two_key.getDomainId(),
1912                                                                       new BasicSpecies( "rabbit" ) );
1913             one.addCombinableDomain( a.getDomainId() );
1914             one.addCombinableDomain( a.getDomainId() );
1915             two.addCombinableDomain( new BasicDomain( "A", 1, 5, ( short ) 1, ( short ) 4, 0.1, -12 ).getDomainId() );
1916             two.addCombinableDomain( b.getDomainId() );
1917             two.addCombinableDomain( c.getDomainId() );
1918             final PairwiseDomainSimilarityCalculator calc = new CombinationsBasedPairwiseDomainSimilarityCalculator();
1919             final PairwiseDomainSimilarity s1 = calc.calculateSimilarity( one, two );
1920             if ( !TestSurfacing.isEqual( s1.getSimilarityScore(), 1.0 / ( 1 + 2 ) ) ) {
1921                 return false;
1922             }
1923             if ( s1.getDifferenceInCounts() != ( 1 - 3 ) ) {
1924                 return false;
1925             }
1926             if ( ( ( CombinationsBasedPairwiseDomainSimilarity ) s1 ).getNumberOfDifferentDomains() != 2 ) {
1927                 return false;
1928             }
1929             one.addCombinableDomain( b.getDomainId() );
1930             one.addCombinableDomain( c.getDomainId() );
1931             final PairwiseDomainSimilarity s2 = calc.calculateSimilarity( one, two );
1932             if ( !TestSurfacing.isEqual( s2.getSimilarityScore(), 3.0 / ( 0 + 3 ) ) ) {
1933                 return false;
1934             }
1935             if ( s2.getDifferenceInCounts() != 0 ) {
1936                 return false;
1937             }
1938             if ( ( ( CombinationsBasedPairwiseDomainSimilarity ) s2 ).getNumberOfDifferentDomains() != 0 ) {
1939                 return false;
1940             }
1941             final Domain d = new BasicDomain( "D", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1942             final Domain e = new BasicDomain( "E", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1943             final Domain f = new BasicDomain( "F", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1944             one.addCombinableDomain( d.getDomainId() );
1945             one.addCombinableDomain( d.getDomainId() );
1946             one.addCombinableDomain( e.getDomainId() );
1947             one.addCombinableDomain( f.getDomainId() );
1948             final PairwiseDomainSimilarity s3 = calc.calculateSimilarity( one, two );
1949             if ( !TestSurfacing.isEqual( s3.getSimilarityScore(), 3.0 / ( 3 + 3 ) ) ) {
1950                 return false;
1951             }
1952             if ( s3.getDifferenceInCounts() != ( 6 - 3 ) ) {
1953                 return false;
1954             }
1955             if ( ( ( CombinationsBasedPairwiseDomainSimilarity ) s3 ).getNumberOfDifferentDomains() != 3 ) {
1956                 return false;
1957             }
1958             final Domain aaa = new BasicDomain( "aaa", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1959             final Domain bbb = new BasicDomain( "bbb", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1960             final Domain three_key = new BasicDomain( "bcl2", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1961             final Domain four_key = new BasicDomain( "bcl2", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1962             final CombinableDomains three = new BasicCombinableDomains( three_key.getDomainId(),
1963                                                                         new BasicSpecies( "mouse" ) );
1964             final CombinableDomains four = new BasicCombinableDomains( four_key.getDomainId(),
1965                                                                        new BasicSpecies( "rabbit" ) );
1966             three.addCombinableDomain( aaa.getDomainId() );
1967             four.addCombinableDomain( bbb.getDomainId() );
1968             final PairwiseDomainSimilarityCalculator calc2 = new CombinationsBasedPairwiseDomainSimilarityCalculator();
1969             final PairwiseDomainSimilarity s4 = calc2.calculateSimilarity( three, four );
1970             if ( !TestSurfacing.isEqual( s4.getSimilarityScore(), 0.0 / ( 0 + 2 ) ) ) {
1971                 return false;
1972             }
1973             final Domain aaa2 = new BasicDomain( "aaa", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1974             four.addCombinableDomain( aaa2.getDomainId() );
1975             final PairwiseDomainSimilarity s5 = calc.calculateSimilarity( three, four );
1976             if ( !TestSurfacing.isEqual( s5.getSimilarityScore(), 1.0 / ( 1 + 1 ) ) ) {
1977                 return false;
1978             }
1979         }
1980         catch ( final Exception e ) {
1981             e.printStackTrace( System.out );
1982             return false;
1983         }
1984         return true;
1985     }
1986
1987     private static boolean testCopyNumberBasedPairwiseSimilarityCalculator() {
1988         try {
1989             final Domain one_key = new BasicDomain( "bcl2", 4, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1990             final Domain two_key = new BasicDomain( "bcl2", 5, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1991             final CombinableDomains one = new BasicCombinableDomains( one_key.getDomainId(), new BasicSpecies( "mouse" ) );
1992             final CombinableDomains two = new BasicCombinableDomains( two_key.getDomainId(),
1993                                                                       new BasicSpecies( "rabbit" ) );
1994             one.setKeyDomainCount( 2 );
1995             two.setKeyDomainCount( 3 );
1996             final PairwiseDomainSimilarityCalculator calc = new DomainCountsBasedPairwiseSimilarityCalculator();
1997             PairwiseDomainSimilarity s1 = calc.calculateSimilarity( one, two );
1998             if ( !TestSurfacing.isEqual( s1.getSimilarityScore(), 1.0 - ( 3 - 2.0 ) / ( 2 + 3 ) ) ) {
1999                 return false;
2000             }
2001             if ( s1.getDifferenceInCounts() != ( 2 - 3 ) ) {
2002                 return false;
2003             }
2004             one.setKeyDomainCount( 1 );
2005             two.setKeyDomainCount( 1 );
2006             s1 = calc.calculateSimilarity( one, two );
2007             if ( !TestSurfacing.isEqual( s1.getSimilarityScore(), 1.0 ) ) {
2008                 return false;
2009             }
2010             if ( s1.getDifferenceInCounts() != ( 1 - 1 ) ) {
2011                 return false;
2012             }
2013             one.setKeyDomainCount( 1 );
2014             two.setKeyDomainCount( 1000 );
2015             s1 = calc.calculateSimilarity( one, two );
2016             if ( !TestSurfacing.isEqual( s1.getSimilarityScore(), 1.0 - 999.0 / 1001 ) ) {
2017                 return false;
2018             }
2019             if ( s1.getDifferenceInCounts() != ( 1 - 1000 ) ) {
2020                 return false;
2021             }
2022         }
2023         catch ( final Exception e ) {
2024             e.printStackTrace( System.out );
2025             return false;
2026         }
2027         return true;
2028     }
2029
2030     private static boolean testDirectedCombinableDomains() {
2031         try {
2032             final Domain key0 = new BasicDomain( "key0", 10, 20, ( short ) 1, ( short ) 4, 0.1, -12 );
2033             final Domain a = new BasicDomain( "a", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2034             final Domain b = new BasicDomain( "b", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2035             final Domain c = new BasicDomain( "c", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2036             final CombinableDomains cd0 = new DirectedCombinableDomains( key0.getDomainId(), new BasicSpecies( "eel" ) );
2037             cd0.addCombinableDomain( a.getDomainId() );
2038             cd0.addCombinableDomain( b.getDomainId() );
2039             cd0.addCombinableDomain( b.getDomainId() );
2040             cd0.addCombinableDomain( c.getDomainId() );
2041             cd0.addCombinableDomain( c.getDomainId() );
2042             cd0.addCombinableDomain( c.getDomainId() );
2043             if ( cd0.getNumberOfCombinableDomains() != 3 ) {
2044                 return false;
2045             }
2046             if ( cd0.getNumberOfProteinsExhibitingCombination( a.getDomainId() ) != 1 ) {
2047                 return false;
2048             }
2049             if ( cd0.getNumberOfProteinsExhibitingCombination( b.getDomainId() ) != 2 ) {
2050                 return false;
2051             }
2052             if ( cd0.getNumberOfProteinsExhibitingCombination( c.getDomainId() ) != 3 ) {
2053                 return false;
2054             }
2055             if ( cd0.getNumberOfProteinsExhibitingCombination( key0.getDomainId() ) != 0 ) {
2056                 return false;
2057             }
2058             if ( cd0.getAllDomains().size() != 4 ) {
2059                 return false;
2060             }
2061             if ( !cd0.getAllDomains().contains( a.getDomainId() ) ) {
2062                 return false;
2063             }
2064             if ( !cd0.getAllDomains().contains( b.getDomainId() ) ) {
2065                 return false;
2066             }
2067             if ( !cd0.getAllDomains().contains( c.getDomainId() ) ) {
2068                 return false;
2069             }
2070             if ( !cd0.getAllDomains().contains( key0.getDomainId() ) ) {
2071                 return false;
2072             }
2073             if ( cd0.toBinaryDomainCombinations().size() != 3 ) {
2074                 return false;
2075             }
2076             final BinaryDomainCombination s0 = new DirectedBinaryDomainCombination( "key0", "a" );
2077             final BinaryDomainCombination s1 = new DirectedBinaryDomainCombination( "b", "key0" );
2078             final BinaryDomainCombination s2 = new DirectedBinaryDomainCombination( "key0", "c" );
2079             final BinaryDomainCombination s3 = new DirectedBinaryDomainCombination( "key0", "cc" );
2080             final BinaryDomainCombination s4 = new DirectedBinaryDomainCombination( "a", "b" );
2081             final BinaryDomainCombination s5 = new DirectedBinaryDomainCombination( "b", "a" );
2082             final BinaryDomainCombination s6 = new DirectedBinaryDomainCombination( "key0", "b" );
2083             final BinaryDomainCombination s7 = new DirectedBinaryDomainCombination( "a", "key0" );
2084             final BinaryDomainCombination s8 = new DirectedBinaryDomainCombination( "c", "key0" );
2085             if ( !cd0.toBinaryDomainCombinations().contains( s0 ) ) {
2086                 return false;
2087             }
2088             if ( cd0.toBinaryDomainCombinations().contains( s1 ) ) {
2089                 return false;
2090             }
2091             if ( !cd0.toBinaryDomainCombinations().contains( s2 ) ) {
2092                 return false;
2093             }
2094             if ( cd0.toBinaryDomainCombinations().contains( s3 ) ) {
2095                 return false;
2096             }
2097             if ( cd0.toBinaryDomainCombinations().contains( s4 ) ) {
2098                 return false;
2099             }
2100             if ( cd0.toBinaryDomainCombinations().contains( s5 ) ) {
2101                 return false;
2102             }
2103             if ( !cd0.toBinaryDomainCombinations().contains( s6 ) ) {
2104                 return false;
2105             }
2106             if ( cd0.toBinaryDomainCombinations().contains( s7 ) ) {
2107                 return false;
2108             }
2109             if ( cd0.toBinaryDomainCombinations().contains( s8 ) ) {
2110                 return false;
2111             }
2112             final Domain key1 = new BasicDomain( "key1", 1, 2, ( short ) 1, ( short ) 4, 0.1, -12 );
2113             final Domain a1 = new BasicDomain( "a1", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2114             final Domain b1 = new BasicDomain( "b1", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2115             final Domain c1 = new BasicDomain( "c1", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2116             final CombinableDomains cd1 = new DirectedCombinableDomains( key1.getDomainId(), new BasicSpecies( "eel" ) );
2117             cd1.addCombinableDomain( a1.getDomainId() );
2118             cd1.addCombinableDomain( b1.getDomainId() );
2119             cd1.addCombinableDomain( c1.getDomainId() );
2120             cd1.addCombinableDomain( key1.getDomainId() );
2121             if ( cd1.getNumberOfCombinableDomains() != 4 ) {
2122                 return false;
2123             }
2124             if ( cd1.getNumberOfProteinsExhibitingCombination( a1.getDomainId() ) != 1 ) {
2125                 return false;
2126             }
2127             if ( cd1.getNumberOfProteinsExhibitingCombination( b1.getDomainId() ) != 1 ) {
2128                 return false;
2129             }
2130             if ( cd1.getNumberOfProteinsExhibitingCombination( c1.getDomainId() ) != 1 ) {
2131                 return false;
2132             }
2133             if ( cd1.getNumberOfProteinsExhibitingCombination( key1.getDomainId() ) != 1 ) {
2134                 return false;
2135             }
2136             if ( cd1.getAllDomains().size() != 4 ) {
2137                 return false;
2138             }
2139             if ( cd1.toBinaryDomainCombinations().size() != 4 ) {
2140                 return false;
2141             }
2142             final BinaryDomainCombination kk = new DirectedBinaryDomainCombination( "key1", "key1" );
2143             if ( !cd1.toBinaryDomainCombinations().contains( kk ) ) {
2144                 return false;
2145             }
2146         }
2147         catch ( final Exception e ) {
2148             e.printStackTrace( System.out );
2149             return false;
2150         }
2151         return true;
2152     }
2153
2154     private static boolean testDirectedness() {
2155         try {
2156             final BinaryStates X = BinaryStates.PRESENT;
2157             final BinaryStates O = BinaryStates.ABSENT;
2158             final GainLossStates G = GainLossStates.GAIN;
2159             final GainLossStates L = GainLossStates.LOSS;
2160             final GainLossStates A = GainLossStates.UNCHANGED_ABSENT;
2161             final GainLossStates P = GainLossStates.UNCHANGED_PRESENT;
2162             final Protein one_1 = new BasicProtein( "one", "1", 0 );
2163             final Protein two_1 = new BasicProtein( "two", "1", 0 );
2164             final Protein three_1 = new BasicProtein( "three", "1", 0 );
2165             final Protein four_1 = new BasicProtein( "four", "1", 0 );
2166             final Protein five_1 = new BasicProtein( "five", "1", 0 );
2167             one_1.addProteinDomain( new BasicDomain( "B", 12, 14, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2168             one_1.addProteinDomain( new BasicDomain( "C", 13, 14, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2169             one_1.addProteinDomain( new BasicDomain( "A", 11, 12, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2170             one_1.addProteinDomain( new BasicDomain( "X", 100, 110, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2171             one_1.addProteinDomain( new BasicDomain( "Y", 200, 210, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2172             two_1.addProteinDomain( new BasicDomain( "A", 10, 20, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2173             two_1.addProteinDomain( new BasicDomain( "B", 30, 40, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2174             two_1.addProteinDomain( new BasicDomain( "Y", 1, 2, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2175             two_1.addProteinDomain( new BasicDomain( "X", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2176             three_1.addProteinDomain( new BasicDomain( "P", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2177             three_1.addProteinDomain( new BasicDomain( "M", 1, 2, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2178             three_1.addProteinDomain( new BasicDomain( "M", 5, 6, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2179             three_1.addProteinDomain( new BasicDomain( "N", 7, 8, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2180             three_1.addProteinDomain( new BasicDomain( "N", 3, 4, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2181             four_1.addProteinDomain( new BasicDomain( "XX", 10, 20, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2182             five_1.addProteinDomain( new BasicDomain( "YY", 30, 40, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2183             final List<Protein> list_1 = new ArrayList<Protein>();
2184             list_1.add( one_1 );
2185             list_1.add( two_1 );
2186             list_1.add( three_1 );
2187             list_1.add( four_1 );
2188             list_1.add( five_1 );
2189             final GenomeWideCombinableDomains gwcd_1 = BasicGenomeWideCombinableDomains
2190                     .createInstance( list_1, false, new BasicSpecies( "1" ), DomainCombinationType.DIRECTED );
2191             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "A", "B" ) ) ) {
2192                 return false;
2193             }
2194             if ( gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "B", "A" ) ) ) {
2195                 return false;
2196             }
2197             if ( gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "A", "A" ) ) ) {
2198                 return false;
2199             }
2200             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "A", "C" ) ) ) {
2201                 return false;
2202             }
2203             if ( gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "C", "A" ) ) ) {
2204                 return false;
2205             }
2206             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "B", "C" ) ) ) {
2207                 return false;
2208             }
2209             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "C", "X" ) ) ) {
2210                 return false;
2211             }
2212             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "C", "Y" ) ) ) {
2213                 return false;
2214             }
2215             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "A", "X" ) ) ) {
2216                 return false;
2217             }
2218             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "A", "Y" ) ) ) {
2219                 return false;
2220             }
2221             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "Y", "A" ) ) ) {
2222                 return false;
2223             }
2224             if ( gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "X", "A" ) ) ) {
2225                 return false;
2226             }
2227             if ( gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "C", "B" ) ) ) {
2228                 return false;
2229             }
2230             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "X", "Y" ) ) ) {
2231                 return false;
2232             }
2233             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "Y", "X" ) ) ) {
2234                 return false;
2235             }
2236             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "A", "Y" ) ) ) {
2237                 return false;
2238             }
2239             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "A", "X" ) ) ) {
2240                 return false;
2241             }
2242             if ( gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "Y", "C" ) ) ) {
2243                 return false;
2244             }
2245             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "M", "N" ) ) ) {
2246                 return false;
2247             }
2248             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "N", "M" ) ) ) {
2249                 return false;
2250             }
2251             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "N", "P" ) ) ) {
2252                 return false;
2253             }
2254             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "M", "P" ) ) ) {
2255                 return false;
2256             }
2257             if ( gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "P", "N" ) ) ) {
2258                 return false;
2259             }
2260             if ( gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "P", "M" ) ) ) {
2261                 return false;
2262             }
2263             if ( gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "XX", "YY" ) ) ) {
2264                 return false;
2265             }
2266             if ( gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "YY", "XX" ) ) ) {
2267                 return false;
2268             }
2269             if ( gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "B", "B" ) ) ) {
2270                 return false;
2271             }
2272             //            final List<GenomeWideCombinableDomains> gwcd_list = new ArrayList<GenomeWideCombinableDomains>();
2273             //            gwcd_list.add( gwcd_1 );
2274             //            gwcd_list.add( gwcd_2 );
2275             //            final CharacterStateMatrix<BinaryStates> matrix_d = DomainParsimonyCalculator
2276             //                    .createMatrixOfDomainPresenceOrAbsence( gwcd_list );
2277             //            final CharacterStateMatrix<BinaryStates> matrix_bc = DomainParsimonyCalculator
2278             //                    .createMatrixOfBinaryDomainCombinationPresenceOrAbsence( gwcd_list );
2279             //            if ( matrix_d.getState( 0, 0 ) != X ) {
2280             //                return false;
2281             //            }
2282             //            if ( matrix_bc.getState( 0, 0 ) != X ) {
2283             //                return false;
2284             //            }
2285             //        
2286             //
2287             //            final BasicCharacterStateMatrix<BinaryStates> dm = new BasicCharacterStateMatrix<BinaryStates>( new BinaryStates[][] {
2288             //                    { X, X, X, X, X, X }, { X, X, X, X, X, X } } );
2289             //            if ( !matrix_d.equals( dm ) ) {
2290             //                return false;
2291             //            }
2292             //            final BasicCharacterStateMatrix<BinaryStates> bcm = new BasicCharacterStateMatrix<BinaryStates>( new BinaryStates[][] {
2293             //                    { X, O, X, X, X, X, O, X, X, O, X, X }, { X, X, X, O, O, O, O, X, O, O, X, X } } );
2294             //            if ( !matrix_d.equals( dm ) ) {
2295             //                return false;
2296             //            }
2297             //``````````````````````````
2298             //            final List<GenomeWideCombinableDomains> gwcd_list = new ArrayList<GenomeWideCombinableDomains>();
2299             //            gwcd_list.add( one );
2300             //            gwcd_list.add( two );
2301             //            gwcd_list.add( three );
2302             //            gwcd_list.add( four );
2303             //            final CharacterStateMatrix<BinaryStates> matrix_d = DomainParsimony
2304             //                    .createMatrixOfDomainPresenceOrAbsence( gwcd_list );
2305             //            final CharacterStateMatrix<BinaryStates> matrix_bc = DomainParsimony
2306             //                    .createMatrixOfBinaryDomainCombinationPresenceOrAbsence( gwcd_list );
2307             //            //         System.out.println( "d:"  );
2308             //            //         System.out.println(matrix_d.toStringBuffer().toString()  );
2309             //            //         System.out.println( "bc:"  );
2310             //            //        System.out.println(matrix_bc.toStringBuffer().toString()  );
2311             //            // 1 a b c e f g h l m
2312             //            // 2 a b c e f g i n o
2313             //            // 3 a b d e f g j p q
2314             //            // 4 a b d p r
2315             //            if ( matrix_d.getState( 0, 0 ) != X ) {
2316             //                return false;
2317             //            }
2318             //            if ( matrix_d.getState( 0, 1 ) != X ) {
2319             //                return false;
2320             //            }
2321             //            if ( matrix_d.getState( 0, 2 ) != X ) {
2322             //                return false;
2323             //            }
2324             //            if ( matrix_d.getState( 0, 3 ) != O ) {
2325             //                return false;
2326             //            }
2327             //            if ( matrix_d.getState( 0, 4 ) != X ) {
2328             //                return false;
2329             //            }
2330             //            if ( matrix_d.getState( 0, 5 ) != X ) {
2331             //                return false;
2332             //            }
2333             //            if ( matrix_d.getState( 0, 6 ) != X ) {
2334             //                return false;
2335             //            }
2336             //            if ( matrix_d.getState( 0, 7 ) != X ) {
2337             //                return false;
2338             //            }
2339             //            if ( matrix_d.getState( 0, 8 ) != O ) {
2340             //                return false;
2341             //            }
2342             //            // 1 a-a a-b a-c e-f e-g e-h f-g f-h g-h l-m
2343             //            // 2 a-b a-c e-f e-g e-i f-g f-i g-i n-o
2344             //            // 3 a-b a-d e-f e-g e-j f-g f-j g-j p-q
2345             //            // 4 a-b a-d p-r
2346             //            if ( matrix_bc.getState( 0, 0 ) != X ) {
2347             //                return false;
2348             //            }
2349             //            if ( matrix_bc.getState( 0, 1 ) != X ) {
2350             //                return false;
2351             //            }
2352             //            if ( matrix_bc.getState( 0, 2 ) != X ) {
2353             //                return false;
2354             //            }
2355             //            if ( matrix_bc.getState( 0, 3 ) != O ) {
2356             //                return false;
2357             //            }
2358             //            if ( matrix_bc.getState( 0, 4 ) != X ) {
2359             //                return false;
2360             //            }
2361             //            if ( matrix_bc.getState( 1, 0 ) != O ) {
2362             //                return false;
2363             //            }
2364             //            if ( matrix_bc.getState( 1, 1 ) != X ) {
2365             //                return false;
2366             //            }
2367             //            if ( matrix_bc.getState( 1, 2 ) != X ) {
2368             //                return false;
2369             //            }
2370             //            if ( matrix_bc.getState( 1, 3 ) != O ) {
2371             //                return false;
2372             //            }
2373             //            if ( matrix_bc.getState( 1, 4 ) != X ) {
2374             //                return false;
2375             //            }
2376             //            if ( matrix_bc.getState( 2, 0 ) != O ) {
2377             //                return false;
2378             //            }
2379             //            if ( matrix_bc.getState( 2, 1 ) != X ) {
2380             //                return false;
2381             //            }
2382             //            if ( matrix_bc.getState( 2, 2 ) != O ) {
2383             //                return false;
2384             //            }
2385             //            if ( matrix_bc.getState( 2, 3 ) != X ) {
2386             //                return false;
2387             //            }
2388             //            if ( matrix_bc.getState( 2, 4 ) != X ) {
2389             //                return false;
2390             //            }
2391             //            final PhylogenyFactory factory0 = ParserBasedPhylogenyFactory.getInstance();
2392             //            final String p0_str = "((one,two)1-2,(three,four)3-4)root";
2393             //            final Phylogeny p0 = factory0.create( p0_str, new NHXParser() )[ 0 ];
2394             //            final DomainParsimony dp0 = DomainParsimony.createInstance( p0, gwcd_list );
2395             //            dp0.executeDolloParsimonyOnDomainPresence();
2396             //            final CharacterStateMatrix<GainLossStates> gl_matrix_d = dp0.getGainLossMatrix();
2397             //            final CharacterStateMatrix<BinaryStates> is_matrix_d = dp0.getInternalStatesMatrix();
2398             //            dp0.executeDolloParsimonyOnBinaryDomainCombintionPresence();
2399             //            final CharacterStateMatrix<GainLossStates> gl_matrix_bc = dp0.getGainLossMatrix();
2400             //            final CharacterStateMatrix<BinaryStates> is_matrix_bc = dp0.getInternalStatesMatrix();
2401             //            if ( is_matrix_d.getState( "root", "A" ) != X ) {
2402             //                return false;
2403             //            }
2404             //            if ( is_matrix_d.getState( "root", "B" ) != X ) {
2405             //                return false;
2406             //            }
2407             //            if ( is_matrix_d.getState( "root", "C" ) != O ) {
2408             //                return false;
2409             //            }
2410             //            if ( is_matrix_d.getState( "root", "D" ) != O ) {
2411             //                return false;
2412             //            }
2413             //            if ( is_matrix_d.getState( "root", "E" ) != X ) {
2414             //                return false;
2415             //            }
2416             //            if ( is_matrix_bc.getState( "root", "A=A" ) != O ) {
2417             //                return false;
2418             //            }
2419             //            if ( is_matrix_bc.getState( "root", "A=B" ) != X ) {
2420             //                return false;
2421             //            }
2422             //            if ( is_matrix_bc.getState( "root", "A=C" ) != O ) {
2423             //                return false;
2424             //            }
2425             //            if ( is_matrix_bc.getState( "root", "A=D" ) != O ) {
2426             //                return false;
2427             //            }
2428             //            if ( is_matrix_bc.getState( "root", "G=H" ) != O ) {
2429             //                return false;
2430             //            }
2431             //            if ( is_matrix_bc.getState( "1-2", "G=H" ) != O ) {
2432             //                return false;
2433             //            }
2434             //            if ( is_matrix_bc.getState( "root", "E=F" ) != X ) {
2435             //                return false;
2436             //            }
2437             //            if ( gl_matrix_bc.getState( "root", "E=F" ) != P ) {
2438             //                return false;
2439             //            }
2440             //            if ( gl_matrix_bc.getState( "root", "A=A" ) != A ) {
2441             //                return false;
2442             //            }
2443             //            if ( gl_matrix_bc.getState( "one", "A=A" ) != G ) {
2444             //                return false;
2445             //            }
2446             //            if ( gl_matrix_bc.getState( "root", "A=B" ) != P ) {
2447             //                return false;
2448             //            }
2449             //            if ( gl_matrix_bc.getState( "3-4", "A=D" ) != G ) {
2450             //                return false;
2451             //            }
2452             //            if ( gl_matrix_bc.getState( "four", "E=F" ) != L ) {
2453             //                return false;
2454             //            }
2455             //            if ( gl_matrix_d.getState( "3-4", "P" ) != G ) {
2456             //                return false;
2457             //            }
2458             //            final Protein ab_1 = new BasicProtein( "ab", "one" );
2459             //            ab_1.addProteinDomain( a );
2460             //            ab_1.addProteinDomain( b );
2461             //            final Protein ac_1 = new BasicProtein( "ac", "one" );
2462             //            ac_1.addProteinDomain( a );
2463             //            ac_1.addProteinDomain( c );
2464             //            final Protein de_1 = new BasicProtein( "de", "one" );
2465             //            de_1.addProteinDomain( d );
2466             //            de_1.addProteinDomain( e );
2467             //            final Protein ac_2 = new BasicProtein( "ac", "two" );
2468             //            ac_2.addProteinDomain( a );
2469             //            ac_2.addProteinDomain( c );
2470             //            final Protein ab_3 = new BasicProtein( "ab", "three" );
2471             //            ab_3.addProteinDomain( a );
2472             //            ab_3.addProteinDomain( b );
2473             //            final Protein de_4 = new BasicProtein( "de", "four" );
2474             //            de_4.addProteinDomain( d );
2475             //            de_4.addProteinDomain( e );
2476             //            final Protein ab_6 = new BasicProtein( "ab", "six" );
2477             //            ab_6.addProteinDomain( a );
2478             //            ab_6.addProteinDomain( b );
2479             //            final List<Protein> spec_one = new ArrayList<Protein>();
2480             //            final List<Protein> spec_two = new ArrayList<Protein>();
2481             //            final List<Protein> spec_three = new ArrayList<Protein>();
2482             //            final List<Protein> spec_four = new ArrayList<Protein>();
2483             //            final List<Protein> spec_five = new ArrayList<Protein>();
2484             //            final List<Protein> spec_six = new ArrayList<Protein>();
2485             //            final List<Protein> spec_seven = new ArrayList<Protein>();
2486             //            spec_one.add( ab_1 );
2487             //            spec_one.add( ac_1 );
2488             //            spec_one.add( de_1 );
2489             //            spec_two.add( ac_2 );
2490             //            spec_three.add( ab_3 );
2491             //            spec_four.add( de_4 );
2492             //            spec_six.add( ab_6 );
2493             //            final GenomeWideCombinableDomains one_gwcd = BasicGenomeWideCombinableDomains
2494             //                    .createInstance( spec_one, false, new BasicSpecies( "one" ), false );
2495             //            final GenomeWideCombinableDomains two_gwcd = BasicGenomeWideCombinableDomains
2496             //                    .createInstance( spec_two, false, new BasicSpecies( "two" ), false );
2497             //            final GenomeWideCombinableDomains three_gwcd = BasicGenomeWideCombinableDomains
2498             //                    .createInstance( spec_three, false, new BasicSpecies( "three" ), false );
2499             //            final GenomeWideCombinableDomains four_gwcd = BasicGenomeWideCombinableDomains
2500             //                    .createInstance( spec_four, false, new BasicSpecies( "four" ), false );
2501             //            final GenomeWideCombinableDomains five_gwcd = BasicGenomeWideCombinableDomains
2502             //                    .createInstance( spec_five, false, new BasicSpecies( "five" ), false );
2503             //            final GenomeWideCombinableDomains six_gwcd = BasicGenomeWideCombinableDomains
2504             //                    .createInstance( spec_six, false, new BasicSpecies( "six" ), false );
2505             //            final GenomeWideCombinableDomains seven_gwcd = BasicGenomeWideCombinableDomains
2506             //                    .createInstance( spec_seven, false, new BasicSpecies( "seven" ), false
2507             //                                    );
2508             //            final List<GenomeWideCombinableDomains> gwcd_list1 = new ArrayList<GenomeWideCombinableDomains>();
2509             //            gwcd_list1.add( one_gwcd );
2510             //            gwcd_list1.add( two_gwcd );
2511             //            gwcd_list1.add( three_gwcd );
2512             //            gwcd_list1.add( four_gwcd );
2513             //            gwcd_list1.add( five_gwcd );
2514             //            gwcd_list1.add( six_gwcd );
2515             //            gwcd_list1.add( seven_gwcd );
2516             //            final PhylogenyFactory factory1 = ParserBasedPhylogenyFactory.getInstance();
2517             //            final String p1_str = "(((((one,two)12,three)123,(four,five)45)12345,six)123456,seven)root";
2518             //            final Phylogeny p1 = factory1.create( p1_str, new NHXParser() )[ 0 ];
2519             //            final DomainParsimony dp1 = DomainParsimony.createInstance( p1, gwcd_list1 );
2520             //            dp1.executeDolloParsimonyOnDomainPresence();
2521             //            final CharacterStateMatrix<GainLossStates> gl_dollo_d = dp1.getGainLossMatrix();
2522             //            final CharacterStateMatrix<BinaryStates> i_dollo_d = dp1.getInternalStatesMatrix();
2523             //            if ( dp1.getCost() != 14 ) {
2524             //                return false;
2525             //            }
2526             //            if ( dp1.getTotalGains() != 5 ) {
2527             //                return false;
2528             //            }
2529             //            if ( dp1.getTotalLosses() != 9 ) {
2530             //                return false;
2531             //            }
2532             //            if ( dp1.getTotalUnchanged() != 51 ) {
2533             //                return false;
2534             //            }
2535             //            if ( dp1.getNetGainsOnNode( "45" ) != -2 ) {
2536             //                return false;
2537             //            }
2538             //            if ( dp1.getSumOfGainsOnNode( "45" ) != 0 ) {
2539             //                return false;
2540             //            }
2541             //            if ( dp1.getSumOfLossesOnNode( "45" ) != 2 ) {
2542             //                return false;
2543             //            }
2544             //            if ( dp1.getSumOfUnchangedOnNode( "45" ) != 3 ) {
2545             //                return false;
2546             //            }
2547             //            if ( dp1.getSumOfUnchangedPresentOnNode( "45" ) != 2 ) {
2548             //                return false;
2549             //            }
2550             //            if ( dp1.getSumOfUnchangedAbsentOnNode( "45" ) != 1 ) {
2551             //                return false;
2552             //            }
2553             //            if ( dp1.getUnitsGainedOnNode( "45" ).contains( "A" ) ) {
2554             //                return false;
2555             //            }
2556             //            if ( !dp1.getUnitsLostOnNode( "45" ).contains( "A" ) ) {
2557             //                return false;
2558             //            }
2559             //            if ( !dp1.getUnitsLostOnNode( "45" ).contains( "B" ) ) {
2560             //                return false;
2561             //            }
2562             //            if ( !dp1.getUnitsGainedOnNode( "12345" ).contains( "D" ) ) {
2563             //                return false;
2564             //            }
2565             //            if ( !dp1.getUnitsOnNode( "12" ).contains( "A" ) ) {
2566             //                return false;
2567             //            }
2568             //            if ( !dp1.getUnitsOnNode( "12" ).contains( "B" ) ) {
2569             //                return false;
2570             //            }
2571             //            if ( !dp1.getUnitsOnNode( "12" ).contains( "C" ) ) {
2572             //                return false;
2573             //            }
2574             //            if ( !dp1.getUnitsOnNode( "12" ).contains( "D" ) ) {
2575             //                return false;
2576             //            }
2577             //            if ( !dp1.getUnitsOnNode( "12" ).contains( "E" ) ) {
2578             //                return false;
2579             //            }
2580             //            if ( dp1.getNetGainsOnNode( "123456" ) != 2 ) {
2581             //                return false;
2582             //            }
2583             //            if ( dp1.getSumOfGainsOnNode( "123456" ) != 2 ) {
2584             //                return false;
2585             //            }
2586             //            dp1.executeDolloParsimonyOnBinaryDomainCombintionPresence();
2587             //            final CharacterStateMatrix<GainLossStates> gl_dollo_bc = dp1.getGainLossMatrix();
2588             //            final CharacterStateMatrix<BinaryStates> i_dollo_bc = dp1.getInternalStatesMatrix();
2589             //            if ( dp1.getCost() != 8 ) {
2590             //                return false;
2591             //            }
2592             //            if ( dp1.getTotalGains() != 3 ) {
2593             //                return false;
2594             //            }
2595             //            if ( dp1.getTotalLosses() != 5 ) {
2596             //                return false;
2597             //            }
2598             //            if ( dp1.getTotalUnchanged() != 31 ) {
2599             //                return false;
2600             //            }
2601             //            if ( !dp1.getUnitsLostOnNode( "45" ).contains( "A=B" ) ) {
2602             //                return false;
2603             //            }
2604             //            if ( !dp1.getUnitsGainedOnNode( "12345" ).contains( "D=E" ) ) {
2605             //                return false;
2606             //            }
2607             //            dp1.executeFitchParsimonyOnDomainPresence();
2608             //            final CharacterStateMatrix<GainLossStates> gl_fitch_d = dp1.getGainLossMatrix();
2609             //            final CharacterStateMatrix<BinaryStates> i_fitch_d = dp1.getInternalStatesMatrix();
2610             //            if ( dp1.getCost() != 10 ) {
2611             //                return false;
2612             //            }
2613             //            if ( dp1.getTotalGains() != 7 ) {
2614             //                return false;
2615             //            }
2616             //            if ( dp1.getTotalLosses() != 3 ) {
2617             //                return false;
2618             //            }
2619             //            if ( dp1.getTotalUnchanged() != 55 ) {
2620             //                return false;
2621             //            }
2622             //            if ( !dp1.getUnitsGainedOnNode( "four" ).contains( "E" ) ) {
2623             //                return false;
2624             //            }
2625             //            dp1.executeFitchParsimonyOnBinaryDomainCombintion();
2626             //            final CharacterStateMatrix<GainLossStates> gl_fitch_bc = dp1.getGainLossMatrix();
2627             //            final CharacterStateMatrix<BinaryStates> i_fitch_bc = dp1.getInternalStatesMatrix();
2628             //            if ( dp1.getCost() != 6 ) {
2629             //                return false;
2630             //            }
2631             //            if ( dp1.getTotalGains() != 4 ) {
2632             //                return false;
2633             //            }
2634             //            if ( dp1.getTotalLosses() != 2 ) {
2635             //                return false;
2636             //            }
2637             //            if ( dp1.getTotalUnchanged() != 33 ) {
2638             //                return false;
2639             //            }
2640             //            if ( !dp1.getUnitsLostOnNode( "45" ).contains( "A=B" ) ) {
2641             //                return false;
2642             //            }
2643             //            if ( !dp1.getUnitsGainedOnNode( "four" ).contains( "D=E" ) ) {
2644             //                return false;
2645             //            }
2646             //            if ( dp1.getNetGainsOnNode( "two" ) != -1 ) {
2647             //                return false;
2648             //            }
2649             //            if ( dp1.getNetGainsOnNode( "123" ) != 0 ) {
2650             //                return false;
2651             //            }
2652             //            if ( dp1.getSumOfUnchangedPresentOnNode( "123" ) != 1 ) {
2653             //                return false;
2654             //            }
2655             //            if ( dp1.getSumOfUnchangedAbsentOnNode( "123" ) != 2 ) {
2656             //                return false;
2657             //            }
2658             //            if ( dp1.getSumOfUnchangedOnNode( "123" ) != 3 ) {
2659             //                return false;
2660             //            }
2661             //            if ( dp1.getSumOfUnchangedOnNode( "two" ) != 2 ) {
2662             //                return false;
2663             //            }
2664             //            if ( !dp1.getUnitsUnchangedAbsentOnNode( "two" ).contains( "D=E" ) ) {
2665             //                return false;
2666             //            }
2667             //            if ( !dp1.getUnitsUnchangedPresentOnNode( "two" ).contains( "A=C" ) ) {
2668             //                return false;
2669             //            }
2670             //            if ( !dp1.getUnitsUnchangedAbsentOnNode( "123" ).contains( "A=C" ) ) {
2671             //                return false;
2672             //            }
2673             //            if ( !dp1.getUnitsUnchangedPresentOnNode( "123" ).contains( "A=B" ) ) {
2674             //                return false;
2675             //            }
2676             //            if ( !dp1.getUnitsUnchangedAbsentOnNode( "123" ).contains( "D=E" ) ) {
2677             //                return false;
2678             //            }
2679             //            CharacterStateMatrix<BinaryStates> bsm = null;
2680             //            CharacterStateMatrix<GainLossStates> glm = null;
2681             //            bsm = new BasicCharacterStateMatrix<BinaryStates>( new BinaryStates[][] { { X, X, X, X, X },
2682             //                    { X, X, O, X, X }, { O, O, O, X, X }, { X, X, O, X, X }, { X, X, O, O, O }, { O, O, O, O, O } } );
2683             //            if ( !bsm.equals( i_dollo_d ) ) {
2684             //                return false;
2685             //            }
2686             //            bsm = new BasicCharacterStateMatrix<BinaryStates>( new BinaryStates[][] { { X, X, X, O, O },
2687             //                    { X, X, O, O, O }, { O, O, O, O, O }, { X, X, O, O, O }, { X, X, O, O, O }, { O, O, O, O, O } } );
2688             //            if ( !bsm.equals( i_fitch_d ) ) {
2689             //                return false;
2690             //            }
2691             //            glm = new BasicCharacterStateMatrix<GainLossStates>( new GainLossStates[][] { { P, P, P, P, P },
2692             //                    { P, L, P, L, L }, { P, P, G, P, P }, { P, P, A, L, L }, { P, P, A, P, P }, { A, A, A, P, P },
2693             //                    { A, A, A, L, L }, { L, L, A, P, P }, { P, P, A, G, G }, { P, P, A, A, A }, { G, G, A, A, A },
2694             //                    { A, A, A, A, A }, { A, A, A, A, A } } );
2695             //            if ( !glm.equals( gl_dollo_d ) ) {
2696             //                return false;
2697             //            }
2698             //            glm = new BasicCharacterStateMatrix<GainLossStates>( new GainLossStates[][] { { P, P, P, G, G },
2699             //                    { P, L, P, A, A }, { P, P, G, A, A }, { P, P, A, A, A }, { P, P, A, A, A }, { A, A, A, G, G },
2700             //                    { A, A, A, A, A }, { L, L, A, A, A }, { P, P, A, A, A }, { P, P, A, A, A }, { G, G, A, A, A },
2701             //                    { A, A, A, A, A }, { A, A, A, A, A } } );
2702             //            if ( !glm.equals( gl_fitch_d ) ) {
2703             //                return false;
2704             //            }
2705             //            bsm = new BasicCharacterStateMatrix<BinaryStates>( new BinaryStates[][] { { X, X, X }, { X, O, X },
2706             //                    { O, O, X }, { X, O, X }, { X, O, O }, { O, O, O } } );
2707             //            if ( !bsm.equals( i_dollo_bc ) ) {
2708             //                return false;
2709             //            }
2710             //            bsm = new BasicCharacterStateMatrix<BinaryStates>( new BinaryStates[][] { { X, X, O }, { X, O, O },
2711             //                    { O, O, O }, { X, O, O }, { X, O, O }, { O, O, O } } );
2712             //            if ( !bsm.equals( i_fitch_bc ) ) {
2713             //                return false;
2714             //            }
2715             //            glm = new BasicCharacterStateMatrix<GainLossStates>( new GainLossStates[][] { { P, P, P }, { L, P, L },
2716             //                    { P, G, P }, { P, A, L }, { P, A, P }, { A, A, P }, { A, A, L }, { L, A, P }, { P, A, G },
2717             //                    { P, A, A }, { G, A, A }, { A, A, A }, { A, A, A } } );
2718             //            if ( !glm.equals( gl_dollo_bc ) ) {
2719             //                return false;
2720             //            }
2721             //            glm = new BasicCharacterStateMatrix<GainLossStates>( new GainLossStates[][] { { P, P, G }, { L, P, A },
2722             //                    { P, G, A }, { P, A, A }, { P, A, A }, { A, A, G }, { A, A, A }, { L, A, A }, { P, A, A },
2723             //                    { P, A, A }, { G, A, A }, { A, A, A }, { A, A, A } } );
2724             //            if ( !glm.equals( gl_fitch_bc ) ) {
2725             //                return false;
2726             //            }
2727         }
2728         catch ( final Exception e ) {
2729             e.printStackTrace( System.out );
2730             return false;
2731         }
2732         return true;
2733     }
2734
2735     private static boolean testDirectednessAndAdjacency() {
2736         try {
2737             final Protein one_1 = new BasicProtein( "one", "1", 0 );
2738             final Protein two_1 = new BasicProtein( "two", "1", 0 );
2739             final Protein three_1 = new BasicProtein( "three", "1", 0 );
2740             final Protein four_1 = new BasicProtein( "four", "1", 0 );
2741             final Protein five_1 = new BasicProtein( "five", "1", 0 );
2742             one_1.addProteinDomain( new BasicDomain( "B", 12, 14, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2743             one_1.addProteinDomain( new BasicDomain( "C", 13, 14, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2744             one_1.addProteinDomain( new BasicDomain( "A", 11, 12, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2745             one_1.addProteinDomain( new BasicDomain( "X", 100, 110, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2746             one_1.addProteinDomain( new BasicDomain( "Y", 200, 210, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2747             two_1.addProteinDomain( new BasicDomain( "A", 10, 20, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2748             two_1.addProteinDomain( new BasicDomain( "B", 30, 40, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2749             two_1.addProteinDomain( new BasicDomain( "Y", 1, 2, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2750             two_1.addProteinDomain( new BasicDomain( "X", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2751             three_1.addProteinDomain( new BasicDomain( "P", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2752             three_1.addProteinDomain( new BasicDomain( "M", 1, 2, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2753             three_1.addProteinDomain( new BasicDomain( "M", 5, 6, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2754             three_1.addProteinDomain( new BasicDomain( "N", 7, 8, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2755             three_1.addProteinDomain( new BasicDomain( "N", 3, 4, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2756             four_1.addProteinDomain( new BasicDomain( "XX", 10, 20, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2757             five_1.addProteinDomain( new BasicDomain( "YY", 30, 40, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2758             final List<Protein> list_1 = new ArrayList<Protein>();
2759             list_1.add( one_1 );
2760             list_1.add( two_1 );
2761             list_1.add( three_1 );
2762             list_1.add( four_1 );
2763             list_1.add( five_1 );
2764             final GenomeWideCombinableDomains gwcd_1 = BasicGenomeWideCombinableDomains
2765                     .createInstance( list_1, false, new BasicSpecies( "1" ), DomainCombinationType.DIRECTED_ADJACTANT );
2766             if ( !gwcd_1.toBinaryDomainCombinations()
2767                     .contains( new AdjactantDirectedBinaryDomainCombination( "A", "B" ) ) ) {
2768                 return false;
2769             }
2770             if ( gwcd_1.toBinaryDomainCombinations()
2771                     .contains( new AdjactantDirectedBinaryDomainCombination( "B", "A" ) ) ) {
2772                 return false;
2773             }
2774             if ( gwcd_1.toBinaryDomainCombinations()
2775                     .contains( new AdjactantDirectedBinaryDomainCombination( "A", "A" ) ) ) {
2776                 return false;
2777             }
2778             if ( gwcd_1.toBinaryDomainCombinations()
2779                     .contains( new AdjactantDirectedBinaryDomainCombination( "A", "C" ) ) ) {
2780                 return false;
2781             }
2782             if ( gwcd_1.toBinaryDomainCombinations()
2783                     .contains( new AdjactantDirectedBinaryDomainCombination( "C", "A" ) ) ) {
2784                 return false;
2785             }
2786             if ( !gwcd_1.toBinaryDomainCombinations()
2787                     .contains( new AdjactantDirectedBinaryDomainCombination( "B", "C" ) ) ) {
2788                 return false;
2789             }
2790             if ( !gwcd_1.toBinaryDomainCombinations()
2791                     .contains( new AdjactantDirectedBinaryDomainCombination( "C", "X" ) ) ) {
2792                 return false;
2793             }
2794             if ( gwcd_1.toBinaryDomainCombinations()
2795                     .contains( new AdjactantDirectedBinaryDomainCombination( "C", "Y" ) ) ) {
2796                 return false;
2797             }
2798             if ( !gwcd_1.toBinaryDomainCombinations()
2799                     .contains( new AdjactantDirectedBinaryDomainCombination( "X", "Y" ) ) ) {
2800                 return false;
2801             }
2802             if ( gwcd_1.toBinaryDomainCombinations()
2803                     .contains( new AdjactantDirectedBinaryDomainCombination( "A", "X" ) ) ) {
2804                 return false;
2805             }
2806             if ( gwcd_1.toBinaryDomainCombinations()
2807                     .contains( new AdjactantDirectedBinaryDomainCombination( "A", "Y" ) ) ) {
2808                 return false;
2809             }
2810             if ( !gwcd_1.toBinaryDomainCombinations()
2811                     .contains( new AdjactantDirectedBinaryDomainCombination( "Y", "A" ) ) ) {
2812                 return false;
2813             }
2814             if ( gwcd_1.toBinaryDomainCombinations()
2815                     .contains( new AdjactantDirectedBinaryDomainCombination( "X", "A" ) ) ) {
2816                 return false;
2817             }
2818             if ( gwcd_1.toBinaryDomainCombinations()
2819                     .contains( new AdjactantDirectedBinaryDomainCombination( "C", "B" ) ) ) {
2820                 return false;
2821             }
2822             if ( !gwcd_1.toBinaryDomainCombinations()
2823                     .contains( new AdjactantDirectedBinaryDomainCombination( "X", "Y" ) ) ) {
2824                 return false;
2825             }
2826             if ( gwcd_1.toBinaryDomainCombinations()
2827                     .contains( new AdjactantDirectedBinaryDomainCombination( "Y", "X" ) ) ) {
2828                 return false;
2829             }
2830             if ( gwcd_1.toBinaryDomainCombinations()
2831                     .contains( new AdjactantDirectedBinaryDomainCombination( "A", "Y" ) ) ) {
2832                 return false;
2833             }
2834             if ( gwcd_1.toBinaryDomainCombinations()
2835                     .contains( new AdjactantDirectedBinaryDomainCombination( "A", "X" ) ) ) {
2836                 return false;
2837             }
2838             if ( gwcd_1.toBinaryDomainCombinations()
2839                     .contains( new AdjactantDirectedBinaryDomainCombination( "Y", "C" ) ) ) {
2840                 return false;
2841             }
2842             if ( !gwcd_1.toBinaryDomainCombinations()
2843                     .contains( new AdjactantDirectedBinaryDomainCombination( "M", "N" ) ) ) {
2844                 return false;
2845             }
2846             if ( !gwcd_1.toBinaryDomainCombinations()
2847                     .contains( new AdjactantDirectedBinaryDomainCombination( "N", "M" ) ) ) {
2848                 return false;
2849             }
2850             if ( !gwcd_1.toBinaryDomainCombinations()
2851                     .contains( new AdjactantDirectedBinaryDomainCombination( "N", "P" ) ) ) {
2852                 return false;
2853             }
2854             if ( gwcd_1.toBinaryDomainCombinations()
2855                     .contains( new AdjactantDirectedBinaryDomainCombination( "M", "P" ) ) ) {
2856                 return false;
2857             }
2858             if ( gwcd_1.toBinaryDomainCombinations()
2859                     .contains( new AdjactantDirectedBinaryDomainCombination( "P", "N" ) ) ) {
2860                 return false;
2861             }
2862             if ( gwcd_1.toBinaryDomainCombinations()
2863                     .contains( new AdjactantDirectedBinaryDomainCombination( "P", "M" ) ) ) {
2864                 return false;
2865             }
2866             if ( gwcd_1.toBinaryDomainCombinations()
2867                     .contains( new AdjactantDirectedBinaryDomainCombination( "XX", "YY" ) ) ) {
2868                 return false;
2869             }
2870             if ( gwcd_1.toBinaryDomainCombinations()
2871                     .contains( new AdjactantDirectedBinaryDomainCombination( "YY", "XX" ) ) ) {
2872                 return false;
2873             }
2874             if ( gwcd_1.toBinaryDomainCombinations()
2875                     .contains( new AdjactantDirectedBinaryDomainCombination( "B", "B" ) ) ) {
2876                 return false;
2877             }
2878         }
2879         catch ( final Exception e ) {
2880             e.printStackTrace( System.out );
2881             return false;
2882         }
2883         return true;
2884     }
2885
2886     private static boolean testDomainArchitectureBasedGenomeSimilarityCalculator() {
2887         try {
2888             final Domain a = new BasicDomain( "a", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2889             final Domain b = new BasicDomain( "b", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2890             final Domain c = new BasicDomain( "c", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2891             final Domain d = new BasicDomain( "d", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2892             final Domain e = new BasicDomain( "e", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2893             final Domain f = new BasicDomain( "f", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2894             final Domain g = new BasicDomain( "g", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2895             final Domain h = new BasicDomain( "h", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2896             final Domain i = new BasicDomain( "i", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2897             final Domain j = new BasicDomain( "j", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2898             final Domain k = new BasicDomain( "k", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2899             final Domain l = new BasicDomain( "l", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2900             final Domain m = new BasicDomain( "m", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2901             final Domain n = new BasicDomain( "n", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2902             final Protein eel_0 = new BasicProtein( "0", "eel", 0 );
2903             final Protein eel_1 = new BasicProtein( "1", "eel", 0 );
2904             final Protein eel_2 = new BasicProtein( "2", "eel", 0 );
2905             final Protein eel_3 = new BasicProtein( "3", "eel", 0 );
2906             final Protein eel_4 = new BasicProtein( "4", "eel", 0 );
2907             final Protein eel_5 = new BasicProtein( "5", "eel", 0 );
2908             final Protein eel_6 = new BasicProtein( "6", "eel", 0 );
2909             final Protein rat_0 = new BasicProtein( "0", "rat", 0 );
2910             final Protein rat_1 = new BasicProtein( "1", "rat", 0 );
2911             final Protein rat_2 = new BasicProtein( "2", "rat", 0 );
2912             final Protein rat_3 = new BasicProtein( "3", "rat", 0 );
2913             final Protein rat_4 = new BasicProtein( "4", "rat", 0 );
2914             final Protein rat_5 = new BasicProtein( "5", "rat", 0 );
2915             final Protein rat_6 = new BasicProtein( "6", "rat", 0 );
2916             final Protein rat_7 = new BasicProtein( "7", "rat", 0 );
2917             eel_1.addProteinDomain( a );
2918             eel_2.addProteinDomain( a );
2919             eel_2.addProteinDomain( b );
2920             eel_3.addProteinDomain( a );
2921             eel_3.addProteinDomain( a );
2922             eel_3.addProteinDomain( b );
2923             eel_4.addProteinDomain( a );
2924             eel_4.addProteinDomain( b );
2925             eel_4.addProteinDomain( c );
2926             eel_4.addProteinDomain( d );
2927             eel_4.addProteinDomain( e );
2928             eel_5.addProteinDomain( e );
2929             eel_5.addProteinDomain( e );
2930             eel_5.addProteinDomain( f );
2931             eel_5.addProteinDomain( f );
2932             eel_5.addProteinDomain( f );
2933             eel_5.addProteinDomain( f );
2934             eel_6.addProteinDomain( g );
2935             eel_6.addProteinDomain( h );
2936             rat_1.addProteinDomain( a );
2937             rat_2.addProteinDomain( a );
2938             rat_2.addProteinDomain( b );
2939             rat_3.addProteinDomain( a );
2940             rat_3.addProteinDomain( a );
2941             rat_3.addProteinDomain( b );
2942             rat_4.addProteinDomain( a );
2943             rat_4.addProteinDomain( b );
2944             rat_4.addProteinDomain( c );
2945             rat_4.addProteinDomain( i );
2946             rat_4.addProteinDomain( l );
2947             rat_5.addProteinDomain( i );
2948             rat_5.addProteinDomain( f );
2949             rat_5.addProteinDomain( f );
2950             rat_6.addProteinDomain( j );
2951             rat_6.addProteinDomain( k );
2952             rat_7.addProteinDomain( m );
2953             rat_7.addProteinDomain( n );
2954             final List<Protein> protein_list_eel = new ArrayList<Protein>();
2955             protein_list_eel.add( eel_0 );
2956             protein_list_eel.add( eel_1 );
2957             protein_list_eel.add( eel_2 );
2958             protein_list_eel.add( eel_3 );
2959             protein_list_eel.add( eel_4 );
2960             protein_list_eel.add( eel_5 );
2961             protein_list_eel.add( eel_6 );
2962             final List<Protein> protein_list_rat = new ArrayList<Protein>();
2963             protein_list_rat.add( rat_0 );
2964             protein_list_rat.add( rat_1 );
2965             protein_list_rat.add( rat_2 );
2966             protein_list_rat.add( rat_3 );
2967             protein_list_rat.add( rat_4 );
2968             protein_list_rat.add( rat_5 );
2969             protein_list_rat.add( rat_6 );
2970             protein_list_rat.add( rat_7 );
2971             final GenomeWideCombinableDomains eel_not_ignore = BasicGenomeWideCombinableDomains
2972                     .createInstance( protein_list_eel, false, new BasicSpecies( "eel" ) );
2973             final GenomeWideCombinableDomains eel_ignore = BasicGenomeWideCombinableDomains
2974                     .createInstance( protein_list_eel, true, new BasicSpecies( "eel" ) );
2975             final GenomeWideCombinableDomains rat_not_ignore = BasicGenomeWideCombinableDomains
2976                     .createInstance( protein_list_rat, false, new BasicSpecies( "rat" ) );
2977             final GenomeWideCombinableDomains rat_ignore = BasicGenomeWideCombinableDomains
2978                     .createInstance( protein_list_rat, true, new BasicSpecies( "rat" ) );
2979             final DomainArchitectureBasedGenomeSimilarityCalculator calc_ni = new DomainArchitectureBasedGenomeSimilarityCalculator( eel_not_ignore,
2980                                                                                                                                      rat_not_ignore );
2981             final DomainArchitectureBasedGenomeSimilarityCalculator calc_i = new DomainArchitectureBasedGenomeSimilarityCalculator( eel_ignore,
2982                                                                                                                                     rat_ignore );
2983             if ( calc_ni.getAllDomains().size() != 14 ) {
2984                 return false;
2985             }
2986             if ( calc_i.getAllDomains().size() != 14 ) {
2987                 return false;
2988             }
2989             if ( calc_ni.getDomainsSpecificToGenome0().size() != 4 ) {
2990                 return false;
2991             }
2992             if ( calc_i.getDomainsSpecificToGenome0().size() != 4 ) {
2993                 return false;
2994             }
2995             if ( calc_ni.getDomainsSpecificToGenome1().size() != 6 ) {
2996                 return false;
2997             }
2998             if ( calc_i.getDomainsSpecificToGenome1().size() != 6 ) {
2999                 return false;
3000             }
3001             if ( calc_i.getSharedDomains().size() != 4 ) {
3002                 return false;
3003             }
3004             if ( calc_ni.getSharedDomains().size() != 4 ) {
3005                 return false;
3006             }
3007             if ( !calc_ni.getDomainsSpecificToGenome0().contains( d.getDomainId() ) ) {
3008                 return false;
3009             }
3010             if ( !calc_ni.getDomainsSpecificToGenome0().contains( e.getDomainId() ) ) {
3011                 return false;
3012             }
3013             if ( !calc_ni.getDomainsSpecificToGenome0().contains( g.getDomainId() ) ) {
3014                 return false;
3015             }
3016             if ( !calc_ni.getDomainsSpecificToGenome0().contains( h.getDomainId() ) ) {
3017                 return false;
3018             }
3019             if ( calc_ni.getDomainsSpecificToGenome0().contains( a.getDomainId() ) ) {
3020                 return false;
3021             }
3022             if ( calc_ni.getDomainsSpecificToGenome0().contains( i.getDomainId() ) ) {
3023                 return false;
3024             }
3025             if ( !calc_i.getDomainsSpecificToGenome0().contains( d.getDomainId() ) ) {
3026                 return false;
3027             }
3028             if ( !calc_i.getDomainsSpecificToGenome0().contains( e.getDomainId() ) ) {
3029                 return false;
3030             }
3031             if ( !calc_i.getDomainsSpecificToGenome0().contains( g.getDomainId() ) ) {
3032                 return false;
3033             }
3034             if ( !calc_i.getDomainsSpecificToGenome0().contains( h.getDomainId() ) ) {
3035                 return false;
3036             }
3037             if ( calc_i.getDomainsSpecificToGenome0().contains( a.getDomainId() ) ) {
3038                 return false;
3039             }
3040             if ( calc_i.getDomainsSpecificToGenome0().contains( i.getDomainId() ) ) {
3041                 return false;
3042             }
3043             if ( !calc_ni.getDomainsSpecificToGenome1().contains( i.getDomainId() ) ) {
3044                 return false;
3045             }
3046             if ( !calc_ni.getDomainsSpecificToGenome1().contains( l.getDomainId() ) ) {
3047                 return false;
3048             }
3049             if ( !calc_ni.getDomainsSpecificToGenome1().contains( j.getDomainId() ) ) {
3050                 return false;
3051             }
3052             if ( !calc_ni.getDomainsSpecificToGenome1().contains( k.getDomainId() ) ) {
3053                 return false;
3054             }
3055             if ( !calc_ni.getDomainsSpecificToGenome1().contains( m.getDomainId() ) ) {
3056                 return false;
3057             }
3058             if ( !calc_ni.getDomainsSpecificToGenome1().contains( n.getDomainId() ) ) {
3059                 return false;
3060             }
3061             if ( calc_ni.getDomainsSpecificToGenome1().contains( a.getDomainId() ) ) {
3062                 return false;
3063             }
3064             if ( calc_ni.getDomainsSpecificToGenome1().contains( b.getDomainId() ) ) {
3065                 return false;
3066             }
3067             if ( calc_ni.getDomainsSpecificToGenome1().contains( d.getDomainId() ) ) {
3068                 return false;
3069             }
3070             if ( !calc_i.getDomainsSpecificToGenome1().contains( i.getDomainId() ) ) {
3071                 return false;
3072             }
3073             if ( !calc_i.getDomainsSpecificToGenome1().contains( l.getDomainId() ) ) {
3074                 return false;
3075             }
3076             if ( !calc_i.getDomainsSpecificToGenome1().contains( j.getDomainId() ) ) {
3077                 return false;
3078             }
3079             if ( !calc_i.getDomainsSpecificToGenome1().contains( k.getDomainId() ) ) {
3080                 return false;
3081             }
3082             if ( !calc_i.getDomainsSpecificToGenome1().contains( m.getDomainId() ) ) {
3083                 return false;
3084             }
3085             if ( !calc_i.getDomainsSpecificToGenome1().contains( n.getDomainId() ) ) {
3086                 return false;
3087             }
3088             if ( calc_i.getDomainsSpecificToGenome1().contains( a.getDomainId() ) ) {
3089                 return false;
3090             }
3091             if ( calc_i.getDomainsSpecificToGenome1().contains( b.getDomainId() ) ) {
3092                 return false;
3093             }
3094             if ( calc_i.getDomainsSpecificToGenome1().contains( d.getDomainId() ) ) {
3095                 return false;
3096             }
3097             if ( !calc_i.getSharedDomains().contains( a.getDomainId() ) ) {
3098                 return false;
3099             }
3100             if ( !calc_i.getSharedDomains().contains( b.getDomainId() ) ) {
3101                 return false;
3102             }
3103             if ( !calc_i.getSharedDomains().contains( c.getDomainId() ) ) {
3104                 return false;
3105             }
3106             if ( !calc_i.getSharedDomains().contains( f.getDomainId() ) ) {
3107                 return false;
3108             }
3109             final Set<DomainId> all = calc_ni.getAllDomains();
3110             if ( !all.contains( a.getDomainId() ) ) {
3111                 return false;
3112             }
3113             if ( !all.contains( b.getDomainId() ) ) {
3114                 return false;
3115             }
3116             if ( !all.contains( c.getDomainId() ) ) {
3117                 return false;
3118             }
3119             if ( !all.contains( d.getDomainId() ) ) {
3120                 return false;
3121             }
3122             if ( !all.contains( e.getDomainId() ) ) {
3123                 return false;
3124             }
3125             if ( !all.contains( f.getDomainId() ) ) {
3126                 return false;
3127             }
3128             if ( !all.contains( g.getDomainId() ) ) {
3129                 return false;
3130             }
3131             if ( !all.contains( h.getDomainId() ) ) {
3132                 return false;
3133             }
3134             if ( !all.contains( i.getDomainId() ) ) {
3135                 return false;
3136             }
3137             if ( !all.contains( l.getDomainId() ) ) {
3138                 return false;
3139             }
3140             if ( !all.contains( j.getDomainId() ) ) {
3141                 return false;
3142             }
3143             if ( !all.contains( k.getDomainId() ) ) {
3144                 return false;
3145             }
3146             if ( !all.contains( m.getDomainId() ) ) {
3147                 return false;
3148             }
3149             if ( !all.contains( n.getDomainId() ) ) {
3150                 return false;
3151             }
3152             final Set<BinaryDomainCombination> s_0_ni = calc_ni.getBinaryDomainCombinationsSpecificToGenome0();
3153             final Set<BinaryDomainCombination> s_0_i = calc_i.getBinaryDomainCombinationsSpecificToGenome0();
3154             final Set<BinaryDomainCombination> s_1_ni = calc_ni.getBinaryDomainCombinationsSpecificToGenome1();
3155             final Set<BinaryDomainCombination> s_1_i = calc_i.getBinaryDomainCombinationsSpecificToGenome1();
3156             final Set<BinaryDomainCombination> a_ni = calc_ni.getAllBinaryDomainCombinations();
3157             final Set<BinaryDomainCombination> a_i = calc_i.getAllBinaryDomainCombinations();
3158             final Set<BinaryDomainCombination> shared_ni = calc_ni.getSharedBinaryDomainCombinations();
3159             final Set<BinaryDomainCombination> shared_i = calc_i.getSharedBinaryDomainCombinations();
3160             if ( a_ni.size() != 25 ) {
3161                 return false;
3162             }
3163             if ( a_i.size() != 22 ) {
3164                 return false;
3165             }
3166             if ( s_0_ni.size() != 10 ) {
3167                 return false;
3168             }
3169             if ( s_0_i.size() != 9 ) {
3170                 return false;
3171             }
3172             if ( s_1_ni.size() != 10 ) {
3173                 return false;
3174             }
3175             if ( s_1_i.size() != 10 ) {
3176                 return false;
3177             }
3178             if ( shared_ni.size() != 5 ) {
3179                 return false;
3180             }
3181             if ( shared_i.size() != 3 ) {
3182                 return false;
3183             }
3184             if ( !a_ni.contains( new BasicBinaryDomainCombination( "a", "a" ) ) ) {
3185                 return false;
3186             }
3187             if ( !a_ni.contains( new BasicBinaryDomainCombination( "b", "a" ) ) ) {
3188                 return false;
3189             }
3190             if ( !a_ni.contains( new BasicBinaryDomainCombination( "a", "c" ) ) ) {
3191                 return false;
3192             }
3193             if ( !a_ni.contains( new BasicBinaryDomainCombination( "a", "d" ) ) ) {
3194                 return false;
3195             }
3196             if ( !a_ni.contains( new BasicBinaryDomainCombination( "a", "e" ) ) ) {
3197                 return false;
3198             }
3199             if ( !a_ni.contains( new BasicBinaryDomainCombination( "b", "c" ) ) ) {
3200                 return false;
3201             }
3202             if ( !a_ni.contains( new BasicBinaryDomainCombination( "b", "d" ) ) ) {
3203                 return false;
3204             }
3205             if ( !a_ni.contains( new BasicBinaryDomainCombination( "b", "e" ) ) ) {
3206                 return false;
3207             }
3208             if ( !a_ni.contains( new BasicBinaryDomainCombination( "c", "d" ) ) ) {
3209                 return false;
3210             }
3211             if ( !a_ni.contains( new BasicBinaryDomainCombination( "c", "e" ) ) ) {
3212                 return false;
3213             }
3214             if ( !a_ni.contains( new BasicBinaryDomainCombination( "d", "e" ) ) ) {
3215                 return false;
3216             }
3217             if ( !a_ni.contains( new BasicBinaryDomainCombination( "e", "f" ) ) ) {
3218                 return false;
3219             }
3220             if ( !a_ni.contains( new BasicBinaryDomainCombination( "g", "h" ) ) ) {
3221                 return false;
3222             }
3223             if ( !a_ni.contains( new BasicBinaryDomainCombination( "f", "f" ) ) ) {
3224                 return false;
3225             }
3226             if ( !a_ni.contains( new BasicBinaryDomainCombination( "e", "e" ) ) ) {
3227                 return false;
3228             }
3229             if ( !a_ni.contains( new BasicBinaryDomainCombination( "a", "i" ) ) ) {
3230                 return false;
3231             }
3232             if ( !a_ni.contains( new BasicBinaryDomainCombination( "a", "l" ) ) ) {
3233                 return false;
3234             }
3235             if ( !a_ni.contains( new BasicBinaryDomainCombination( "b", "i" ) ) ) {
3236                 return false;
3237             }
3238             if ( !a_ni.contains( new BasicBinaryDomainCombination( "b", "l" ) ) ) {
3239                 return false;
3240             }
3241             if ( !a_ni.contains( new BasicBinaryDomainCombination( "c", "i" ) ) ) {
3242                 return false;
3243             }
3244             if ( !a_ni.contains( new BasicBinaryDomainCombination( "c", "l" ) ) ) {
3245                 return false;
3246             }
3247             if ( !a_ni.contains( new BasicBinaryDomainCombination( "i", "l" ) ) ) {
3248                 return false;
3249             }
3250             if ( !a_ni.contains( new BasicBinaryDomainCombination( "i", "f" ) ) ) {
3251                 return false;
3252             }
3253             if ( !a_ni.contains( new BasicBinaryDomainCombination( "m", "n" ) ) ) {
3254                 return false;
3255             }
3256             if ( !a_ni.contains( new BasicBinaryDomainCombination( "j", "k" ) ) ) {
3257                 return false;
3258             }
3259             if ( a_ni.contains( new BasicBinaryDomainCombination( "a", "g" ) ) ) {
3260                 return false;
3261             }
3262             if ( a_ni.contains( new BasicBinaryDomainCombination( "a", "m" ) ) ) {
3263                 return false;
3264             }
3265             if ( a_i.contains( new BasicBinaryDomainCombination( "a", "a" ) ) ) {
3266                 return false;
3267             }
3268             if ( a_i.contains( new BasicBinaryDomainCombination( "f", "f" ) ) ) {
3269                 return false;
3270             }
3271             if ( a_i.contains( new BasicBinaryDomainCombination( "e", "e" ) ) ) {
3272                 return false;
3273             }
3274             if ( !shared_ni.contains( new BasicBinaryDomainCombination( "a", "a" ) ) ) {
3275                 return false;
3276             }
3277             if ( !shared_ni.contains( new BasicBinaryDomainCombination( "a", "b" ) ) ) {
3278                 return false;
3279             }
3280             if ( !shared_ni.contains( new BasicBinaryDomainCombination( "a", "c" ) ) ) {
3281                 return false;
3282             }
3283             if ( !shared_ni.contains( new BasicBinaryDomainCombination( "b", "c" ) ) ) {
3284                 return false;
3285             }
3286             if ( !shared_ni.contains( new BasicBinaryDomainCombination( "f", "f" ) ) ) {
3287                 return false;
3288             }
3289             if ( shared_ni.contains( new BasicBinaryDomainCombination( "m", "n" ) ) ) {
3290                 return false;
3291             }
3292             if ( shared_i.contains( new BasicBinaryDomainCombination( "a", "a" ) ) ) {
3293                 return false;
3294             }
3295             if ( !shared_i.contains( new BasicBinaryDomainCombination( "a", "b" ) ) ) {
3296                 return false;
3297             }
3298             if ( !shared_i.contains( new BasicBinaryDomainCombination( "a", "c" ) ) ) {
3299                 return false;
3300             }
3301             if ( !shared_i.contains( new BasicBinaryDomainCombination( "b", "c" ) ) ) {
3302                 return false;
3303             }
3304             if ( shared_i.contains( new BasicBinaryDomainCombination( "f", "f" ) ) ) {
3305                 return false;
3306             }
3307             if ( shared_i.contains( new BasicBinaryDomainCombination( "m", "n" ) ) ) {
3308                 return false;
3309             }
3310             if ( !s_0_ni.contains( new BasicBinaryDomainCombination( "a", "d" ) ) ) {
3311                 return false;
3312             }
3313             if ( !s_0_ni.contains( new BasicBinaryDomainCombination( "a", "e" ) ) ) {
3314                 return false;
3315             }
3316             if ( !s_0_ni.contains( new BasicBinaryDomainCombination( "b", "d" ) ) ) {
3317                 return false;
3318             }
3319             if ( !s_0_ni.contains( new BasicBinaryDomainCombination( "b", "e" ) ) ) {
3320                 return false;
3321             }
3322             if ( !s_0_ni.contains( new BasicBinaryDomainCombination( "c", "d" ) ) ) {
3323                 return false;
3324             }
3325             if ( !s_0_ni.contains( new BasicBinaryDomainCombination( "c", "e" ) ) ) {
3326                 return false;
3327             }
3328             if ( !s_0_ni.contains( new BasicBinaryDomainCombination( "d", "e" ) ) ) {
3329                 return false;
3330             }
3331             if ( !s_0_ni.contains( new BasicBinaryDomainCombination( "e", "f" ) ) ) {
3332                 return false;
3333             }
3334             if ( !s_0_ni.contains( new BasicBinaryDomainCombination( "g", "h" ) ) ) {
3335                 return false;
3336             }
3337             if ( !s_0_ni.contains( new BasicBinaryDomainCombination( "e", "e" ) ) ) {
3338                 return false;
3339             }
3340             if ( !s_0_i.contains( new BasicBinaryDomainCombination( "a", "d" ) ) ) {
3341                 return false;
3342             }
3343             if ( !s_0_i.contains( new BasicBinaryDomainCombination( "a", "e" ) ) ) {
3344                 return false;
3345             }
3346             if ( !s_0_i.contains( new BasicBinaryDomainCombination( "b", "d" ) ) ) {
3347                 return false;
3348             }
3349             if ( !s_0_i.contains( new BasicBinaryDomainCombination( "b", "e" ) ) ) {
3350                 return false;
3351             }
3352             if ( !s_0_i.contains( new BasicBinaryDomainCombination( "c", "d" ) ) ) {
3353                 return false;
3354             }
3355             if ( !s_0_i.contains( new BasicBinaryDomainCombination( "c", "e" ) ) ) {
3356                 return false;
3357             }
3358             if ( !s_0_i.contains( new BasicBinaryDomainCombination( "d", "e" ) ) ) {
3359                 return false;
3360             }
3361             if ( !s_0_i.contains( new BasicBinaryDomainCombination( "e", "f" ) ) ) {
3362                 return false;
3363             }
3364             if ( !s_0_i.contains( new BasicBinaryDomainCombination( "g", "h" ) ) ) {
3365                 return false;
3366             }
3367             if ( s_0_i.contains( new BasicBinaryDomainCombination( "e", "e" ) ) ) {
3368                 return false;
3369             }
3370             if ( !s_1_ni.contains( new BasicBinaryDomainCombination( "a", "i" ) ) ) {
3371                 return false;
3372             }
3373             if ( !s_1_ni.contains( new BasicBinaryDomainCombination( "a", "l" ) ) ) {
3374                 return false;
3375             }
3376             if ( !s_1_ni.contains( new BasicBinaryDomainCombination( "b", "i" ) ) ) {
3377                 return false;
3378             }
3379             if ( !s_1_ni.contains( new BasicBinaryDomainCombination( "b", "l" ) ) ) {
3380                 return false;
3381             }
3382             if ( !s_1_ni.contains( new BasicBinaryDomainCombination( "c", "i" ) ) ) {
3383                 return false;
3384             }
3385             if ( !s_1_ni.contains( new BasicBinaryDomainCombination( "c", "l" ) ) ) {
3386                 return false;
3387             }
3388             if ( !s_1_ni.contains( new BasicBinaryDomainCombination( "l", "i" ) ) ) {
3389                 return false;
3390             }
3391             if ( !s_1_ni.contains( new BasicBinaryDomainCombination( "i", "f" ) ) ) {
3392                 return false;
3393             }
3394             if ( !s_1_ni.contains( new BasicBinaryDomainCombination( "m", "n" ) ) ) {
3395                 return false;
3396             }
3397             if ( !s_1_ni.contains( new BasicBinaryDomainCombination( "j", "k" ) ) ) {
3398                 return false;
3399             }
3400             if ( s_1_ni.contains( new BasicBinaryDomainCombination( "a", "b" ) ) ) {
3401                 return false;
3402             }
3403             if ( !s_1_i.contains( new BasicBinaryDomainCombination( "a", "i" ) ) ) {
3404                 return false;
3405             }
3406             if ( !s_1_i.contains( new BasicBinaryDomainCombination( "a", "l" ) ) ) {
3407                 return false;
3408             }
3409             if ( !s_1_i.contains( new BasicBinaryDomainCombination( "b", "i" ) ) ) {
3410                 return false;
3411             }
3412             if ( !s_1_i.contains( new BasicBinaryDomainCombination( "b", "l" ) ) ) {
3413                 return false;
3414             }
3415             if ( !s_1_i.contains( new BasicBinaryDomainCombination( "c", "i" ) ) ) {
3416                 return false;
3417             }
3418             if ( !s_1_i.contains( new BasicBinaryDomainCombination( "c", "l" ) ) ) {
3419                 return false;
3420             }
3421             if ( !s_1_i.contains( new BasicBinaryDomainCombination( "l", "i" ) ) ) {
3422                 return false;
3423             }
3424             if ( !s_1_i.contains( new BasicBinaryDomainCombination( "i", "f" ) ) ) {
3425                 return false;
3426             }
3427             if ( !s_1_i.contains( new BasicBinaryDomainCombination( "m", "n" ) ) ) {
3428                 return false;
3429             }
3430             if ( !s_1_i.contains( new BasicBinaryDomainCombination( "j", "k" ) ) ) {
3431                 return false;
3432             }
3433             if ( s_1_i.contains( new BasicBinaryDomainCombination( "a", "b" ) ) ) {
3434                 return false;
3435             }
3436             if ( !isEqual( calc_ni.calculateSharedBinaryDomainCombinationBasedGenomeSimilarityScore(),
3437                            1.0 - ( 25.0 - 5.0 ) / 25.0 ) ) {
3438                 return false;
3439             }
3440             if ( !isEqual( calc_i.calculateSharedBinaryDomainCombinationBasedGenomeSimilarityScore(),
3441                            1.0 - ( 22.0 - 3.0 ) / 22.0 ) ) {
3442                 return false;
3443             }
3444             if ( !isEqual( calc_ni.calculateSharedDomainsBasedGenomeSimilarityScore(), 1.0 - ( 14.0 - 4.0 ) / 14.0 ) ) {
3445                 return false;
3446             }
3447             if ( !isEqual( calc_i.calculateSharedDomainsBasedGenomeSimilarityScore(), 1.0 - ( 14.0 - 4.0 ) / 14.0 ) ) {
3448                 return false;
3449             }
3450             final Domain u = new BasicDomain( "u", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
3451             final Domain v = new BasicDomain( "v", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
3452             final Domain w = new BasicDomain( "w", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
3453             final Domain x = new BasicDomain( "x", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
3454             final Domain y = new BasicDomain( "y", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
3455             final Domain z = new BasicDomain( "z", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
3456             final Protein a_0 = new BasicProtein( "0", "a", 0 );
3457             final Protein a_1 = new BasicProtein( "1", "a", 0 );
3458             final Protein a_2 = new BasicProtein( "2", "a", 0 );
3459             final Protein b_0 = new BasicProtein( "0", "b", 0 );
3460             final Protein b_1 = new BasicProtein( "1", "b", 0 );
3461             a_0.addProteinDomain( u );
3462             a_0.addProteinDomain( v );
3463             a_0.addProteinDomain( w );
3464             a_1.addProteinDomain( w );
3465             a_1.addProteinDomain( x );
3466             a_2.addProteinDomain( y );
3467             a_2.addProteinDomain( z );
3468             b_0.addProteinDomain( u );
3469             b_0.addProteinDomain( w );
3470             b_1.addProteinDomain( y );
3471             b_1.addProteinDomain( z );
3472             final List<Protein> protein_list_a = new ArrayList<Protein>();
3473             protein_list_a.add( a_0 );
3474             protein_list_a.add( a_1 );
3475             protein_list_a.add( a_2 );
3476             final List<Protein> protein_list_b = new ArrayList<Protein>();
3477             protein_list_b.add( b_0 );
3478             protein_list_b.add( b_1 );
3479             final GenomeWideCombinableDomains ca = BasicGenomeWideCombinableDomains
3480                     .createInstance( protein_list_a, false, new BasicSpecies( "a" ) );
3481             final GenomeWideCombinableDomains cb = BasicGenomeWideCombinableDomains
3482                     .createInstance( protein_list_b, true, new BasicSpecies( "b" ) );
3483             final DomainArchitectureBasedGenomeSimilarityCalculator calc_u = new DomainArchitectureBasedGenomeSimilarityCalculator( ca,
3484                                                                                                                                     cb );
3485             calc_u.setAllowDomainsToBeIgnored( true );
3486             if ( calc_u.getAllDomains().size() != 6 ) {
3487                 return false;
3488             }
3489             if ( calc_u.getDomainsSpecificToGenome0().size() != 2 ) {
3490                 return false;
3491             }
3492             if ( calc_u.getDomainsSpecificToGenome1().size() != 0 ) {
3493                 return false;
3494             }
3495             if ( !calc_u.getDomainsSpecificToGenome0().contains( v.getDomainId() ) ) {
3496                 return false;
3497             }
3498             if ( !calc_u.getDomainsSpecificToGenome0().contains( x.getDomainId() ) ) {
3499                 return false;
3500             }
3501             if ( calc_u.getSharedDomains().size() != 4 ) {
3502                 return false;
3503             }
3504             if ( !calc_u.getSharedDomains().contains( u.getDomainId() ) ) {
3505                 return false;
3506             }
3507             if ( !calc_u.getSharedDomains().contains( w.getDomainId() ) ) {
3508                 return false;
3509             }
3510             if ( !calc_u.getSharedDomains().contains( y.getDomainId() ) ) {
3511                 return false;
3512             }
3513             if ( !calc_u.getSharedDomains().contains( z.getDomainId() ) ) {
3514                 return false;
3515             }
3516             if ( calc_u.getAllDomains().size() != 6 ) {
3517                 return false;
3518             }
3519             if ( !calc_u.getAllDomains().contains( u.getDomainId() ) ) {
3520                 return false;
3521             }
3522             if ( !calc_u.getAllDomains().contains( w.getDomainId() ) ) {
3523                 return false;
3524             }
3525             if ( !calc_u.getAllDomains().contains( y.getDomainId() ) ) {
3526                 return false;
3527             }
3528             if ( !calc_u.getAllDomains().contains( z.getDomainId() ) ) {
3529                 return false;
3530             }
3531             if ( !calc_u.getAllDomains().contains( v.getDomainId() ) ) {
3532                 return false;
3533             }
3534             if ( !calc_u.getAllDomains().contains( x.getDomainId() ) ) {
3535                 return false;
3536             }
3537             if ( calc_u.getBinaryDomainCombinationsSpecificToGenome0().size() != 3 ) {
3538                 return false;
3539             }
3540             if ( calc_u.getBinaryDomainCombinationsSpecificToGenome1().size() != 0 ) {
3541                 return false;
3542             }
3543             if ( calc_u.getSharedBinaryDomainCombinations().size() != 2 ) {
3544                 return false;
3545             }
3546             if ( calc_u.getAllBinaryDomainCombinations().size() != 5 ) {
3547                 return false;
3548             }
3549             if ( !calc_u.getBinaryDomainCombinationsSpecificToGenome0()
3550                     .contains( new BasicBinaryDomainCombination( "v", "u" ) ) ) {
3551                 return false;
3552             }
3553             if ( !calc_u.getBinaryDomainCombinationsSpecificToGenome0()
3554                     .contains( new BasicBinaryDomainCombination( "w", "v" ) ) ) {
3555                 return false;
3556             }
3557             if ( !calc_u.getBinaryDomainCombinationsSpecificToGenome0()
3558                     .contains( new BasicBinaryDomainCombination( "w", "x" ) ) ) {
3559                 return false;
3560             }
3561             if ( !calc_u.getSharedBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "w", "u" ) ) ) {
3562                 return false;
3563             }
3564             if ( !calc_u.getSharedBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "z", "y" ) ) ) {
3565                 return false;
3566             }
3567             if ( !calc_u.getAllBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "v", "u" ) ) ) {
3568                 return false;
3569             }
3570             if ( !calc_u.getAllBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "w", "v" ) ) ) {
3571                 return false;
3572             }
3573             if ( !calc_u.getAllBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "w", "x" ) ) ) {
3574                 return false;
3575             }
3576             if ( !calc_u.getAllBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "w", "u" ) ) ) {
3577                 return false;
3578             }
3579             if ( !calc_u.getAllBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "z", "y" ) ) ) {
3580                 return false;
3581             }
3582             calc_u.setAllowDomainsToBeIgnored( true );
3583             calc_u.addDomainIdToIgnore( u.getDomainId() );
3584             calc_u.addDomainIdToIgnore( new DomainId( "other" ) );
3585             calc_u.addDomainIdToIgnore( new DomainId( "other_too" ) );
3586             if ( calc_u.getAllDomains().size() != 5 ) {
3587                 return false;
3588             }
3589             if ( calc_u.getDomainsSpecificToGenome0().size() != 2 ) {
3590                 return false;
3591             }
3592             if ( calc_u.getDomainsSpecificToGenome1().size() != 0 ) {
3593                 return false;
3594             }
3595             if ( !calc_u.getDomainsSpecificToGenome0().contains( v.getDomainId() ) ) {
3596                 return false;
3597             }
3598             if ( !calc_u.getDomainsSpecificToGenome0().contains( x.getDomainId() ) ) {
3599                 return false;
3600             }
3601             if ( calc_u.getSharedDomains().size() != 3 ) {
3602                 return false;
3603             }
3604             if ( calc_u.getSharedDomains().contains( u.getDomainId() ) ) {
3605                 return false;
3606             }
3607             if ( !calc_u.getSharedDomains().contains( w.getDomainId() ) ) {
3608                 return false;
3609             }
3610             if ( !calc_u.getSharedDomains().contains( y.getDomainId() ) ) {
3611                 return false;
3612             }
3613             if ( !calc_u.getSharedDomains().contains( z.getDomainId() ) ) {
3614                 return false;
3615             }
3616             if ( calc_u.getAllDomains().size() != 5 ) {
3617                 return false;
3618             }
3619             if ( calc_u.getAllDomains().contains( u.getDomainId() ) ) {
3620                 return false;
3621             }
3622             if ( !calc_u.getAllDomains().contains( w.getDomainId() ) ) {
3623                 return false;
3624             }
3625             if ( !calc_u.getAllDomains().contains( y.getDomainId() ) ) {
3626                 return false;
3627             }
3628             if ( !calc_u.getAllDomains().contains( z.getDomainId() ) ) {
3629                 return false;
3630             }
3631             if ( !calc_u.getAllDomains().contains( v.getDomainId() ) ) {
3632                 return false;
3633             }
3634             if ( !calc_u.getAllDomains().contains( x.getDomainId() ) ) {
3635                 return false;
3636             }
3637             if ( calc_u.getBinaryDomainCombinationsSpecificToGenome0().size() != 2 ) {
3638                 return false;
3639             }
3640             if ( calc_u.getBinaryDomainCombinationsSpecificToGenome1().size() != 0 ) {
3641                 return false;
3642             }
3643             if ( calc_u.getSharedBinaryDomainCombinations().size() != 1 ) {
3644                 return false;
3645             }
3646             if ( calc_u.getAllBinaryDomainCombinations().size() != 3 ) {
3647                 return false;
3648             }
3649             if ( calc_u.getBinaryDomainCombinationsSpecificToGenome0()
3650                     .contains( new BasicBinaryDomainCombination( "v", "u" ) ) ) {
3651                 return false;
3652             }
3653             if ( !calc_u.getBinaryDomainCombinationsSpecificToGenome0()
3654                     .contains( new BasicBinaryDomainCombination( "w", "v" ) ) ) {
3655                 return false;
3656             }
3657             if ( !calc_u.getBinaryDomainCombinationsSpecificToGenome0()
3658                     .contains( new BasicBinaryDomainCombination( "w", "x" ) ) ) {
3659                 return false;
3660             }
3661             if ( calc_u.getSharedBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "w", "u" ) ) ) {
3662                 return false;
3663             }
3664             if ( !calc_u.getSharedBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "z", "y" ) ) ) {
3665                 return false;
3666             }
3667             if ( calc_u.getAllBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "v", "u" ) ) ) {
3668                 return false;
3669             }
3670             if ( !calc_u.getAllBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "w", "v" ) ) ) {
3671                 return false;
3672             }
3673             if ( !calc_u.getAllBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "w", "x" ) ) ) {
3674                 return false;
3675             }
3676             if ( calc_u.getAllBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "w", "u" ) ) ) {
3677                 return false;
3678             }
3679             if ( !calc_u.getAllBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "z", "y" ) ) ) {
3680                 return false;
3681             }
3682             calc_u.setAllowDomainsToBeIgnored( false );
3683             if ( calc_u.getAllDomains().size() != 6 ) {
3684                 return false;
3685             }
3686             //------------
3687             calc_u.setAllowDomainsToBeIgnored( true );
3688             calc_u.deleteAllDomainIdsToIgnore();
3689             calc_u.addDomainIdToIgnore( new DomainId( "v" ) );
3690             calc_u.addDomainIdToIgnore( new DomainId( "w" ) );
3691             calc_u.addDomainIdToIgnore( new DomainId( "other" ) );
3692             calc_u.addDomainIdToIgnore( new DomainId( "other_too" ) );
3693             if ( calc_u.getAllDomains().size() != 4 ) {
3694                 return false;
3695             }
3696             if ( calc_u.getDomainsSpecificToGenome0().size() != 1 ) {
3697                 return false;
3698             }
3699             if ( calc_u.getDomainsSpecificToGenome1().size() != 0 ) {
3700                 return false;
3701             }
3702             if ( calc_u.getDomainsSpecificToGenome0().contains( v.getDomainId() ) ) {
3703                 return false;
3704             }
3705             if ( !calc_u.getDomainsSpecificToGenome0().contains( x.getDomainId() ) ) {
3706                 return false;
3707             }
3708             if ( calc_u.getSharedDomains().size() != 3 ) {
3709                 return false;
3710             }
3711             if ( !calc_u.getSharedDomains().contains( u.getDomainId() ) ) {
3712                 return false;
3713             }
3714             if ( calc_u.getSharedDomains().contains( w.getDomainId() ) ) {
3715                 return false;
3716             }
3717             if ( !calc_u.getSharedDomains().contains( y.getDomainId() ) ) {
3718                 return false;
3719             }
3720             if ( !calc_u.getSharedDomains().contains( z.getDomainId() ) ) {
3721                 return false;
3722             }
3723             if ( calc_u.getAllDomains().size() != 4 ) {
3724                 return false;
3725             }
3726             if ( !calc_u.getAllDomains().contains( u.getDomainId() ) ) {
3727                 return false;
3728             }
3729             if ( calc_u.getAllDomains().contains( w.getDomainId() ) ) {
3730                 return false;
3731             }
3732             if ( !calc_u.getAllDomains().contains( y.getDomainId() ) ) {
3733                 return false;
3734             }
3735             if ( !calc_u.getAllDomains().contains( z.getDomainId() ) ) {
3736                 return false;
3737             }
3738             if ( calc_u.getAllDomains().contains( v.getDomainId() ) ) {
3739                 return false;
3740             }
3741             if ( !calc_u.getAllDomains().contains( x.getDomainId() ) ) {
3742                 return false;
3743             }
3744             if ( calc_u.getBinaryDomainCombinationsSpecificToGenome0().size() != 0 ) {
3745                 return false;
3746             }
3747             if ( calc_u.getBinaryDomainCombinationsSpecificToGenome1().size() != 0 ) {
3748                 return false;
3749             }
3750             if ( calc_u.getSharedBinaryDomainCombinations().size() != 1 ) {
3751                 return false;
3752             }
3753             if ( calc_u.getAllBinaryDomainCombinations().size() != 1 ) {
3754                 return false;
3755             }
3756             if ( !calc_u.getSharedBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "y", "z" ) ) ) {
3757                 return false;
3758             }
3759             if ( !calc_u.getAllBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "z", "y" ) ) ) {
3760                 return false;
3761             }
3762             if ( !isEqual( calc_u.calculateSharedBinaryDomainCombinationBasedGenomeSimilarityScore(),
3763                            1.0 - ( 1.0 - 1.0 ) / 1.0 ) ) {
3764                 return false;
3765             }
3766             if ( !isEqual( calc_u.calculateSharedDomainsBasedGenomeSimilarityScore(), 1.0 - ( 4.0 - 3.0 ) / 4.0 ) ) {
3767                 return false;
3768             }
3769             calc_u.setAllowDomainsToBeIgnored( false );
3770             if ( !isEqual( calc_u.calculateSharedBinaryDomainCombinationBasedGenomeSimilarityScore(),
3771                            1.0 - ( 5.0 - 2.0 ) / 5.0 ) ) {
3772                 return false;
3773             }
3774             if ( !isEqual( calc_u.calculateSharedDomainsBasedGenomeSimilarityScore(), 1.0 - ( 6.0 - 4.0 ) / 6.0 ) ) {
3775                 return false;
3776             }
3777             calc_u.setAllowDomainsToBeIgnored( true );
3778             if ( !isEqual( calc_u.calculateSharedBinaryDomainCombinationBasedGenomeSimilarityScore(),
3779                            1.0 - ( 1.0 - 1.0 ) / 1.0 ) ) {
3780                 return false;
3781             }
3782             if ( !isEqual( calc_u.calculateSharedDomainsBasedGenomeSimilarityScore(), 1.0 - ( 4.0 - 3.0 ) / 4.0 ) ) {
3783                 return false;
3784             }
3785             calc_u.deleteAllDomainIdsToIgnore();
3786             if ( !isEqual( calc_u.calculateSharedBinaryDomainCombinationBasedGenomeSimilarityScore(),
3787                            1.0 - ( 5.0 - 2.0 ) / 5.0 ) ) {
3788                 return false;
3789             }
3790             if ( !isEqual( calc_u.calculateSharedDomainsBasedGenomeSimilarityScore(), 1.0 - ( 6.0 - 4.0 ) / 6.0 ) ) {
3791                 return false;
3792             }
3793         }
3794         catch ( final Exception e ) {
3795             e.printStackTrace( System.out );
3796             return false;
3797         }
3798         return true;
3799     }
3800
3801     private static boolean testDomainCombinationCounting( final File test_dir ) {
3802         try {
3803             final HmmPfamOutputParser parser = new HmmPfamOutputParser( new File( test_dir
3804                     + ForesterUtil.getFileSeparator() + "hmmpfam_output2" ), "human", "ls" );
3805             parser.setEValueMaximum( 0.2 );
3806             parser.setIgnoreDufs( true );
3807             parser.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
3808             final List<Protein> domain_collections = parser.parse();
3809             final BasicGenomeWideCombinableDomains cdcc = BasicGenomeWideCombinableDomains
3810                     .createInstance( domain_collections, false, new BasicSpecies( "human" ) );
3811             CombinableDomains cd = cdcc.get( new DomainId( "A" ) );
3812             if ( cd.getKeyDomainCount() != 9 ) {
3813                 return false;
3814             }
3815             if ( cd.getKeyDomainProteinsCount() != 7 ) {
3816                 return false;
3817             }
3818             if ( cd.getNumberOfCombinableDomains() != 11 ) {
3819                 return false;
3820             }
3821             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "A" ).getDomainId() ) != 2 ) {
3822                 return false;
3823             }
3824             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "B" ).getDomainId() ) != 6 ) {
3825                 return false;
3826             }
3827             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "C" ).getDomainId() ) != 4 ) {
3828                 return false;
3829             }
3830             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "D" ).getDomainId() ) != 3 ) {
3831                 return false;
3832             }
3833             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "E" ).getDomainId() ) != 1 ) {
3834                 return false;
3835             }
3836             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "U" ).getDomainId() ) != 1 ) {
3837                 return false;
3838             }
3839             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "V" ).getDomainId() ) != 1 ) {
3840                 return false;
3841             }
3842             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "W" ).getDomainId() ) != 1 ) {
3843                 return false;
3844             }
3845             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "X" ).getDomainId() ) != 1 ) {
3846                 return false;
3847             }
3848             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "Y" ).getDomainId() ) != 1 ) {
3849                 return false;
3850             }
3851             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "Z" ).getDomainId() ) != 1 ) {
3852                 return false;
3853             }
3854             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "NN" ).getDomainId() ) != 0 ) {
3855                 return false;
3856             }
3857             if ( cd.getKeyDomainCount() != 9 ) {
3858                 return false;
3859             }
3860             cd = cdcc.get( new DomainId( "B" ) );
3861             if ( cd.getKeyDomainCount() != 12 ) {
3862                 return false;
3863             }
3864             if ( cd.getKeyDomainProteinsCount() != 7 ) {
3865                 return false;
3866             }
3867             if ( cd.getNumberOfCombinableDomains() != 11 ) {
3868                 return false;
3869             }
3870             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "A" ).getDomainId() ) != 6 ) {
3871                 return false;
3872             }
3873             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "B" ).getDomainId() ) != 4 ) {
3874                 return false;
3875             }
3876             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "C" ).getDomainId() ) != 4 ) {
3877                 return false;
3878             }
3879             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "D" ).getDomainId() ) != 3 ) {
3880                 return false;
3881             }
3882             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "E" ).getDomainId() ) != 1 ) {
3883                 return false;
3884             }
3885             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "U" ).getDomainId() ) != 1 ) {
3886                 return false;
3887             }
3888             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "V" ).getDomainId() ) != 1 ) {
3889                 return false;
3890             }
3891             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "W" ).getDomainId() ) != 1 ) {
3892                 return false;
3893             }
3894             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "X" ).getDomainId() ) != 1 ) {
3895                 return false;
3896             }
3897             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "Y" ).getDomainId() ) != 1 ) {
3898                 return false;
3899             }
3900             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "Z" ).getDomainId() ) != 1 ) {
3901                 return false;
3902             }
3903             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "NN" ).getDomainId() ) != 0 ) {
3904                 return false;
3905             }
3906             if ( cd.getKeyDomainCount() != 12 ) {
3907                 return false;
3908             }
3909             cd = cdcc.get( new DomainId( "C" ) );
3910             if ( cd.getKeyDomainCount() != 10 ) {
3911                 return false;
3912             }
3913             if ( cd.getKeyDomainProteinsCount() != 7 ) {
3914                 return false;
3915             }
3916             if ( cd.getNumberOfCombinableDomains() != 11 ) {
3917                 return false;
3918             }
3919             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "A" ).getDomainId() ) != 4 ) {
3920                 return false;
3921             }
3922             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "B" ).getDomainId() ) != 4 ) {
3923                 return false;
3924             }
3925             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "C" ).getDomainId() ) != 2 ) {
3926                 return false;
3927             }
3928             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "D" ).getDomainId() ) != 3 ) {
3929                 return false;
3930             }
3931             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "E" ).getDomainId() ) != 1 ) {
3932                 return false;
3933             }
3934             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "U" ).getDomainId() ) != 1 ) {
3935                 return false;
3936             }
3937             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "V" ).getDomainId() ) != 1 ) {
3938                 return false;
3939             }
3940             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "W" ).getDomainId() ) != 1 ) {
3941                 return false;
3942             }
3943             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "X" ).getDomainId() ) != 2 ) {
3944                 return false;
3945             }
3946             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "Y" ).getDomainId() ) != 2 ) {
3947                 return false;
3948             }
3949             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "Z" ).getDomainId() ) != 2 ) {
3950                 return false;
3951             }
3952             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "NN" ).getDomainId() ) != 0 ) {
3953                 return false;
3954             }
3955             cd = cdcc.get( new DomainId( "D" ) );
3956             if ( cd.getKeyDomainCount() != 15 ) {
3957                 return false;
3958             }
3959             if ( cd.getKeyDomainProteinsCount() != 6 ) {
3960                 return false;
3961             }
3962             if ( cd.getNumberOfCombinableDomains() != 11 ) {
3963                 return false;
3964             }
3965             cd = cdcc.get( new DomainId( "E" ) );
3966             if ( cd.getNumberOfCombinableDomains() != 10 ) {
3967                 return false;
3968             }
3969             if ( cd.getKeyDomainCount() != 1 ) {
3970                 return false;
3971             }
3972             if ( cd.getKeyDomainProteinsCount() != 1 ) {
3973                 return false;
3974             }
3975             cd = cdcc.get( new DomainId( "U" ) );
3976             if ( cd.getNumberOfCombinableDomains() != 11 ) {
3977                 return false;
3978             }
3979             if ( cd.getKeyDomainCount() != 6 ) {
3980                 return false;
3981             }
3982             if ( cd.getKeyDomainProteinsCount() != 3 ) {
3983                 return false;
3984             }
3985             cd = cdcc.get( new DomainId( "V" ) );
3986             if ( cd.getNumberOfCombinableDomains() != 11 ) {
3987                 return false;
3988             }
3989             if ( cd.getKeyDomainCount() != 3 ) {
3990                 return false;
3991             }
3992             if ( cd.getKeyDomainProteinsCount() != 2 ) {
3993                 return false;
3994             }
3995             cd = cdcc.get( new DomainId( "W" ) );
3996             if ( cd.getNumberOfCombinableDomains() != 10 ) {
3997                 return false;
3998             }
3999             if ( cd.getKeyDomainCount() != 2 ) {
4000                 return false;
4001             }
4002             if ( cd.getKeyDomainProteinsCount() != 2 ) {
4003                 return false;
4004             }
4005             cd = cdcc.get( new DomainId( "X" ) );
4006             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4007                 return false;
4008             }
4009             if ( cd.getKeyDomainCount() != 2 ) {
4010                 return false;
4011             }
4012             cd = cdcc.get( new DomainId( "Y" ) );
4013             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4014                 return false;
4015             }
4016             cd = cdcc.get( new DomainId( "Z" ) );
4017             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4018                 return false;
4019             }
4020             cd = cdcc.get( new DomainId( "NN" ) );
4021             if ( cd.getKeyDomainCount() != 1 ) {
4022                 return false;
4023             }
4024             if ( cd.getKeyDomainProteinsCount() != 1 ) {
4025                 return false;
4026             }
4027             if ( cd.getNumberOfCombinableDomains() != 0 ) {
4028                 return false;
4029             }
4030             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "NN" ).getDomainId() ) != 0 ) {
4031                 return false;
4032             }
4033             cd = cdcc.get( new DomainId( "MM" ) );
4034             if ( cd.getNumberOfCombinableDomains() != 1 ) {
4035                 return false;
4036             }
4037             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "MM" ).getDomainId() ) != 0 ) {
4038                 return false;
4039             }
4040             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "OO" ).getDomainId() ) != 1 ) {
4041                 return false;
4042             }
4043             cd = cdcc.get( new DomainId( "OO" ) );
4044             if ( cd.getNumberOfCombinableDomains() != 2 ) {
4045                 return false;
4046             }
4047             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "OO" ).getDomainId() ) != 1 ) {
4048                 return false;
4049             }
4050             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "MM" ).getDomainId() ) != 1 ) {
4051                 return false;
4052             }
4053             cd = cdcc.get( new DomainId( "QQ" ) );
4054             if ( cd.getNumberOfCombinableDomains() != 1 ) {
4055                 return false;
4056             }
4057             if ( cd.getKeyDomainCount() != 17 ) {
4058                 return false;
4059             }
4060             if ( cd.getKeyDomainProteinsCount() != 4 ) {
4061                 return false;
4062             }
4063             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "QQ" ).getDomainId() ) != 3 ) {
4064                 return false;
4065             }
4066             cd = cdcc.get( new DomainId( "PP" ) );
4067             if ( cd.getNumberOfCombinableDomains() != 0 ) {
4068                 return false;
4069             }
4070             if ( cd.getKeyDomainCount() != 2 ) {
4071                 return false;
4072             }
4073             if ( cd.getKeyDomainProteinsCount() != 2 ) {
4074                 return false;
4075             }
4076             cd = cdcc.get( new DomainId( "singlet" ) );
4077             if ( cd.getKeyDomainCount() != 1 ) {
4078                 return false;
4079             }
4080             if ( cd.getKeyDomainProteinsCount() != 1 ) {
4081                 return false;
4082             }
4083             if ( cd.getNumberOfCombinableDomains() != 0 ) {
4084                 return false;
4085             }
4086             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "singlet" ).getDomainId() ) != 0 ) {
4087                 return false;
4088             }
4089             cd = cdcc.get( new DomainId( "three" ) );
4090             if ( cd.getKeyDomainCount() != 3 ) {
4091                 return false;
4092             }
4093             if ( cd.getKeyDomainProteinsCount() != 1 ) {
4094                 return false;
4095             }
4096             if ( cd.getNumberOfCombinableDomains() != 1 ) {
4097                 return false;
4098             }
4099             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "three" ) ) != 1 ) {
4100                 return false;
4101             }
4102             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "so_far_so_bad" ) ) != 0 ) {
4103                 return false;
4104             }
4105             // Ignore combinations with same:
4106             final BasicGenomeWideCombinableDomains cdcc2 = BasicGenomeWideCombinableDomains
4107                     .createInstance( domain_collections,
4108                                      true,
4109                                      new BasicSpecies( "human" ),
4110                                      null,
4111                                      DomainCombinationType.BASIC );
4112             cd = cdcc2.get( new DomainId( "A" ) );
4113             if ( cd.getKeyDomainCount() != 9 ) {
4114                 return false;
4115             }
4116             if ( cd.getKeyDomainProteinsCount() != 7 ) {
4117                 return false;
4118             }
4119             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4120                 return false;
4121             }
4122             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "A" ).getDomainId() ) != 0 ) {
4123                 return false;
4124             }
4125             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "B" ).getDomainId() ) != 6 ) {
4126                 return false;
4127             }
4128             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "C" ).getDomainId() ) != 4 ) {
4129                 return false;
4130             }
4131             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "D" ).getDomainId() ) != 3 ) {
4132                 return false;
4133             }
4134             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "E" ).getDomainId() ) != 1 ) {
4135                 return false;
4136             }
4137             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "U" ) ) != 1 ) {
4138                 return false;
4139             }
4140             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "V" ) ) != 1 ) {
4141                 return false;
4142             }
4143             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "W" ) ) != 1 ) {
4144                 return false;
4145             }
4146             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "X" ) ) != 1 ) {
4147                 return false;
4148             }
4149             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "Y" ) ) != 1 ) {
4150                 return false;
4151             }
4152             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "Z" ) ) != 1 ) {
4153                 return false;
4154             }
4155             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "NN" ) ) != 0 ) {
4156                 return false;
4157             }
4158             cd = cdcc2.get( new DomainId( "B" ) );
4159             if ( cd.getKeyDomainCount() != 12 ) {
4160                 return false;
4161             }
4162             if ( cd.getKeyDomainProteinsCount() != 7 ) {
4163                 return false;
4164             }
4165             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4166                 return false;
4167             }
4168             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "A" ) ) != 6 ) {
4169                 return false;
4170             }
4171             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "B" ) ) != 0 ) {
4172                 return false;
4173             }
4174             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "C" ) ) != 4 ) {
4175                 return false;
4176             }
4177             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "D" ) ) != 3 ) {
4178                 return false;
4179             }
4180             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "E" ) ) != 1 ) {
4181                 return false;
4182             }
4183             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "U" ) ) != 1 ) {
4184                 return false;
4185             }
4186             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "V" ) ) != 1 ) {
4187                 return false;
4188             }
4189             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "W" ) ) != 1 ) {
4190                 return false;
4191             }
4192             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "X" ) ) != 1 ) {
4193                 return false;
4194             }
4195             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "Y" ) ) != 1 ) {
4196                 return false;
4197             }
4198             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "Z" ) ) != 1 ) {
4199                 return false;
4200             }
4201             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "NN" ) ) != 0 ) {
4202                 return false;
4203             }
4204             cd = cdcc2.get( new DomainId( "C" ) );
4205             if ( cd.getKeyDomainCount() != 10 ) {
4206                 return false;
4207             }
4208             if ( cd.getKeyDomainProteinsCount() != 7 ) {
4209                 return false;
4210             }
4211             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4212                 return false;
4213             }
4214             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "A" ) ) != 4 ) {
4215                 return false;
4216             }
4217             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "B" ) ) != 4 ) {
4218                 return false;
4219             }
4220             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "C" ) ) != 0 ) {
4221                 return false;
4222             }
4223             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "D" ) ) != 3 ) {
4224                 return false;
4225             }
4226             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "E" ) ) != 1 ) {
4227                 return false;
4228             }
4229             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "U" ) ) != 1 ) {
4230                 return false;
4231             }
4232             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "V" ) ) != 1 ) {
4233                 return false;
4234             }
4235             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "W" ) ) != 1 ) {
4236                 return false;
4237             }
4238             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "X" ) ) != 2 ) {
4239                 return false;
4240             }
4241             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "Y" ) ) != 2 ) {
4242                 return false;
4243             }
4244             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "Z" ) ) != 2 ) {
4245                 return false;
4246             }
4247             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "NN" ) ) != 0 ) {
4248                 return false;
4249             }
4250             cd = cdcc2.get( new DomainId( "D" ) );
4251             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4252                 return false;
4253             }
4254             cd = cdcc2.get( new DomainId( "E" ) );
4255             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4256                 return false;
4257             }
4258             if ( cd.getKeyDomainCount() != 1 ) {
4259                 return false;
4260             }
4261             cd = cdcc2.get( new DomainId( "U" ) );
4262             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4263                 return false;
4264             }
4265             cd = cdcc2.get( new DomainId( "V" ) );
4266             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4267                 return false;
4268             }
4269             cd = cdcc2.get( new DomainId( "W" ) );
4270             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4271                 return false;
4272             }
4273             cd = cdcc2.get( new DomainId( "X" ) );
4274             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4275                 return false;
4276             }
4277             cd = cdcc2.get( new DomainId( "Y" ) );
4278             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4279                 return false;
4280             }
4281             cd = cdcc2.get( new DomainId( "Z" ) );
4282             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4283                 return false;
4284             }
4285             cd = cdcc2.get( new DomainId( "NN" ) );
4286             if ( cd.getNumberOfCombinableDomains() != 0 ) {
4287                 return false;
4288             }
4289             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "NN" ) ) != 0 ) {
4290                 return false;
4291             }
4292             cd = cdcc2.get( new DomainId( "MM" ) );
4293             if ( cd.getNumberOfCombinableDomains() != 1 ) {
4294                 return false;
4295             }
4296             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "MM" ) ) != 0 ) {
4297                 return false;
4298             }
4299             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "OO" ) ) != 1 ) {
4300                 return false;
4301             }
4302             cd = cdcc2.get( new DomainId( "OO" ) );
4303             if ( cd.getNumberOfCombinableDomains() != 1 ) {
4304                 return false;
4305             }
4306             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "OO" ) ) != 0 ) {
4307                 return false;
4308             }
4309             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "MM" ) ) != 1 ) {
4310                 return false;
4311             }
4312             cd = cdcc2.get( new DomainId( "QQ" ) );
4313             if ( cd.getNumberOfCombinableDomains() != 0 ) {
4314                 return false;
4315             }
4316             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "QQ" ) ) != 0 ) {
4317                 return false;
4318             }
4319             cd = cdcc2.get( new DomainId( "singlet" ) );
4320             if ( cd.getKeyDomainCount() != 1 ) {
4321                 return false;
4322             }
4323             if ( cd.getKeyDomainProteinsCount() != 1 ) {
4324                 return false;
4325             }
4326             if ( cd.getNumberOfCombinableDomains() != 0 ) {
4327                 return false;
4328             }
4329             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "singlet" ) ) != 0 ) {
4330                 return false;
4331             }
4332             cd = cdcc2.get( new DomainId( "three" ) );
4333             if ( cd.getKeyDomainCount() != 3 ) {
4334                 return false;
4335             }
4336             if ( cd.getKeyDomainProteinsCount() != 1 ) {
4337                 return false;
4338             }
4339             if ( cd.getNumberOfCombinableDomains() != 0 ) {
4340                 return false;
4341             }
4342             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "three" ) ) != 0 ) {
4343                 return false;
4344             }
4345             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "so_far_so_bad" ) ) != 0 ) {
4346                 return false;
4347             }
4348         }
4349         catch ( final Exception e ) {
4350             e.printStackTrace( System.out );
4351             return false;
4352         }
4353         return true;
4354     }
4355
4356     private static boolean testDomainId() {
4357         try {
4358             final DomainId id1 = new DomainId( "a" );
4359             final DomainId id2 = new DomainId( "a" );
4360             final DomainId id3 = new DomainId( "A" );
4361             final DomainId id4 = new DomainId( "b" );
4362             if ( !id1.equals( id1 ) ) {
4363                 return false;
4364             }
4365             if ( id1.getId().equals( "x" ) ) {
4366                 return false;
4367             }
4368             if ( id1.getId().equals( null ) ) {
4369                 return false;
4370             }
4371             if ( !id1.equals( id2 ) ) {
4372                 return false;
4373             }
4374             if ( id1.equals( id3 ) ) {
4375                 return false;
4376             }
4377             if ( id1.hashCode() != id1.hashCode() ) {
4378                 return false;
4379             }
4380             if ( id1.hashCode() != id2.hashCode() ) {
4381                 return false;
4382             }
4383             if ( id1.hashCode() == id3.hashCode() ) {
4384                 return false;
4385             }
4386             if ( id1.compareTo( id1 ) != 0 ) {
4387                 return false;
4388             }
4389             if ( id1.compareTo( id2 ) != 0 ) {
4390                 return false;
4391             }
4392             if ( id1.compareTo( id3 ) != 0 ) {
4393                 return false;
4394             }
4395             if ( id1.compareTo( id4 ) >= 0 ) {
4396                 return false;
4397             }
4398             if ( id4.compareTo( id1 ) <= 0 ) {
4399                 return false;
4400             }
4401             if ( !id4.getId().equals( "b" ) ) {
4402                 return false;
4403             }
4404             final DomainId id5 = new DomainId( " C " );
4405             if ( !id5.getId().equals( "C" ) ) {
4406                 return false;
4407             }
4408             if ( id5.equals( id1 ) ) {
4409                 return false;
4410             }
4411         }
4412         catch ( final Exception e ) {
4413             e.printStackTrace( System.out );
4414             return false;
4415         }
4416         return true;
4417     }
4418
4419     private static boolean testDomainSorting() {
4420         try {
4421             final Domain A = new BasicDomain( "A", ( short ) 1, ( short ) 2, ( short ) 1, ( short ) 1, 0.1, -12 );
4422             final Domain B = new BasicDomain( "B", ( short ) 1, ( short ) 2, ( short ) 1, ( short ) 1, 0.1, -12 );
4423             final Domain C = new BasicDomain( "C", ( short ) 1, ( short ) 2, ( short ) 1, ( short ) 1, 0.2, -12 );
4424             final Domain D = new BasicDomain( "D", ( short ) 1, ( short ) 2, ( short ) 1, ( short ) 1, 0.3, -12 );
4425             final Domain E = new BasicDomain( "E", ( short ) 1, ( short ) 2, ( short ) 1, ( short ) 1, 0.4, -12 );
4426             final Domain F = new BasicDomain( "F", ( short ) 1, ( short ) 2, ( short ) 1, ( short ) 1, 0.5, -12 );
4427             final Domain G = new BasicDomain( "G", ( short ) 1, ( short ) 2, ( short ) 1, ( short ) 1, 0.6, -12 );
4428             final Domain H1 = new BasicDomain( "H", ( short ) 100, ( short ) 200, ( short ) 1, ( short ) 5, 0.7, -12 );
4429             final Domain H2 = new BasicDomain( "H", ( short ) 300, ( short ) 400, ( short ) 2, ( short ) 5, 0.7, -12 );
4430             final Domain H3 = new BasicDomain( "H", ( short ) 500, ( short ) 600, ( short ) 3, ( short ) 5, 0.7, -12 );
4431             final Domain H4 = new BasicDomain( "H", ( short ) 700, ( short ) 800, ( short ) 4, ( short ) 5, 0.7, -12 );
4432             final Domain H5 = new BasicDomain( "H", ( short ) 700, ( short ) 800, ( short ) 5, ( short ) 5, 0.7, -12 );
4433             final Domain H6 = new BasicDomain( "H",
4434                                                ( short ) 1199,
4435                                                ( short ) 1299,
4436                                                ( short ) 6,
4437                                                ( short ) 6,
4438                                                0.7,
4439                                                -0.111 );
4440             final Domain H7 = new BasicDomain( "H7", ( short ) 700, ( short ) 800, ( short ) 5, ( short ) 5, 0.7, -12 );
4441             final Domain H8 = new BasicDomain( "H7", ( short ) 700, ( short ) 800, ( short ) 5, ( short ) 200, 0.7, -12 );
4442             final Protein protein = new BasicProtein( "00", "bat", 0 );
4443             protein.addProteinDomain( H5 );
4444             protein.addProteinDomain( H2 );
4445             protein.addProteinDomain( H7 );
4446             protein.addProteinDomain( H6 );
4447             protein.addProteinDomain( A );
4448             protein.addProteinDomain( G );
4449             protein.addProteinDomain( H4 );
4450             protein.addProteinDomain( D );
4451             protein.addProteinDomain( H1 );
4452             protein.addProteinDomain( C );
4453             protein.addProteinDomain( E );
4454             protein.addProteinDomain( F );
4455             protein.addProteinDomain( B );
4456             protein.addProteinDomain( H3 );
4457             protein.addProteinDomain( H7 );
4458             protein.addProteinDomain( H7 );
4459             protein.addProteinDomain( H8 );
4460             final List<Domain> sorted = SurfacingUtil.sortDomainsWithAscendingConfidenceValues( protein );
4461             if ( sorted.size() != 17 ) {
4462                 return false;
4463             }
4464             if ( !sorted.get( 0 ).getDomainId().getId().equals( "A" ) ) {
4465                 return false;
4466             }
4467             if ( sorted.get( 0 ).getNumber() != 1 ) {
4468                 return false;
4469             }
4470             if ( !sorted.get( 1 ).getDomainId().getId().equals( "B" ) ) {
4471                 return false;
4472             }
4473             if ( sorted.get( 1 ).getNumber() != 1 ) {
4474                 return false;
4475             }
4476             if ( !sorted.get( 2 ).getDomainId().getId().equals( "C" ) ) {
4477                 return false;
4478             }
4479             if ( sorted.get( 2 ).getNumber() != 1 ) {
4480                 return false;
4481             }
4482             if ( !sorted.get( 3 ).getDomainId().getId().equals( "D" ) ) {
4483                 return false;
4484             }
4485             if ( sorted.get( 3 ).getNumber() != 1 ) {
4486                 return false;
4487             }
4488             if ( !sorted.get( 4 ).getDomainId().getId().equals( "E" ) ) {
4489                 return false;
4490             }
4491             if ( sorted.get( 4 ).getNumber() != 1 ) {
4492                 return false;
4493             }
4494             if ( !sorted.get( 5 ).getDomainId().getId().equals( "F" ) ) {
4495                 return false;
4496             }
4497             if ( sorted.get( 5 ).getNumber() != 1 ) {
4498                 return false;
4499             }
4500             if ( !sorted.get( 6 ).getDomainId().getId().equals( "G" ) ) {
4501                 return false;
4502             }
4503             if ( sorted.get( 6 ).getNumber() != 1 ) {
4504                 return false;
4505             }
4506             if ( !sorted.get( 7 ).getDomainId().getId().equals( "H" ) ) {
4507                 return false;
4508             }
4509             if ( sorted.get( 7 ).getNumber() != 5 ) {
4510                 return false;
4511             }
4512             if ( !sorted.get( 8 ).getDomainId().getId().equals( "H" ) ) {
4513                 return false;
4514             }
4515             if ( sorted.get( 8 ).getNumber() != 2 ) {
4516                 return false;
4517             }
4518             if ( !sorted.get( 9 ).getDomainId().getId().equals( "H" ) ) {
4519                 return false;
4520             }
4521             if ( sorted.get( 9 ).getNumber() != 6 ) {
4522                 return false;
4523             }
4524             if ( !sorted.get( 10 ).getDomainId().getId().equals( "H" ) ) {
4525                 return false;
4526             }
4527             if ( sorted.get( 10 ).getNumber() != 4 ) {
4528                 return false;
4529             }
4530             if ( !sorted.get( 11 ).getDomainId().getId().equals( "H" ) ) {
4531                 return false;
4532             }
4533             if ( sorted.get( 11 ).getNumber() != 1 ) {
4534                 return false;
4535             }
4536             if ( sorted.get( 11 ).getTotalCount() != 5 ) {
4537                 return false;
4538             }
4539             if ( !sorted.get( 12 ).getDomainId().getId().equals( "H" ) ) {
4540                 return false;
4541             }
4542             if ( sorted.get( 12 ).getNumber() != 3 ) {
4543                 return false;
4544             }
4545             if ( !sorted.get( 13 ).getDomainId().getId().equals( "H7" ) ) {
4546                 return false;
4547             }
4548             if ( sorted.get( 13 ).getNumber() != 5 ) {
4549                 return false;
4550             }
4551             if ( !sorted.get( 14 ).getDomainId().getId().equals( "H7" ) ) {
4552                 return false;
4553             }
4554             if ( sorted.get( 14 ).getNumber() != 5 ) {
4555                 return false;
4556             }
4557             if ( !sorted.get( 15 ).getDomainId().getId().equals( "H7" ) ) {
4558                 return false;
4559             }
4560             if ( sorted.get( 15 ).getNumber() != 5 ) {
4561                 return false;
4562             }
4563             // To check if sorting is stable [as claimed by Sun for
4564             // Collections.sort( List )]
4565             if ( !sorted.get( 16 ).getDomainId().getId().equals( "H7" ) ) {
4566                 return false;
4567             }
4568             if ( sorted.get( 16 ).getNumber() != 5 ) {
4569                 return false;
4570             }
4571             if ( sorted.get( 16 ).getTotalCount() != 200 ) {
4572                 return false;
4573             }
4574         }
4575         catch ( final Exception e ) {
4576             e.printStackTrace( System.out );
4577             return false;
4578         }
4579         return true;
4580     }
4581
4582     private static boolean testEngulfingOverlapRemoval() {
4583         try {
4584             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
4585             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
4586             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
4587             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
4588             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
4589             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
4590             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
4591             final List<Boolean> covered = new ArrayList<Boolean>();
4592             covered.add( true ); // 0
4593             covered.add( false ); // 1
4594             covered.add( true ); // 2
4595             covered.add( false ); // 3
4596             covered.add( true ); // 4
4597             covered.add( true ); // 5
4598             covered.add( false ); // 6
4599             covered.add( true ); // 7
4600             covered.add( true ); // 8
4601             if ( SurfacingUtil.isEngulfed( d0, covered ) ) {
4602                 return false;
4603             }
4604             if ( SurfacingUtil.isEngulfed( d1, covered ) ) {
4605                 return false;
4606             }
4607             if ( SurfacingUtil.isEngulfed( d2, covered ) ) {
4608                 return false;
4609             }
4610             if ( !SurfacingUtil.isEngulfed( d3, covered ) ) {
4611                 return false;
4612             }
4613             if ( SurfacingUtil.isEngulfed( d4, covered ) ) {
4614                 return false;
4615             }
4616             if ( SurfacingUtil.isEngulfed( d5, covered ) ) {
4617                 return false;
4618             }
4619             if ( !SurfacingUtil.isEngulfed( d6, covered ) ) {
4620                 return false;
4621             }
4622             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
4623             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
4624             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
4625             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
4626             abc.addProteinDomain( a );
4627             abc.addProteinDomain( b );
4628             abc.addProteinDomain( c );
4629             final Protein abc_r1 = SurfacingUtil.removeOverlappingDomains( 3, false, abc );
4630             final Protein abc_r2 = SurfacingUtil.removeOverlappingDomains( 3, true, abc );
4631             if ( abc.getNumberOfProteinDomains() != 3 ) {
4632                 return false;
4633             }
4634             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
4635                 return false;
4636             }
4637             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
4638                 return false;
4639             }
4640             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().getId().equals( "a" ) ) {
4641                 return false;
4642             }
4643             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().getId().equals( "b" ) ) {
4644                 return false;
4645             }
4646             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
4647             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
4648             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
4649             final Protein def = new BasicProtein( "def", "nemve", 0 );
4650             def.addProteinDomain( d );
4651             def.addProteinDomain( e );
4652             def.addProteinDomain( f );
4653             final Protein def_r1 = SurfacingUtil.removeOverlappingDomains( 5, false, def );
4654             final Protein def_r2 = SurfacingUtil.removeOverlappingDomains( 5, true, def );
4655             if ( def.getNumberOfProteinDomains() != 3 ) {
4656                 return false;
4657             }
4658             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
4659                 return false;
4660             }
4661             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
4662                 return false;
4663             }
4664             if ( !def_r2.getProteinDomain( 0 ).getDomainId().getId().equals( "d" ) ) {
4665                 return false;
4666             }
4667             if ( !def_r2.getProteinDomain( 1 ).getDomainId().getId().equals( "f" ) ) {
4668                 return false;
4669             }
4670             if ( !def_r2.getProteinDomain( 2 ).getDomainId().getId().equals( "e" ) ) {
4671                 return false;
4672             }
4673         }
4674         catch ( final Exception e ) {
4675             e.printStackTrace( System.out );
4676             return false;
4677         }
4678         return true;
4679     }
4680
4681     private static boolean testGenomeWideCombinableDomains() {
4682         try {
4683             final Domain a = new BasicDomain( "a", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
4684             final Domain b = new BasicDomain( "b", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
4685             final Domain c = new BasicDomain( "c", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
4686             final Domain d = new BasicDomain( "d", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
4687             final Domain e = new BasicDomain( "e", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
4688             final Domain f = new BasicDomain( "f", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
4689             final Domain g = new BasicDomain( "g", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
4690             final Domain h = new BasicDomain( "h", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
4691             final Domain x = new BasicDomain( "x", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
4692             final Protein eel_0 = new BasicProtein( "0", "eel", 0 );
4693             final Protein eel_1 = new BasicProtein( "1", "eel", 0 );
4694             final Protein eel_2 = new BasicProtein( "2", "eel", 0 );
4695             final Protein eel_3 = new BasicProtein( "3", "eel", 0 );
4696             final Protein eel_4 = new BasicProtein( "4", "eel", 0 );
4697             final Protein eel_5 = new BasicProtein( "5", "eel", 0 );
4698             final Protein eel_6 = new BasicProtein( "6", "eel", 0 );
4699             eel_1.addProteinDomain( a );
4700             eel_2.addProteinDomain( a );
4701             eel_2.addProteinDomain( b );
4702             eel_3.addProteinDomain( a );
4703             eel_3.addProteinDomain( a );
4704             eel_3.addProteinDomain( b );
4705             eel_4.addProteinDomain( a );
4706             eel_4.addProteinDomain( b );
4707             eel_4.addProteinDomain( c );
4708             eel_4.addProteinDomain( d );
4709             eel_4.addProteinDomain( e );
4710             eel_5.addProteinDomain( e );
4711             eel_5.addProteinDomain( e );
4712             eel_5.addProteinDomain( f );
4713             eel_5.addProteinDomain( f );
4714             eel_5.addProteinDomain( f );
4715             eel_5.addProteinDomain( f );
4716             eel_6.addProteinDomain( g );
4717             eel_6.addProteinDomain( h );
4718             final List<Protein> protein_list_eel = new ArrayList<Protein>();
4719             protein_list_eel.add( eel_0 );
4720             protein_list_eel.add( eel_1 );
4721             protein_list_eel.add( eel_2 );
4722             protein_list_eel.add( eel_3 );
4723             protein_list_eel.add( eel_4 );
4724             protein_list_eel.add( eel_5 );
4725             protein_list_eel.add( eel_6 );
4726             final BasicGenomeWideCombinableDomains eel_not_ignore = BasicGenomeWideCombinableDomains
4727                     .createInstance( protein_list_eel, false, new BasicSpecies( "eel" ) );
4728             final BasicGenomeWideCombinableDomains eel_ignore = BasicGenomeWideCombinableDomains
4729                     .createInstance( protein_list_eel, true, new BasicSpecies( "eel" ) );
4730             if ( !eel_not_ignore.contains( new DomainId( "a" ) ) ) {
4731                 return false;
4732             }
4733             if ( !eel_not_ignore.contains( new DomainId( "b" ) ) ) {
4734                 return false;
4735             }
4736             if ( !eel_not_ignore.contains( new DomainId( "c" ) ) ) {
4737                 return false;
4738             }
4739             if ( !eel_not_ignore.contains( new DomainId( "d" ) ) ) {
4740                 return false;
4741             }
4742             if ( !eel_not_ignore.contains( new DomainId( "e" ) ) ) {
4743                 return false;
4744             }
4745             if ( !eel_not_ignore.contains( new DomainId( "f" ) ) ) {
4746                 return false;
4747             }
4748             if ( !eel_not_ignore.contains( new DomainId( "g" ) ) ) {
4749                 return false;
4750             }
4751             if ( !eel_not_ignore.contains( new DomainId( "h" ) ) ) {
4752                 return false;
4753             }
4754             if ( eel_not_ignore.contains( new DomainId( "x" ) ) ) {
4755                 return false;
4756             }
4757             if ( !eel_ignore.contains( new DomainId( "a" ) ) ) {
4758                 return false;
4759             }
4760             if ( !eel_ignore.contains( new DomainId( "b" ) ) ) {
4761                 return false;
4762             }
4763             if ( !eel_ignore.contains( new DomainId( "c" ) ) ) {
4764                 return false;
4765             }
4766             if ( !eel_ignore.contains( new DomainId( "d" ) ) ) {
4767                 return false;
4768             }
4769             if ( !eel_ignore.contains( new DomainId( "e" ) ) ) {
4770                 return false;
4771             }
4772             if ( !eel_ignore.contains( new DomainId( "f" ) ) ) {
4773                 return false;
4774             }
4775             if ( !eel_ignore.contains( new DomainId( "g" ) ) ) {
4776                 return false;
4777             }
4778             if ( !eel_ignore.contains( new DomainId( "h" ) ) ) {
4779                 return false;
4780             }
4781             if ( eel_ignore.contains( new DomainId( "x" ) ) ) {
4782                 return false;
4783             }
4784             if ( eel_not_ignore.getSize() != 8 ) {
4785                 return false;
4786             }
4787             if ( eel_ignore.getSize() != 8 ) {
4788                 return false;
4789             }
4790             if ( eel_not_ignore.get( new DomainId( "a" ) ).getCombinableDomainsIds().size() != 5 ) {
4791                 return false;
4792             }
4793             if ( eel_not_ignore.get( new DomainId( "b" ) ).getCombinableDomainsIds().size() != 4 ) {
4794                 return false;
4795             }
4796             if ( eel_not_ignore.get( new DomainId( "c" ) ).getCombinableDomainsIds().size() != 4 ) {
4797                 return false;
4798             }
4799             if ( eel_not_ignore.get( new DomainId( "d" ) ).getCombinableDomainsIds().size() != 4 ) {
4800                 return false;
4801             }
4802             if ( eel_not_ignore.get( new DomainId( "e" ) ).getCombinableDomainsIds().size() != 6 ) {
4803                 return false;
4804             }
4805             if ( eel_not_ignore.get( new DomainId( "f" ) ).getCombinableDomainsIds().size() != 2 ) {
4806                 return false;
4807             }
4808             if ( eel_not_ignore.get( new DomainId( "g" ) ).getCombinableDomainsIds().size() != 1 ) {
4809                 return false;
4810             }
4811             if ( eel_not_ignore.get( new DomainId( "h" ) ).getCombinableDomainsIds().size() != 1 ) {
4812                 return false;
4813             }
4814             if ( eel_ignore.get( new DomainId( "a" ) ).getCombinableDomainsIds().size() != 4 ) {
4815                 return false;
4816             }
4817             if ( eel_ignore.get( new DomainId( "b" ) ).getCombinableDomainsIds().size() != 4 ) {
4818                 return false;
4819             }
4820             if ( eel_ignore.get( new DomainId( "c" ) ).getCombinableDomainsIds().size() != 4 ) {
4821                 return false;
4822             }
4823             if ( eel_ignore.get( new DomainId( "d" ) ).getCombinableDomainsIds().size() != 4 ) {
4824                 return false;
4825             }
4826             if ( eel_ignore.get( new DomainId( "e" ) ).getCombinableDomainsIds().size() != 5 ) {
4827                 return false;
4828             }
4829             if ( eel_ignore.get( new DomainId( "f" ) ).getCombinableDomainsIds().size() != 1 ) {
4830                 return false;
4831             }
4832             if ( eel_ignore.get( new DomainId( "g" ) ).getCombinableDomainsIds().size() != 1 ) {
4833                 return false;
4834             }
4835             if ( eel_ignore.get( new DomainId( "h" ) ).getCombinableDomainsIds().size() != 1 ) {
4836                 return false;
4837             }
4838             if ( eel_not_ignore.getAllDomainIds().size() != 8 ) {
4839                 return false;
4840             }
4841             if ( !eel_not_ignore.getAllDomainIds().contains( a.getDomainId() ) ) {
4842                 return false;
4843             }
4844             if ( !eel_not_ignore.getAllDomainIds().contains( b.getDomainId() ) ) {
4845                 return false;
4846             }
4847             if ( !eel_not_ignore.getAllDomainIds().contains( c.getDomainId() ) ) {
4848                 return false;
4849             }
4850             if ( !eel_not_ignore.getAllDomainIds().contains( d.getDomainId() ) ) {
4851                 return false;
4852             }
4853             if ( !eel_not_ignore.getAllDomainIds().contains( e.getDomainId() ) ) {
4854                 return false;
4855             }
4856             if ( !eel_not_ignore.getAllDomainIds().contains( f.getDomainId() ) ) {
4857                 return false;
4858             }
4859             if ( !eel_not_ignore.getAllDomainIds().contains( g.getDomainId() ) ) {
4860                 return false;
4861             }
4862             if ( !eel_not_ignore.getAllDomainIds().contains( h.getDomainId() ) ) {
4863                 return false;
4864             }
4865             if ( eel_not_ignore.getAllDomainIds().contains( x.getDomainId() ) ) {
4866                 return false;
4867             }
4868             if ( eel_ignore.getAllDomainIds().size() != 8 ) {
4869                 return false;
4870             }
4871             if ( !eel_ignore.getAllDomainIds().contains( a.getDomainId() ) ) {
4872                 return false;
4873             }
4874             if ( !eel_ignore.getAllDomainIds().contains( b.getDomainId() ) ) {
4875                 return false;
4876             }
4877             if ( !eel_ignore.getAllDomainIds().contains( c.getDomainId() ) ) {
4878                 return false;
4879             }
4880             if ( !eel_ignore.getAllDomainIds().contains( d.getDomainId() ) ) {
4881                 return false;
4882             }
4883             if ( !eel_ignore.getAllDomainIds().contains( e.getDomainId() ) ) {
4884                 return false;
4885             }
4886             if ( !eel_ignore.getAllDomainIds().contains( f.getDomainId() ) ) {
4887                 return false;
4888             }
4889             if ( !eel_ignore.getAllDomainIds().contains( g.getDomainId() ) ) {
4890                 return false;
4891             }
4892             if ( !eel_ignore.getAllDomainIds().contains( h.getDomainId() ) ) {
4893                 return false;
4894             }
4895             if ( eel_ignore.getAllDomainIds().contains( x.getDomainId() ) ) {
4896                 return false;
4897             }
4898             final SortedSet<BinaryDomainCombination> bc0 = eel_not_ignore.toBinaryDomainCombinations();
4899             if ( bc0.size() != 15 ) {
4900                 return false;
4901             }
4902             if ( !bc0.contains( new BasicBinaryDomainCombination( "a", "a" ) ) ) {
4903                 return false;
4904             }
4905             if ( !bc0.contains( new BasicBinaryDomainCombination( "a", "b" ) ) ) {
4906                 return false;
4907             }
4908             if ( !bc0.contains( new BasicBinaryDomainCombination( "b", "a" ) ) ) {
4909                 return false;
4910             }
4911             if ( !bc0.contains( new BasicBinaryDomainCombination( "a", "c" ) ) ) {
4912                 return false;
4913             }
4914             if ( !bc0.contains( new BasicBinaryDomainCombination( "a", "d" ) ) ) {
4915                 return false;
4916             }
4917             if ( !bc0.contains( new BasicBinaryDomainCombination( "a", "e" ) ) ) {
4918                 return false;
4919             }
4920             if ( !bc0.contains( new BasicBinaryDomainCombination( "b", "c" ) ) ) {
4921                 return false;
4922             }
4923             if ( !bc0.contains( new BasicBinaryDomainCombination( "b", "d" ) ) ) {
4924                 return false;
4925             }
4926             if ( !bc0.contains( new BasicBinaryDomainCombination( "b", "e" ) ) ) {
4927                 return false;
4928             }
4929             if ( !bc0.contains( new BasicBinaryDomainCombination( "c", "d" ) ) ) {
4930                 return false;
4931             }
4932             if ( !bc0.contains( new BasicBinaryDomainCombination( "c", "e" ) ) ) {
4933                 return false;
4934             }
4935             if ( !bc0.contains( new BasicBinaryDomainCombination( "d", "e" ) ) ) {
4936                 return false;
4937             }
4938             if ( !bc0.contains( new BasicBinaryDomainCombination( "e", "f" ) ) ) {
4939                 return false;
4940             }
4941             if ( !bc0.contains( new BasicBinaryDomainCombination( "e", "e" ) ) ) {
4942                 return false;
4943             }
4944             if ( !bc0.contains( new BasicBinaryDomainCombination( "f", "f" ) ) ) {
4945                 return false;
4946             }
4947             if ( !bc0.contains( new BasicBinaryDomainCombination( "g", "h" ) ) ) {
4948                 return false;
4949             }
4950             if ( bc0.contains( new BasicBinaryDomainCombination( "f", "a" ) ) ) {
4951                 return false;
4952             }
4953             if ( bc0.contains( new BasicBinaryDomainCombination( "f", "b" ) ) ) {
4954                 return false;
4955             }
4956             if ( bc0.contains( new BasicBinaryDomainCombination( "a", "h" ) ) ) {
4957                 return false;
4958             }
4959             if ( bc0.contains( new BasicBinaryDomainCombination( "a", "g" ) ) ) {
4960                 return false;
4961             }
4962             final SortedSet<BinaryDomainCombination> bc1 = eel_ignore.toBinaryDomainCombinations();
4963             if ( bc1.size() != 12 ) {
4964                 return false;
4965             }
4966             if ( bc1.contains( new BasicBinaryDomainCombination( "a", "a" ) ) ) {
4967                 return false;
4968             }
4969             if ( !bc1.contains( new BasicBinaryDomainCombination( "a", "b" ) ) ) {
4970                 return false;
4971             }
4972             if ( !bc1.contains( new BasicBinaryDomainCombination( "b", "a" ) ) ) {
4973                 return false;
4974             }
4975             if ( !bc1.contains( new BasicBinaryDomainCombination( "a", "c" ) ) ) {
4976                 return false;
4977             }
4978             if ( !bc1.contains( new BasicBinaryDomainCombination( "a", "d" ) ) ) {
4979                 return false;
4980             }
4981             if ( !bc1.contains( new BasicBinaryDomainCombination( "a", "e" ) ) ) {
4982                 return false;
4983             }
4984             if ( !bc1.contains( new BasicBinaryDomainCombination( "b", "c" ) ) ) {
4985                 return false;
4986             }
4987             if ( !bc1.contains( new BasicBinaryDomainCombination( "b", "d" ) ) ) {
4988                 return false;
4989             }
4990             if ( !bc1.contains( new BasicBinaryDomainCombination( "b", "e" ) ) ) {
4991                 return false;
4992             }
4993             if ( !bc1.contains( new BasicBinaryDomainCombination( "c", "d" ) ) ) {
4994                 return false;
4995             }
4996             if ( !bc1.contains( new BasicBinaryDomainCombination( "c", "e" ) ) ) {
4997                 return false;
4998             }
4999             if ( !bc1.contains( new BasicBinaryDomainCombination( "d", "e" ) ) ) {
5000                 return false;
5001             }
5002             if ( !bc1.contains( new BasicBinaryDomainCombination( "e", "f" ) ) ) {
5003                 return false;
5004             }
5005             if ( !bc1.contains( new BasicBinaryDomainCombination( "g", "h" ) ) ) {
5006                 return false;
5007             }
5008             if ( bc1.contains( new BasicBinaryDomainCombination( "e", "e" ) ) ) {
5009                 return false;
5010             }
5011             if ( bc1.contains( new BasicBinaryDomainCombination( "f", "f" ) ) ) {
5012                 return false;
5013             }
5014             if ( bc1.contains( new BasicBinaryDomainCombination( "f", "a" ) ) ) {
5015                 return false;
5016             }
5017             if ( bc1.contains( new BasicBinaryDomainCombination( "f", "b" ) ) ) {
5018                 return false;
5019             }
5020             if ( bc1.contains( new BasicBinaryDomainCombination( "a", "g" ) ) ) {
5021                 return false;
5022             }
5023             if ( bc1.contains( new BasicBinaryDomainCombination( "b", "g" ) ) ) {
5024                 return false;
5025             }
5026         }
5027         catch ( final Exception e ) {
5028             e.printStackTrace( System.out );
5029             return false;
5030         }
5031         return true;
5032     }
5033
5034     private static boolean testHmmPfamOutputParser( final File test_dir ) {
5035         try {
5036             final HmmPfamOutputParser parser = new HmmPfamOutputParser( new File( test_dir
5037                     + ForesterUtil.getFileSeparator() + "hmmpfam_output" ), "human", "ls" );
5038             parser.setEValueMaximum( 0.2 );
5039             parser.setIgnoreDufs( true );
5040             parser.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
5041             List<?> domain_collections = null;
5042             domain_collections = parser.parse();
5043             if ( parser.getDomainsEncountered() != 4 ) {
5044                 return false;
5045             }
5046             if ( parser.getDomainsIgnoredDueToDuf() != 0 ) {
5047                 return false;
5048             }
5049             if ( parser.getDomainsIgnoredDueToEval() != 1 ) {
5050                 return false;
5051             }
5052             if ( parser.getDomainsIgnoredDueToOverlap() != 0 ) {
5053                 return false;
5054             }
5055             if ( parser.getDomainsStored() != 3 ) {
5056                 return false;
5057             }
5058             if ( domain_collections.size() != 1 ) {
5059                 return false;
5060             }
5061             final Protein pdc = ( Protein ) domain_collections.get( 0 );
5062             if ( !pdc.getProteinId().equals( new ProteinId( "ENSP00000285681" ) ) ) {
5063                 return false;
5064             }
5065             if ( !pdc.getSpecies().getSpeciesId().equals( "human" ) ) {
5066                 return false;
5067             }
5068             if ( pdc.getNumberOfProteinDomains() != 3 ) {
5069                 return false;
5070             }
5071             if ( !pdc.getAccession().equals( "acc_ENSP00000285681" ) ) {
5072                 return false;
5073             }
5074             if ( !pdc
5075                     .getDescription()
5076                     .equals( "pep:known chromosome:NCBI36:21:16024215:16174248:1 gene:ENSG00000155313 transcript:ENST00000285681" ) ) {
5077                 return false;
5078             }
5079             final List<Domain> uba = pdc.getProteinDomains( new DomainId( "UBA" ) );
5080             final List<Domain> uim = pdc.getProteinDomains( new DomainId( "UIM" ) );
5081             final List<Domain> uch = pdc.getProteinDomains( new DomainId( "UCH" ) );
5082             if ( uba.size() != 1 ) {
5083                 return false;
5084             }
5085             if ( uim.size() != 2 ) {
5086                 return false;
5087             }
5088             if ( uch.size() != 0 ) {
5089                 return false;
5090             }
5091             final BasicDomain uim_domain = ( BasicDomain ) uim.get( 1 );
5092             if ( !uim_domain.getDomainId().equals( new DomainId( "UIM" ) ) ) {
5093                 return false;
5094             }
5095             if ( uim_domain.getTotalCount() != 2 ) {
5096                 return false;
5097             }
5098             final BasicDomain uba_domain = ( BasicDomain ) uba.get( 0 );
5099             if ( !uba_domain.getDomainId().equals( new DomainId( "UBA" ) ) ) {
5100                 return false;
5101             }
5102             if ( uba_domain.getNumber() != 1 ) {
5103                 return false;
5104             }
5105             if ( uba_domain.getTotalCount() != 1 ) {
5106                 return false;
5107             }
5108             if ( uba_domain.getFrom() != 16 ) {
5109                 return false;
5110             }
5111             if ( uba_domain.getTo() != 57 ) {
5112                 return false;
5113             }
5114             if ( !Test.isEqual( uba_domain.getPerSequenceEvalue(), 0.00084 ) ) {
5115                 return false;
5116             }
5117             if ( !Test.isEqual( uba_domain.getPerSequenceScore(), 23.2 ) ) {
5118                 return false;
5119             }
5120             final HmmPfamOutputParser parser2 = new HmmPfamOutputParser( new File( test_dir
5121                     + ForesterUtil.getFileSeparator() + "hmmpfam_output_short" ), "human", "ls" );
5122             parser2.setEValueMaximum( 0.2 );
5123             parser2.setIgnoreDufs( true );
5124             parser2.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
5125             List<Protein> domain_collections2 = null;
5126             domain_collections2 = parser2.parse();
5127             if ( parser2.getDomainsEncountered() != 4 ) {
5128                 return false;
5129             }
5130             if ( parser.getDomainsIgnoredDueToDuf() != 0 ) {
5131                 return false;
5132             }
5133             if ( parser.getDomainsIgnoredDueToEval() != 1 ) {
5134                 return false;
5135             }
5136             if ( parser.getDomainsIgnoredDueToOverlap() != 0 ) {
5137                 return false;
5138             }
5139             if ( parser2.getDomainsStored() != 3 ) {
5140                 return false;
5141             }
5142             if ( domain_collections2.size() != 1 ) {
5143                 return false;
5144             }
5145             final Protein pdc2 = domain_collections2.get( 0 );
5146             if ( !pdc2.getProteinId().getId().equals( "ENSP00000285681" ) ) {
5147                 return false;
5148             }
5149             if ( !pdc2.getSpecies().getSpeciesId().equals( "human" ) ) {
5150                 return false;
5151             }
5152             if ( !pdc2.getName().equals( "" ) ) {
5153                 return false;
5154             }
5155             if ( !pdc2.getAccession().equals( "223" ) ) {
5156                 return false;
5157             }
5158             if ( !pdc2
5159                     .getDescription()
5160                     .equals( "pep:known chromosome:NCBI36:21:16024215:16174248:1 gene:ENSG00000155313 transcript:ENST00000285681" ) ) {
5161                 return false;
5162             }
5163             if ( pdc2.getNumberOfProteinDomains() != 3 ) {
5164                 return false;
5165             }
5166             final List<Domain> uba2 = pdc2.getProteinDomains( new DomainId( "UBA" ) );
5167             final List<Domain> uim2 = pdc2.getProteinDomains( new DomainId( "UIM" ) );
5168             final List<Domain> uch2 = pdc2.getProteinDomains( new DomainId( "UCH" ) );
5169             if ( uba2.size() != 1 ) {
5170                 return false;
5171             }
5172             if ( uim2.size() != 2 ) {
5173                 return false;
5174             }
5175             if ( uch2.size() != 0 ) {
5176                 return false;
5177             }
5178             final BasicDomain uim_domain2 = ( BasicDomain ) uim2.get( 1 );
5179             if ( !uim_domain2.getDomainId().getId().equals( "UIM" ) ) {
5180                 return false;
5181             }
5182             if ( uim_domain2.getTotalCount() != 2 ) {
5183                 return false;
5184             }
5185             final BasicDomain uba_domain2 = ( BasicDomain ) uba2.get( 0 );
5186             if ( !uba_domain2.getDomainId().getId().equals( "UBA" ) ) {
5187                 return false;
5188             }
5189             if ( uba_domain2.getNumber() != 1 ) {
5190                 return false;
5191             }
5192             if ( uba_domain2.getTotalCount() != 1 ) {
5193                 return false;
5194             }
5195             if ( uba_domain2.getFrom() != 16 ) {
5196                 return false;
5197             }
5198             if ( uba_domain2.getTo() != 57 ) {
5199                 return false;
5200             }
5201             if ( !Test.isEqual( uba_domain2.getPerSequenceEvalue(), 0.00084 ) ) {
5202                 return false;
5203             }
5204         }
5205         catch ( final Exception e ) {
5206             e.printStackTrace( System.out );
5207             return false;
5208         }
5209         return true;
5210     }
5211
5212     private static boolean testHmmPfamOutputParserWithFilter( final File test_dir ) {
5213         try {
5214             HmmPfamOutputParser parser = new HmmPfamOutputParser( new File( test_dir + ForesterUtil.getFileSeparator()
5215                     + "hmmpfam_output3" ), "human", "ls" );
5216             parser.setEValueMaximum( 0.2 );
5217             parser.setIgnoreDufs( true );
5218             parser.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
5219             List<Protein> proteins = null;
5220             proteins = parser.parse();
5221             if ( parser.getProteinsIgnoredDueToFilter() != 0 ) {
5222                 return false;
5223             }
5224             if ( proteins.size() != 4 ) {
5225                 return false;
5226             }
5227             //
5228             Set<DomainId> filter = new TreeSet<DomainId>();
5229             filter.add( new DomainId( "beauty" ) );
5230             filter.add( new DomainId( "strange" ) );
5231             parser = new HmmPfamOutputParser( new File( test_dir + ForesterUtil.getFileSeparator() + "hmmpfam_output3" ),
5232                                               "human",
5233                                               "ls",
5234                                               filter,
5235                                               HmmPfamOutputParser.FilterType.NEGATIVE_PROTEIN );
5236             parser.setEValueMaximum( 0.2 );
5237             parser.setIgnoreDufs( true );
5238             parser.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
5239             proteins = null;
5240             proteins = parser.parse();
5241             if ( parser.getProteinsIgnoredDueToFilter() != 0 ) {
5242                 return false;
5243             }
5244             if ( proteins.size() != 4 ) {
5245                 return false;
5246             }
5247             //
5248             filter = new TreeSet<DomainId>();
5249             filter.add( new DomainId( "beauty" ) );
5250             filter.add( new DomainId( "strange" ) );
5251             parser = new HmmPfamOutputParser( new File( test_dir + ForesterUtil.getFileSeparator() + "hmmpfam_output3" ),
5252                                               "human",
5253                                               "ls",
5254                                               filter,
5255                                               HmmPfamOutputParser.FilterType.POSITIVE_PROTEIN );
5256             parser.setEValueMaximum( 0.2 );
5257             parser.setIgnoreDufs( true );
5258             parser.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
5259             proteins = null;
5260             proteins = parser.parse();
5261             if ( parser.getProteinsIgnoredDueToFilter() != 4 ) {
5262                 return false;
5263             }
5264             if ( proteins.size() != 0 ) {
5265                 return false;
5266             }
5267             //
5268             filter = new TreeSet<DomainId>();
5269             filter.add( new DomainId( "UIM" ) );
5270             filter.add( new DomainId( "A" ) );
5271             filter.add( new DomainId( "C" ) );
5272             parser = new HmmPfamOutputParser( new File( test_dir + ForesterUtil.getFileSeparator() + "hmmpfam_output3" ),
5273                                               "human",
5274                                               "ls",
5275                                               filter,
5276                                               HmmPfamOutputParser.FilterType.POSITIVE_PROTEIN );
5277             parser.setEValueMaximum( 0.2 );
5278             parser.setIgnoreDufs( true );
5279             parser.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
5280             proteins = null;
5281             proteins = parser.parse();
5282             if ( parser.getProteinsIgnoredDueToFilter() != 0 ) {
5283                 return false;
5284             }
5285             if ( proteins.size() != 4 ) {
5286                 return false;
5287             }
5288             //
5289             filter = new TreeSet<DomainId>();
5290             filter.add( new DomainId( "UIM" ) );
5291             filter.add( new DomainId( "A" ) );
5292             filter.add( new DomainId( "C" ) );
5293             filter.add( new DomainId( "X" ) );
5294             parser = new HmmPfamOutputParser( new File( test_dir + ForesterUtil.getFileSeparator() + "hmmpfam_output3" ),
5295                                               "human",
5296                                               "ls",
5297                                               filter,
5298                                               HmmPfamOutputParser.FilterType.NEGATIVE_DOMAIN );
5299             parser.setEValueMaximum( 0.2 );
5300             parser.setIgnoreDufs( true );
5301             parser.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
5302             proteins = null;
5303             proteins = parser.parse();
5304             if ( parser.getDomainsIgnoredDueToNegativeDomainFilter() != 7 ) {
5305                 return false;
5306             }
5307             if ( proteins.size() != 3 ) {
5308                 return false;
5309             }
5310             //
5311             filter = new TreeSet<DomainId>();
5312             filter.add( new DomainId( "UIM" ) );
5313             filter.add( new DomainId( "A" ) );
5314             filter.add( new DomainId( "C" ) );
5315             parser = new HmmPfamOutputParser( new File( test_dir + ForesterUtil.getFileSeparator() + "hmmpfam_output3" ),
5316                                               "human",
5317                                               "ls",
5318                                               filter,
5319                                               HmmPfamOutputParser.FilterType.NEGATIVE_PROTEIN );
5320             parser.setEValueMaximum( 0.2 );
5321             parser.setIgnoreDufs( true );
5322             parser.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
5323             proteins = null;
5324             proteins = parser.parse();
5325             if ( parser.getProteinsIgnoredDueToFilter() != 4 ) {
5326                 return false;
5327             }
5328             if ( proteins.size() != 0 ) {
5329                 return false;
5330             }
5331             //
5332             filter = new TreeSet<DomainId>();
5333             filter.add( new DomainId( "UIM" ) );
5334             parser = new HmmPfamOutputParser( new File( test_dir + ForesterUtil.getFileSeparator() + "hmmpfam_output3" ),
5335                                               "human",
5336                                               "ls",
5337                                               filter,
5338                                               HmmPfamOutputParser.FilterType.NEGATIVE_PROTEIN );
5339             parser.setEValueMaximum( 0.2 );
5340             parser.setIgnoreDufs( true );
5341             parser.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
5342             proteins = null;
5343             proteins = parser.parse();
5344             if ( parser.getProteinsIgnoredDueToFilter() != 1 ) {
5345                 return false;
5346             }
5347             if ( parser.getProteinsStored() != 3 ) {
5348                 return false;
5349             }
5350             if ( proteins.size() != 3 ) {
5351                 return false;
5352             }
5353             //
5354             filter = new TreeSet<DomainId>();
5355             filter.add( new DomainId( "UIM" ) );
5356             parser = new HmmPfamOutputParser( new File( test_dir + ForesterUtil.getFileSeparator() + "hmmpfam_output3" ),
5357                                               "human",
5358                                               "ls",
5359                                               filter,
5360                                               HmmPfamOutputParser.FilterType.POSITIVE_PROTEIN );
5361             parser.setEValueMaximum( 0.2 );
5362             parser.setIgnoreDufs( true );
5363             parser.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
5364             proteins = null;
5365             proteins = parser.parse();
5366             if ( parser.getProteinsIgnoredDueToFilter() != 3 ) {
5367                 return false;
5368             }
5369             if ( parser.getProteinsStored() != 1 ) {
5370                 return false;
5371             }
5372             if ( proteins.size() != 1 ) {
5373                 return false;
5374             }
5375             //
5376             filter = new TreeSet<DomainId>();
5377             filter.add( new DomainId( "A" ) );
5378             filter.add( new DomainId( "C" ) );
5379             parser = new HmmPfamOutputParser( new File( test_dir + ForesterUtil.getFileSeparator() + "hmmpfam_output3" ),
5380                                               "human",
5381                                               "ls",
5382                                               filter,
5383                                               HmmPfamOutputParser.FilterType.POSITIVE_PROTEIN );
5384             parser.setEValueMaximum( 0.2 );
5385             parser.setIgnoreDufs( true );
5386             parser.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
5387             proteins = null;
5388             proteins = parser.parse();
5389             if ( parser.getDomainsEncountered() != 11 ) {
5390                 return false;
5391             }
5392             if ( parser.getProteinsEncountered() != 4 ) {
5393                 return false;
5394             }
5395             if ( parser.getProteinsIgnoredDueToFilter() != 1 ) {
5396                 return false;
5397             }
5398             if ( parser.getProteinsStored() != 3 ) {
5399                 return false;
5400             }
5401             if ( proteins.size() != 3 ) {
5402                 return false;
5403             }
5404         }
5405         catch ( final Exception e ) {
5406             e.printStackTrace( System.out );
5407             return false;
5408         }
5409         return true;
5410     }
5411
5412     private static boolean testOverlapRemoval() {
5413         try {
5414             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
5415             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
5416             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
5417             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
5418             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
5419             final List<Boolean> covered = new ArrayList<Boolean>();
5420             covered.add( true ); // 0
5421             covered.add( false ); // 1
5422             covered.add( true ); // 2
5423             covered.add( false ); // 3
5424             covered.add( true ); // 4
5425             covered.add( true ); // 5
5426             covered.add( false ); // 6
5427             covered.add( true ); // 7
5428             covered.add( true ); // 8
5429             if ( SurfacingUtil.calculateOverlap( d0, covered ) != 3 ) {
5430                 return false;
5431             }
5432             if ( SurfacingUtil.calculateOverlap( d1, covered ) != 2 ) {
5433                 return false;
5434             }
5435             if ( SurfacingUtil.calculateOverlap( d2, covered ) != 6 ) {
5436                 return false;
5437             }
5438             if ( SurfacingUtil.calculateOverlap( d3, covered ) != 0 ) {
5439                 return false;
5440             }
5441             if ( SurfacingUtil.calculateOverlap( d4, covered ) != 2 ) {
5442                 return false;
5443             }
5444             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.01, 1 );
5445             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
5446             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
5447             ab.addProteinDomain( a );
5448             ab.addProteinDomain( b );
5449             final Protein ab_s0 = SurfacingUtil.removeOverlappingDomains( 3, false, ab );
5450             if ( ab.getNumberOfProteinDomains() != 2 ) {
5451                 return false;
5452             }
5453             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
5454                 return false;
5455             }
5456             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().getId().equals( "a" ) ) {
5457                 return false;
5458             }
5459             final Protein ab_s1 = SurfacingUtil.removeOverlappingDomains( 4, false, ab );
5460             if ( ab.getNumberOfProteinDomains() != 2 ) {
5461                 return false;
5462             }
5463             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
5464                 return false;
5465             }
5466             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
5467             final Domain d = new BasicDomain( "d",
5468                                               ( short ) 10000,
5469                                               ( short ) 10500,
5470                                               ( short ) 1,
5471                                               ( short ) 1,
5472                                               0.0000001,
5473                                               1 );
5474             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
5475             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
5476             cde.addProteinDomain( c );
5477             cde.addProteinDomain( d );
5478             cde.addProteinDomain( e );
5479             final Protein cde_s0 = SurfacingUtil.removeOverlappingDomains( 0, false, cde );
5480             if ( cde.getNumberOfProteinDomains() != 3 ) {
5481                 return false;
5482             }
5483             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
5484                 return false;
5485             }
5486             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
5487             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
5488             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
5489             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
5490             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
5491             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
5492             fghi.addProteinDomain( f );
5493             fghi.addProteinDomain( g );
5494             fghi.addProteinDomain( h );
5495             fghi.addProteinDomain( i );
5496             fghi.addProteinDomain( i );
5497             fghi.addProteinDomain( i );
5498             fghi.addProteinDomain( i2 );
5499             final Protein fghi_s0 = SurfacingUtil.removeOverlappingDomains( 10, false, fghi );
5500             if ( fghi.getNumberOfProteinDomains() != 7 ) {
5501                 return false;
5502             }
5503             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
5504                 return false;
5505             }
5506             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().getId().equals( "h" ) ) {
5507                 return false;
5508             }
5509             final Protein fghi_s1 = SurfacingUtil.removeOverlappingDomains( 11, false, fghi );
5510             if ( fghi.getNumberOfProteinDomains() != 7 ) {
5511                 return false;
5512             }
5513             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
5514                 return false;
5515             }
5516             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
5517             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
5518             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
5519             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
5520             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
5521             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
5522             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
5523             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
5524             jklm.addProteinDomain( j );
5525             jklm.addProteinDomain( k );
5526             jklm.addProteinDomain( l );
5527             jklm.addProteinDomain( m );
5528             jklm.addProteinDomain( m0 );
5529             jklm.addProteinDomain( m1 );
5530             jklm.addProteinDomain( m2 );
5531             final Protein jklm_s0 = SurfacingUtil.removeOverlappingDomains( 10, false, jklm );
5532             if ( jklm.getNumberOfProteinDomains() != 7 ) {
5533                 return false;
5534             }
5535             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
5536                 return false;
5537             }
5538             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().getId().equals( "l" ) ) {
5539                 return false;
5540             }
5541             final Protein jklm_s1 = SurfacingUtil.removeOverlappingDomains( 11, false, jklm );
5542             if ( jklm.getNumberOfProteinDomains() != 7 ) {
5543                 return false;
5544             }
5545             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
5546                 return false;
5547             }
5548             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
5549             final Protein od = new BasicProtein( "od", "varanus", 0 );
5550             od.addProteinDomain( only );
5551             final Protein od_s0 = SurfacingUtil.removeOverlappingDomains( 0, false, od );
5552             if ( od.getNumberOfProteinDomains() != 1 ) {
5553                 return false;
5554             }
5555             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
5556                 return false;
5557             }
5558         }
5559         catch ( final Exception e ) {
5560             e.printStackTrace( System.out );
5561             return false;
5562         }
5563         return true;
5564     }
5565
5566     private static boolean testParsimony() {
5567         try {
5568             final BinaryStates X = BinaryStates.PRESENT;
5569             final BinaryStates O = BinaryStates.ABSENT;
5570             final GainLossStates G = GainLossStates.GAIN;
5571             final GainLossStates L = GainLossStates.LOSS;
5572             final GainLossStates A = GainLossStates.UNCHANGED_ABSENT;
5573             final GainLossStates P = GainLossStates.UNCHANGED_PRESENT;
5574             final Domain a = new BasicDomain( "A", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5575             final Domain b = new BasicDomain( "B", 2, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5576             final Domain c = new BasicDomain( "C", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5577             final Domain d = new BasicDomain( "D", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5578             final Domain e = new BasicDomain( "E", 2, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5579             final Domain f = new BasicDomain( "F", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5580             final Domain g = new BasicDomain( "G", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5581             final Domain h = new BasicDomain( "H", 2, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5582             final Domain i = new BasicDomain( "I", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5583             final Domain j = new BasicDomain( "J", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5584             final Domain l = new BasicDomain( "L", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5585             final Domain m = new BasicDomain( "M", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5586             final Domain n = new BasicDomain( "N", 2, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5587             final Domain o = new BasicDomain( "O", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5588             final Domain p = new BasicDomain( "P", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5589             final Domain q = new BasicDomain( "Q", 2, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5590             final Domain r = new BasicDomain( "R", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5591             // 1 a-a a-b a-c e-f-g-h l-m
5592             // 2 a-b a-c e-f-g-i n-o
5593             // 3 a-b a-d e-f-g-j p-q
5594             // 4 a-b a-d p-r
5595             // 1 a-a a-b a-c e-f e-g e-h f-g f-h g-h l-m
5596             // 2 a-b a-c e-f e-g e-i f-g f-i g-i n-o
5597             // 3 a-b a-d e-f e-g e-j f-g f-j g-j p-q
5598             // 4 a-b a-d p-r
5599             // 1 a b c e f g h l m
5600             // 2 a b c e f g i n o
5601             // 3 a b d e f g j p q
5602             // 4 a b d p r
5603             final Protein aa1 = new BasicProtein( "aa1", "one", 0 );
5604             aa1.addProteinDomain( a );
5605             aa1.addProteinDomain( a );
5606             final Protein ab1 = new BasicProtein( "ab1", "one", 0 );
5607             ab1.addProteinDomain( a );
5608             ab1.addProteinDomain( b );
5609             final Protein ac1 = new BasicProtein( "ac1", "one", 0 );
5610             ac1.addProteinDomain( a );
5611             ac1.addProteinDomain( c );
5612             final Protein efgh1 = new BasicProtein( "efgh1", "one", 0 );
5613             efgh1.addProteinDomain( e );
5614             efgh1.addProteinDomain( f );
5615             efgh1.addProteinDomain( g );
5616             efgh1.addProteinDomain( h );
5617             final Protein lm1 = new BasicProtein( "lm1", "one", 0 );
5618             lm1.addProteinDomain( l );
5619             lm1.addProteinDomain( m );
5620             final Protein ab2 = new BasicProtein( "ab2", "two", 0 );
5621             ab2.addProteinDomain( a );
5622             ab2.addProteinDomain( b );
5623             final Protein ac2 = new BasicProtein( "ac2", "two", 0 );
5624             ac2.addProteinDomain( a );
5625             ac2.addProteinDomain( c );
5626             final Protein efgi2 = new BasicProtein( "efgi2", "two", 0 );
5627             efgi2.addProteinDomain( e );
5628             efgi2.addProteinDomain( f );
5629             efgi2.addProteinDomain( g );
5630             efgi2.addProteinDomain( i );
5631             final Protein no2 = new BasicProtein( "no2", "two", 0 );
5632             no2.addProteinDomain( n );
5633             no2.addProteinDomain( o );
5634             final Protein ab3 = new BasicProtein( "ab3", "three", 0 );
5635             ab3.addProteinDomain( a );
5636             ab3.addProteinDomain( b );
5637             final Protein ad3 = new BasicProtein( "ad3", "three", 0 );
5638             ad3.addProteinDomain( a );
5639             ad3.addProteinDomain( d );
5640             final Protein efgj3 = new BasicProtein( "efgj3", "three", 0 );
5641             efgj3.addProteinDomain( e );
5642             efgj3.addProteinDomain( f );
5643             efgj3.addProteinDomain( g );
5644             efgj3.addProteinDomain( j );
5645             final Protein pq3 = new BasicProtein( "pq3", "three", 0 );
5646             pq3.addProteinDomain( p );
5647             pq3.addProteinDomain( q );
5648             final Protein ab4 = new BasicProtein( "ab4", "four", 0 );
5649             ab4.addProteinDomain( a );
5650             ab4.addProteinDomain( b );
5651             final Protein ad4 = new BasicProtein( "ad4", "four", 0 );
5652             ad4.addProteinDomain( a );
5653             ad4.addProteinDomain( d );
5654             final Protein pr4 = new BasicProtein( "pr4", "four", 0 );
5655             pr4.addProteinDomain( p );
5656             pr4.addProteinDomain( r );
5657             final List<Protein> one_list = new ArrayList<Protein>();
5658             one_list.add( aa1 );
5659             one_list.add( ab1 );
5660             one_list.add( ac1 );
5661             one_list.add( efgh1 );
5662             one_list.add( lm1 );
5663             final List<Protein> two_list = new ArrayList<Protein>();
5664             two_list.add( ab2 );
5665             two_list.add( ac2 );
5666             two_list.add( efgi2 );
5667             two_list.add( no2 );
5668             final List<Protein> three_list = new ArrayList<Protein>();
5669             three_list.add( ab3 );
5670             three_list.add( ad3 );
5671             three_list.add( efgj3 );
5672             three_list.add( pq3 );
5673             final List<Protein> four_list = new ArrayList<Protein>();
5674             four_list.add( ab4 );
5675             four_list.add( ad4 );
5676             four_list.add( pr4 );
5677             final GenomeWideCombinableDomains one = BasicGenomeWideCombinableDomains
5678                     .createInstance( one_list, false, new BasicSpecies( "one" ) );
5679             final GenomeWideCombinableDomains two = BasicGenomeWideCombinableDomains
5680                     .createInstance( two_list, false, new BasicSpecies( "two" ) );
5681             final GenomeWideCombinableDomains three = BasicGenomeWideCombinableDomains
5682                     .createInstance( three_list, false, new BasicSpecies( "three" ) );
5683             final GenomeWideCombinableDomains four = BasicGenomeWideCombinableDomains
5684                     .createInstance( four_list, false, new BasicSpecies( "four" ) );
5685             final List<GenomeWideCombinableDomains> gwcd_list = new ArrayList<GenomeWideCombinableDomains>();
5686             gwcd_list.add( one );
5687             gwcd_list.add( two );
5688             gwcd_list.add( three );
5689             gwcd_list.add( four );
5690             final CharacterStateMatrix<BinaryStates> matrix_d = DomainParsimonyCalculator
5691                     .createMatrixOfDomainPresenceOrAbsence( gwcd_list );
5692             final CharacterStateMatrix<BinaryStates> matrix_bc = DomainParsimonyCalculator
5693                     .createMatrixOfBinaryDomainCombinationPresenceOrAbsence( gwcd_list );
5694             // 1 a b c e f g h l m
5695             // 2 a b c e f g i n o
5696             // 3 a b d e f g j p q
5697             // 4 a b d p r
5698             if ( matrix_d.getState( 0, 0 ) != X ) {
5699                 return false;
5700             }
5701             if ( matrix_d.getState( 0, 1 ) != X ) {
5702                 return false;
5703             }
5704             if ( matrix_d.getState( 0, 2 ) != X ) {
5705                 return false;
5706             }
5707             if ( matrix_d.getState( 0, 3 ) != O ) {
5708                 return false;
5709             }
5710             if ( matrix_d.getState( 0, 4 ) != X ) {
5711                 return false;
5712             }
5713             if ( matrix_d.getState( 0, 5 ) != X ) {
5714                 return false;
5715             }
5716             if ( matrix_d.getState( 0, 6 ) != X ) {
5717                 return false;
5718             }
5719             if ( matrix_d.getState( 0, 7 ) != X ) {
5720                 return false;
5721             }
5722             if ( matrix_d.getState( 0, 8 ) != O ) {
5723                 return false;
5724             }
5725             // 1 a-a a-b a-c e-f e-g e-h f-g f-h g-h l-m
5726             // 2 a-b a-c e-f e-g e-i f-g f-i g-i n-o
5727             // 3 a-b a-d e-f e-g e-j f-g f-j g-j p-q
5728             // 4 a-b a-d p-r
5729             if ( matrix_bc.getState( 0, 0 ) != X ) {
5730                 return false;
5731             }
5732             if ( matrix_bc.getState( 0, 1 ) != X ) {
5733                 return false;
5734             }
5735             if ( matrix_bc.getState( 0, 2 ) != X ) {
5736                 return false;
5737             }
5738             if ( matrix_bc.getState( 0, 3 ) != O ) {
5739                 return false;
5740             }
5741             if ( matrix_bc.getState( 0, 4 ) != X ) {
5742                 return false;
5743             }
5744             if ( matrix_bc.getState( 1, 0 ) != O ) {
5745                 return false;
5746             }
5747             if ( matrix_bc.getState( 1, 1 ) != X ) {
5748                 return false;
5749             }
5750             if ( matrix_bc.getState( 1, 2 ) != X ) {
5751                 return false;
5752             }
5753             if ( matrix_bc.getState( 1, 3 ) != O ) {
5754                 return false;
5755             }
5756             if ( matrix_bc.getState( 1, 4 ) != X ) {
5757                 return false;
5758             }
5759             if ( matrix_bc.getState( 2, 0 ) != O ) {
5760                 return false;
5761             }
5762             if ( matrix_bc.getState( 2, 1 ) != X ) {
5763                 return false;
5764             }
5765             if ( matrix_bc.getState( 2, 2 ) != O ) {
5766                 return false;
5767             }
5768             if ( matrix_bc.getState( 2, 3 ) != X ) {
5769                 return false;
5770             }
5771             if ( matrix_bc.getState( 2, 4 ) != X ) {
5772                 return false;
5773             }
5774             final PhylogenyFactory factory0 = ParserBasedPhylogenyFactory.getInstance();
5775             final String p0_str = "((one,two)1-2,(three,four)3-4)root";
5776             final Phylogeny p0 = factory0.create( p0_str, new NHXParser() )[ 0 ];
5777             final DomainParsimonyCalculator dp0 = DomainParsimonyCalculator.createInstance( p0, gwcd_list );
5778             dp0.executeDolloParsimonyOnDomainPresence();
5779             final CharacterStateMatrix<GainLossStates> gl_matrix_d = dp0.getGainLossMatrix();
5780             final CharacterStateMatrix<BinaryStates> is_matrix_d = dp0.getInternalStatesMatrix();
5781             dp0.executeDolloParsimonyOnBinaryDomainCombintionPresence();
5782             final CharacterStateMatrix<GainLossStates> gl_matrix_bc = dp0.getGainLossMatrix();
5783             final CharacterStateMatrix<BinaryStates> is_matrix_bc = dp0.getInternalStatesMatrix();
5784             if ( is_matrix_d.getState( "root", "A" ) != X ) {
5785                 return false;
5786             }
5787             if ( is_matrix_d.getState( "root", "B" ) != X ) {
5788                 return false;
5789             }
5790             if ( is_matrix_d.getState( "root", "C" ) != O ) {
5791                 return false;
5792             }
5793             if ( is_matrix_d.getState( "root", "D" ) != O ) {
5794                 return false;
5795             }
5796             if ( is_matrix_d.getState( "root", "E" ) != X ) {
5797                 return false;
5798             }
5799             if ( is_matrix_bc.getState( "root", "A=A" ) != O ) {
5800                 return false;
5801             }
5802             if ( is_matrix_bc.getState( "root", "A=B" ) != X ) {
5803                 return false;
5804             }
5805             if ( is_matrix_bc.getState( "root", "A=C" ) != O ) {
5806                 return false;
5807             }
5808             if ( is_matrix_bc.getState( "root", "A=D" ) != O ) {
5809                 return false;
5810             }
5811             if ( is_matrix_bc.getState( "root", "G=H" ) != O ) {
5812                 return false;
5813             }
5814             if ( is_matrix_bc.getState( "1-2", "G=H" ) != O ) {
5815                 return false;
5816             }
5817             if ( is_matrix_bc.getState( "root", "E=F" ) != X ) {
5818                 return false;
5819             }
5820             if ( gl_matrix_bc.getState( "root", "E=F" ) != P ) {
5821                 return false;
5822             }
5823             if ( gl_matrix_bc.getState( "root", "A=A" ) != A ) {
5824                 return false;
5825             }
5826             if ( gl_matrix_bc.getState( "one", "A=A" ) != G ) {
5827                 return false;
5828             }
5829             if ( gl_matrix_bc.getState( "root", "A=B" ) != P ) {
5830                 return false;
5831             }
5832             if ( gl_matrix_bc.getState( "3-4", "A=D" ) != G ) {
5833                 return false;
5834             }
5835             if ( gl_matrix_bc.getState( "four", "E=F" ) != L ) {
5836                 return false;
5837             }
5838             if ( gl_matrix_d.getState( "3-4", "P" ) != G ) {
5839                 return false;
5840             }
5841         }
5842         catch ( final Exception e ) {
5843             e.printStackTrace( System.out );
5844             return false;
5845         }
5846         return true;
5847     }
5848
5849     private static boolean testParsimonyOnSecondaryFeatures() {
5850         try {
5851             final BinaryStates X = BinaryStates.PRESENT;
5852             final BinaryStates O = BinaryStates.ABSENT;
5853             final GainLossStates G = GainLossStates.GAIN;
5854             final GainLossStates L = GainLossStates.LOSS;
5855             final GainLossStates A = GainLossStates.UNCHANGED_ABSENT;
5856             final GainLossStates P = GainLossStates.UNCHANGED_PRESENT;
5857             final Domain a = new BasicDomain( "A", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5858             final Domain b = new BasicDomain( "B", 2, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5859             final Domain c = new BasicDomain( "C", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5860             final Domain d = new BasicDomain( "D", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5861             final Domain e = new BasicDomain( "E", 2, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5862             final Domain f = new BasicDomain( "F", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5863             final Domain g = new BasicDomain( "G", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5864             final Domain h = new BasicDomain( "H", 2, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5865             final Domain i = new BasicDomain( "I", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5866             final Domain j = new BasicDomain( "J", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5867             final Domain l = new BasicDomain( "L", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5868             final Domain m = new BasicDomain( "M", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5869             final Domain n = new BasicDomain( "N", 2, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5870             final Domain o = new BasicDomain( "O", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5871             final Domain p = new BasicDomain( "P", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5872             final Domain q = new BasicDomain( "Q", 2, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5873             final Domain r = new BasicDomain( "R", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5874             // 1 a-a a-b a-c e-f-g-h l-m
5875             // 2 a-b a-c e-f-g-i n-o
5876             // 3 a-b a-d e-f-g-j p-q
5877             // 4 a-b a-d p-r
5878             // 1 a-a a-b a-c e-f e-g e-h f-g f-h g-h l-m
5879             // 2 a-b a-c e-f e-g e-i f-g f-i g-i n-o
5880             // 3 a-b a-d e-f e-g e-j f-g f-j g-j p-q
5881             // 4 a-b a-d p-r
5882             // 1 a b c e f g h l m
5883             // 2 a b c e f g i n o
5884             // 3 a b d e f g j p q
5885             // 4 a b d p r
5886             final Protein aa1 = new BasicProtein( "aa1", "one", 0 );
5887             aa1.addProteinDomain( a );
5888             aa1.addProteinDomain( a );
5889             final Protein ab1 = new BasicProtein( "ab1", "one", 0 );
5890             ab1.addProteinDomain( a );
5891             ab1.addProteinDomain( b );
5892             final Protein ac1 = new BasicProtein( "ac1", "one", 0 );
5893             ac1.addProteinDomain( a );
5894             ac1.addProteinDomain( c );
5895             final Protein efgh1 = new BasicProtein( "efgh1", "one", 0 );
5896             efgh1.addProteinDomain( e );
5897             efgh1.addProteinDomain( f );
5898             efgh1.addProteinDomain( g );
5899             efgh1.addProteinDomain( h );
5900             final Protein lm1 = new BasicProtein( "lm1", "one", 0 );
5901             lm1.addProteinDomain( l );
5902             lm1.addProteinDomain( m );
5903             final Protein ab2 = new BasicProtein( "ab2", "two", 0 );
5904             ab2.addProteinDomain( a );
5905             ab2.addProteinDomain( b );
5906             final Protein ac2 = new BasicProtein( "ac2", "two", 0 );
5907             ac2.addProteinDomain( a );
5908             ac2.addProteinDomain( c );
5909             final Protein efgi2 = new BasicProtein( "efgi2", "two", 0 );
5910             efgi2.addProteinDomain( e );
5911             efgi2.addProteinDomain( f );
5912             efgi2.addProteinDomain( g );
5913             efgi2.addProteinDomain( i );
5914             final Protein no2 = new BasicProtein( "no2", "two", 0 );
5915             no2.addProteinDomain( n );
5916             no2.addProteinDomain( o );
5917             final Protein ab3 = new BasicProtein( "ab3", "three", 0 );
5918             ab3.addProteinDomain( a );
5919             ab3.addProteinDomain( b );
5920             final Protein ad3 = new BasicProtein( "ad3", "three", 0 );
5921             ad3.addProteinDomain( a );
5922             ad3.addProteinDomain( d );
5923             final Protein efgj3 = new BasicProtein( "efgj3", "three", 0 );
5924             efgj3.addProteinDomain( e );
5925             efgj3.addProteinDomain( f );
5926             efgj3.addProteinDomain( g );
5927             efgj3.addProteinDomain( j );
5928             final Protein pq3 = new BasicProtein( "pq3", "three", 0 );
5929             pq3.addProteinDomain( p );
5930             pq3.addProteinDomain( q );
5931             final Protein ab4 = new BasicProtein( "ab4", "four", 0 );
5932             ab4.addProteinDomain( a );
5933             ab4.addProteinDomain( b );
5934             final Protein ad4 = new BasicProtein( "ad4", "four", 0 );
5935             ad4.addProteinDomain( a );
5936             ad4.addProteinDomain( d );
5937             final Protein pr4 = new BasicProtein( "pr4", "four", 0 );
5938             pr4.addProteinDomain( p );
5939             pr4.addProteinDomain( r );
5940             final List<Protein> one_list = new ArrayList<Protein>();
5941             one_list.add( aa1 );
5942             one_list.add( ab1 );
5943             one_list.add( ac1 );
5944             one_list.add( efgh1 );
5945             one_list.add( lm1 );
5946             final List<Protein> two_list = new ArrayList<Protein>();
5947             two_list.add( ab2 );
5948             two_list.add( ac2 );
5949             two_list.add( efgi2 );
5950             two_list.add( no2 );
5951             final List<Protein> three_list = new ArrayList<Protein>();
5952             three_list.add( ab3 );
5953             three_list.add( ad3 );
5954             three_list.add( efgj3 );
5955             three_list.add( pq3 );
5956             final List<Protein> four_list = new ArrayList<Protein>();
5957             four_list.add( ab4 );
5958             four_list.add( ad4 );
5959             four_list.add( pr4 );
5960             final GenomeWideCombinableDomains one = BasicGenomeWideCombinableDomains
5961                     .createInstance( one_list, false, new BasicSpecies( "one" ) );
5962             final GenomeWideCombinableDomains two = BasicGenomeWideCombinableDomains
5963                     .createInstance( two_list, false, new BasicSpecies( "two" ) );
5964             final GenomeWideCombinableDomains three = BasicGenomeWideCombinableDomains
5965                     .createInstance( three_list, false, new BasicSpecies( "three" ) );
5966             final GenomeWideCombinableDomains four = BasicGenomeWideCombinableDomains
5967                     .createInstance( four_list, false, new BasicSpecies( "four" ) );
5968             final List<GenomeWideCombinableDomains> gwcd_list = new ArrayList<GenomeWideCombinableDomains>();
5969             gwcd_list.add( one );
5970             gwcd_list.add( two );
5971             gwcd_list.add( three );
5972             gwcd_list.add( four );
5973             final Map<DomainId, Set<String>> map_same = new HashMap<DomainId, Set<String>>();
5974             final HashSet<String> a_s = new HashSet<String>();
5975             a_s.add( "AAA" );
5976             final HashSet<String> b_s = new HashSet<String>();
5977             b_s.add( "BBB" );
5978             final HashSet<String> c_s = new HashSet<String>();
5979             c_s.add( "CCC" );
5980             final HashSet<String> d_s = new HashSet<String>();
5981             d_s.add( "DDD" );
5982             final HashSet<String> e_s = new HashSet<String>();
5983             e_s.add( "EEE" );
5984             final HashSet<String> f_s = new HashSet<String>();
5985             f_s.add( "FFF" );
5986             final HashSet<String> g_s = new HashSet<String>();
5987             g_s.add( "GGG" );
5988             final HashSet<String> h_s = new HashSet<String>();
5989             h_s.add( "HHH" );
5990             final HashSet<String> i_s = new HashSet<String>();
5991             i_s.add( "III" );
5992             final HashSet<String> j_s = new HashSet<String>();
5993             j_s.add( "JJJ" );
5994             final HashSet<String> l_s = new HashSet<String>();
5995             l_s.add( "LLL" );
5996             final HashSet<String> m_s = new HashSet<String>();
5997             m_s.add( "MMM" );
5998             final HashSet<String> n_s = new HashSet<String>();
5999             n_s.add( "NNN" );
6000             final HashSet<String> o_s = new HashSet<String>();
6001             o_s.add( "OOO" );
6002             final HashSet<String> p_s = new HashSet<String>();
6003             p_s.add( "PPP" );
6004             final HashSet<String> q_s = new HashSet<String>();
6005             q_s.add( "QQQ" );
6006             final HashSet<String> r_s = new HashSet<String>();
6007             r_s.add( "RRR" );
6008             map_same.put( a.getDomainId(), a_s );
6009             map_same.put( b.getDomainId(), b_s );
6010             map_same.put( c.getDomainId(), c_s );
6011             map_same.put( d.getDomainId(), d_s );
6012             map_same.put( e.getDomainId(), e_s );
6013             map_same.put( f.getDomainId(), f_s );
6014             map_same.put( g.getDomainId(), g_s );
6015             map_same.put( h.getDomainId(), h_s );
6016             map_same.put( i.getDomainId(), i_s );
6017             map_same.put( j.getDomainId(), j_s );
6018             map_same.put( l.getDomainId(), l_s );
6019             map_same.put( m.getDomainId(), m_s );
6020             map_same.put( n.getDomainId(), n_s );
6021             map_same.put( o.getDomainId(), o_s );
6022             map_same.put( p.getDomainId(), p_s );
6023             map_same.put( q.getDomainId(), q_s );
6024             map_same.put( r.getDomainId(), r_s );
6025             final CharacterStateMatrix<BinaryStates> matrix_s = DomainParsimonyCalculator
6026                     .createMatrixOfSecondaryFeaturePresenceOrAbsence( gwcd_list, map_same, null );
6027             // 1 a b c e f g h l m
6028             // 2 a b c e f g i n o
6029             // 3 a b d e f g j p q
6030             // 4 a b d p r
6031             if ( matrix_s.getState( 0, 0 ) != X ) {
6032                 return false;
6033             }
6034             if ( matrix_s.getState( 0, 1 ) != X ) {
6035                 return false;
6036             }
6037             if ( matrix_s.getState( 0, 2 ) != X ) {
6038                 return false;
6039             }
6040             if ( matrix_s.getState( 0, 3 ) != O ) {
6041                 return false;
6042             }
6043             if ( matrix_s.getState( 0, 4 ) != X ) {
6044                 return false;
6045             }
6046             if ( matrix_s.getState( 0, 5 ) != X ) {
6047                 return false;
6048             }
6049             if ( matrix_s.getState( 0, 6 ) != X ) {
6050                 return false;
6051             }
6052             if ( matrix_s.getState( 0, 7 ) != X ) {
6053                 return false;
6054             }
6055             if ( matrix_s.getState( 0, 8 ) != O ) {
6056                 return false;
6057             }
6058             final PhylogenyFactory factory0 = ParserBasedPhylogenyFactory.getInstance();
6059             final String p0_str = "((one,two)1-2,(three,four)3-4)root";
6060             final Phylogeny p0 = factory0.create( p0_str, new NHXParser() )[ 0 ];
6061             final DomainParsimonyCalculator dp0 = DomainParsimonyCalculator.createInstance( p0, gwcd_list, map_same );
6062             dp0.executeDolloParsimonyOnSecondaryFeatures( null );
6063             final CharacterStateMatrix<GainLossStates> gl_matrix_d = dp0.getGainLossMatrix();
6064             final CharacterStateMatrix<BinaryStates> is_matrix_d = dp0.getInternalStatesMatrix();
6065             if ( is_matrix_d.getState( "root", "AAA" ) != X ) {
6066                 return false;
6067             }
6068             if ( is_matrix_d.getState( "root", "BBB" ) != X ) {
6069                 return false;
6070             }
6071             if ( is_matrix_d.getState( "root", "CCC" ) != O ) {
6072                 return false;
6073             }
6074             if ( is_matrix_d.getState( "root", "DDD" ) != O ) {
6075                 return false;
6076             }
6077             if ( is_matrix_d.getState( "root", "EEE" ) != X ) {
6078                 return false;
6079             }
6080             if ( gl_matrix_d.getState( "3-4", "PPP" ) != G ) {
6081                 return false;
6082             }
6083         }
6084         catch ( final Exception e ) {
6085             e.printStackTrace( System.out );
6086             return false;
6087         }
6088         return true;
6089     }
6090
6091     private static boolean testPaupLogParser( final File test_dir ) {
6092         try {
6093             final PaupLogParser parser = new PaupLogParser();
6094             parser.setSource( new File( test_dir + ForesterUtil.getFileSeparator() + "paup_log_test_1" ) );
6095             final CharacterStateMatrix<BinaryStates> matrix = parser.parse();
6096             if ( matrix.getNumberOfIdentifiers() != 8 ) {
6097                 return false;
6098             }
6099             if ( !matrix.getIdentifier( 0 ).equals( "MOUSE" ) ) {
6100                 return false;
6101             }
6102             if ( !matrix.getIdentifier( 1 ).equals( "NEMVE" ) ) {
6103                 return false;
6104             }
6105             if ( !matrix.getIdentifier( 2 ).equals( "MONBE" ) ) {
6106                 return false;
6107             }
6108             if ( !matrix.getIdentifier( 3 ).equals( "DICDI" ) ) {
6109                 return false;
6110             }
6111             if ( !matrix.getIdentifier( 4 ).equals( "ARATH" ) ) {
6112                 return false;
6113             }
6114             if ( !matrix.getIdentifier( 5 ).equals( "6" ) ) {
6115                 return false;
6116             }
6117             if ( !matrix.getIdentifier( 6 ).equals( "7" ) ) {
6118                 return false;
6119             }
6120             if ( !matrix.getIdentifier( 7 ).equals( "8" ) ) {
6121                 return false;
6122             }
6123             if ( matrix.getNumberOfCharacters() != ( 66 + 66 + 28 ) ) {
6124                 return false;
6125             }
6126             if ( matrix.getState( 0, 4 ) != BinaryStates.ABSENT ) {
6127                 return false;
6128             }
6129             if ( matrix.getState( 0, 5 ) != BinaryStates.PRESENT ) {
6130                 return false;
6131             }
6132             if ( matrix.getState( 1, 5 ) != BinaryStates.PRESENT ) {
6133                 return false;
6134             }
6135             if ( matrix.getState( 7, 154 ) != BinaryStates.ABSENT ) {
6136                 return false;
6137             }
6138             if ( matrix.getState( 7, 155 ) != BinaryStates.PRESENT ) {
6139                 return false;
6140             }
6141             if ( matrix.getState( 7, 156 ) != BinaryStates.PRESENT ) {
6142                 return false;
6143             }
6144             if ( matrix.getState( 7, 157 ) != BinaryStates.ABSENT ) {
6145                 return false;
6146             }
6147             if ( matrix.getState( 7, 158 ) != BinaryStates.PRESENT ) {
6148                 return false;
6149             }
6150             if ( matrix.getState( 7, 159 ) != BinaryStates.ABSENT ) {
6151                 return false;
6152             }
6153         }
6154         catch ( final Exception e ) {
6155             e.printStackTrace( System.out );
6156             return false;
6157         }
6158         return true;
6159     }
6160
6161     private static boolean testProteinId() {
6162         try {
6163             final ProteinId id1 = new ProteinId( "a" );
6164             final ProteinId id2 = new ProteinId( "a" );
6165             final ProteinId id3 = new ProteinId( "A" );
6166             final ProteinId id4 = new ProteinId( "b" );
6167             if ( !id1.equals( id1 ) ) {
6168                 return false;
6169             }
6170             if ( id1.getId().equals( "x" ) ) {
6171                 return false;
6172             }
6173             if ( id1.getId().equals( null ) ) {
6174                 return false;
6175             }
6176             if ( !id1.equals( id2 ) ) {
6177                 return false;
6178             }
6179             if ( id1.equals( id3 ) ) {
6180                 return false;
6181             }
6182             if ( id1.hashCode() != id1.hashCode() ) {
6183                 return false;
6184             }
6185             if ( id1.hashCode() != id2.hashCode() ) {
6186                 return false;
6187             }
6188             if ( id1.hashCode() == id3.hashCode() ) {
6189                 return false;
6190             }
6191             if ( id1.compareTo( id1 ) != 0 ) {
6192                 return false;
6193             }
6194             if ( id1.compareTo( id2 ) != 0 ) {
6195                 return false;
6196             }
6197             if ( id1.compareTo( id3 ) != 0 ) {
6198                 return false;
6199             }
6200             if ( id1.compareTo( id4 ) >= 0 ) {
6201                 return false;
6202             }
6203             if ( id4.compareTo( id1 ) <= 0 ) {
6204                 return false;
6205             }
6206             if ( !id4.getId().equals( "b" ) ) {
6207                 return false;
6208             }
6209             final ProteinId id5 = new ProteinId( " C " );
6210             if ( !id5.getId().equals( "C" ) ) {
6211                 return false;
6212             }
6213             if ( id5.equals( id1 ) ) {
6214                 return false;
6215             }
6216         }
6217         catch ( final Exception e ) {
6218             e.printStackTrace( System.out );
6219             return false;
6220         }
6221         return true;
6222     }
6223
6224     private static boolean testSpecies() {
6225         try {
6226             final Species s1 = new BasicSpecies( "a" );
6227             final Species s2 = new BasicSpecies( "a" );
6228             final Species s3 = new BasicSpecies( "A" );
6229             final Species s4 = new BasicSpecies( "b" );
6230             if ( !s1.equals( s1 ) ) {
6231                 return false;
6232             }
6233             if ( s1.getSpeciesId().equals( "x" ) ) {
6234                 return false;
6235             }
6236             if ( s1.getSpeciesId().equals( null ) ) {
6237                 return false;
6238             }
6239             if ( !s1.equals( s2 ) ) {
6240                 return false;
6241             }
6242             if ( s1.equals( s3 ) ) {
6243                 return false;
6244             }
6245             if ( s1.hashCode() != s1.hashCode() ) {
6246                 return false;
6247             }
6248             if ( s1.hashCode() != s2.hashCode() ) {
6249                 return false;
6250             }
6251             if ( s1.hashCode() == s3.hashCode() ) {
6252                 return false;
6253             }
6254             if ( s1.compareTo( s1 ) != 0 ) {
6255                 return false;
6256             }
6257             if ( s1.compareTo( s2 ) != 0 ) {
6258                 return false;
6259             }
6260             if ( s1.compareTo( s3 ) != 0 ) {
6261                 return false;
6262             }
6263             if ( s1.compareTo( s4 ) >= 0 ) {
6264                 return false;
6265             }
6266             if ( s4.compareTo( s1 ) <= 0 ) {
6267                 return false;
6268             }
6269             if ( !s4.getSpeciesId().equals( "b" ) ) {
6270                 return false;
6271             }
6272             final Species s5 = new BasicSpecies( " C " );
6273             if ( !s5.getSpeciesId().equals( "C" ) ) {
6274                 return false;
6275             }
6276             if ( s5.equals( s1 ) ) {
6277                 return false;
6278             }
6279         }
6280         catch ( final Exception e ) {
6281             e.printStackTrace( System.out );
6282             return false;
6283         }
6284         return true;
6285     }
6286 }