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