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