in progress
[jalview.git] / forester / java / src / org / forester / surfacing / TestSurfacing.java
1 // $Id:
2 //
3 // FORESTER -- software libraries and applications
4 // for evolutionary biology research and applications.
5 //
6 // Copyright (C) 2008-2009 Christian M. Zmasek
7 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
8 // All rights reserved
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 //
24 // Contact: phylosoft @ gmail . com
25 // WWW: www.phylosoft.org/forester
26
27 package org.forester.surfacing;
28
29 import java.io.File;
30 import java.util.ArrayList;
31 import java.util.HashMap;
32 import java.util.HashSet;
33 import java.util.Iterator;
34 import java.util.List;
35 import java.util.Map;
36 import java.util.Set;
37 import java.util.SortedSet;
38 import java.util.TreeSet;
39
40 import org.forester.evoinference.matrix.character.BasicCharacterStateMatrix;
41 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
42 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
43 import org.forester.evoinference.matrix.character.CharacterStateMatrix.GainLossStates;
44 import org.forester.io.parsers.HmmPfamOutputParser;
45 import org.forester.io.parsers.nexus.PaupLogParser;
46 import org.forester.io.parsers.nhx.NHXParser;
47 import org.forester.phylogeny.Phylogeny;
48 import org.forester.phylogeny.PhylogenyNode;
49 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
50 import org.forester.phylogeny.factories.PhylogenyFactory;
51 import org.forester.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                 System.out.println( s9.toString() );
1598                 return false;
1599             }
1600             if ( !s0.equals( s0 ) ) {
1601                 return false;
1602             }
1603             if ( s0.equals( s1 ) ) {
1604                 return false;
1605             }
1606             if ( s1.equals( s0 ) ) {
1607                 return false;
1608             }
1609             if ( !s1.equals( s2 ) ) {
1610                 return false;
1611             }
1612             if ( !s2.equals( s1 ) ) {
1613                 return false;
1614             }
1615             if ( s2.equals( s3 ) ) {
1616                 return false;
1617             }
1618             if ( s2.equals( s3 ) ) {
1619                 return false;
1620             }
1621             if ( s2.equals( s4 ) ) {
1622                 return false;
1623             }
1624             final SortedSet<BasicBinaryDomainCombination> sorted = new TreeSet<BasicBinaryDomainCombination>();
1625             sorted.add( s0 );
1626             sorted.add( s1 );
1627             sorted.add( s2 );
1628             sorted.add( s3 );
1629             sorted.add( s3 );
1630             sorted.add( s3 );
1631             sorted.add( s4 );
1632             sorted.add( s5 );
1633             sorted.add( s6 );
1634             sorted.add( s7 );
1635             sorted.add( s7 );
1636             sorted.add( s8 );
1637             if ( sorted.size() != 6 ) {
1638                 return false;
1639             }
1640             final DirectedBinaryDomainCombination aa = new DirectedBinaryDomainCombination( "a", "a" );
1641             final DirectedBinaryDomainCombination ba = new DirectedBinaryDomainCombination( "b", "a" );
1642             final DirectedBinaryDomainCombination ab = new DirectedBinaryDomainCombination( "a", "b" );
1643             final DirectedBinaryDomainCombination bb = new DirectedBinaryDomainCombination( "b", "b" );
1644             if ( !aa.equals( aa ) ) {
1645                 return false;
1646             }
1647             if ( aa.equals( bb ) ) {
1648                 return false;
1649             }
1650             if ( ab.equals( ba ) ) {
1651                 return false;
1652             }
1653             if ( ba.equals( ab ) ) {
1654                 return false;
1655             }
1656             if ( !ab.equals( ab ) ) {
1657                 return false;
1658             }
1659             if ( ab.equals( aa ) ) {
1660                 return false;
1661             }
1662             if ( ab.equals( bb ) ) {
1663                 return false;
1664             }
1665         }
1666         catch ( final Exception e ) {
1667             e.printStackTrace( System.out );
1668             return false;
1669         }
1670         return true;
1671     }
1672
1673     private static boolean testBinaryStateMatrixToGainLossMatrix( final File test_dir ) {
1674         final BinaryStates I = BinaryStates.PRESENT;
1675         final BinaryStates O = BinaryStates.ABSENT;
1676         try {
1677             final CharacterStateMatrix<BinaryStates> binary_states_matrix_0 = new BasicCharacterStateMatrix<BinaryStates>( 7,
1678                                                                                                                            6 );
1679             binary_states_matrix_0.setIdentifier( 0, "A" );
1680             binary_states_matrix_0.setIdentifier( 1, "B" );
1681             binary_states_matrix_0.setIdentifier( 2, "C" );
1682             binary_states_matrix_0.setIdentifier( 3, "D" );
1683             binary_states_matrix_0.setIdentifier( 4, "1" );
1684             binary_states_matrix_0.setIdentifier( 5, "2" );
1685             binary_states_matrix_0.setIdentifier( 6, "3" );
1686             binary_states_matrix_0.setState( 0, 0, O );
1687             binary_states_matrix_0.setState( 1, 0, O );
1688             binary_states_matrix_0.setState( 2, 0, O );
1689             binary_states_matrix_0.setState( 3, 0, O );
1690             binary_states_matrix_0.setState( 4, 0, O );
1691             binary_states_matrix_0.setState( 5, 0, O );
1692             binary_states_matrix_0.setState( 6, 0, O );
1693             binary_states_matrix_0.setState( 0, 1, I );
1694             binary_states_matrix_0.setState( 1, 1, O );
1695             binary_states_matrix_0.setState( 2, 1, O );
1696             binary_states_matrix_0.setState( 3, 1, O );
1697             binary_states_matrix_0.setState( 4, 1, O );
1698             binary_states_matrix_0.setState( 5, 1, O );
1699             binary_states_matrix_0.setState( 6, 1, O );
1700             binary_states_matrix_0.setState( 0, 2, O );
1701             binary_states_matrix_0.setState( 1, 2, O );
1702             binary_states_matrix_0.setState( 2, 2, O );
1703             binary_states_matrix_0.setState( 3, 2, O );
1704             binary_states_matrix_0.setState( 4, 2, I );
1705             binary_states_matrix_0.setState( 5, 2, O );
1706             binary_states_matrix_0.setState( 6, 2, O );
1707             binary_states_matrix_0.setState( 0, 3, I );
1708             binary_states_matrix_0.setState( 1, 3, O );
1709             binary_states_matrix_0.setState( 2, 3, O );
1710             binary_states_matrix_0.setState( 3, 3, O );
1711             binary_states_matrix_0.setState( 4, 3, I );
1712             binary_states_matrix_0.setState( 5, 3, O );
1713             binary_states_matrix_0.setState( 6, 3, I );
1714             binary_states_matrix_0.setState( 0, 4, I );
1715             binary_states_matrix_0.setState( 1, 4, O );
1716             binary_states_matrix_0.setState( 2, 4, I );
1717             binary_states_matrix_0.setState( 3, 4, O );
1718             binary_states_matrix_0.setState( 4, 4, I );
1719             binary_states_matrix_0.setState( 5, 4, O );
1720             binary_states_matrix_0.setState( 6, 4, I );
1721             binary_states_matrix_0.setState( 0, 5, I );
1722             binary_states_matrix_0.setState( 1, 5, I );
1723             binary_states_matrix_0.setState( 2, 5, I );
1724             binary_states_matrix_0.setState( 3, 5, I );
1725             binary_states_matrix_0.setState( 4, 5, I );
1726             binary_states_matrix_0.setState( 5, 5, I );
1727             binary_states_matrix_0.setState( 6, 5, I );
1728             final String[] character_labels_0 = new String[ 6 ];
1729             character_labels_0[ 0 ] = "first";
1730             character_labels_0[ 1 ] = "second";
1731             character_labels_0[ 2 ] = "third";
1732             character_labels_0[ 3 ] = "forth";
1733             character_labels_0[ 4 ] = "fifth";
1734             character_labels_0[ 5 ] = "sixth";
1735             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1736             final Phylogeny phylogeny_0 = factory.create( "(((A,B)1,C)2,D)3", new NHXParser() )[ 0 ];
1737             final DomainParsimonyCalculator dom_pars = DomainParsimonyCalculator.createInstance( phylogeny_0 );
1738             dom_pars.executeOnGivenBinaryStatesMatrix( binary_states_matrix_0, character_labels_0 );
1739             final CharacterStateMatrix<GainLossStates> gl_matrix_0 = dom_pars.getGainLossMatrix();
1740             // final StringWriter sw = new StringWriter();
1741             //  gl_matrix_0.toWriter( sw );
1742             // System.out.println( sw.toString() );
1743             if ( dom_pars.getCost() != 13 ) {
1744                 return false;
1745             }
1746             if ( dom_pars.getTotalGains() != 5 ) {
1747                 return false;
1748             }
1749             if ( dom_pars.getTotalLosses() != 8 ) {
1750                 return false;
1751             }
1752             if ( dom_pars.getTotalUnchanged() != 29 ) {
1753                 return false;
1754             }
1755             if ( gl_matrix_0.getState( "A", 1 ) != GainLossStates.GAIN ) {
1756                 return false;
1757             }
1758             if ( gl_matrix_0.getState( "A", 4 ) != GainLossStates.UNCHANGED_PRESENT ) {
1759                 return false;
1760             }
1761             if ( gl_matrix_0.getState( "B", 4 ) != GainLossStates.LOSS ) {
1762                 return false;
1763             }
1764             if ( gl_matrix_0.getState( "C", 4 ) != GainLossStates.GAIN ) {
1765                 return false;
1766             }
1767             if ( gl_matrix_0.getState( "D", 4 ) != GainLossStates.LOSS ) {
1768                 return false;
1769             }
1770             if ( gl_matrix_0.getState( "1", 4 ) != GainLossStates.GAIN ) {
1771                 return false;
1772             }
1773             if ( gl_matrix_0.getState( "2", 4 ) != GainLossStates.LOSS ) {
1774                 return false;
1775             }
1776             if ( gl_matrix_0.getState( "3", 4 ) != GainLossStates.UNCHANGED_PRESENT ) {
1777                 return false;
1778             }
1779         }
1780         catch ( final Exception e ) {
1781             e.printStackTrace( System.out );
1782             return false;
1783         }
1784         return true;
1785     }
1786
1787     private static boolean testCombinableDomains() {
1788         try {
1789             final Domain key0 = new BasicDomain( "key0", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1790             final Domain a = new BasicDomain( "a", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1791             final Domain b = new BasicDomain( "b", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1792             final Domain c = new BasicDomain( "c", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1793             final CombinableDomains cd0 = new BasicCombinableDomains( key0.getDomainId(), new BasicSpecies( "eel" ) );
1794             cd0.addCombinableDomain( a.getDomainId() );
1795             cd0.addCombinableDomain( b.getDomainId() );
1796             cd0.addCombinableDomain( b.getDomainId() );
1797             cd0.addCombinableDomain( c.getDomainId() );
1798             cd0.addCombinableDomain( c.getDomainId() );
1799             cd0.addCombinableDomain( c.getDomainId() );
1800             if ( cd0.getNumberOfCombinableDomains() != 3 ) {
1801                 return false;
1802             }
1803             if ( cd0.getNumberOfProteinsExhibitingCombination( a.getDomainId() ) != 1 ) {
1804                 return false;
1805             }
1806             if ( cd0.getNumberOfProteinsExhibitingCombination( b.getDomainId() ) != 2 ) {
1807                 return false;
1808             }
1809             if ( cd0.getNumberOfProteinsExhibitingCombination( c.getDomainId() ) != 3 ) {
1810                 return false;
1811             }
1812             if ( cd0.getNumberOfProteinsExhibitingCombination( key0.getDomainId() ) != 0 ) {
1813                 return false;
1814             }
1815             if ( cd0.getAllDomains().size() != 4 ) {
1816                 return false;
1817             }
1818             if ( !cd0.getAllDomains().contains( a.getDomainId() ) ) {
1819                 return false;
1820             }
1821             if ( !cd0.getAllDomains().contains( b.getDomainId() ) ) {
1822                 return false;
1823             }
1824             if ( !cd0.getAllDomains().contains( c.getDomainId() ) ) {
1825                 return false;
1826             }
1827             if ( !cd0.getAllDomains().contains( key0.getDomainId() ) ) {
1828                 return false;
1829             }
1830             if ( cd0.toBinaryDomainCombinations().size() != 3 ) {
1831                 return false;
1832             }
1833             final BasicBinaryDomainCombination s0 = new BasicBinaryDomainCombination( "key0", "a" );
1834             final BasicBinaryDomainCombination s1 = new BasicBinaryDomainCombination( "b", "key0" );
1835             final BasicBinaryDomainCombination s2 = new BasicBinaryDomainCombination( "key0", "c" );
1836             final BasicBinaryDomainCombination s3 = new BasicBinaryDomainCombination( "key0", "cc" );
1837             final BasicBinaryDomainCombination s4 = new BasicBinaryDomainCombination( "c", "key0" );
1838             if ( !cd0.toBinaryDomainCombinations().contains( s0 ) ) {
1839                 return false;
1840             }
1841             if ( !cd0.toBinaryDomainCombinations().contains( s1 ) ) {
1842                 return false;
1843             }
1844             if ( !cd0.toBinaryDomainCombinations().contains( s2 ) ) {
1845                 return false;
1846             }
1847             if ( cd0.toBinaryDomainCombinations().contains( s3 ) ) {
1848                 return false;
1849             }
1850             if ( !cd0.toBinaryDomainCombinations().contains( s4 ) ) {
1851                 return false;
1852             }
1853             final Domain key1 = new BasicDomain( "key1", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1854             final Domain a1 = new BasicDomain( "a1", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1855             final Domain b1 = new BasicDomain( "b1", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1856             final Domain c1 = new BasicDomain( "c1", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1857             final CombinableDomains cd1 = new BasicCombinableDomains( key1.getDomainId(), new BasicSpecies( "eel" ) );
1858             cd1.addCombinableDomain( a1.getDomainId() );
1859             cd1.addCombinableDomain( b1.getDomainId() );
1860             cd1.addCombinableDomain( c1.getDomainId() );
1861             cd1.addCombinableDomain( key1.getDomainId() );
1862             if ( cd1.getNumberOfCombinableDomains() != 4 ) {
1863                 return false;
1864             }
1865             if ( cd1.getNumberOfProteinsExhibitingCombination( a1.getDomainId() ) != 1 ) {
1866                 return false;
1867             }
1868             if ( cd1.getNumberOfProteinsExhibitingCombination( b1.getDomainId() ) != 1 ) {
1869                 return false;
1870             }
1871             if ( cd1.getNumberOfProteinsExhibitingCombination( c1.getDomainId() ) != 1 ) {
1872                 return false;
1873             }
1874             if ( cd1.getNumberOfProteinsExhibitingCombination( key1.getDomainId() ) != 1 ) {
1875                 return false;
1876             }
1877             if ( cd1.getAllDomains().size() != 4 ) {
1878                 return false;
1879             }
1880             if ( cd1.toBinaryDomainCombinations().size() != 4 ) {
1881                 return false;
1882             }
1883             final BasicBinaryDomainCombination kk = new BasicBinaryDomainCombination( "key1", "key1" );
1884             if ( !cd1.toBinaryDomainCombinations().contains( kk ) ) {
1885                 return false;
1886             }
1887         }
1888         catch ( final Exception e ) {
1889             e.printStackTrace( System.out );
1890             return false;
1891         }
1892         return true;
1893     }
1894
1895     private static boolean testCombinationsBasedPairwiseSimilarityCalculator() {
1896         try {
1897             final Domain a = new BasicDomain( "A", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1898             final Domain b = new BasicDomain( "B", 2, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1899             final Domain c = new BasicDomain( "C", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1900             final Domain one_key = new BasicDomain( "bcl2", 4, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1901             final Domain two_key = new BasicDomain( "bcl2", 5, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1902             final CombinableDomains one = new BasicCombinableDomains( one_key.getDomainId(), new BasicSpecies( "mouse" ) );
1903             final CombinableDomains two = new BasicCombinableDomains( two_key.getDomainId(),
1904                                                                       new BasicSpecies( "rabbit" ) );
1905             one.addCombinableDomain( a.getDomainId() );
1906             one.addCombinableDomain( a.getDomainId() );
1907             two.addCombinableDomain( new BasicDomain( "A", 1, 5, ( short ) 1, ( short ) 4, 0.1, -12 ).getDomainId() );
1908             two.addCombinableDomain( b.getDomainId() );
1909             two.addCombinableDomain( c.getDomainId() );
1910             final PairwiseDomainSimilarityCalculator calc = new CombinationsBasedPairwiseDomainSimilarityCalculator();
1911             final PairwiseDomainSimilarity s1 = calc.calculateSimilarity( one, two );
1912             if ( !TestSurfacing.isEqual( s1.getSimilarityScore(), 1.0 / ( 1 + 2 ) ) ) {
1913                 return false;
1914             }
1915             if ( s1.getDifferenceInCounts() != ( 1 - 3 ) ) {
1916                 return false;
1917             }
1918             if ( ( ( CombinationsBasedPairwiseDomainSimilarity ) s1 ).getNumberOfDifferentDomains() != 2 ) {
1919                 return false;
1920             }
1921             one.addCombinableDomain( b.getDomainId() );
1922             one.addCombinableDomain( c.getDomainId() );
1923             final PairwiseDomainSimilarity s2 = calc.calculateSimilarity( one, two );
1924             if ( !TestSurfacing.isEqual( s2.getSimilarityScore(), 3.0 / ( 0 + 3 ) ) ) {
1925                 return false;
1926             }
1927             if ( s2.getDifferenceInCounts() != 0 ) {
1928                 return false;
1929             }
1930             if ( ( ( CombinationsBasedPairwiseDomainSimilarity ) s2 ).getNumberOfDifferentDomains() != 0 ) {
1931                 return false;
1932             }
1933             final Domain d = new BasicDomain( "D", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1934             final Domain e = new BasicDomain( "E", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1935             final Domain f = new BasicDomain( "F", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1936             one.addCombinableDomain( d.getDomainId() );
1937             one.addCombinableDomain( d.getDomainId() );
1938             one.addCombinableDomain( e.getDomainId() );
1939             one.addCombinableDomain( f.getDomainId() );
1940             final PairwiseDomainSimilarity s3 = calc.calculateSimilarity( one, two );
1941             if ( !TestSurfacing.isEqual( s3.getSimilarityScore(), 3.0 / ( 3 + 3 ) ) ) {
1942                 return false;
1943             }
1944             if ( s3.getDifferenceInCounts() != ( 6 - 3 ) ) {
1945                 return false;
1946             }
1947             if ( ( ( CombinationsBasedPairwiseDomainSimilarity ) s3 ).getNumberOfDifferentDomains() != 3 ) {
1948                 return false;
1949             }
1950             final Domain aaa = new BasicDomain( "aaa", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1951             final Domain bbb = new BasicDomain( "bbb", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1952             final Domain three_key = new BasicDomain( "bcl2", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1953             final Domain four_key = new BasicDomain( "bcl2", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1954             final CombinableDomains three = new BasicCombinableDomains( three_key.getDomainId(),
1955                                                                         new BasicSpecies( "mouse" ) );
1956             final CombinableDomains four = new BasicCombinableDomains( four_key.getDomainId(),
1957                                                                        new BasicSpecies( "rabbit" ) );
1958             three.addCombinableDomain( aaa.getDomainId() );
1959             four.addCombinableDomain( bbb.getDomainId() );
1960             final PairwiseDomainSimilarityCalculator calc2 = new CombinationsBasedPairwiseDomainSimilarityCalculator();
1961             final PairwiseDomainSimilarity s4 = calc2.calculateSimilarity( three, four );
1962             if ( !TestSurfacing.isEqual( s4.getSimilarityScore(), 0.0 / ( 0 + 2 ) ) ) {
1963                 return false;
1964             }
1965             final Domain aaa2 = new BasicDomain( "aaa", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1966             four.addCombinableDomain( aaa2.getDomainId() );
1967             final PairwiseDomainSimilarity s5 = calc.calculateSimilarity( three, four );
1968             if ( !TestSurfacing.isEqual( s5.getSimilarityScore(), 1.0 / ( 1 + 1 ) ) ) {
1969                 return false;
1970             }
1971         }
1972         catch ( final Exception e ) {
1973             e.printStackTrace( System.out );
1974             return false;
1975         }
1976         return true;
1977     }
1978
1979     private static boolean testCopyNumberBasedPairwiseSimilarityCalculator() {
1980         try {
1981             final Domain one_key = new BasicDomain( "bcl2", 4, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1982             final Domain two_key = new BasicDomain( "bcl2", 5, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1983             final CombinableDomains one = new BasicCombinableDomains( one_key.getDomainId(), new BasicSpecies( "mouse" ) );
1984             final CombinableDomains two = new BasicCombinableDomains( two_key.getDomainId(),
1985                                                                       new BasicSpecies( "rabbit" ) );
1986             one.setKeyDomainCount( 2 );
1987             two.setKeyDomainCount( 3 );
1988             final PairwiseDomainSimilarityCalculator calc = new DomainCountsBasedPairwiseSimilarityCalculator();
1989             PairwiseDomainSimilarity s1 = calc.calculateSimilarity( one, two );
1990             if ( !TestSurfacing.isEqual( s1.getSimilarityScore(), 1.0 - ( 3 - 2.0 ) / ( 2 + 3 ) ) ) {
1991                 return false;
1992             }
1993             if ( s1.getDifferenceInCounts() != ( 2 - 3 ) ) {
1994                 return false;
1995             }
1996             one.setKeyDomainCount( 1 );
1997             two.setKeyDomainCount( 1 );
1998             s1 = calc.calculateSimilarity( one, two );
1999             if ( !TestSurfacing.isEqual( s1.getSimilarityScore(), 1.0 ) ) {
2000                 return false;
2001             }
2002             if ( s1.getDifferenceInCounts() != ( 1 - 1 ) ) {
2003                 return false;
2004             }
2005             one.setKeyDomainCount( 1 );
2006             two.setKeyDomainCount( 1000 );
2007             s1 = calc.calculateSimilarity( one, two );
2008             if ( !TestSurfacing.isEqual( s1.getSimilarityScore(), 1.0 - 999.0 / 1001 ) ) {
2009                 return false;
2010             }
2011             if ( s1.getDifferenceInCounts() != ( 1 - 1000 ) ) {
2012                 return false;
2013             }
2014         }
2015         catch ( final Exception e ) {
2016             e.printStackTrace( System.out );
2017             return false;
2018         }
2019         return true;
2020     }
2021
2022     private static boolean testDirectedCombinableDomains() {
2023         try {
2024             final Domain key0 = new BasicDomain( "key0", 10, 20, ( short ) 1, ( short ) 4, 0.1, -12 );
2025             final Domain a = new BasicDomain( "a", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2026             final Domain b = new BasicDomain( "b", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2027             final Domain c = new BasicDomain( "c", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2028             final CombinableDomains cd0 = new DirectedCombinableDomains( key0.getDomainId(), new BasicSpecies( "eel" ) );
2029             cd0.addCombinableDomain( a.getDomainId() );
2030             cd0.addCombinableDomain( b.getDomainId() );
2031             cd0.addCombinableDomain( b.getDomainId() );
2032             cd0.addCombinableDomain( c.getDomainId() );
2033             cd0.addCombinableDomain( c.getDomainId() );
2034             cd0.addCombinableDomain( c.getDomainId() );
2035             if ( cd0.getNumberOfCombinableDomains() != 3 ) {
2036                 return false;
2037             }
2038             if ( cd0.getNumberOfProteinsExhibitingCombination( a.getDomainId() ) != 1 ) {
2039                 return false;
2040             }
2041             if ( cd0.getNumberOfProteinsExhibitingCombination( b.getDomainId() ) != 2 ) {
2042                 return false;
2043             }
2044             if ( cd0.getNumberOfProteinsExhibitingCombination( c.getDomainId() ) != 3 ) {
2045                 return false;
2046             }
2047             if ( cd0.getNumberOfProteinsExhibitingCombination( key0.getDomainId() ) != 0 ) {
2048                 return false;
2049             }
2050             if ( cd0.getAllDomains().size() != 4 ) {
2051                 return false;
2052             }
2053             if ( !cd0.getAllDomains().contains( a.getDomainId() ) ) {
2054                 return false;
2055             }
2056             if ( !cd0.getAllDomains().contains( b.getDomainId() ) ) {
2057                 return false;
2058             }
2059             if ( !cd0.getAllDomains().contains( c.getDomainId() ) ) {
2060                 return false;
2061             }
2062             if ( !cd0.getAllDomains().contains( key0.getDomainId() ) ) {
2063                 return false;
2064             }
2065             if ( cd0.toBinaryDomainCombinations().size() != 3 ) {
2066                 return false;
2067             }
2068             final BinaryDomainCombination s0 = new DirectedBinaryDomainCombination( "key0", "a" );
2069             final BinaryDomainCombination s1 = new DirectedBinaryDomainCombination( "b", "key0" );
2070             final BinaryDomainCombination s2 = new DirectedBinaryDomainCombination( "key0", "c" );
2071             final BinaryDomainCombination s3 = new DirectedBinaryDomainCombination( "key0", "cc" );
2072             final BinaryDomainCombination s4 = new DirectedBinaryDomainCombination( "a", "b" );
2073             final BinaryDomainCombination s5 = new DirectedBinaryDomainCombination( "b", "a" );
2074             final BinaryDomainCombination s6 = new DirectedBinaryDomainCombination( "key0", "b" );
2075             final BinaryDomainCombination s7 = new DirectedBinaryDomainCombination( "a", "key0" );
2076             final BinaryDomainCombination s8 = new DirectedBinaryDomainCombination( "c", "key0" );
2077             if ( !cd0.toBinaryDomainCombinations().contains( s0 ) ) {
2078                 return false;
2079             }
2080             if ( cd0.toBinaryDomainCombinations().contains( s1 ) ) {
2081                 return false;
2082             }
2083             if ( !cd0.toBinaryDomainCombinations().contains( s2 ) ) {
2084                 return false;
2085             }
2086             if ( cd0.toBinaryDomainCombinations().contains( s3 ) ) {
2087                 return false;
2088             }
2089             if ( cd0.toBinaryDomainCombinations().contains( s4 ) ) {
2090                 return false;
2091             }
2092             if ( cd0.toBinaryDomainCombinations().contains( s5 ) ) {
2093                 return false;
2094             }
2095             if ( !cd0.toBinaryDomainCombinations().contains( s6 ) ) {
2096                 return false;
2097             }
2098             if ( cd0.toBinaryDomainCombinations().contains( s7 ) ) {
2099                 return false;
2100             }
2101             if ( cd0.toBinaryDomainCombinations().contains( s8 ) ) {
2102                 return false;
2103             }
2104             final Domain key1 = new BasicDomain( "key1", 1, 2, ( short ) 1, ( short ) 4, 0.1, -12 );
2105             final Domain a1 = new BasicDomain( "a1", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2106             final Domain b1 = new BasicDomain( "b1", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2107             final Domain c1 = new BasicDomain( "c1", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2108             final CombinableDomains cd1 = new DirectedCombinableDomains( key1.getDomainId(), new BasicSpecies( "eel" ) );
2109             cd1.addCombinableDomain( a1.getDomainId() );
2110             cd1.addCombinableDomain( b1.getDomainId() );
2111             cd1.addCombinableDomain( c1.getDomainId() );
2112             cd1.addCombinableDomain( key1.getDomainId() );
2113             if ( cd1.getNumberOfCombinableDomains() != 4 ) {
2114                 return false;
2115             }
2116             if ( cd1.getNumberOfProteinsExhibitingCombination( a1.getDomainId() ) != 1 ) {
2117                 return false;
2118             }
2119             if ( cd1.getNumberOfProteinsExhibitingCombination( b1.getDomainId() ) != 1 ) {
2120                 return false;
2121             }
2122             if ( cd1.getNumberOfProteinsExhibitingCombination( c1.getDomainId() ) != 1 ) {
2123                 return false;
2124             }
2125             if ( cd1.getNumberOfProteinsExhibitingCombination( key1.getDomainId() ) != 1 ) {
2126                 return false;
2127             }
2128             if ( cd1.getAllDomains().size() != 4 ) {
2129                 return false;
2130             }
2131             if ( cd1.toBinaryDomainCombinations().size() != 4 ) {
2132                 return false;
2133             }
2134             final BinaryDomainCombination kk = new DirectedBinaryDomainCombination( "key1", "key1" );
2135             if ( !cd1.toBinaryDomainCombinations().contains( kk ) ) {
2136                 return false;
2137             }
2138         }
2139         catch ( final Exception e ) {
2140             e.printStackTrace( System.out );
2141             return false;
2142         }
2143         return true;
2144     }
2145
2146     private static boolean testDirectedness() {
2147         try {
2148             final BinaryStates X = BinaryStates.PRESENT;
2149             final BinaryStates O = BinaryStates.ABSENT;
2150             final GainLossStates G = GainLossStates.GAIN;
2151             final GainLossStates L = GainLossStates.LOSS;
2152             final GainLossStates A = GainLossStates.UNCHANGED_ABSENT;
2153             final GainLossStates P = GainLossStates.UNCHANGED_PRESENT;
2154             final Protein one_1 = new BasicProtein( "one", "1" );
2155             final Protein two_1 = new BasicProtein( "two", "1" );
2156             final Protein three_1 = new BasicProtein( "three", "1" );
2157             final Protein four_1 = new BasicProtein( "four", "1" );
2158             final Protein five_1 = new BasicProtein( "five", "1" );
2159             one_1.addProteinDomain( new BasicDomain( "B", 12, 14, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2160             one_1.addProteinDomain( new BasicDomain( "C", 13, 14, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2161             one_1.addProteinDomain( new BasicDomain( "A", 11, 12, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2162             one_1.addProteinDomain( new BasicDomain( "X", 100, 110, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2163             one_1.addProteinDomain( new BasicDomain( "Y", 200, 210, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2164             two_1.addProteinDomain( new BasicDomain( "A", 10, 20, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2165             two_1.addProteinDomain( new BasicDomain( "B", 30, 40, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2166             two_1.addProteinDomain( new BasicDomain( "Y", 1, 2, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2167             two_1.addProteinDomain( new BasicDomain( "X", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2168             three_1.addProteinDomain( new BasicDomain( "P", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2169             three_1.addProteinDomain( new BasicDomain( "M", 1, 2, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2170             three_1.addProteinDomain( new BasicDomain( "M", 5, 6, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2171             three_1.addProteinDomain( new BasicDomain( "N", 7, 8, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2172             three_1.addProteinDomain( new BasicDomain( "N", 3, 4, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2173             four_1.addProteinDomain( new BasicDomain( "XX", 10, 20, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2174             five_1.addProteinDomain( new BasicDomain( "YY", 30, 40, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2175             final List<Protein> list_1 = new ArrayList<Protein>();
2176             list_1.add( one_1 );
2177             list_1.add( two_1 );
2178             list_1.add( three_1 );
2179             list_1.add( four_1 );
2180             list_1.add( five_1 );
2181             final GenomeWideCombinableDomains gwcd_1 = BasicGenomeWideCombinableDomains
2182                     .createInstance( list_1, false, new BasicSpecies( "1" ), DomainCombinationType.DIRECTED );
2183             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "A", "B" ) ) ) {
2184                 return false;
2185             }
2186             if ( gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "B", "A" ) ) ) {
2187                 return false;
2188             }
2189             if ( gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "A", "A" ) ) ) {
2190                 return false;
2191             }
2192             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "A", "C" ) ) ) {
2193                 return false;
2194             }
2195             if ( gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "C", "A" ) ) ) {
2196                 return false;
2197             }
2198             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "B", "C" ) ) ) {
2199                 return false;
2200             }
2201             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "C", "X" ) ) ) {
2202                 return false;
2203             }
2204             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "C", "Y" ) ) ) {
2205                 return false;
2206             }
2207             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "A", "X" ) ) ) {
2208                 return false;
2209             }
2210             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "A", "Y" ) ) ) {
2211                 return false;
2212             }
2213             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "Y", "A" ) ) ) {
2214                 return false;
2215             }
2216             if ( gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "X", "A" ) ) ) {
2217                 return false;
2218             }
2219             if ( gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "C", "B" ) ) ) {
2220                 return false;
2221             }
2222             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "X", "Y" ) ) ) {
2223                 return false;
2224             }
2225             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "Y", "X" ) ) ) {
2226                 return false;
2227             }
2228             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "A", "Y" ) ) ) {
2229                 return false;
2230             }
2231             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "A", "X" ) ) ) {
2232                 return false;
2233             }
2234             if ( gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "Y", "C" ) ) ) {
2235                 return false;
2236             }
2237             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "M", "N" ) ) ) {
2238                 return false;
2239             }
2240             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "N", "M" ) ) ) {
2241                 return false;
2242             }
2243             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "N", "P" ) ) ) {
2244                 return false;
2245             }
2246             if ( !gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "M", "P" ) ) ) {
2247                 return false;
2248             }
2249             if ( gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "P", "N" ) ) ) {
2250                 return false;
2251             }
2252             if ( gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "P", "M" ) ) ) {
2253                 return false;
2254             }
2255             if ( gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "XX", "YY" ) ) ) {
2256                 return false;
2257             }
2258             if ( gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "YY", "XX" ) ) ) {
2259                 return false;
2260             }
2261             if ( gwcd_1.toBinaryDomainCombinations().contains( new DirectedBinaryDomainCombination( "B", "B" ) ) ) {
2262                 return false;
2263             }
2264             //            final List<GenomeWideCombinableDomains> gwcd_list = new ArrayList<GenomeWideCombinableDomains>();
2265             //            gwcd_list.add( gwcd_1 );
2266             //            gwcd_list.add( gwcd_2 );
2267             //            final CharacterStateMatrix<BinaryStates> matrix_d = DomainParsimonyCalculator
2268             //                    .createMatrixOfDomainPresenceOrAbsence( gwcd_list );
2269             //            final CharacterStateMatrix<BinaryStates> matrix_bc = DomainParsimonyCalculator
2270             //                    .createMatrixOfBinaryDomainCombinationPresenceOrAbsence( gwcd_list );
2271             //            if ( matrix_d.getState( 0, 0 ) != X ) {
2272             //                return false;
2273             //            }
2274             //            if ( matrix_bc.getState( 0, 0 ) != X ) {
2275             //                return false;
2276             //            }
2277             //        
2278             //
2279             //            final BasicCharacterStateMatrix<BinaryStates> dm = new BasicCharacterStateMatrix<BinaryStates>( new BinaryStates[][] {
2280             //                    { X, X, X, X, X, X }, { X, X, X, X, X, X } } );
2281             //            if ( !matrix_d.equals( dm ) ) {
2282             //                return false;
2283             //            }
2284             //            final BasicCharacterStateMatrix<BinaryStates> bcm = new BasicCharacterStateMatrix<BinaryStates>( new BinaryStates[][] {
2285             //                    { X, O, X, X, X, X, O, X, X, O, X, X }, { X, X, X, O, O, O, O, X, O, O, X, X } } );
2286             //            if ( !matrix_d.equals( dm ) ) {
2287             //                return false;
2288             //            }
2289             //``````````````````````````
2290             //            final List<GenomeWideCombinableDomains> gwcd_list = new ArrayList<GenomeWideCombinableDomains>();
2291             //            gwcd_list.add( one );
2292             //            gwcd_list.add( two );
2293             //            gwcd_list.add( three );
2294             //            gwcd_list.add( four );
2295             //            final CharacterStateMatrix<BinaryStates> matrix_d = DomainParsimony
2296             //                    .createMatrixOfDomainPresenceOrAbsence( gwcd_list );
2297             //            final CharacterStateMatrix<BinaryStates> matrix_bc = DomainParsimony
2298             //                    .createMatrixOfBinaryDomainCombinationPresenceOrAbsence( gwcd_list );
2299             //            //         System.out.println( "d:"  );
2300             //            //         System.out.println(matrix_d.toStringBuffer().toString()  );
2301             //            //         System.out.println( "bc:"  );
2302             //            //        System.out.println(matrix_bc.toStringBuffer().toString()  );
2303             //            // 1 a b c e f g h l m
2304             //            // 2 a b c e f g i n o
2305             //            // 3 a b d e f g j p q
2306             //            // 4 a b d p r
2307             //            if ( matrix_d.getState( 0, 0 ) != X ) {
2308             //                return false;
2309             //            }
2310             //            if ( matrix_d.getState( 0, 1 ) != X ) {
2311             //                return false;
2312             //            }
2313             //            if ( matrix_d.getState( 0, 2 ) != X ) {
2314             //                return false;
2315             //            }
2316             //            if ( matrix_d.getState( 0, 3 ) != O ) {
2317             //                return false;
2318             //            }
2319             //            if ( matrix_d.getState( 0, 4 ) != X ) {
2320             //                return false;
2321             //            }
2322             //            if ( matrix_d.getState( 0, 5 ) != X ) {
2323             //                return false;
2324             //            }
2325             //            if ( matrix_d.getState( 0, 6 ) != X ) {
2326             //                return false;
2327             //            }
2328             //            if ( matrix_d.getState( 0, 7 ) != X ) {
2329             //                return false;
2330             //            }
2331             //            if ( matrix_d.getState( 0, 8 ) != O ) {
2332             //                return false;
2333             //            }
2334             //            // 1 a-a a-b a-c e-f e-g e-h f-g f-h g-h l-m
2335             //            // 2 a-b a-c e-f e-g e-i f-g f-i g-i n-o
2336             //            // 3 a-b a-d e-f e-g e-j f-g f-j g-j p-q
2337             //            // 4 a-b a-d p-r
2338             //            if ( matrix_bc.getState( 0, 0 ) != X ) {
2339             //                return false;
2340             //            }
2341             //            if ( matrix_bc.getState( 0, 1 ) != X ) {
2342             //                return false;
2343             //            }
2344             //            if ( matrix_bc.getState( 0, 2 ) != X ) {
2345             //                return false;
2346             //            }
2347             //            if ( matrix_bc.getState( 0, 3 ) != O ) {
2348             //                return false;
2349             //            }
2350             //            if ( matrix_bc.getState( 0, 4 ) != X ) {
2351             //                return false;
2352             //            }
2353             //            if ( matrix_bc.getState( 1, 0 ) != O ) {
2354             //                return false;
2355             //            }
2356             //            if ( matrix_bc.getState( 1, 1 ) != X ) {
2357             //                return false;
2358             //            }
2359             //            if ( matrix_bc.getState( 1, 2 ) != X ) {
2360             //                return false;
2361             //            }
2362             //            if ( matrix_bc.getState( 1, 3 ) != O ) {
2363             //                return false;
2364             //            }
2365             //            if ( matrix_bc.getState( 1, 4 ) != X ) {
2366             //                return false;
2367             //            }
2368             //            if ( matrix_bc.getState( 2, 0 ) != O ) {
2369             //                return false;
2370             //            }
2371             //            if ( matrix_bc.getState( 2, 1 ) != X ) {
2372             //                return false;
2373             //            }
2374             //            if ( matrix_bc.getState( 2, 2 ) != O ) {
2375             //                return false;
2376             //            }
2377             //            if ( matrix_bc.getState( 2, 3 ) != X ) {
2378             //                return false;
2379             //            }
2380             //            if ( matrix_bc.getState( 2, 4 ) != X ) {
2381             //                return false;
2382             //            }
2383             //            final PhylogenyFactory factory0 = ParserBasedPhylogenyFactory.getInstance();
2384             //            final String p0_str = "((one,two)1-2,(three,four)3-4)root";
2385             //            final Phylogeny p0 = factory0.create( p0_str, new NHXParser() )[ 0 ];
2386             //            final DomainParsimony dp0 = DomainParsimony.createInstance( p0, gwcd_list );
2387             //            dp0.executeDolloParsimonyOnDomainPresence();
2388             //            final CharacterStateMatrix<GainLossStates> gl_matrix_d = dp0.getGainLossMatrix();
2389             //            final CharacterStateMatrix<BinaryStates> is_matrix_d = dp0.getInternalStatesMatrix();
2390             //            dp0.executeDolloParsimonyOnBinaryDomainCombintionPresence();
2391             //            final CharacterStateMatrix<GainLossStates> gl_matrix_bc = dp0.getGainLossMatrix();
2392             //            final CharacterStateMatrix<BinaryStates> is_matrix_bc = dp0.getInternalStatesMatrix();
2393             //            if ( is_matrix_d.getState( "root", "A" ) != X ) {
2394             //                return false;
2395             //            }
2396             //            if ( is_matrix_d.getState( "root", "B" ) != X ) {
2397             //                return false;
2398             //            }
2399             //            if ( is_matrix_d.getState( "root", "C" ) != O ) {
2400             //                return false;
2401             //            }
2402             //            if ( is_matrix_d.getState( "root", "D" ) != O ) {
2403             //                return false;
2404             //            }
2405             //            if ( is_matrix_d.getState( "root", "E" ) != X ) {
2406             //                return false;
2407             //            }
2408             //            if ( is_matrix_bc.getState( "root", "A=A" ) != O ) {
2409             //                return false;
2410             //            }
2411             //            if ( is_matrix_bc.getState( "root", "A=B" ) != X ) {
2412             //                return false;
2413             //            }
2414             //            if ( is_matrix_bc.getState( "root", "A=C" ) != O ) {
2415             //                return false;
2416             //            }
2417             //            if ( is_matrix_bc.getState( "root", "A=D" ) != O ) {
2418             //                return false;
2419             //            }
2420             //            if ( is_matrix_bc.getState( "root", "G=H" ) != O ) {
2421             //                return false;
2422             //            }
2423             //            if ( is_matrix_bc.getState( "1-2", "G=H" ) != O ) {
2424             //                return false;
2425             //            }
2426             //            if ( is_matrix_bc.getState( "root", "E=F" ) != X ) {
2427             //                return false;
2428             //            }
2429             //            if ( gl_matrix_bc.getState( "root", "E=F" ) != P ) {
2430             //                return false;
2431             //            }
2432             //            if ( gl_matrix_bc.getState( "root", "A=A" ) != A ) {
2433             //                return false;
2434             //            }
2435             //            if ( gl_matrix_bc.getState( "one", "A=A" ) != G ) {
2436             //                return false;
2437             //            }
2438             //            if ( gl_matrix_bc.getState( "root", "A=B" ) != P ) {
2439             //                return false;
2440             //            }
2441             //            if ( gl_matrix_bc.getState( "3-4", "A=D" ) != G ) {
2442             //                return false;
2443             //            }
2444             //            if ( gl_matrix_bc.getState( "four", "E=F" ) != L ) {
2445             //                return false;
2446             //            }
2447             //            if ( gl_matrix_d.getState( "3-4", "P" ) != G ) {
2448             //                return false;
2449             //            }
2450             //            final Protein ab_1 = new BasicProtein( "ab", "one" );
2451             //            ab_1.addProteinDomain( a );
2452             //            ab_1.addProteinDomain( b );
2453             //            final Protein ac_1 = new BasicProtein( "ac", "one" );
2454             //            ac_1.addProteinDomain( a );
2455             //            ac_1.addProteinDomain( c );
2456             //            final Protein de_1 = new BasicProtein( "de", "one" );
2457             //            de_1.addProteinDomain( d );
2458             //            de_1.addProteinDomain( e );
2459             //            final Protein ac_2 = new BasicProtein( "ac", "two" );
2460             //            ac_2.addProteinDomain( a );
2461             //            ac_2.addProteinDomain( c );
2462             //            final Protein ab_3 = new BasicProtein( "ab", "three" );
2463             //            ab_3.addProteinDomain( a );
2464             //            ab_3.addProteinDomain( b );
2465             //            final Protein de_4 = new BasicProtein( "de", "four" );
2466             //            de_4.addProteinDomain( d );
2467             //            de_4.addProteinDomain( e );
2468             //            final Protein ab_6 = new BasicProtein( "ab", "six" );
2469             //            ab_6.addProteinDomain( a );
2470             //            ab_6.addProteinDomain( b );
2471             //            final List<Protein> spec_one = new ArrayList<Protein>();
2472             //            final List<Protein> spec_two = new ArrayList<Protein>();
2473             //            final List<Protein> spec_three = new ArrayList<Protein>();
2474             //            final List<Protein> spec_four = new ArrayList<Protein>();
2475             //            final List<Protein> spec_five = new ArrayList<Protein>();
2476             //            final List<Protein> spec_six = new ArrayList<Protein>();
2477             //            final List<Protein> spec_seven = new ArrayList<Protein>();
2478             //            spec_one.add( ab_1 );
2479             //            spec_one.add( ac_1 );
2480             //            spec_one.add( de_1 );
2481             //            spec_two.add( ac_2 );
2482             //            spec_three.add( ab_3 );
2483             //            spec_four.add( de_4 );
2484             //            spec_six.add( ab_6 );
2485             //            final GenomeWideCombinableDomains one_gwcd = BasicGenomeWideCombinableDomains
2486             //                    .createInstance( spec_one, false, new BasicSpecies( "one" ), false );
2487             //            final GenomeWideCombinableDomains two_gwcd = BasicGenomeWideCombinableDomains
2488             //                    .createInstance( spec_two, false, new BasicSpecies( "two" ), false );
2489             //            final GenomeWideCombinableDomains three_gwcd = BasicGenomeWideCombinableDomains
2490             //                    .createInstance( spec_three, false, new BasicSpecies( "three" ), false );
2491             //            final GenomeWideCombinableDomains four_gwcd = BasicGenomeWideCombinableDomains
2492             //                    .createInstance( spec_four, false, new BasicSpecies( "four" ), false );
2493             //            final GenomeWideCombinableDomains five_gwcd = BasicGenomeWideCombinableDomains
2494             //                    .createInstance( spec_five, false, new BasicSpecies( "five" ), false );
2495             //            final GenomeWideCombinableDomains six_gwcd = BasicGenomeWideCombinableDomains
2496             //                    .createInstance( spec_six, false, new BasicSpecies( "six" ), false );
2497             //            final GenomeWideCombinableDomains seven_gwcd = BasicGenomeWideCombinableDomains
2498             //                    .createInstance( spec_seven, false, new BasicSpecies( "seven" ), false
2499             //                                    );
2500             //            final List<GenomeWideCombinableDomains> gwcd_list1 = new ArrayList<GenomeWideCombinableDomains>();
2501             //            gwcd_list1.add( one_gwcd );
2502             //            gwcd_list1.add( two_gwcd );
2503             //            gwcd_list1.add( three_gwcd );
2504             //            gwcd_list1.add( four_gwcd );
2505             //            gwcd_list1.add( five_gwcd );
2506             //            gwcd_list1.add( six_gwcd );
2507             //            gwcd_list1.add( seven_gwcd );
2508             //            final PhylogenyFactory factory1 = ParserBasedPhylogenyFactory.getInstance();
2509             //            final String p1_str = "(((((one,two)12,three)123,(four,five)45)12345,six)123456,seven)root";
2510             //            final Phylogeny p1 = factory1.create( p1_str, new NHXParser() )[ 0 ];
2511             //            final DomainParsimony dp1 = DomainParsimony.createInstance( p1, gwcd_list1 );
2512             //            dp1.executeDolloParsimonyOnDomainPresence();
2513             //            final CharacterStateMatrix<GainLossStates> gl_dollo_d = dp1.getGainLossMatrix();
2514             //            final CharacterStateMatrix<BinaryStates> i_dollo_d = dp1.getInternalStatesMatrix();
2515             //            if ( dp1.getCost() != 14 ) {
2516             //                return false;
2517             //            }
2518             //            if ( dp1.getTotalGains() != 5 ) {
2519             //                return false;
2520             //            }
2521             //            if ( dp1.getTotalLosses() != 9 ) {
2522             //                return false;
2523             //            }
2524             //            if ( dp1.getTotalUnchanged() != 51 ) {
2525             //                return false;
2526             //            }
2527             //            if ( dp1.getNetGainsOnNode( "45" ) != -2 ) {
2528             //                return false;
2529             //            }
2530             //            if ( dp1.getSumOfGainsOnNode( "45" ) != 0 ) {
2531             //                return false;
2532             //            }
2533             //            if ( dp1.getSumOfLossesOnNode( "45" ) != 2 ) {
2534             //                return false;
2535             //            }
2536             //            if ( dp1.getSumOfUnchangedOnNode( "45" ) != 3 ) {
2537             //                return false;
2538             //            }
2539             //            if ( dp1.getSumOfUnchangedPresentOnNode( "45" ) != 2 ) {
2540             //                return false;
2541             //            }
2542             //            if ( dp1.getSumOfUnchangedAbsentOnNode( "45" ) != 1 ) {
2543             //                return false;
2544             //            }
2545             //            if ( dp1.getUnitsGainedOnNode( "45" ).contains( "A" ) ) {
2546             //                return false;
2547             //            }
2548             //            if ( !dp1.getUnitsLostOnNode( "45" ).contains( "A" ) ) {
2549             //                return false;
2550             //            }
2551             //            if ( !dp1.getUnitsLostOnNode( "45" ).contains( "B" ) ) {
2552             //                return false;
2553             //            }
2554             //            if ( !dp1.getUnitsGainedOnNode( "12345" ).contains( "D" ) ) {
2555             //                return false;
2556             //            }
2557             //            if ( !dp1.getUnitsOnNode( "12" ).contains( "A" ) ) {
2558             //                return false;
2559             //            }
2560             //            if ( !dp1.getUnitsOnNode( "12" ).contains( "B" ) ) {
2561             //                return false;
2562             //            }
2563             //            if ( !dp1.getUnitsOnNode( "12" ).contains( "C" ) ) {
2564             //                return false;
2565             //            }
2566             //            if ( !dp1.getUnitsOnNode( "12" ).contains( "D" ) ) {
2567             //                return false;
2568             //            }
2569             //            if ( !dp1.getUnitsOnNode( "12" ).contains( "E" ) ) {
2570             //                return false;
2571             //            }
2572             //            if ( dp1.getNetGainsOnNode( "123456" ) != 2 ) {
2573             //                return false;
2574             //            }
2575             //            if ( dp1.getSumOfGainsOnNode( "123456" ) != 2 ) {
2576             //                return false;
2577             //            }
2578             //            dp1.executeDolloParsimonyOnBinaryDomainCombintionPresence();
2579             //            final CharacterStateMatrix<GainLossStates> gl_dollo_bc = dp1.getGainLossMatrix();
2580             //            final CharacterStateMatrix<BinaryStates> i_dollo_bc = dp1.getInternalStatesMatrix();
2581             //            if ( dp1.getCost() != 8 ) {
2582             //                return false;
2583             //            }
2584             //            if ( dp1.getTotalGains() != 3 ) {
2585             //                return false;
2586             //            }
2587             //            if ( dp1.getTotalLosses() != 5 ) {
2588             //                return false;
2589             //            }
2590             //            if ( dp1.getTotalUnchanged() != 31 ) {
2591             //                return false;
2592             //            }
2593             //            if ( !dp1.getUnitsLostOnNode( "45" ).contains( "A=B" ) ) {
2594             //                return false;
2595             //            }
2596             //            if ( !dp1.getUnitsGainedOnNode( "12345" ).contains( "D=E" ) ) {
2597             //                return false;
2598             //            }
2599             //            dp1.executeFitchParsimonyOnDomainPresence();
2600             //            final CharacterStateMatrix<GainLossStates> gl_fitch_d = dp1.getGainLossMatrix();
2601             //            final CharacterStateMatrix<BinaryStates> i_fitch_d = dp1.getInternalStatesMatrix();
2602             //            if ( dp1.getCost() != 10 ) {
2603             //                return false;
2604             //            }
2605             //            if ( dp1.getTotalGains() != 7 ) {
2606             //                return false;
2607             //            }
2608             //            if ( dp1.getTotalLosses() != 3 ) {
2609             //                return false;
2610             //            }
2611             //            if ( dp1.getTotalUnchanged() != 55 ) {
2612             //                return false;
2613             //            }
2614             //            if ( !dp1.getUnitsGainedOnNode( "four" ).contains( "E" ) ) {
2615             //                return false;
2616             //            }
2617             //            dp1.executeFitchParsimonyOnBinaryDomainCombintion();
2618             //            final CharacterStateMatrix<GainLossStates> gl_fitch_bc = dp1.getGainLossMatrix();
2619             //            final CharacterStateMatrix<BinaryStates> i_fitch_bc = dp1.getInternalStatesMatrix();
2620             //            if ( dp1.getCost() != 6 ) {
2621             //                return false;
2622             //            }
2623             //            if ( dp1.getTotalGains() != 4 ) {
2624             //                return false;
2625             //            }
2626             //            if ( dp1.getTotalLosses() != 2 ) {
2627             //                return false;
2628             //            }
2629             //            if ( dp1.getTotalUnchanged() != 33 ) {
2630             //                return false;
2631             //            }
2632             //            if ( !dp1.getUnitsLostOnNode( "45" ).contains( "A=B" ) ) {
2633             //                return false;
2634             //            }
2635             //            if ( !dp1.getUnitsGainedOnNode( "four" ).contains( "D=E" ) ) {
2636             //                return false;
2637             //            }
2638             //            if ( dp1.getNetGainsOnNode( "two" ) != -1 ) {
2639             //                return false;
2640             //            }
2641             //            if ( dp1.getNetGainsOnNode( "123" ) != 0 ) {
2642             //                return false;
2643             //            }
2644             //            if ( dp1.getSumOfUnchangedPresentOnNode( "123" ) != 1 ) {
2645             //                return false;
2646             //            }
2647             //            if ( dp1.getSumOfUnchangedAbsentOnNode( "123" ) != 2 ) {
2648             //                return false;
2649             //            }
2650             //            if ( dp1.getSumOfUnchangedOnNode( "123" ) != 3 ) {
2651             //                return false;
2652             //            }
2653             //            if ( dp1.getSumOfUnchangedOnNode( "two" ) != 2 ) {
2654             //                return false;
2655             //            }
2656             //            if ( !dp1.getUnitsUnchangedAbsentOnNode( "two" ).contains( "D=E" ) ) {
2657             //                return false;
2658             //            }
2659             //            if ( !dp1.getUnitsUnchangedPresentOnNode( "two" ).contains( "A=C" ) ) {
2660             //                return false;
2661             //            }
2662             //            if ( !dp1.getUnitsUnchangedAbsentOnNode( "123" ).contains( "A=C" ) ) {
2663             //                return false;
2664             //            }
2665             //            if ( !dp1.getUnitsUnchangedPresentOnNode( "123" ).contains( "A=B" ) ) {
2666             //                return false;
2667             //            }
2668             //            if ( !dp1.getUnitsUnchangedAbsentOnNode( "123" ).contains( "D=E" ) ) {
2669             //                return false;
2670             //            }
2671             //            CharacterStateMatrix<BinaryStates> bsm = null;
2672             //            CharacterStateMatrix<GainLossStates> glm = null;
2673             //            bsm = new BasicCharacterStateMatrix<BinaryStates>( new BinaryStates[][] { { X, X, X, X, X },
2674             //                    { 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 } } );
2675             //            if ( !bsm.equals( i_dollo_d ) ) {
2676             //                return false;
2677             //            }
2678             //            bsm = new BasicCharacterStateMatrix<BinaryStates>( new BinaryStates[][] { { X, X, X, O, O },
2679             //                    { 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 } } );
2680             //            if ( !bsm.equals( i_fitch_d ) ) {
2681             //                return false;
2682             //            }
2683             //            glm = new BasicCharacterStateMatrix<GainLossStates>( new GainLossStates[][] { { P, P, P, P, P },
2684             //                    { 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 },
2685             //                    { 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 },
2686             //                    { A, A, A, A, A }, { A, A, A, A, A } } );
2687             //            if ( !glm.equals( gl_dollo_d ) ) {
2688             //                return false;
2689             //            }
2690             //            glm = new BasicCharacterStateMatrix<GainLossStates>( new GainLossStates[][] { { P, P, P, G, G },
2691             //                    { 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 },
2692             //                    { 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 },
2693             //                    { A, A, A, A, A }, { A, A, A, A, A } } );
2694             //            if ( !glm.equals( gl_fitch_d ) ) {
2695             //                return false;
2696             //            }
2697             //            bsm = new BasicCharacterStateMatrix<BinaryStates>( new BinaryStates[][] { { X, X, X }, { X, O, X },
2698             //                    { O, O, X }, { X, O, X }, { X, O, O }, { O, O, O } } );
2699             //            if ( !bsm.equals( i_dollo_bc ) ) {
2700             //                return false;
2701             //            }
2702             //            bsm = new BasicCharacterStateMatrix<BinaryStates>( new BinaryStates[][] { { X, X, O }, { X, O, O },
2703             //                    { O, O, O }, { X, O, O }, { X, O, O }, { O, O, O } } );
2704             //            if ( !bsm.equals( i_fitch_bc ) ) {
2705             //                return false;
2706             //            }
2707             //            glm = new BasicCharacterStateMatrix<GainLossStates>( new GainLossStates[][] { { P, P, P }, { L, P, L },
2708             //                    { P, G, P }, { P, A, L }, { P, A, P }, { A, A, P }, { A, A, L }, { L, A, P }, { P, A, G },
2709             //                    { P, A, A }, { G, A, A }, { A, A, A }, { A, A, A } } );
2710             //            if ( !glm.equals( gl_dollo_bc ) ) {
2711             //                return false;
2712             //            }
2713             //            glm = new BasicCharacterStateMatrix<GainLossStates>( new GainLossStates[][] { { P, P, G }, { L, P, A },
2714             //                    { P, G, A }, { P, A, A }, { P, A, A }, { A, A, G }, { A, A, A }, { L, A, A }, { P, A, A },
2715             //                    { P, A, A }, { G, A, A }, { A, A, A }, { A, A, A } } );
2716             //            if ( !glm.equals( gl_fitch_bc ) ) {
2717             //                return false;
2718             //            }
2719         }
2720         catch ( final Exception e ) {
2721             e.printStackTrace( System.out );
2722             return false;
2723         }
2724         return true;
2725     }
2726
2727     private static boolean testDirectednessAndAdjacency() {
2728         try {
2729             final Protein one_1 = new BasicProtein( "one", "1" );
2730             final Protein two_1 = new BasicProtein( "two", "1" );
2731             final Protein three_1 = new BasicProtein( "three", "1" );
2732             final Protein four_1 = new BasicProtein( "four", "1" );
2733             final Protein five_1 = new BasicProtein( "five", "1" );
2734             one_1.addProteinDomain( new BasicDomain( "B", 12, 14, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2735             one_1.addProteinDomain( new BasicDomain( "C", 13, 14, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2736             one_1.addProteinDomain( new BasicDomain( "A", 11, 12, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2737             one_1.addProteinDomain( new BasicDomain( "X", 100, 110, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2738             one_1.addProteinDomain( new BasicDomain( "Y", 200, 210, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2739             two_1.addProteinDomain( new BasicDomain( "A", 10, 20, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2740             two_1.addProteinDomain( new BasicDomain( "B", 30, 40, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2741             two_1.addProteinDomain( new BasicDomain( "Y", 1, 2, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2742             two_1.addProteinDomain( new BasicDomain( "X", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2743             three_1.addProteinDomain( new BasicDomain( "P", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2744             three_1.addProteinDomain( new BasicDomain( "M", 1, 2, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2745             three_1.addProteinDomain( new BasicDomain( "M", 5, 6, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2746             three_1.addProteinDomain( new BasicDomain( "N", 7, 8, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2747             three_1.addProteinDomain( new BasicDomain( "N", 3, 4, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2748             four_1.addProteinDomain( new BasicDomain( "XX", 10, 20, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2749             five_1.addProteinDomain( new BasicDomain( "YY", 30, 40, ( short ) 1, ( short ) 4, 0.1, -12 ) );
2750             final List<Protein> list_1 = new ArrayList<Protein>();
2751             list_1.add( one_1 );
2752             list_1.add( two_1 );
2753             list_1.add( three_1 );
2754             list_1.add( four_1 );
2755             list_1.add( five_1 );
2756             final GenomeWideCombinableDomains gwcd_1 = BasicGenomeWideCombinableDomains
2757                     .createInstance( list_1, false, new BasicSpecies( "1" ), DomainCombinationType.DIRECTED_ADJACTANT );
2758             if ( !gwcd_1.toBinaryDomainCombinations()
2759                     .contains( new AdjactantDirectedBinaryDomainCombination( "A", "B" ) ) ) {
2760                 return false;
2761             }
2762             if ( gwcd_1.toBinaryDomainCombinations()
2763                     .contains( new AdjactantDirectedBinaryDomainCombination( "B", "A" ) ) ) {
2764                 return false;
2765             }
2766             if ( gwcd_1.toBinaryDomainCombinations()
2767                     .contains( new AdjactantDirectedBinaryDomainCombination( "A", "A" ) ) ) {
2768                 return false;
2769             }
2770             if ( gwcd_1.toBinaryDomainCombinations()
2771                     .contains( new AdjactantDirectedBinaryDomainCombination( "A", "C" ) ) ) {
2772                 return false;
2773             }
2774             if ( gwcd_1.toBinaryDomainCombinations()
2775                     .contains( new AdjactantDirectedBinaryDomainCombination( "C", "A" ) ) ) {
2776                 return false;
2777             }
2778             if ( !gwcd_1.toBinaryDomainCombinations()
2779                     .contains( new AdjactantDirectedBinaryDomainCombination( "B", "C" ) ) ) {
2780                 return false;
2781             }
2782             if ( !gwcd_1.toBinaryDomainCombinations()
2783                     .contains( new AdjactantDirectedBinaryDomainCombination( "C", "X" ) ) ) {
2784                 return false;
2785             }
2786             if ( gwcd_1.toBinaryDomainCombinations()
2787                     .contains( new AdjactantDirectedBinaryDomainCombination( "C", "Y" ) ) ) {
2788                 return false;
2789             }
2790             if ( !gwcd_1.toBinaryDomainCombinations()
2791                     .contains( new AdjactantDirectedBinaryDomainCombination( "X", "Y" ) ) ) {
2792                 return false;
2793             }
2794             if ( gwcd_1.toBinaryDomainCombinations()
2795                     .contains( new AdjactantDirectedBinaryDomainCombination( "A", "X" ) ) ) {
2796                 return false;
2797             }
2798             if ( gwcd_1.toBinaryDomainCombinations()
2799                     .contains( new AdjactantDirectedBinaryDomainCombination( "A", "Y" ) ) ) {
2800                 return false;
2801             }
2802             if ( !gwcd_1.toBinaryDomainCombinations()
2803                     .contains( new AdjactantDirectedBinaryDomainCombination( "Y", "A" ) ) ) {
2804                 return false;
2805             }
2806             if ( gwcd_1.toBinaryDomainCombinations()
2807                     .contains( new AdjactantDirectedBinaryDomainCombination( "X", "A" ) ) ) {
2808                 return false;
2809             }
2810             if ( gwcd_1.toBinaryDomainCombinations()
2811                     .contains( new AdjactantDirectedBinaryDomainCombination( "C", "B" ) ) ) {
2812                 return false;
2813             }
2814             if ( !gwcd_1.toBinaryDomainCombinations()
2815                     .contains( new AdjactantDirectedBinaryDomainCombination( "X", "Y" ) ) ) {
2816                 return false;
2817             }
2818             if ( gwcd_1.toBinaryDomainCombinations()
2819                     .contains( new AdjactantDirectedBinaryDomainCombination( "Y", "X" ) ) ) {
2820                 return false;
2821             }
2822             if ( gwcd_1.toBinaryDomainCombinations()
2823                     .contains( new AdjactantDirectedBinaryDomainCombination( "A", "Y" ) ) ) {
2824                 return false;
2825             }
2826             if ( gwcd_1.toBinaryDomainCombinations()
2827                     .contains( new AdjactantDirectedBinaryDomainCombination( "A", "X" ) ) ) {
2828                 return false;
2829             }
2830             if ( gwcd_1.toBinaryDomainCombinations()
2831                     .contains( new AdjactantDirectedBinaryDomainCombination( "Y", "C" ) ) ) {
2832                 return false;
2833             }
2834             if ( !gwcd_1.toBinaryDomainCombinations()
2835                     .contains( new AdjactantDirectedBinaryDomainCombination( "M", "N" ) ) ) {
2836                 return false;
2837             }
2838             if ( !gwcd_1.toBinaryDomainCombinations()
2839                     .contains( new AdjactantDirectedBinaryDomainCombination( "N", "M" ) ) ) {
2840                 return false;
2841             }
2842             if ( !gwcd_1.toBinaryDomainCombinations()
2843                     .contains( new AdjactantDirectedBinaryDomainCombination( "N", "P" ) ) ) {
2844                 return false;
2845             }
2846             if ( gwcd_1.toBinaryDomainCombinations()
2847                     .contains( new AdjactantDirectedBinaryDomainCombination( "M", "P" ) ) ) {
2848                 return false;
2849             }
2850             if ( gwcd_1.toBinaryDomainCombinations()
2851                     .contains( new AdjactantDirectedBinaryDomainCombination( "P", "N" ) ) ) {
2852                 return false;
2853             }
2854             if ( gwcd_1.toBinaryDomainCombinations()
2855                     .contains( new AdjactantDirectedBinaryDomainCombination( "P", "M" ) ) ) {
2856                 return false;
2857             }
2858             if ( gwcd_1.toBinaryDomainCombinations()
2859                     .contains( new AdjactantDirectedBinaryDomainCombination( "XX", "YY" ) ) ) {
2860                 return false;
2861             }
2862             if ( gwcd_1.toBinaryDomainCombinations()
2863                     .contains( new AdjactantDirectedBinaryDomainCombination( "YY", "XX" ) ) ) {
2864                 return false;
2865             }
2866             if ( gwcd_1.toBinaryDomainCombinations()
2867                     .contains( new AdjactantDirectedBinaryDomainCombination( "B", "B" ) ) ) {
2868                 return false;
2869             }
2870         }
2871         catch ( final Exception e ) {
2872             e.printStackTrace( System.out );
2873             return false;
2874         }
2875         return true;
2876     }
2877
2878     private static boolean testDomainArchitectureBasedGenomeSimilarityCalculator() {
2879         try {
2880             final Domain a = new BasicDomain( "a", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2881             final Domain b = new BasicDomain( "b", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2882             final Domain c = new BasicDomain( "c", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2883             final Domain d = new BasicDomain( "d", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2884             final Domain e = new BasicDomain( "e", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2885             final Domain f = new BasicDomain( "f", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2886             final Domain g = new BasicDomain( "g", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2887             final Domain h = new BasicDomain( "h", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2888             final Domain i = new BasicDomain( "i", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2889             final Domain j = new BasicDomain( "j", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2890             final Domain k = new BasicDomain( "k", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2891             final Domain l = new BasicDomain( "l", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2892             final Domain m = new BasicDomain( "m", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2893             final Domain n = new BasicDomain( "n", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2894             final Protein eel_0 = new BasicProtein( "0", "eel" );
2895             final Protein eel_1 = new BasicProtein( "1", "eel" );
2896             final Protein eel_2 = new BasicProtein( "2", "eel" );
2897             final Protein eel_3 = new BasicProtein( "3", "eel" );
2898             final Protein eel_4 = new BasicProtein( "4", "eel" );
2899             final Protein eel_5 = new BasicProtein( "5", "eel" );
2900             final Protein eel_6 = new BasicProtein( "6", "eel" );
2901             final Protein rat_0 = new BasicProtein( "0", "rat" );
2902             final Protein rat_1 = new BasicProtein( "1", "rat" );
2903             final Protein rat_2 = new BasicProtein( "2", "rat" );
2904             final Protein rat_3 = new BasicProtein( "3", "rat" );
2905             final Protein rat_4 = new BasicProtein( "4", "rat" );
2906             final Protein rat_5 = new BasicProtein( "5", "rat" );
2907             final Protein rat_6 = new BasicProtein( "6", "rat" );
2908             final Protein rat_7 = new BasicProtein( "7", "rat" );
2909             eel_1.addProteinDomain( a );
2910             eel_2.addProteinDomain( a );
2911             eel_2.addProteinDomain( b );
2912             eel_3.addProteinDomain( a );
2913             eel_3.addProteinDomain( a );
2914             eel_3.addProteinDomain( b );
2915             eel_4.addProteinDomain( a );
2916             eel_4.addProteinDomain( b );
2917             eel_4.addProteinDomain( c );
2918             eel_4.addProteinDomain( d );
2919             eel_4.addProteinDomain( e );
2920             eel_5.addProteinDomain( e );
2921             eel_5.addProteinDomain( e );
2922             eel_5.addProteinDomain( f );
2923             eel_5.addProteinDomain( f );
2924             eel_5.addProteinDomain( f );
2925             eel_5.addProteinDomain( f );
2926             eel_6.addProteinDomain( g );
2927             eel_6.addProteinDomain( h );
2928             rat_1.addProteinDomain( a );
2929             rat_2.addProteinDomain( a );
2930             rat_2.addProteinDomain( b );
2931             rat_3.addProteinDomain( a );
2932             rat_3.addProteinDomain( a );
2933             rat_3.addProteinDomain( b );
2934             rat_4.addProteinDomain( a );
2935             rat_4.addProteinDomain( b );
2936             rat_4.addProteinDomain( c );
2937             rat_4.addProteinDomain( i );
2938             rat_4.addProteinDomain( l );
2939             rat_5.addProteinDomain( i );
2940             rat_5.addProteinDomain( f );
2941             rat_5.addProteinDomain( f );
2942             rat_6.addProteinDomain( j );
2943             rat_6.addProteinDomain( k );
2944             rat_7.addProteinDomain( m );
2945             rat_7.addProteinDomain( n );
2946             final List<Protein> protein_list_eel = new ArrayList<Protein>();
2947             protein_list_eel.add( eel_0 );
2948             protein_list_eel.add( eel_1 );
2949             protein_list_eel.add( eel_2 );
2950             protein_list_eel.add( eel_3 );
2951             protein_list_eel.add( eel_4 );
2952             protein_list_eel.add( eel_5 );
2953             protein_list_eel.add( eel_6 );
2954             final List<Protein> protein_list_rat = new ArrayList<Protein>();
2955             protein_list_rat.add( rat_0 );
2956             protein_list_rat.add( rat_1 );
2957             protein_list_rat.add( rat_2 );
2958             protein_list_rat.add( rat_3 );
2959             protein_list_rat.add( rat_4 );
2960             protein_list_rat.add( rat_5 );
2961             protein_list_rat.add( rat_6 );
2962             protein_list_rat.add( rat_7 );
2963             final GenomeWideCombinableDomains eel_not_ignore = BasicGenomeWideCombinableDomains
2964                     .createInstance( protein_list_eel, false, new BasicSpecies( "eel" ) );
2965             final GenomeWideCombinableDomains eel_ignore = BasicGenomeWideCombinableDomains
2966                     .createInstance( protein_list_eel, true, new BasicSpecies( "eel" ) );
2967             final GenomeWideCombinableDomains rat_not_ignore = BasicGenomeWideCombinableDomains
2968                     .createInstance( protein_list_rat, false, new BasicSpecies( "rat" ) );
2969             final GenomeWideCombinableDomains rat_ignore = BasicGenomeWideCombinableDomains
2970                     .createInstance( protein_list_rat, true, new BasicSpecies( "rat" ) );
2971             final DomainArchitectureBasedGenomeSimilarityCalculator calc_ni = new DomainArchitectureBasedGenomeSimilarityCalculator( eel_not_ignore,
2972                                                                                                                                      rat_not_ignore );
2973             final DomainArchitectureBasedGenomeSimilarityCalculator calc_i = new DomainArchitectureBasedGenomeSimilarityCalculator( eel_ignore,
2974                                                                                                                                     rat_ignore );
2975             if ( calc_ni.getAllDomains().size() != 14 ) {
2976                 return false;
2977             }
2978             if ( calc_i.getAllDomains().size() != 14 ) {
2979                 return false;
2980             }
2981             if ( calc_ni.getDomainsSpecificToGenome0().size() != 4 ) {
2982                 return false;
2983             }
2984             if ( calc_i.getDomainsSpecificToGenome0().size() != 4 ) {
2985                 return false;
2986             }
2987             if ( calc_ni.getDomainsSpecificToGenome1().size() != 6 ) {
2988                 return false;
2989             }
2990             if ( calc_i.getDomainsSpecificToGenome1().size() != 6 ) {
2991                 return false;
2992             }
2993             if ( calc_i.getSharedDomains().size() != 4 ) {
2994                 return false;
2995             }
2996             if ( calc_ni.getSharedDomains().size() != 4 ) {
2997                 return false;
2998             }
2999             if ( !calc_ni.getDomainsSpecificToGenome0().contains( d.getDomainId() ) ) {
3000                 return false;
3001             }
3002             if ( !calc_ni.getDomainsSpecificToGenome0().contains( e.getDomainId() ) ) {
3003                 return false;
3004             }
3005             if ( !calc_ni.getDomainsSpecificToGenome0().contains( g.getDomainId() ) ) {
3006                 return false;
3007             }
3008             if ( !calc_ni.getDomainsSpecificToGenome0().contains( h.getDomainId() ) ) {
3009                 return false;
3010             }
3011             if ( calc_ni.getDomainsSpecificToGenome0().contains( a.getDomainId() ) ) {
3012                 return false;
3013             }
3014             if ( calc_ni.getDomainsSpecificToGenome0().contains( i.getDomainId() ) ) {
3015                 return false;
3016             }
3017             if ( !calc_i.getDomainsSpecificToGenome0().contains( d.getDomainId() ) ) {
3018                 return false;
3019             }
3020             if ( !calc_i.getDomainsSpecificToGenome0().contains( e.getDomainId() ) ) {
3021                 return false;
3022             }
3023             if ( !calc_i.getDomainsSpecificToGenome0().contains( g.getDomainId() ) ) {
3024                 return false;
3025             }
3026             if ( !calc_i.getDomainsSpecificToGenome0().contains( h.getDomainId() ) ) {
3027                 return false;
3028             }
3029             if ( calc_i.getDomainsSpecificToGenome0().contains( a.getDomainId() ) ) {
3030                 return false;
3031             }
3032             if ( calc_i.getDomainsSpecificToGenome0().contains( i.getDomainId() ) ) {
3033                 return false;
3034             }
3035             if ( !calc_ni.getDomainsSpecificToGenome1().contains( i.getDomainId() ) ) {
3036                 return false;
3037             }
3038             if ( !calc_ni.getDomainsSpecificToGenome1().contains( l.getDomainId() ) ) {
3039                 return false;
3040             }
3041             if ( !calc_ni.getDomainsSpecificToGenome1().contains( j.getDomainId() ) ) {
3042                 return false;
3043             }
3044             if ( !calc_ni.getDomainsSpecificToGenome1().contains( k.getDomainId() ) ) {
3045                 return false;
3046             }
3047             if ( !calc_ni.getDomainsSpecificToGenome1().contains( m.getDomainId() ) ) {
3048                 return false;
3049             }
3050             if ( !calc_ni.getDomainsSpecificToGenome1().contains( n.getDomainId() ) ) {
3051                 return false;
3052             }
3053             if ( calc_ni.getDomainsSpecificToGenome1().contains( a.getDomainId() ) ) {
3054                 return false;
3055             }
3056             if ( calc_ni.getDomainsSpecificToGenome1().contains( b.getDomainId() ) ) {
3057                 return false;
3058             }
3059             if ( calc_ni.getDomainsSpecificToGenome1().contains( d.getDomainId() ) ) {
3060                 return false;
3061             }
3062             if ( !calc_i.getDomainsSpecificToGenome1().contains( i.getDomainId() ) ) {
3063                 return false;
3064             }
3065             if ( !calc_i.getDomainsSpecificToGenome1().contains( l.getDomainId() ) ) {
3066                 return false;
3067             }
3068             if ( !calc_i.getDomainsSpecificToGenome1().contains( j.getDomainId() ) ) {
3069                 return false;
3070             }
3071             if ( !calc_i.getDomainsSpecificToGenome1().contains( k.getDomainId() ) ) {
3072                 return false;
3073             }
3074             if ( !calc_i.getDomainsSpecificToGenome1().contains( m.getDomainId() ) ) {
3075                 return false;
3076             }
3077             if ( !calc_i.getDomainsSpecificToGenome1().contains( n.getDomainId() ) ) {
3078                 return false;
3079             }
3080             if ( calc_i.getDomainsSpecificToGenome1().contains( a.getDomainId() ) ) {
3081                 return false;
3082             }
3083             if ( calc_i.getDomainsSpecificToGenome1().contains( b.getDomainId() ) ) {
3084                 return false;
3085             }
3086             if ( calc_i.getDomainsSpecificToGenome1().contains( d.getDomainId() ) ) {
3087                 return false;
3088             }
3089             if ( !calc_i.getSharedDomains().contains( a.getDomainId() ) ) {
3090                 return false;
3091             }
3092             if ( !calc_i.getSharedDomains().contains( b.getDomainId() ) ) {
3093                 return false;
3094             }
3095             if ( !calc_i.getSharedDomains().contains( c.getDomainId() ) ) {
3096                 return false;
3097             }
3098             if ( !calc_i.getSharedDomains().contains( f.getDomainId() ) ) {
3099                 return false;
3100             }
3101             final Set<DomainId> all = calc_ni.getAllDomains();
3102             if ( !all.contains( a.getDomainId() ) ) {
3103                 return false;
3104             }
3105             if ( !all.contains( b.getDomainId() ) ) {
3106                 return false;
3107             }
3108             if ( !all.contains( c.getDomainId() ) ) {
3109                 return false;
3110             }
3111             if ( !all.contains( d.getDomainId() ) ) {
3112                 return false;
3113             }
3114             if ( !all.contains( e.getDomainId() ) ) {
3115                 return false;
3116             }
3117             if ( !all.contains( f.getDomainId() ) ) {
3118                 return false;
3119             }
3120             if ( !all.contains( g.getDomainId() ) ) {
3121                 return false;
3122             }
3123             if ( !all.contains( h.getDomainId() ) ) {
3124                 return false;
3125             }
3126             if ( !all.contains( i.getDomainId() ) ) {
3127                 return false;
3128             }
3129             if ( !all.contains( l.getDomainId() ) ) {
3130                 return false;
3131             }
3132             if ( !all.contains( j.getDomainId() ) ) {
3133                 return false;
3134             }
3135             if ( !all.contains( k.getDomainId() ) ) {
3136                 return false;
3137             }
3138             if ( !all.contains( m.getDomainId() ) ) {
3139                 return false;
3140             }
3141             if ( !all.contains( n.getDomainId() ) ) {
3142                 return false;
3143             }
3144             final Set<BinaryDomainCombination> s_0_ni = calc_ni.getBinaryDomainCombinationsSpecificToGenome0();
3145             final Set<BinaryDomainCombination> s_0_i = calc_i.getBinaryDomainCombinationsSpecificToGenome0();
3146             final Set<BinaryDomainCombination> s_1_ni = calc_ni.getBinaryDomainCombinationsSpecificToGenome1();
3147             final Set<BinaryDomainCombination> s_1_i = calc_i.getBinaryDomainCombinationsSpecificToGenome1();
3148             final Set<BinaryDomainCombination> a_ni = calc_ni.getAllBinaryDomainCombinations();
3149             final Set<BinaryDomainCombination> a_i = calc_i.getAllBinaryDomainCombinations();
3150             final Set<BinaryDomainCombination> shared_ni = calc_ni.getSharedBinaryDomainCombinations();
3151             final Set<BinaryDomainCombination> shared_i = calc_i.getSharedBinaryDomainCombinations();
3152             if ( a_ni.size() != 25 ) {
3153                 return false;
3154             }
3155             if ( a_i.size() != 22 ) {
3156                 return false;
3157             }
3158             if ( s_0_ni.size() != 10 ) {
3159                 return false;
3160             }
3161             if ( s_0_i.size() != 9 ) {
3162                 return false;
3163             }
3164             if ( s_1_ni.size() != 10 ) {
3165                 return false;
3166             }
3167             if ( s_1_i.size() != 10 ) {
3168                 return false;
3169             }
3170             if ( shared_ni.size() != 5 ) {
3171                 return false;
3172             }
3173             if ( shared_i.size() != 3 ) {
3174                 return false;
3175             }
3176             if ( !a_ni.contains( new BasicBinaryDomainCombination( "a", "a" ) ) ) {
3177                 return false;
3178             }
3179             if ( !a_ni.contains( new BasicBinaryDomainCombination( "b", "a" ) ) ) {
3180                 return false;
3181             }
3182             if ( !a_ni.contains( new BasicBinaryDomainCombination( "a", "c" ) ) ) {
3183                 return false;
3184             }
3185             if ( !a_ni.contains( new BasicBinaryDomainCombination( "a", "d" ) ) ) {
3186                 return false;
3187             }
3188             if ( !a_ni.contains( new BasicBinaryDomainCombination( "a", "e" ) ) ) {
3189                 return false;
3190             }
3191             if ( !a_ni.contains( new BasicBinaryDomainCombination( "b", "c" ) ) ) {
3192                 return false;
3193             }
3194             if ( !a_ni.contains( new BasicBinaryDomainCombination( "b", "d" ) ) ) {
3195                 return false;
3196             }
3197             if ( !a_ni.contains( new BasicBinaryDomainCombination( "b", "e" ) ) ) {
3198                 return false;
3199             }
3200             if ( !a_ni.contains( new BasicBinaryDomainCombination( "c", "d" ) ) ) {
3201                 return false;
3202             }
3203             if ( !a_ni.contains( new BasicBinaryDomainCombination( "c", "e" ) ) ) {
3204                 return false;
3205             }
3206             if ( !a_ni.contains( new BasicBinaryDomainCombination( "d", "e" ) ) ) {
3207                 return false;
3208             }
3209             if ( !a_ni.contains( new BasicBinaryDomainCombination( "e", "f" ) ) ) {
3210                 return false;
3211             }
3212             if ( !a_ni.contains( new BasicBinaryDomainCombination( "g", "h" ) ) ) {
3213                 return false;
3214             }
3215             if ( !a_ni.contains( new BasicBinaryDomainCombination( "f", "f" ) ) ) {
3216                 return false;
3217             }
3218             if ( !a_ni.contains( new BasicBinaryDomainCombination( "e", "e" ) ) ) {
3219                 return false;
3220             }
3221             if ( !a_ni.contains( new BasicBinaryDomainCombination( "a", "i" ) ) ) {
3222                 return false;
3223             }
3224             if ( !a_ni.contains( new BasicBinaryDomainCombination( "a", "l" ) ) ) {
3225                 return false;
3226             }
3227             if ( !a_ni.contains( new BasicBinaryDomainCombination( "b", "i" ) ) ) {
3228                 return false;
3229             }
3230             if ( !a_ni.contains( new BasicBinaryDomainCombination( "b", "l" ) ) ) {
3231                 return false;
3232             }
3233             if ( !a_ni.contains( new BasicBinaryDomainCombination( "c", "i" ) ) ) {
3234                 return false;
3235             }
3236             if ( !a_ni.contains( new BasicBinaryDomainCombination( "c", "l" ) ) ) {
3237                 return false;
3238             }
3239             if ( !a_ni.contains( new BasicBinaryDomainCombination( "i", "l" ) ) ) {
3240                 return false;
3241             }
3242             if ( !a_ni.contains( new BasicBinaryDomainCombination( "i", "f" ) ) ) {
3243                 return false;
3244             }
3245             if ( !a_ni.contains( new BasicBinaryDomainCombination( "m", "n" ) ) ) {
3246                 return false;
3247             }
3248             if ( !a_ni.contains( new BasicBinaryDomainCombination( "j", "k" ) ) ) {
3249                 return false;
3250             }
3251             if ( a_ni.contains( new BasicBinaryDomainCombination( "a", "g" ) ) ) {
3252                 return false;
3253             }
3254             if ( a_ni.contains( new BasicBinaryDomainCombination( "a", "m" ) ) ) {
3255                 return false;
3256             }
3257             if ( a_i.contains( new BasicBinaryDomainCombination( "a", "a" ) ) ) {
3258                 return false;
3259             }
3260             if ( a_i.contains( new BasicBinaryDomainCombination( "f", "f" ) ) ) {
3261                 return false;
3262             }
3263             if ( a_i.contains( new BasicBinaryDomainCombination( "e", "e" ) ) ) {
3264                 return false;
3265             }
3266             if ( !shared_ni.contains( new BasicBinaryDomainCombination( "a", "a" ) ) ) {
3267                 return false;
3268             }
3269             if ( !shared_ni.contains( new BasicBinaryDomainCombination( "a", "b" ) ) ) {
3270                 return false;
3271             }
3272             if ( !shared_ni.contains( new BasicBinaryDomainCombination( "a", "c" ) ) ) {
3273                 return false;
3274             }
3275             if ( !shared_ni.contains( new BasicBinaryDomainCombination( "b", "c" ) ) ) {
3276                 return false;
3277             }
3278             if ( !shared_ni.contains( new BasicBinaryDomainCombination( "f", "f" ) ) ) {
3279                 return false;
3280             }
3281             if ( shared_ni.contains( new BasicBinaryDomainCombination( "m", "n" ) ) ) {
3282                 return false;
3283             }
3284             if ( shared_i.contains( new BasicBinaryDomainCombination( "a", "a" ) ) ) {
3285                 return false;
3286             }
3287             if ( !shared_i.contains( new BasicBinaryDomainCombination( "a", "b" ) ) ) {
3288                 return false;
3289             }
3290             if ( !shared_i.contains( new BasicBinaryDomainCombination( "a", "c" ) ) ) {
3291                 return false;
3292             }
3293             if ( !shared_i.contains( new BasicBinaryDomainCombination( "b", "c" ) ) ) {
3294                 return false;
3295             }
3296             if ( shared_i.contains( new BasicBinaryDomainCombination( "f", "f" ) ) ) {
3297                 return false;
3298             }
3299             if ( shared_i.contains( new BasicBinaryDomainCombination( "m", "n" ) ) ) {
3300                 return false;
3301             }
3302             if ( !s_0_ni.contains( new BasicBinaryDomainCombination( "a", "d" ) ) ) {
3303                 return false;
3304             }
3305             if ( !s_0_ni.contains( new BasicBinaryDomainCombination( "a", "e" ) ) ) {
3306                 return false;
3307             }
3308             if ( !s_0_ni.contains( new BasicBinaryDomainCombination( "b", "d" ) ) ) {
3309                 return false;
3310             }
3311             if ( !s_0_ni.contains( new BasicBinaryDomainCombination( "b", "e" ) ) ) {
3312                 return false;
3313             }
3314             if ( !s_0_ni.contains( new BasicBinaryDomainCombination( "c", "d" ) ) ) {
3315                 return false;
3316             }
3317             if ( !s_0_ni.contains( new BasicBinaryDomainCombination( "c", "e" ) ) ) {
3318                 return false;
3319             }
3320             if ( !s_0_ni.contains( new BasicBinaryDomainCombination( "d", "e" ) ) ) {
3321                 return false;
3322             }
3323             if ( !s_0_ni.contains( new BasicBinaryDomainCombination( "e", "f" ) ) ) {
3324                 return false;
3325             }
3326             if ( !s_0_ni.contains( new BasicBinaryDomainCombination( "g", "h" ) ) ) {
3327                 return false;
3328             }
3329             if ( !s_0_ni.contains( new BasicBinaryDomainCombination( "e", "e" ) ) ) {
3330                 return false;
3331             }
3332             if ( !s_0_i.contains( new BasicBinaryDomainCombination( "a", "d" ) ) ) {
3333                 return false;
3334             }
3335             if ( !s_0_i.contains( new BasicBinaryDomainCombination( "a", "e" ) ) ) {
3336                 return false;
3337             }
3338             if ( !s_0_i.contains( new BasicBinaryDomainCombination( "b", "d" ) ) ) {
3339                 return false;
3340             }
3341             if ( !s_0_i.contains( new BasicBinaryDomainCombination( "b", "e" ) ) ) {
3342                 return false;
3343             }
3344             if ( !s_0_i.contains( new BasicBinaryDomainCombination( "c", "d" ) ) ) {
3345                 return false;
3346             }
3347             if ( !s_0_i.contains( new BasicBinaryDomainCombination( "c", "e" ) ) ) {
3348                 return false;
3349             }
3350             if ( !s_0_i.contains( new BasicBinaryDomainCombination( "d", "e" ) ) ) {
3351                 return false;
3352             }
3353             if ( !s_0_i.contains( new BasicBinaryDomainCombination( "e", "f" ) ) ) {
3354                 return false;
3355             }
3356             if ( !s_0_i.contains( new BasicBinaryDomainCombination( "g", "h" ) ) ) {
3357                 return false;
3358             }
3359             if ( s_0_i.contains( new BasicBinaryDomainCombination( "e", "e" ) ) ) {
3360                 return false;
3361             }
3362             if ( !s_1_ni.contains( new BasicBinaryDomainCombination( "a", "i" ) ) ) {
3363                 return false;
3364             }
3365             if ( !s_1_ni.contains( new BasicBinaryDomainCombination( "a", "l" ) ) ) {
3366                 return false;
3367             }
3368             if ( !s_1_ni.contains( new BasicBinaryDomainCombination( "b", "i" ) ) ) {
3369                 return false;
3370             }
3371             if ( !s_1_ni.contains( new BasicBinaryDomainCombination( "b", "l" ) ) ) {
3372                 return false;
3373             }
3374             if ( !s_1_ni.contains( new BasicBinaryDomainCombination( "c", "i" ) ) ) {
3375                 return false;
3376             }
3377             if ( !s_1_ni.contains( new BasicBinaryDomainCombination( "c", "l" ) ) ) {
3378                 return false;
3379             }
3380             if ( !s_1_ni.contains( new BasicBinaryDomainCombination( "l", "i" ) ) ) {
3381                 return false;
3382             }
3383             if ( !s_1_ni.contains( new BasicBinaryDomainCombination( "i", "f" ) ) ) {
3384                 return false;
3385             }
3386             if ( !s_1_ni.contains( new BasicBinaryDomainCombination( "m", "n" ) ) ) {
3387                 return false;
3388             }
3389             if ( !s_1_ni.contains( new BasicBinaryDomainCombination( "j", "k" ) ) ) {
3390                 return false;
3391             }
3392             if ( s_1_ni.contains( new BasicBinaryDomainCombination( "a", "b" ) ) ) {
3393                 return false;
3394             }
3395             if ( !s_1_i.contains( new BasicBinaryDomainCombination( "a", "i" ) ) ) {
3396                 return false;
3397             }
3398             if ( !s_1_i.contains( new BasicBinaryDomainCombination( "a", "l" ) ) ) {
3399                 return false;
3400             }
3401             if ( !s_1_i.contains( new BasicBinaryDomainCombination( "b", "i" ) ) ) {
3402                 return false;
3403             }
3404             if ( !s_1_i.contains( new BasicBinaryDomainCombination( "b", "l" ) ) ) {
3405                 return false;
3406             }
3407             if ( !s_1_i.contains( new BasicBinaryDomainCombination( "c", "i" ) ) ) {
3408                 return false;
3409             }
3410             if ( !s_1_i.contains( new BasicBinaryDomainCombination( "c", "l" ) ) ) {
3411                 return false;
3412             }
3413             if ( !s_1_i.contains( new BasicBinaryDomainCombination( "l", "i" ) ) ) {
3414                 return false;
3415             }
3416             if ( !s_1_i.contains( new BasicBinaryDomainCombination( "i", "f" ) ) ) {
3417                 return false;
3418             }
3419             if ( !s_1_i.contains( new BasicBinaryDomainCombination( "m", "n" ) ) ) {
3420                 return false;
3421             }
3422             if ( !s_1_i.contains( new BasicBinaryDomainCombination( "j", "k" ) ) ) {
3423                 return false;
3424             }
3425             if ( s_1_i.contains( new BasicBinaryDomainCombination( "a", "b" ) ) ) {
3426                 return false;
3427             }
3428             if ( !isEqual( calc_ni.calculateSharedBinaryDomainCombinationBasedGenomeSimilarityScore(),
3429                            1.0 - ( 25.0 - 5.0 ) / 25.0 ) ) {
3430                 return false;
3431             }
3432             if ( !isEqual( calc_i.calculateSharedBinaryDomainCombinationBasedGenomeSimilarityScore(),
3433                            1.0 - ( 22.0 - 3.0 ) / 22.0 ) ) {
3434                 return false;
3435             }
3436             if ( !isEqual( calc_ni.calculateSharedDomainsBasedGenomeSimilarityScore(), 1.0 - ( 14.0 - 4.0 ) / 14.0 ) ) {
3437                 return false;
3438             }
3439             if ( !isEqual( calc_i.calculateSharedDomainsBasedGenomeSimilarityScore(), 1.0 - ( 14.0 - 4.0 ) / 14.0 ) ) {
3440                 return false;
3441             }
3442             final Domain u = new BasicDomain( "u", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
3443             final Domain v = new BasicDomain( "v", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
3444             final Domain w = new BasicDomain( "w", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
3445             final Domain x = new BasicDomain( "x", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
3446             final Domain y = new BasicDomain( "y", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
3447             final Domain z = new BasicDomain( "z", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
3448             final Protein a_0 = new BasicProtein( "0", "a" );
3449             final Protein a_1 = new BasicProtein( "1", "a" );
3450             final Protein a_2 = new BasicProtein( "2", "a" );
3451             final Protein b_0 = new BasicProtein( "0", "b" );
3452             final Protein b_1 = new BasicProtein( "1", "b" );
3453             a_0.addProteinDomain( u );
3454             a_0.addProteinDomain( v );
3455             a_0.addProteinDomain( w );
3456             a_1.addProteinDomain( w );
3457             a_1.addProteinDomain( x );
3458             a_2.addProteinDomain( y );
3459             a_2.addProteinDomain( z );
3460             b_0.addProteinDomain( u );
3461             b_0.addProteinDomain( w );
3462             b_1.addProteinDomain( y );
3463             b_1.addProteinDomain( z );
3464             final List<Protein> protein_list_a = new ArrayList<Protein>();
3465             protein_list_a.add( a_0 );
3466             protein_list_a.add( a_1 );
3467             protein_list_a.add( a_2 );
3468             final List<Protein> protein_list_b = new ArrayList<Protein>();
3469             protein_list_b.add( b_0 );
3470             protein_list_b.add( b_1 );
3471             final GenomeWideCombinableDomains ca = BasicGenomeWideCombinableDomains
3472                     .createInstance( protein_list_a, false, new BasicSpecies( "a" ) );
3473             final GenomeWideCombinableDomains cb = BasicGenomeWideCombinableDomains
3474                     .createInstance( protein_list_b, true, new BasicSpecies( "b" ) );
3475             final DomainArchitectureBasedGenomeSimilarityCalculator calc_u = new DomainArchitectureBasedGenomeSimilarityCalculator( ca,
3476                                                                                                                                     cb );
3477             calc_u.setAllowDomainsToBeIgnored( true );
3478             if ( calc_u.getAllDomains().size() != 6 ) {
3479                 return false;
3480             }
3481             if ( calc_u.getDomainsSpecificToGenome0().size() != 2 ) {
3482                 return false;
3483             }
3484             if ( calc_u.getDomainsSpecificToGenome1().size() != 0 ) {
3485                 return false;
3486             }
3487             if ( !calc_u.getDomainsSpecificToGenome0().contains( v.getDomainId() ) ) {
3488                 return false;
3489             }
3490             if ( !calc_u.getDomainsSpecificToGenome0().contains( x.getDomainId() ) ) {
3491                 return false;
3492             }
3493             if ( calc_u.getSharedDomains().size() != 4 ) {
3494                 return false;
3495             }
3496             if ( !calc_u.getSharedDomains().contains( u.getDomainId() ) ) {
3497                 return false;
3498             }
3499             if ( !calc_u.getSharedDomains().contains( w.getDomainId() ) ) {
3500                 return false;
3501             }
3502             if ( !calc_u.getSharedDomains().contains( y.getDomainId() ) ) {
3503                 return false;
3504             }
3505             if ( !calc_u.getSharedDomains().contains( z.getDomainId() ) ) {
3506                 return false;
3507             }
3508             if ( calc_u.getAllDomains().size() != 6 ) {
3509                 return false;
3510             }
3511             if ( !calc_u.getAllDomains().contains( u.getDomainId() ) ) {
3512                 return false;
3513             }
3514             if ( !calc_u.getAllDomains().contains( w.getDomainId() ) ) {
3515                 return false;
3516             }
3517             if ( !calc_u.getAllDomains().contains( y.getDomainId() ) ) {
3518                 return false;
3519             }
3520             if ( !calc_u.getAllDomains().contains( z.getDomainId() ) ) {
3521                 return false;
3522             }
3523             if ( !calc_u.getAllDomains().contains( v.getDomainId() ) ) {
3524                 return false;
3525             }
3526             if ( !calc_u.getAllDomains().contains( x.getDomainId() ) ) {
3527                 return false;
3528             }
3529             if ( calc_u.getBinaryDomainCombinationsSpecificToGenome0().size() != 3 ) {
3530                 return false;
3531             }
3532             if ( calc_u.getBinaryDomainCombinationsSpecificToGenome1().size() != 0 ) {
3533                 return false;
3534             }
3535             if ( calc_u.getSharedBinaryDomainCombinations().size() != 2 ) {
3536                 return false;
3537             }
3538             if ( calc_u.getAllBinaryDomainCombinations().size() != 5 ) {
3539                 return false;
3540             }
3541             if ( !calc_u.getBinaryDomainCombinationsSpecificToGenome0()
3542                     .contains( new BasicBinaryDomainCombination( "v", "u" ) ) ) {
3543                 return false;
3544             }
3545             if ( !calc_u.getBinaryDomainCombinationsSpecificToGenome0()
3546                     .contains( new BasicBinaryDomainCombination( "w", "v" ) ) ) {
3547                 return false;
3548             }
3549             if ( !calc_u.getBinaryDomainCombinationsSpecificToGenome0()
3550                     .contains( new BasicBinaryDomainCombination( "w", "x" ) ) ) {
3551                 return false;
3552             }
3553             if ( !calc_u.getSharedBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "w", "u" ) ) ) {
3554                 return false;
3555             }
3556             if ( !calc_u.getSharedBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "z", "y" ) ) ) {
3557                 return false;
3558             }
3559             if ( !calc_u.getAllBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "v", "u" ) ) ) {
3560                 return false;
3561             }
3562             if ( !calc_u.getAllBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "w", "v" ) ) ) {
3563                 return false;
3564             }
3565             if ( !calc_u.getAllBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "w", "x" ) ) ) {
3566                 return false;
3567             }
3568             if ( !calc_u.getAllBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "w", "u" ) ) ) {
3569                 return false;
3570             }
3571             if ( !calc_u.getAllBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "z", "y" ) ) ) {
3572                 return false;
3573             }
3574             calc_u.setAllowDomainsToBeIgnored( true );
3575             calc_u.addDomainIdToIgnore( u.getDomainId() );
3576             calc_u.addDomainIdToIgnore( new DomainId( "other" ) );
3577             calc_u.addDomainIdToIgnore( new DomainId( "other_too" ) );
3578             if ( calc_u.getAllDomains().size() != 5 ) {
3579                 return false;
3580             }
3581             if ( calc_u.getDomainsSpecificToGenome0().size() != 2 ) {
3582                 return false;
3583             }
3584             if ( calc_u.getDomainsSpecificToGenome1().size() != 0 ) {
3585                 return false;
3586             }
3587             if ( !calc_u.getDomainsSpecificToGenome0().contains( v.getDomainId() ) ) {
3588                 return false;
3589             }
3590             if ( !calc_u.getDomainsSpecificToGenome0().contains( x.getDomainId() ) ) {
3591                 return false;
3592             }
3593             if ( calc_u.getSharedDomains().size() != 3 ) {
3594                 return false;
3595             }
3596             if ( calc_u.getSharedDomains().contains( u.getDomainId() ) ) {
3597                 return false;
3598             }
3599             if ( !calc_u.getSharedDomains().contains( w.getDomainId() ) ) {
3600                 return false;
3601             }
3602             if ( !calc_u.getSharedDomains().contains( y.getDomainId() ) ) {
3603                 return false;
3604             }
3605             if ( !calc_u.getSharedDomains().contains( z.getDomainId() ) ) {
3606                 return false;
3607             }
3608             if ( calc_u.getAllDomains().size() != 5 ) {
3609                 return false;
3610             }
3611             if ( calc_u.getAllDomains().contains( u.getDomainId() ) ) {
3612                 return false;
3613             }
3614             if ( !calc_u.getAllDomains().contains( w.getDomainId() ) ) {
3615                 return false;
3616             }
3617             if ( !calc_u.getAllDomains().contains( y.getDomainId() ) ) {
3618                 return false;
3619             }
3620             if ( !calc_u.getAllDomains().contains( z.getDomainId() ) ) {
3621                 return false;
3622             }
3623             if ( !calc_u.getAllDomains().contains( v.getDomainId() ) ) {
3624                 return false;
3625             }
3626             if ( !calc_u.getAllDomains().contains( x.getDomainId() ) ) {
3627                 return false;
3628             }
3629             if ( calc_u.getBinaryDomainCombinationsSpecificToGenome0().size() != 2 ) {
3630                 return false;
3631             }
3632             if ( calc_u.getBinaryDomainCombinationsSpecificToGenome1().size() != 0 ) {
3633                 return false;
3634             }
3635             if ( calc_u.getSharedBinaryDomainCombinations().size() != 1 ) {
3636                 return false;
3637             }
3638             if ( calc_u.getAllBinaryDomainCombinations().size() != 3 ) {
3639                 return false;
3640             }
3641             if ( calc_u.getBinaryDomainCombinationsSpecificToGenome0()
3642                     .contains( new BasicBinaryDomainCombination( "v", "u" ) ) ) {
3643                 return false;
3644             }
3645             if ( !calc_u.getBinaryDomainCombinationsSpecificToGenome0()
3646                     .contains( new BasicBinaryDomainCombination( "w", "v" ) ) ) {
3647                 return false;
3648             }
3649             if ( !calc_u.getBinaryDomainCombinationsSpecificToGenome0()
3650                     .contains( new BasicBinaryDomainCombination( "w", "x" ) ) ) {
3651                 return false;
3652             }
3653             if ( calc_u.getSharedBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "w", "u" ) ) ) {
3654                 return false;
3655             }
3656             if ( !calc_u.getSharedBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "z", "y" ) ) ) {
3657                 return false;
3658             }
3659             if ( calc_u.getAllBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "v", "u" ) ) ) {
3660                 return false;
3661             }
3662             if ( !calc_u.getAllBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "w", "v" ) ) ) {
3663                 return false;
3664             }
3665             if ( !calc_u.getAllBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "w", "x" ) ) ) {
3666                 return false;
3667             }
3668             if ( calc_u.getAllBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "w", "u" ) ) ) {
3669                 return false;
3670             }
3671             if ( !calc_u.getAllBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "z", "y" ) ) ) {
3672                 return false;
3673             }
3674             calc_u.setAllowDomainsToBeIgnored( false );
3675             if ( calc_u.getAllDomains().size() != 6 ) {
3676                 return false;
3677             }
3678             //------------
3679             calc_u.setAllowDomainsToBeIgnored( true );
3680             calc_u.deleteAllDomainIdsToIgnore();
3681             calc_u.addDomainIdToIgnore( new DomainId( "v" ) );
3682             calc_u.addDomainIdToIgnore( new DomainId( "w" ) );
3683             calc_u.addDomainIdToIgnore( new DomainId( "other" ) );
3684             calc_u.addDomainIdToIgnore( new DomainId( "other_too" ) );
3685             if ( calc_u.getAllDomains().size() != 4 ) {
3686                 return false;
3687             }
3688             if ( calc_u.getDomainsSpecificToGenome0().size() != 1 ) {
3689                 return false;
3690             }
3691             if ( calc_u.getDomainsSpecificToGenome1().size() != 0 ) {
3692                 return false;
3693             }
3694             if ( calc_u.getDomainsSpecificToGenome0().contains( v.getDomainId() ) ) {
3695                 return false;
3696             }
3697             if ( !calc_u.getDomainsSpecificToGenome0().contains( x.getDomainId() ) ) {
3698                 return false;
3699             }
3700             if ( calc_u.getSharedDomains().size() != 3 ) {
3701                 return false;
3702             }
3703             if ( !calc_u.getSharedDomains().contains( u.getDomainId() ) ) {
3704                 return false;
3705             }
3706             if ( calc_u.getSharedDomains().contains( w.getDomainId() ) ) {
3707                 return false;
3708             }
3709             if ( !calc_u.getSharedDomains().contains( y.getDomainId() ) ) {
3710                 return false;
3711             }
3712             if ( !calc_u.getSharedDomains().contains( z.getDomainId() ) ) {
3713                 return false;
3714             }
3715             if ( calc_u.getAllDomains().size() != 4 ) {
3716                 return false;
3717             }
3718             if ( !calc_u.getAllDomains().contains( u.getDomainId() ) ) {
3719                 return false;
3720             }
3721             if ( calc_u.getAllDomains().contains( w.getDomainId() ) ) {
3722                 return false;
3723             }
3724             if ( !calc_u.getAllDomains().contains( y.getDomainId() ) ) {
3725                 return false;
3726             }
3727             if ( !calc_u.getAllDomains().contains( z.getDomainId() ) ) {
3728                 return false;
3729             }
3730             if ( calc_u.getAllDomains().contains( v.getDomainId() ) ) {
3731                 return false;
3732             }
3733             if ( !calc_u.getAllDomains().contains( x.getDomainId() ) ) {
3734                 return false;
3735             }
3736             if ( calc_u.getBinaryDomainCombinationsSpecificToGenome0().size() != 0 ) {
3737                 return false;
3738             }
3739             if ( calc_u.getBinaryDomainCombinationsSpecificToGenome1().size() != 0 ) {
3740                 return false;
3741             }
3742             if ( calc_u.getSharedBinaryDomainCombinations().size() != 1 ) {
3743                 return false;
3744             }
3745             if ( calc_u.getAllBinaryDomainCombinations().size() != 1 ) {
3746                 return false;
3747             }
3748             if ( !calc_u.getSharedBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "y", "z" ) ) ) {
3749                 return false;
3750             }
3751             if ( !calc_u.getAllBinaryDomainCombinations().contains( new BasicBinaryDomainCombination( "z", "y" ) ) ) {
3752                 return false;
3753             }
3754             if ( !isEqual( calc_u.calculateSharedBinaryDomainCombinationBasedGenomeSimilarityScore(),
3755                            1.0 - ( 1.0 - 1.0 ) / 1.0 ) ) {
3756                 return false;
3757             }
3758             if ( !isEqual( calc_u.calculateSharedDomainsBasedGenomeSimilarityScore(), 1.0 - ( 4.0 - 3.0 ) / 4.0 ) ) {
3759                 return false;
3760             }
3761             calc_u.setAllowDomainsToBeIgnored( false );
3762             if ( !isEqual( calc_u.calculateSharedBinaryDomainCombinationBasedGenomeSimilarityScore(),
3763                            1.0 - ( 5.0 - 2.0 ) / 5.0 ) ) {
3764                 return false;
3765             }
3766             if ( !isEqual( calc_u.calculateSharedDomainsBasedGenomeSimilarityScore(), 1.0 - ( 6.0 - 4.0 ) / 6.0 ) ) {
3767                 return false;
3768             }
3769             calc_u.setAllowDomainsToBeIgnored( true );
3770             if ( !isEqual( calc_u.calculateSharedBinaryDomainCombinationBasedGenomeSimilarityScore(),
3771                            1.0 - ( 1.0 - 1.0 ) / 1.0 ) ) {
3772                 return false;
3773             }
3774             if ( !isEqual( calc_u.calculateSharedDomainsBasedGenomeSimilarityScore(), 1.0 - ( 4.0 - 3.0 ) / 4.0 ) ) {
3775                 return false;
3776             }
3777             calc_u.deleteAllDomainIdsToIgnore();
3778             if ( !isEqual( calc_u.calculateSharedBinaryDomainCombinationBasedGenomeSimilarityScore(),
3779                            1.0 - ( 5.0 - 2.0 ) / 5.0 ) ) {
3780                 return false;
3781             }
3782             if ( !isEqual( calc_u.calculateSharedDomainsBasedGenomeSimilarityScore(), 1.0 - ( 6.0 - 4.0 ) / 6.0 ) ) {
3783                 return false;
3784             }
3785         }
3786         catch ( final Exception e ) {
3787             e.printStackTrace( System.out );
3788             return false;
3789         }
3790         return true;
3791     }
3792
3793     private static boolean testDomainCombinationCounting( final File test_dir ) {
3794         try {
3795             final HmmPfamOutputParser parser = new HmmPfamOutputParser( new File( test_dir
3796                     + ForesterUtil.getFileSeparator() + "hmmpfam_output2" ), "human", "ls" );
3797             parser.setEValueMaximum( 0.2 );
3798             parser.setIgnoreDufs( true );
3799             parser.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
3800             final List<Protein> domain_collections = parser.parse();
3801             final BasicGenomeWideCombinableDomains cdcc = BasicGenomeWideCombinableDomains
3802                     .createInstance( domain_collections, false, new BasicSpecies( "human" ) );
3803             CombinableDomains cd = cdcc.get( new DomainId( "A" ) );
3804             if ( cd.getKeyDomainCount() != 9 ) {
3805                 return false;
3806             }
3807             if ( cd.getKeyDomainProteinsCount() != 7 ) {
3808                 return false;
3809             }
3810             if ( cd.getNumberOfCombinableDomains() != 11 ) {
3811                 return false;
3812             }
3813             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "A" ).getDomainId() ) != 2 ) {
3814                 return false;
3815             }
3816             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "B" ).getDomainId() ) != 6 ) {
3817                 return false;
3818             }
3819             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "C" ).getDomainId() ) != 4 ) {
3820                 return false;
3821             }
3822             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "D" ).getDomainId() ) != 3 ) {
3823                 return false;
3824             }
3825             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "E" ).getDomainId() ) != 1 ) {
3826                 return false;
3827             }
3828             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "U" ).getDomainId() ) != 1 ) {
3829                 return false;
3830             }
3831             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "V" ).getDomainId() ) != 1 ) {
3832                 return false;
3833             }
3834             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "W" ).getDomainId() ) != 1 ) {
3835                 return false;
3836             }
3837             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "X" ).getDomainId() ) != 1 ) {
3838                 return false;
3839             }
3840             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "Y" ).getDomainId() ) != 1 ) {
3841                 return false;
3842             }
3843             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "Z" ).getDomainId() ) != 1 ) {
3844                 return false;
3845             }
3846             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "NN" ).getDomainId() ) != 0 ) {
3847                 return false;
3848             }
3849             if ( cd.getKeyDomainCount() != 9 ) {
3850                 return false;
3851             }
3852             cd = cdcc.get( new DomainId( "B" ) );
3853             if ( cd.getKeyDomainCount() != 12 ) {
3854                 return false;
3855             }
3856             if ( cd.getKeyDomainProteinsCount() != 7 ) {
3857                 return false;
3858             }
3859             if ( cd.getNumberOfCombinableDomains() != 11 ) {
3860                 return false;
3861             }
3862             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "A" ).getDomainId() ) != 6 ) {
3863                 return false;
3864             }
3865             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "B" ).getDomainId() ) != 4 ) {
3866                 return false;
3867             }
3868             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "C" ).getDomainId() ) != 4 ) {
3869                 return false;
3870             }
3871             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "D" ).getDomainId() ) != 3 ) {
3872                 return false;
3873             }
3874             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "E" ).getDomainId() ) != 1 ) {
3875                 return false;
3876             }
3877             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "U" ).getDomainId() ) != 1 ) {
3878                 return false;
3879             }
3880             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "V" ).getDomainId() ) != 1 ) {
3881                 return false;
3882             }
3883             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "W" ).getDomainId() ) != 1 ) {
3884                 return false;
3885             }
3886             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "X" ).getDomainId() ) != 1 ) {
3887                 return false;
3888             }
3889             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "Y" ).getDomainId() ) != 1 ) {
3890                 return false;
3891             }
3892             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "Z" ).getDomainId() ) != 1 ) {
3893                 return false;
3894             }
3895             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "NN" ).getDomainId() ) != 0 ) {
3896                 return false;
3897             }
3898             if ( cd.getKeyDomainCount() != 12 ) {
3899                 return false;
3900             }
3901             cd = cdcc.get( new DomainId( "C" ) );
3902             if ( cd.getKeyDomainCount() != 10 ) {
3903                 return false;
3904             }
3905             if ( cd.getKeyDomainProteinsCount() != 7 ) {
3906                 return false;
3907             }
3908             if ( cd.getNumberOfCombinableDomains() != 11 ) {
3909                 return false;
3910             }
3911             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "A" ).getDomainId() ) != 4 ) {
3912                 return false;
3913             }
3914             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "B" ).getDomainId() ) != 4 ) {
3915                 return false;
3916             }
3917             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "C" ).getDomainId() ) != 2 ) {
3918                 return false;
3919             }
3920             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "D" ).getDomainId() ) != 3 ) {
3921                 return false;
3922             }
3923             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "E" ).getDomainId() ) != 1 ) {
3924                 return false;
3925             }
3926             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "U" ).getDomainId() ) != 1 ) {
3927                 return false;
3928             }
3929             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "V" ).getDomainId() ) != 1 ) {
3930                 return false;
3931             }
3932             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "W" ).getDomainId() ) != 1 ) {
3933                 return false;
3934             }
3935             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "X" ).getDomainId() ) != 2 ) {
3936                 return false;
3937             }
3938             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "Y" ).getDomainId() ) != 2 ) {
3939                 return false;
3940             }
3941             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "Z" ).getDomainId() ) != 2 ) {
3942                 return false;
3943             }
3944             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "NN" ).getDomainId() ) != 0 ) {
3945                 return false;
3946             }
3947             cd = cdcc.get( new DomainId( "D" ) );
3948             if ( cd.getKeyDomainCount() != 15 ) {
3949                 return false;
3950             }
3951             if ( cd.getKeyDomainProteinsCount() != 6 ) {
3952                 return false;
3953             }
3954             if ( cd.getNumberOfCombinableDomains() != 11 ) {
3955                 return false;
3956             }
3957             cd = cdcc.get( new DomainId( "E" ) );
3958             if ( cd.getNumberOfCombinableDomains() != 10 ) {
3959                 return false;
3960             }
3961             if ( cd.getKeyDomainCount() != 1 ) {
3962                 return false;
3963             }
3964             if ( cd.getKeyDomainProteinsCount() != 1 ) {
3965                 return false;
3966             }
3967             cd = cdcc.get( new DomainId( "U" ) );
3968             if ( cd.getNumberOfCombinableDomains() != 11 ) {
3969                 return false;
3970             }
3971             if ( cd.getKeyDomainCount() != 6 ) {
3972                 return false;
3973             }
3974             if ( cd.getKeyDomainProteinsCount() != 3 ) {
3975                 return false;
3976             }
3977             cd = cdcc.get( new DomainId( "V" ) );
3978             if ( cd.getNumberOfCombinableDomains() != 11 ) {
3979                 return false;
3980             }
3981             if ( cd.getKeyDomainCount() != 3 ) {
3982                 return false;
3983             }
3984             if ( cd.getKeyDomainProteinsCount() != 2 ) {
3985                 return false;
3986             }
3987             cd = cdcc.get( new DomainId( "W" ) );
3988             if ( cd.getNumberOfCombinableDomains() != 10 ) {
3989                 return false;
3990             }
3991             if ( cd.getKeyDomainCount() != 2 ) {
3992                 return false;
3993             }
3994             if ( cd.getKeyDomainProteinsCount() != 2 ) {
3995                 return false;
3996             }
3997             cd = cdcc.get( new DomainId( "X" ) );
3998             if ( cd.getNumberOfCombinableDomains() != 10 ) {
3999                 return false;
4000             }
4001             if ( cd.getKeyDomainCount() != 2 ) {
4002                 return false;
4003             }
4004             cd = cdcc.get( new DomainId( "Y" ) );
4005             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4006                 return false;
4007             }
4008             cd = cdcc.get( new DomainId( "Z" ) );
4009             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4010                 return false;
4011             }
4012             cd = cdcc.get( new DomainId( "NN" ) );
4013             if ( cd.getKeyDomainCount() != 1 ) {
4014                 return false;
4015             }
4016             if ( cd.getKeyDomainProteinsCount() != 1 ) {
4017                 return false;
4018             }
4019             if ( cd.getNumberOfCombinableDomains() != 0 ) {
4020                 return false;
4021             }
4022             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "NN" ).getDomainId() ) != 0 ) {
4023                 return false;
4024             }
4025             cd = cdcc.get( new DomainId( "MM" ) );
4026             if ( cd.getNumberOfCombinableDomains() != 1 ) {
4027                 return false;
4028             }
4029             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "MM" ).getDomainId() ) != 0 ) {
4030                 return false;
4031             }
4032             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "OO" ).getDomainId() ) != 1 ) {
4033                 return false;
4034             }
4035             cd = cdcc.get( new DomainId( "OO" ) );
4036             if ( cd.getNumberOfCombinableDomains() != 2 ) {
4037                 return false;
4038             }
4039             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "OO" ).getDomainId() ) != 1 ) {
4040                 return false;
4041             }
4042             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "MM" ).getDomainId() ) != 1 ) {
4043                 return false;
4044             }
4045             cd = cdcc.get( new DomainId( "QQ" ) );
4046             if ( cd.getNumberOfCombinableDomains() != 1 ) {
4047                 return false;
4048             }
4049             if ( cd.getKeyDomainCount() != 17 ) {
4050                 return false;
4051             }
4052             if ( cd.getKeyDomainProteinsCount() != 4 ) {
4053                 return false;
4054             }
4055             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "QQ" ).getDomainId() ) != 3 ) {
4056                 return false;
4057             }
4058             cd = cdcc.get( new DomainId( "PP" ) );
4059             if ( cd.getNumberOfCombinableDomains() != 0 ) {
4060                 return false;
4061             }
4062             if ( cd.getKeyDomainCount() != 2 ) {
4063                 return false;
4064             }
4065             if ( cd.getKeyDomainProteinsCount() != 2 ) {
4066                 return false;
4067             }
4068             cd = cdcc.get( new DomainId( "singlet" ) );
4069             if ( cd.getKeyDomainCount() != 1 ) {
4070                 return false;
4071             }
4072             if ( cd.getKeyDomainProteinsCount() != 1 ) {
4073                 return false;
4074             }
4075             if ( cd.getNumberOfCombinableDomains() != 0 ) {
4076                 return false;
4077             }
4078             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "singlet" ).getDomainId() ) != 0 ) {
4079                 return false;
4080             }
4081             cd = cdcc.get( new DomainId( "three" ) );
4082             if ( cd.getKeyDomainCount() != 3 ) {
4083                 return false;
4084             }
4085             if ( cd.getKeyDomainProteinsCount() != 1 ) {
4086                 return false;
4087             }
4088             if ( cd.getNumberOfCombinableDomains() != 1 ) {
4089                 return false;
4090             }
4091             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "three" ) ) != 1 ) {
4092                 return false;
4093             }
4094             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "so_far_so_bad" ) ) != 0 ) {
4095                 return false;
4096             }
4097             // Ignore combinations with same:
4098             final BasicGenomeWideCombinableDomains cdcc2 = BasicGenomeWideCombinableDomains
4099                     .createInstance( domain_collections,
4100                                      true,
4101                                      new BasicSpecies( "human" ),
4102                                      null,
4103                                      DomainCombinationType.BASIC );
4104             cd = cdcc2.get( new DomainId( "A" ) );
4105             if ( cd.getKeyDomainCount() != 9 ) {
4106                 return false;
4107             }
4108             if ( cd.getKeyDomainProteinsCount() != 7 ) {
4109                 return false;
4110             }
4111             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4112                 return false;
4113             }
4114             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "A" ).getDomainId() ) != 0 ) {
4115                 return false;
4116             }
4117             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "B" ).getDomainId() ) != 6 ) {
4118                 return false;
4119             }
4120             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "C" ).getDomainId() ) != 4 ) {
4121                 return false;
4122             }
4123             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "D" ).getDomainId() ) != 3 ) {
4124                 return false;
4125             }
4126             if ( cd.getNumberOfProteinsExhibitingCombination( new SimpleDomain( "E" ).getDomainId() ) != 1 ) {
4127                 return false;
4128             }
4129             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "U" ) ) != 1 ) {
4130                 return false;
4131             }
4132             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "V" ) ) != 1 ) {
4133                 return false;
4134             }
4135             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "W" ) ) != 1 ) {
4136                 return false;
4137             }
4138             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "X" ) ) != 1 ) {
4139                 return false;
4140             }
4141             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "Y" ) ) != 1 ) {
4142                 return false;
4143             }
4144             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "Z" ) ) != 1 ) {
4145                 return false;
4146             }
4147             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "NN" ) ) != 0 ) {
4148                 return false;
4149             }
4150             cd = cdcc2.get( new DomainId( "B" ) );
4151             if ( cd.getKeyDomainCount() != 12 ) {
4152                 return false;
4153             }
4154             if ( cd.getKeyDomainProteinsCount() != 7 ) {
4155                 return false;
4156             }
4157             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4158                 return false;
4159             }
4160             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "A" ) ) != 6 ) {
4161                 return false;
4162             }
4163             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "B" ) ) != 0 ) {
4164                 return false;
4165             }
4166             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "C" ) ) != 4 ) {
4167                 return false;
4168             }
4169             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "D" ) ) != 3 ) {
4170                 return false;
4171             }
4172             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "E" ) ) != 1 ) {
4173                 return false;
4174             }
4175             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "U" ) ) != 1 ) {
4176                 return false;
4177             }
4178             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "V" ) ) != 1 ) {
4179                 return false;
4180             }
4181             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "W" ) ) != 1 ) {
4182                 return false;
4183             }
4184             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "X" ) ) != 1 ) {
4185                 return false;
4186             }
4187             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "Y" ) ) != 1 ) {
4188                 return false;
4189             }
4190             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "Z" ) ) != 1 ) {
4191                 return false;
4192             }
4193             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "NN" ) ) != 0 ) {
4194                 return false;
4195             }
4196             cd = cdcc2.get( new DomainId( "C" ) );
4197             if ( cd.getKeyDomainCount() != 10 ) {
4198                 return false;
4199             }
4200             if ( cd.getKeyDomainProteinsCount() != 7 ) {
4201                 return false;
4202             }
4203             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4204                 return false;
4205             }
4206             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "A" ) ) != 4 ) {
4207                 return false;
4208             }
4209             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "B" ) ) != 4 ) {
4210                 return false;
4211             }
4212             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "C" ) ) != 0 ) {
4213                 return false;
4214             }
4215             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "D" ) ) != 3 ) {
4216                 return false;
4217             }
4218             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "E" ) ) != 1 ) {
4219                 return false;
4220             }
4221             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "U" ) ) != 1 ) {
4222                 return false;
4223             }
4224             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "V" ) ) != 1 ) {
4225                 return false;
4226             }
4227             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "W" ) ) != 1 ) {
4228                 return false;
4229             }
4230             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "X" ) ) != 2 ) {
4231                 return false;
4232             }
4233             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "Y" ) ) != 2 ) {
4234                 return false;
4235             }
4236             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "Z" ) ) != 2 ) {
4237                 return false;
4238             }
4239             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "NN" ) ) != 0 ) {
4240                 return false;
4241             }
4242             cd = cdcc2.get( new DomainId( "D" ) );
4243             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4244                 return false;
4245             }
4246             cd = cdcc2.get( new DomainId( "E" ) );
4247             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4248                 return false;
4249             }
4250             if ( cd.getKeyDomainCount() != 1 ) {
4251                 return false;
4252             }
4253             cd = cdcc2.get( new DomainId( "U" ) );
4254             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4255                 return false;
4256             }
4257             cd = cdcc2.get( new DomainId( "V" ) );
4258             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4259                 return false;
4260             }
4261             cd = cdcc2.get( new DomainId( "W" ) );
4262             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4263                 return false;
4264             }
4265             cd = cdcc2.get( new DomainId( "X" ) );
4266             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4267                 return false;
4268             }
4269             cd = cdcc2.get( new DomainId( "Y" ) );
4270             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4271                 return false;
4272             }
4273             cd = cdcc2.get( new DomainId( "Z" ) );
4274             if ( cd.getNumberOfCombinableDomains() != 10 ) {
4275                 return false;
4276             }
4277             cd = cdcc2.get( new DomainId( "NN" ) );
4278             if ( cd.getNumberOfCombinableDomains() != 0 ) {
4279                 return false;
4280             }
4281             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "NN" ) ) != 0 ) {
4282                 return false;
4283             }
4284             cd = cdcc2.get( new DomainId( "MM" ) );
4285             if ( cd.getNumberOfCombinableDomains() != 1 ) {
4286                 return false;
4287             }
4288             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "MM" ) ) != 0 ) {
4289                 return false;
4290             }
4291             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "OO" ) ) != 1 ) {
4292                 return false;
4293             }
4294             cd = cdcc2.get( new DomainId( "OO" ) );
4295             if ( cd.getNumberOfCombinableDomains() != 1 ) {
4296                 return false;
4297             }
4298             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "OO" ) ) != 0 ) {
4299                 return false;
4300             }
4301             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "MM" ) ) != 1 ) {
4302                 return false;
4303             }
4304             cd = cdcc2.get( new DomainId( "QQ" ) );
4305             if ( cd.getNumberOfCombinableDomains() != 0 ) {
4306                 return false;
4307             }
4308             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "QQ" ) ) != 0 ) {
4309                 return false;
4310             }
4311             cd = cdcc2.get( new DomainId( "singlet" ) );
4312             if ( cd.getKeyDomainCount() != 1 ) {
4313                 return false;
4314             }
4315             if ( cd.getKeyDomainProteinsCount() != 1 ) {
4316                 return false;
4317             }
4318             if ( cd.getNumberOfCombinableDomains() != 0 ) {
4319                 return false;
4320             }
4321             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "singlet" ) ) != 0 ) {
4322                 return false;
4323             }
4324             cd = cdcc2.get( new DomainId( "three" ) );
4325             if ( cd.getKeyDomainCount() != 3 ) {
4326                 return false;
4327             }
4328             if ( cd.getKeyDomainProteinsCount() != 1 ) {
4329                 return false;
4330             }
4331             if ( cd.getNumberOfCombinableDomains() != 0 ) {
4332                 return false;
4333             }
4334             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "three" ) ) != 0 ) {
4335                 return false;
4336             }
4337             if ( cd.getNumberOfProteinsExhibitingCombination( new DomainId( "so_far_so_bad" ) ) != 0 ) {
4338                 return false;
4339             }
4340         }
4341         catch ( final Exception e ) {
4342             e.printStackTrace( System.out );
4343             return false;
4344         }
4345         return true;
4346     }
4347
4348     private static boolean testDomainId() {
4349         try {
4350             final DomainId id1 = new DomainId( "a" );
4351             final DomainId id2 = new DomainId( "a" );
4352             final DomainId id3 = new DomainId( "A" );
4353             final DomainId id4 = new DomainId( "b" );
4354             if ( !id1.equals( id1 ) ) {
4355                 return false;
4356             }
4357             if ( id1.getId().equals( "x" ) ) {
4358                 return false;
4359             }
4360             if ( id1.getId().equals( null ) ) {
4361                 return false;
4362             }
4363             if ( !id1.equals( id2 ) ) {
4364                 return false;
4365             }
4366             if ( id1.equals( id3 ) ) {
4367                 return false;
4368             }
4369             if ( id1.hashCode() != id1.hashCode() ) {
4370                 return false;
4371             }
4372             if ( id1.hashCode() != id2.hashCode() ) {
4373                 return false;
4374             }
4375             if ( id1.hashCode() == id3.hashCode() ) {
4376                 return false;
4377             }
4378             if ( id1.compareTo( id1 ) != 0 ) {
4379                 return false;
4380             }
4381             if ( id1.compareTo( id2 ) != 0 ) {
4382                 return false;
4383             }
4384             if ( id1.compareTo( id3 ) != 0 ) {
4385                 return false;
4386             }
4387             if ( id1.compareTo( id4 ) >= 0 ) {
4388                 return false;
4389             }
4390             if ( id4.compareTo( id1 ) <= 0 ) {
4391                 return false;
4392             }
4393             if ( !id4.getId().equals( "b" ) ) {
4394                 return false;
4395             }
4396             final DomainId id5 = new DomainId( " C " );
4397             if ( !id5.getId().equals( "C" ) ) {
4398                 return false;
4399             }
4400             if ( id5.equals( id1 ) ) {
4401                 return false;
4402             }
4403         }
4404         catch ( final Exception e ) {
4405             e.printStackTrace( System.out );
4406             return false;
4407         }
4408         return true;
4409     }
4410
4411     private static boolean testDomainSorting() {
4412         try {
4413             final Domain A = new BasicDomain( "A", ( short ) 1, ( short ) 2, ( short ) 1, ( short ) 1, 0.1, -12 );
4414             final Domain B = new BasicDomain( "B", ( short ) 1, ( short ) 2, ( short ) 1, ( short ) 1, 0.1, -12 );
4415             final Domain C = new BasicDomain( "C", ( short ) 1, ( short ) 2, ( short ) 1, ( short ) 1, 0.2, -12 );
4416             final Domain D = new BasicDomain( "D", ( short ) 1, ( short ) 2, ( short ) 1, ( short ) 1, 0.3, -12 );
4417             final Domain E = new BasicDomain( "E", ( short ) 1, ( short ) 2, ( short ) 1, ( short ) 1, 0.4, -12 );
4418             final Domain F = new BasicDomain( "F", ( short ) 1, ( short ) 2, ( short ) 1, ( short ) 1, 0.5, -12 );
4419             final Domain G = new BasicDomain( "G", ( short ) 1, ( short ) 2, ( short ) 1, ( short ) 1, 0.6, -12 );
4420             final Domain H1 = new BasicDomain( "H", ( short ) 100, ( short ) 200, ( short ) 1, ( short ) 5, 0.7, -12 );
4421             final Domain H2 = new BasicDomain( "H", ( short ) 300, ( short ) 400, ( short ) 2, ( short ) 5, 0.7, -12 );
4422             final Domain H3 = new BasicDomain( "H", ( short ) 500, ( short ) 600, ( short ) 3, ( short ) 5, 0.7, -12 );
4423             final Domain H4 = new BasicDomain( "H", ( short ) 700, ( short ) 800, ( short ) 4, ( short ) 5, 0.7, -12 );
4424             final Domain H5 = new BasicDomain( "H", ( short ) 700, ( short ) 800, ( short ) 5, ( short ) 5, 0.7, -12 );
4425             final Domain H6 = new BasicDomain( "H",
4426                                                ( short ) 1199,
4427                                                ( short ) 1299,
4428                                                ( short ) 6,
4429                                                ( short ) 6,
4430                                                0.7,
4431                                                -0.111 );
4432             final Domain H7 = new BasicDomain( "H7", ( short ) 700, ( short ) 800, ( short ) 5, ( short ) 5, 0.7, -12 );
4433             final Domain H8 = new BasicDomain( "H7", ( short ) 700, ( short ) 800, ( short ) 5, ( short ) 200, 0.7, -12 );
4434             final Protein protein = new BasicProtein( "00", "bat" );
4435             protein.addProteinDomain( H5 );
4436             protein.addProteinDomain( H2 );
4437             protein.addProteinDomain( H7 );
4438             protein.addProteinDomain( H6 );
4439             protein.addProteinDomain( A );
4440             protein.addProteinDomain( G );
4441             protein.addProteinDomain( H4 );
4442             protein.addProteinDomain( D );
4443             protein.addProteinDomain( H1 );
4444             protein.addProteinDomain( C );
4445             protein.addProteinDomain( E );
4446             protein.addProteinDomain( F );
4447             protein.addProteinDomain( B );
4448             protein.addProteinDomain( H3 );
4449             protein.addProteinDomain( H7 );
4450             protein.addProteinDomain( H7 );
4451             protein.addProteinDomain( H8 );
4452             final List<Domain> sorted = SurfacingUtil.sortDomainsWithAscendingConfidenceValues( protein );
4453             if ( sorted.size() != 17 ) {
4454                 return false;
4455             }
4456             if ( !sorted.get( 0 ).getDomainId().getId().equals( "A" ) ) {
4457                 return false;
4458             }
4459             if ( sorted.get( 0 ).getNumber() != 1 ) {
4460                 return false;
4461             }
4462             if ( !sorted.get( 1 ).getDomainId().getId().equals( "B" ) ) {
4463                 return false;
4464             }
4465             if ( sorted.get( 1 ).getNumber() != 1 ) {
4466                 return false;
4467             }
4468             if ( !sorted.get( 2 ).getDomainId().getId().equals( "C" ) ) {
4469                 return false;
4470             }
4471             if ( sorted.get( 2 ).getNumber() != 1 ) {
4472                 return false;
4473             }
4474             if ( !sorted.get( 3 ).getDomainId().getId().equals( "D" ) ) {
4475                 return false;
4476             }
4477             if ( sorted.get( 3 ).getNumber() != 1 ) {
4478                 return false;
4479             }
4480             if ( !sorted.get( 4 ).getDomainId().getId().equals( "E" ) ) {
4481                 return false;
4482             }
4483             if ( sorted.get( 4 ).getNumber() != 1 ) {
4484                 return false;
4485             }
4486             if ( !sorted.get( 5 ).getDomainId().getId().equals( "F" ) ) {
4487                 return false;
4488             }
4489             if ( sorted.get( 5 ).getNumber() != 1 ) {
4490                 return false;
4491             }
4492             if ( !sorted.get( 6 ).getDomainId().getId().equals( "G" ) ) {
4493                 return false;
4494             }
4495             if ( sorted.get( 6 ).getNumber() != 1 ) {
4496                 return false;
4497             }
4498             if ( !sorted.get( 7 ).getDomainId().getId().equals( "H" ) ) {
4499                 return false;
4500             }
4501             if ( sorted.get( 7 ).getNumber() != 5 ) {
4502                 return false;
4503             }
4504             if ( !sorted.get( 8 ).getDomainId().getId().equals( "H" ) ) {
4505                 return false;
4506             }
4507             if ( sorted.get( 8 ).getNumber() != 2 ) {
4508                 return false;
4509             }
4510             if ( !sorted.get( 9 ).getDomainId().getId().equals( "H" ) ) {
4511                 return false;
4512             }
4513             if ( sorted.get( 9 ).getNumber() != 6 ) {
4514                 return false;
4515             }
4516             if ( !sorted.get( 10 ).getDomainId().getId().equals( "H" ) ) {
4517                 return false;
4518             }
4519             if ( sorted.get( 10 ).getNumber() != 4 ) {
4520                 return false;
4521             }
4522             if ( !sorted.get( 11 ).getDomainId().getId().equals( "H" ) ) {
4523                 return false;
4524             }
4525             if ( sorted.get( 11 ).getNumber() != 1 ) {
4526                 return false;
4527             }
4528             if ( sorted.get( 11 ).getTotalCount() != 5 ) {
4529                 return false;
4530             }
4531             if ( !sorted.get( 12 ).getDomainId().getId().equals( "H" ) ) {
4532                 return false;
4533             }
4534             if ( sorted.get( 12 ).getNumber() != 3 ) {
4535                 return false;
4536             }
4537             if ( !sorted.get( 13 ).getDomainId().getId().equals( "H7" ) ) {
4538                 return false;
4539             }
4540             if ( sorted.get( 13 ).getNumber() != 5 ) {
4541                 return false;
4542             }
4543             if ( !sorted.get( 14 ).getDomainId().getId().equals( "H7" ) ) {
4544                 return false;
4545             }
4546             if ( sorted.get( 14 ).getNumber() != 5 ) {
4547                 return false;
4548             }
4549             if ( !sorted.get( 15 ).getDomainId().getId().equals( "H7" ) ) {
4550                 return false;
4551             }
4552             if ( sorted.get( 15 ).getNumber() != 5 ) {
4553                 return false;
4554             }
4555             // To check if sorting is stable [as claimed by Sun for
4556             // Collections.sort( List )]
4557             if ( !sorted.get( 16 ).getDomainId().getId().equals( "H7" ) ) {
4558                 return false;
4559             }
4560             if ( sorted.get( 16 ).getNumber() != 5 ) {
4561                 return false;
4562             }
4563             if ( sorted.get( 16 ).getTotalCount() != 200 ) {
4564                 return false;
4565             }
4566         }
4567         catch ( final Exception e ) {
4568             e.printStackTrace( System.out );
4569             return false;
4570         }
4571         return true;
4572     }
4573
4574     private static boolean testEngulfingOverlapRemoval() {
4575         try {
4576             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
4577             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
4578             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
4579             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
4580             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
4581             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
4582             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
4583             final List<Boolean> covered = new ArrayList<Boolean>();
4584             covered.add( true ); // 0
4585             covered.add( false ); // 1
4586             covered.add( true ); // 2
4587             covered.add( false ); // 3
4588             covered.add( true ); // 4
4589             covered.add( true ); // 5
4590             covered.add( false ); // 6
4591             covered.add( true ); // 7
4592             covered.add( true ); // 8
4593             if ( SurfacingUtil.isEngulfed( d0, covered ) ) {
4594                 return false;
4595             }
4596             if ( SurfacingUtil.isEngulfed( d1, covered ) ) {
4597                 return false;
4598             }
4599             if ( SurfacingUtil.isEngulfed( d2, covered ) ) {
4600                 return false;
4601             }
4602             if ( !SurfacingUtil.isEngulfed( d3, covered ) ) {
4603                 return false;
4604             }
4605             if ( SurfacingUtil.isEngulfed( d4, covered ) ) {
4606                 return false;
4607             }
4608             if ( SurfacingUtil.isEngulfed( d5, covered ) ) {
4609                 return false;
4610             }
4611             if ( !SurfacingUtil.isEngulfed( d6, covered ) ) {
4612                 return false;
4613             }
4614             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
4615             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
4616             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
4617             final Protein abc = new BasicProtein( "abc", "nemve" );
4618             abc.addProteinDomain( a );
4619             abc.addProteinDomain( b );
4620             abc.addProteinDomain( c );
4621             final Protein abc_r1 = SurfacingUtil.removeOverlappingDomains( 3, false, abc );
4622             final Protein abc_r2 = SurfacingUtil.removeOverlappingDomains( 3, true, abc );
4623             if ( abc.getNumberOfProteinDomains() != 3 ) {
4624                 return false;
4625             }
4626             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
4627                 return false;
4628             }
4629             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
4630                 return false;
4631             }
4632             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().getId().equals( "a" ) ) {
4633                 return false;
4634             }
4635             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().getId().equals( "b" ) ) {
4636                 return false;
4637             }
4638             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
4639             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
4640             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
4641             final Protein def = new BasicProtein( "def", "nemve" );
4642             def.addProteinDomain( d );
4643             def.addProteinDomain( e );
4644             def.addProteinDomain( f );
4645             final Protein def_r1 = SurfacingUtil.removeOverlappingDomains( 5, false, def );
4646             final Protein def_r2 = SurfacingUtil.removeOverlappingDomains( 5, true, def );
4647             if ( def.getNumberOfProteinDomains() != 3 ) {
4648                 return false;
4649             }
4650             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
4651                 return false;
4652             }
4653             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
4654                 return false;
4655             }
4656             if ( !def_r2.getProteinDomain( 0 ).getDomainId().getId().equals( "d" ) ) {
4657                 return false;
4658             }
4659             if ( !def_r2.getProteinDomain( 1 ).getDomainId().getId().equals( "f" ) ) {
4660                 return false;
4661             }
4662             if ( !def_r2.getProteinDomain( 2 ).getDomainId().getId().equals( "e" ) ) {
4663                 return false;
4664             }
4665         }
4666         catch ( final Exception e ) {
4667             e.printStackTrace( System.out );
4668             return false;
4669         }
4670         return true;
4671     }
4672
4673     private static boolean testGenomeWideCombinableDomains() {
4674         try {
4675             final Domain a = new BasicDomain( "a", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
4676             final Domain b = new BasicDomain( "b", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
4677             final Domain c = new BasicDomain( "c", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
4678             final Domain d = new BasicDomain( "d", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
4679             final Domain e = new BasicDomain( "e", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
4680             final Domain f = new BasicDomain( "f", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
4681             final Domain g = new BasicDomain( "g", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
4682             final Domain h = new BasicDomain( "h", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
4683             final Domain x = new BasicDomain( "x", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
4684             final Protein eel_0 = new BasicProtein( "0", "eel" );
4685             final Protein eel_1 = new BasicProtein( "1", "eel" );
4686             final Protein eel_2 = new BasicProtein( "2", "eel" );
4687             final Protein eel_3 = new BasicProtein( "3", "eel" );
4688             final Protein eel_4 = new BasicProtein( "4", "eel" );
4689             final Protein eel_5 = new BasicProtein( "5", "eel" );
4690             final Protein eel_6 = new BasicProtein( "6", "eel" );
4691             eel_1.addProteinDomain( a );
4692             eel_2.addProteinDomain( a );
4693             eel_2.addProteinDomain( b );
4694             eel_3.addProteinDomain( a );
4695             eel_3.addProteinDomain( a );
4696             eel_3.addProteinDomain( b );
4697             eel_4.addProteinDomain( a );
4698             eel_4.addProteinDomain( b );
4699             eel_4.addProteinDomain( c );
4700             eel_4.addProteinDomain( d );
4701             eel_4.addProteinDomain( e );
4702             eel_5.addProteinDomain( e );
4703             eel_5.addProteinDomain( e );
4704             eel_5.addProteinDomain( f );
4705             eel_5.addProteinDomain( f );
4706             eel_5.addProteinDomain( f );
4707             eel_5.addProteinDomain( f );
4708             eel_6.addProteinDomain( g );
4709             eel_6.addProteinDomain( h );
4710             final List<Protein> protein_list_eel = new ArrayList<Protein>();
4711             protein_list_eel.add( eel_0 );
4712             protein_list_eel.add( eel_1 );
4713             protein_list_eel.add( eel_2 );
4714             protein_list_eel.add( eel_3 );
4715             protein_list_eel.add( eel_4 );
4716             protein_list_eel.add( eel_5 );
4717             protein_list_eel.add( eel_6 );
4718             final BasicGenomeWideCombinableDomains eel_not_ignore = BasicGenomeWideCombinableDomains
4719                     .createInstance( protein_list_eel, false, new BasicSpecies( "eel" ) );
4720             final BasicGenomeWideCombinableDomains eel_ignore = BasicGenomeWideCombinableDomains
4721                     .createInstance( protein_list_eel, true, new BasicSpecies( "eel" ) );
4722             if ( !eel_not_ignore.contains( new DomainId( "a" ) ) ) {
4723                 return false;
4724             }
4725             if ( !eel_not_ignore.contains( new DomainId( "b" ) ) ) {
4726                 return false;
4727             }
4728             if ( !eel_not_ignore.contains( new DomainId( "c" ) ) ) {
4729                 return false;
4730             }
4731             if ( !eel_not_ignore.contains( new DomainId( "d" ) ) ) {
4732                 return false;
4733             }
4734             if ( !eel_not_ignore.contains( new DomainId( "e" ) ) ) {
4735                 return false;
4736             }
4737             if ( !eel_not_ignore.contains( new DomainId( "f" ) ) ) {
4738                 return false;
4739             }
4740             if ( !eel_not_ignore.contains( new DomainId( "g" ) ) ) {
4741                 return false;
4742             }
4743             if ( !eel_not_ignore.contains( new DomainId( "h" ) ) ) {
4744                 return false;
4745             }
4746             if ( eel_not_ignore.contains( new DomainId( "x" ) ) ) {
4747                 return false;
4748             }
4749             if ( !eel_ignore.contains( new DomainId( "a" ) ) ) {
4750                 return false;
4751             }
4752             if ( !eel_ignore.contains( new DomainId( "b" ) ) ) {
4753                 return false;
4754             }
4755             if ( !eel_ignore.contains( new DomainId( "c" ) ) ) {
4756                 return false;
4757             }
4758             if ( !eel_ignore.contains( new DomainId( "d" ) ) ) {
4759                 return false;
4760             }
4761             if ( !eel_ignore.contains( new DomainId( "e" ) ) ) {
4762                 return false;
4763             }
4764             if ( !eel_ignore.contains( new DomainId( "f" ) ) ) {
4765                 return false;
4766             }
4767             if ( !eel_ignore.contains( new DomainId( "g" ) ) ) {
4768                 return false;
4769             }
4770             if ( !eel_ignore.contains( new DomainId( "h" ) ) ) {
4771                 return false;
4772             }
4773             if ( eel_ignore.contains( new DomainId( "x" ) ) ) {
4774                 return false;
4775             }
4776             if ( eel_not_ignore.getSize() != 8 ) {
4777                 return false;
4778             }
4779             if ( eel_ignore.getSize() != 8 ) {
4780                 return false;
4781             }
4782             if ( eel_not_ignore.get( new DomainId( "a" ) ).getCombinableDomainsIds().size() != 5 ) {
4783                 return false;
4784             }
4785             if ( eel_not_ignore.get( new DomainId( "b" ) ).getCombinableDomainsIds().size() != 4 ) {
4786                 return false;
4787             }
4788             if ( eel_not_ignore.get( new DomainId( "c" ) ).getCombinableDomainsIds().size() != 4 ) {
4789                 return false;
4790             }
4791             if ( eel_not_ignore.get( new DomainId( "d" ) ).getCombinableDomainsIds().size() != 4 ) {
4792                 return false;
4793             }
4794             if ( eel_not_ignore.get( new DomainId( "e" ) ).getCombinableDomainsIds().size() != 6 ) {
4795                 return false;
4796             }
4797             if ( eel_not_ignore.get( new DomainId( "f" ) ).getCombinableDomainsIds().size() != 2 ) {
4798                 return false;
4799             }
4800             if ( eel_not_ignore.get( new DomainId( "g" ) ).getCombinableDomainsIds().size() != 1 ) {
4801                 return false;
4802             }
4803             if ( eel_not_ignore.get( new DomainId( "h" ) ).getCombinableDomainsIds().size() != 1 ) {
4804                 return false;
4805             }
4806             if ( eel_ignore.get( new DomainId( "a" ) ).getCombinableDomainsIds().size() != 4 ) {
4807                 return false;
4808             }
4809             if ( eel_ignore.get( new DomainId( "b" ) ).getCombinableDomainsIds().size() != 4 ) {
4810                 return false;
4811             }
4812             if ( eel_ignore.get( new DomainId( "c" ) ).getCombinableDomainsIds().size() != 4 ) {
4813                 return false;
4814             }
4815             if ( eel_ignore.get( new DomainId( "d" ) ).getCombinableDomainsIds().size() != 4 ) {
4816                 return false;
4817             }
4818             if ( eel_ignore.get( new DomainId( "e" ) ).getCombinableDomainsIds().size() != 5 ) {
4819                 return false;
4820             }
4821             if ( eel_ignore.get( new DomainId( "f" ) ).getCombinableDomainsIds().size() != 1 ) {
4822                 return false;
4823             }
4824             if ( eel_ignore.get( new DomainId( "g" ) ).getCombinableDomainsIds().size() != 1 ) {
4825                 return false;
4826             }
4827             if ( eel_ignore.get( new DomainId( "h" ) ).getCombinableDomainsIds().size() != 1 ) {
4828                 return false;
4829             }
4830             if ( eel_not_ignore.getAllDomainIds().size() != 8 ) {
4831                 return false;
4832             }
4833             if ( !eel_not_ignore.getAllDomainIds().contains( a.getDomainId() ) ) {
4834                 return false;
4835             }
4836             if ( !eel_not_ignore.getAllDomainIds().contains( b.getDomainId() ) ) {
4837                 return false;
4838             }
4839             if ( !eel_not_ignore.getAllDomainIds().contains( c.getDomainId() ) ) {
4840                 return false;
4841             }
4842             if ( !eel_not_ignore.getAllDomainIds().contains( d.getDomainId() ) ) {
4843                 return false;
4844             }
4845             if ( !eel_not_ignore.getAllDomainIds().contains( e.getDomainId() ) ) {
4846                 return false;
4847             }
4848             if ( !eel_not_ignore.getAllDomainIds().contains( f.getDomainId() ) ) {
4849                 return false;
4850             }
4851             if ( !eel_not_ignore.getAllDomainIds().contains( g.getDomainId() ) ) {
4852                 return false;
4853             }
4854             if ( !eel_not_ignore.getAllDomainIds().contains( h.getDomainId() ) ) {
4855                 return false;
4856             }
4857             if ( eel_not_ignore.getAllDomainIds().contains( x.getDomainId() ) ) {
4858                 return false;
4859             }
4860             if ( eel_ignore.getAllDomainIds().size() != 8 ) {
4861                 return false;
4862             }
4863             if ( !eel_ignore.getAllDomainIds().contains( a.getDomainId() ) ) {
4864                 return false;
4865             }
4866             if ( !eel_ignore.getAllDomainIds().contains( b.getDomainId() ) ) {
4867                 return false;
4868             }
4869             if ( !eel_ignore.getAllDomainIds().contains( c.getDomainId() ) ) {
4870                 return false;
4871             }
4872             if ( !eel_ignore.getAllDomainIds().contains( d.getDomainId() ) ) {
4873                 return false;
4874             }
4875             if ( !eel_ignore.getAllDomainIds().contains( e.getDomainId() ) ) {
4876                 return false;
4877             }
4878             if ( !eel_ignore.getAllDomainIds().contains( f.getDomainId() ) ) {
4879                 return false;
4880             }
4881             if ( !eel_ignore.getAllDomainIds().contains( g.getDomainId() ) ) {
4882                 return false;
4883             }
4884             if ( !eel_ignore.getAllDomainIds().contains( h.getDomainId() ) ) {
4885                 return false;
4886             }
4887             if ( eel_ignore.getAllDomainIds().contains( x.getDomainId() ) ) {
4888                 return false;
4889             }
4890             final SortedSet<BinaryDomainCombination> bc0 = eel_not_ignore.toBinaryDomainCombinations();
4891             if ( bc0.size() != 15 ) {
4892                 return false;
4893             }
4894             if ( !bc0.contains( new BasicBinaryDomainCombination( "a", "a" ) ) ) {
4895                 return false;
4896             }
4897             if ( !bc0.contains( new BasicBinaryDomainCombination( "a", "b" ) ) ) {
4898                 return false;
4899             }
4900             if ( !bc0.contains( new BasicBinaryDomainCombination( "b", "a" ) ) ) {
4901                 return false;
4902             }
4903             if ( !bc0.contains( new BasicBinaryDomainCombination( "a", "c" ) ) ) {
4904                 return false;
4905             }
4906             if ( !bc0.contains( new BasicBinaryDomainCombination( "a", "d" ) ) ) {
4907                 return false;
4908             }
4909             if ( !bc0.contains( new BasicBinaryDomainCombination( "a", "e" ) ) ) {
4910                 return false;
4911             }
4912             if ( !bc0.contains( new BasicBinaryDomainCombination( "b", "c" ) ) ) {
4913                 return false;
4914             }
4915             if ( !bc0.contains( new BasicBinaryDomainCombination( "b", "d" ) ) ) {
4916                 return false;
4917             }
4918             if ( !bc0.contains( new BasicBinaryDomainCombination( "b", "e" ) ) ) {
4919                 return false;
4920             }
4921             if ( !bc0.contains( new BasicBinaryDomainCombination( "c", "d" ) ) ) {
4922                 return false;
4923             }
4924             if ( !bc0.contains( new BasicBinaryDomainCombination( "c", "e" ) ) ) {
4925                 return false;
4926             }
4927             if ( !bc0.contains( new BasicBinaryDomainCombination( "d", "e" ) ) ) {
4928                 return false;
4929             }
4930             if ( !bc0.contains( new BasicBinaryDomainCombination( "e", "f" ) ) ) {
4931                 return false;
4932             }
4933             if ( !bc0.contains( new BasicBinaryDomainCombination( "e", "e" ) ) ) {
4934                 return false;
4935             }
4936             if ( !bc0.contains( new BasicBinaryDomainCombination( "f", "f" ) ) ) {
4937                 return false;
4938             }
4939             if ( !bc0.contains( new BasicBinaryDomainCombination( "g", "h" ) ) ) {
4940                 return false;
4941             }
4942             if ( bc0.contains( new BasicBinaryDomainCombination( "f", "a" ) ) ) {
4943                 return false;
4944             }
4945             if ( bc0.contains( new BasicBinaryDomainCombination( "f", "b" ) ) ) {
4946                 return false;
4947             }
4948             if ( bc0.contains( new BasicBinaryDomainCombination( "a", "h" ) ) ) {
4949                 return false;
4950             }
4951             if ( bc0.contains( new BasicBinaryDomainCombination( "a", "g" ) ) ) {
4952                 return false;
4953             }
4954             final SortedSet<BinaryDomainCombination> bc1 = eel_ignore.toBinaryDomainCombinations();
4955             if ( bc1.size() != 12 ) {
4956                 return false;
4957             }
4958             if ( bc1.contains( new BasicBinaryDomainCombination( "a", "a" ) ) ) {
4959                 return false;
4960             }
4961             if ( !bc1.contains( new BasicBinaryDomainCombination( "a", "b" ) ) ) {
4962                 return false;
4963             }
4964             if ( !bc1.contains( new BasicBinaryDomainCombination( "b", "a" ) ) ) {
4965                 return false;
4966             }
4967             if ( !bc1.contains( new BasicBinaryDomainCombination( "a", "c" ) ) ) {
4968                 return false;
4969             }
4970             if ( !bc1.contains( new BasicBinaryDomainCombination( "a", "d" ) ) ) {
4971                 return false;
4972             }
4973             if ( !bc1.contains( new BasicBinaryDomainCombination( "a", "e" ) ) ) {
4974                 return false;
4975             }
4976             if ( !bc1.contains( new BasicBinaryDomainCombination( "b", "c" ) ) ) {
4977                 return false;
4978             }
4979             if ( !bc1.contains( new BasicBinaryDomainCombination( "b", "d" ) ) ) {
4980                 return false;
4981             }
4982             if ( !bc1.contains( new BasicBinaryDomainCombination( "b", "e" ) ) ) {
4983                 return false;
4984             }
4985             if ( !bc1.contains( new BasicBinaryDomainCombination( "c", "d" ) ) ) {
4986                 return false;
4987             }
4988             if ( !bc1.contains( new BasicBinaryDomainCombination( "c", "e" ) ) ) {
4989                 return false;
4990             }
4991             if ( !bc1.contains( new BasicBinaryDomainCombination( "d", "e" ) ) ) {
4992                 return false;
4993             }
4994             if ( !bc1.contains( new BasicBinaryDomainCombination( "e", "f" ) ) ) {
4995                 return false;
4996             }
4997             if ( !bc1.contains( new BasicBinaryDomainCombination( "g", "h" ) ) ) {
4998                 return false;
4999             }
5000             if ( bc1.contains( new BasicBinaryDomainCombination( "e", "e" ) ) ) {
5001                 return false;
5002             }
5003             if ( bc1.contains( new BasicBinaryDomainCombination( "f", "f" ) ) ) {
5004                 return false;
5005             }
5006             if ( bc1.contains( new BasicBinaryDomainCombination( "f", "a" ) ) ) {
5007                 return false;
5008             }
5009             if ( bc1.contains( new BasicBinaryDomainCombination( "f", "b" ) ) ) {
5010                 return false;
5011             }
5012             if ( bc1.contains( new BasicBinaryDomainCombination( "a", "g" ) ) ) {
5013                 return false;
5014             }
5015             if ( bc1.contains( new BasicBinaryDomainCombination( "b", "g" ) ) ) {
5016                 return false;
5017             }
5018         }
5019         catch ( final Exception e ) {
5020             e.printStackTrace( System.out );
5021             return false;
5022         }
5023         return true;
5024     }
5025
5026     private static boolean testHmmPfamOutputParser( final File test_dir ) {
5027         try {
5028             final HmmPfamOutputParser parser = new HmmPfamOutputParser( new File( test_dir
5029                     + ForesterUtil.getFileSeparator() + "hmmpfam_output" ), "human", "ls" );
5030             parser.setEValueMaximum( 0.2 );
5031             parser.setIgnoreDufs( true );
5032             parser.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
5033             List<?> domain_collections = null;
5034             domain_collections = parser.parse();
5035             if ( parser.getDomainsEncountered() != 4 ) {
5036                 return false;
5037             }
5038             if ( parser.getDomainsIgnoredDueToDuf() != 0 ) {
5039                 return false;
5040             }
5041             if ( parser.getDomainsIgnoredDueToEval() != 1 ) {
5042                 return false;
5043             }
5044             if ( parser.getDomainsIgnoredDueToOverlap() != 0 ) {
5045                 return false;
5046             }
5047             if ( parser.getDomainsStored() != 3 ) {
5048                 return false;
5049             }
5050             if ( domain_collections.size() != 1 ) {
5051                 return false;
5052             }
5053             final Protein pdc = ( Protein ) domain_collections.get( 0 );
5054             if ( !pdc.getProteinId().equals( new ProteinId( "ENSP00000285681" ) ) ) {
5055                 return false;
5056             }
5057             if ( !pdc.getSpecies().getSpeciesId().equals( "human" ) ) {
5058                 return false;
5059             }
5060             if ( pdc.getNumberOfProteinDomains() != 3 ) {
5061                 return false;
5062             }
5063             if ( !pdc.getAccession().equals( "acc_ENSP00000285681" ) ) {
5064                 return false;
5065             }
5066             if ( !pdc
5067                     .getDescription()
5068                     .equals( "pep:known chromosome:NCBI36:21:16024215:16174248:1 gene:ENSG00000155313 transcript:ENST00000285681" ) ) {
5069                 return false;
5070             }
5071             final List<Domain> uba = pdc.getProteinDomains( new DomainId( "UBA" ) );
5072             final List<Domain> uim = pdc.getProteinDomains( new DomainId( "UIM" ) );
5073             final List<Domain> uch = pdc.getProteinDomains( new DomainId( "UCH" ) );
5074             if ( uba.size() != 1 ) {
5075                 return false;
5076             }
5077             if ( uim.size() != 2 ) {
5078                 return false;
5079             }
5080             if ( uch.size() != 0 ) {
5081                 return false;
5082             }
5083             final BasicDomain uim_domain = ( BasicDomain ) uim.get( 1 );
5084             if ( !uim_domain.getDomainId().equals( new DomainId( "UIM" ) ) ) {
5085                 return false;
5086             }
5087             if ( uim_domain.getTotalCount() != 2 ) {
5088                 return false;
5089             }
5090             final BasicDomain uba_domain = ( BasicDomain ) uba.get( 0 );
5091             if ( !uba_domain.getDomainId().equals( new DomainId( "UBA" ) ) ) {
5092                 return false;
5093             }
5094             if ( uba_domain.getNumber() != 1 ) {
5095                 return false;
5096             }
5097             if ( uba_domain.getTotalCount() != 1 ) {
5098                 return false;
5099             }
5100             if ( uba_domain.getFrom() != 16 ) {
5101                 return false;
5102             }
5103             if ( uba_domain.getTo() != 57 ) {
5104                 return false;
5105             }
5106             if ( !Test.isEqual( uba_domain.getPerSequenceEvalue(), 0.00084 ) ) {
5107                 return false;
5108             }
5109             if ( !Test.isEqual( uba_domain.getPerSequenceScore(), 23.2 ) ) {
5110                 return false;
5111             }
5112             final HmmPfamOutputParser parser2 = new HmmPfamOutputParser( new File( test_dir
5113                     + ForesterUtil.getFileSeparator() + "hmmpfam_output_short" ), "human", "ls" );
5114             parser2.setEValueMaximum( 0.2 );
5115             parser2.setIgnoreDufs( true );
5116             parser2.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
5117             List<Protein> domain_collections2 = null;
5118             domain_collections2 = parser2.parse();
5119             if ( parser2.getDomainsEncountered() != 4 ) {
5120                 return false;
5121             }
5122             if ( parser.getDomainsIgnoredDueToDuf() != 0 ) {
5123                 return false;
5124             }
5125             if ( parser.getDomainsIgnoredDueToEval() != 1 ) {
5126                 return false;
5127             }
5128             if ( parser.getDomainsIgnoredDueToOverlap() != 0 ) {
5129                 return false;
5130             }
5131             if ( parser2.getDomainsStored() != 3 ) {
5132                 return false;
5133             }
5134             if ( domain_collections2.size() != 1 ) {
5135                 return false;
5136             }
5137             final Protein pdc2 = domain_collections2.get( 0 );
5138             if ( !pdc2.getProteinId().getId().equals( "ENSP00000285681" ) ) {
5139                 return false;
5140             }
5141             if ( !pdc2.getSpecies().getSpeciesId().equals( "human" ) ) {
5142                 return false;
5143             }
5144             if ( !pdc2.getName().equals( "" ) ) {
5145                 return false;
5146             }
5147             if ( !pdc2.getAccession().equals( "223" ) ) {
5148                 return false;
5149             }
5150             if ( !pdc2
5151                     .getDescription()
5152                     .equals( "pep:known chromosome:NCBI36:21:16024215:16174248:1 gene:ENSG00000155313 transcript:ENST00000285681" ) ) {
5153                 return false;
5154             }
5155             if ( pdc2.getNumberOfProteinDomains() != 3 ) {
5156                 return false;
5157             }
5158             final List<Domain> uba2 = pdc2.getProteinDomains( new DomainId( "UBA" ) );
5159             final List<Domain> uim2 = pdc2.getProteinDomains( new DomainId( "UIM" ) );
5160             final List<Domain> uch2 = pdc2.getProteinDomains( new DomainId( "UCH" ) );
5161             if ( uba2.size() != 1 ) {
5162                 return false;
5163             }
5164             if ( uim2.size() != 2 ) {
5165                 return false;
5166             }
5167             if ( uch2.size() != 0 ) {
5168                 return false;
5169             }
5170             final BasicDomain uim_domain2 = ( BasicDomain ) uim2.get( 1 );
5171             if ( !uim_domain2.getDomainId().getId().equals( "UIM" ) ) {
5172                 return false;
5173             }
5174             if ( uim_domain2.getTotalCount() != 2 ) {
5175                 return false;
5176             }
5177             final BasicDomain uba_domain2 = ( BasicDomain ) uba2.get( 0 );
5178             if ( !uba_domain2.getDomainId().getId().equals( "UBA" ) ) {
5179                 return false;
5180             }
5181             if ( uba_domain2.getNumber() != 1 ) {
5182                 return false;
5183             }
5184             if ( uba_domain2.getTotalCount() != 1 ) {
5185                 return false;
5186             }
5187             if ( uba_domain2.getFrom() != 16 ) {
5188                 return false;
5189             }
5190             if ( uba_domain2.getTo() != 57 ) {
5191                 return false;
5192             }
5193             if ( !Test.isEqual( uba_domain2.getPerSequenceEvalue(), 0.00084 ) ) {
5194                 return false;
5195             }
5196         }
5197         catch ( final Exception e ) {
5198             e.printStackTrace( System.out );
5199             return false;
5200         }
5201         return true;
5202     }
5203
5204     private static boolean testHmmPfamOutputParserWithFilter( final File test_dir ) {
5205         try {
5206             HmmPfamOutputParser parser = new HmmPfamOutputParser( new File( test_dir + ForesterUtil.getFileSeparator()
5207                     + "hmmpfam_output3" ), "human", "ls" );
5208             parser.setEValueMaximum( 0.2 );
5209             parser.setIgnoreDufs( true );
5210             parser.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
5211             List<Protein> proteins = null;
5212             proteins = parser.parse();
5213             if ( parser.getProteinsIgnoredDueToFilter() != 0 ) {
5214                 return false;
5215             }
5216             if ( proteins.size() != 4 ) {
5217                 return false;
5218             }
5219             //
5220             Set<DomainId> filter = new TreeSet<DomainId>();
5221             filter.add( new DomainId( "beauty" ) );
5222             filter.add( new DomainId( "strange" ) );
5223             parser = new HmmPfamOutputParser( new File( test_dir + ForesterUtil.getFileSeparator() + "hmmpfam_output3" ),
5224                                               "human",
5225                                               "ls",
5226                                               filter,
5227                                               HmmPfamOutputParser.FilterType.NEGATIVE_PROTEIN );
5228             parser.setEValueMaximum( 0.2 );
5229             parser.setIgnoreDufs( true );
5230             parser.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
5231             proteins = null;
5232             proteins = parser.parse();
5233             if ( parser.getProteinsIgnoredDueToFilter() != 0 ) {
5234                 return false;
5235             }
5236             if ( proteins.size() != 4 ) {
5237                 return false;
5238             }
5239             //
5240             filter = new TreeSet<DomainId>();
5241             filter.add( new DomainId( "beauty" ) );
5242             filter.add( new DomainId( "strange" ) );
5243             parser = new HmmPfamOutputParser( new File( test_dir + ForesterUtil.getFileSeparator() + "hmmpfam_output3" ),
5244                                               "human",
5245                                               "ls",
5246                                               filter,
5247                                               HmmPfamOutputParser.FilterType.POSITIVE_PROTEIN );
5248             parser.setEValueMaximum( 0.2 );
5249             parser.setIgnoreDufs( true );
5250             parser.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
5251             proteins = null;
5252             proteins = parser.parse();
5253             if ( parser.getProteinsIgnoredDueToFilter() != 4 ) {
5254                 return false;
5255             }
5256             if ( proteins.size() != 0 ) {
5257                 return false;
5258             }
5259             //
5260             filter = new TreeSet<DomainId>();
5261             filter.add( new DomainId( "UIM" ) );
5262             filter.add( new DomainId( "A" ) );
5263             filter.add( new DomainId( "C" ) );
5264             parser = new HmmPfamOutputParser( new File( test_dir + ForesterUtil.getFileSeparator() + "hmmpfam_output3" ),
5265                                               "human",
5266                                               "ls",
5267                                               filter,
5268                                               HmmPfamOutputParser.FilterType.POSITIVE_PROTEIN );
5269             parser.setEValueMaximum( 0.2 );
5270             parser.setIgnoreDufs( true );
5271             parser.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
5272             proteins = null;
5273             proteins = parser.parse();
5274             if ( parser.getProteinsIgnoredDueToFilter() != 0 ) {
5275                 return false;
5276             }
5277             if ( proteins.size() != 4 ) {
5278                 return false;
5279             }
5280             //
5281             filter = new TreeSet<DomainId>();
5282             filter.add( new DomainId( "UIM" ) );
5283             filter.add( new DomainId( "A" ) );
5284             filter.add( new DomainId( "C" ) );
5285             filter.add( new DomainId( "X" ) );
5286             parser = new HmmPfamOutputParser( new File( test_dir + ForesterUtil.getFileSeparator() + "hmmpfam_output3" ),
5287                                               "human",
5288                                               "ls",
5289                                               filter,
5290                                               HmmPfamOutputParser.FilterType.NEGATIVE_DOMAIN );
5291             parser.setEValueMaximum( 0.2 );
5292             parser.setIgnoreDufs( true );
5293             parser.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
5294             proteins = null;
5295             proteins = parser.parse();
5296             if ( parser.getDomainsIgnoredDueToNegativeDomainFilter() != 7 ) {
5297                 return false;
5298             }
5299             if ( proteins.size() != 3 ) {
5300                 return false;
5301             }
5302             //
5303             filter = new TreeSet<DomainId>();
5304             filter.add( new DomainId( "UIM" ) );
5305             filter.add( new DomainId( "A" ) );
5306             filter.add( new DomainId( "C" ) );
5307             parser = new HmmPfamOutputParser( new File( test_dir + ForesterUtil.getFileSeparator() + "hmmpfam_output3" ),
5308                                               "human",
5309                                               "ls",
5310                                               filter,
5311                                               HmmPfamOutputParser.FilterType.NEGATIVE_PROTEIN );
5312             parser.setEValueMaximum( 0.2 );
5313             parser.setIgnoreDufs( true );
5314             parser.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
5315             proteins = null;
5316             proteins = parser.parse();
5317             if ( parser.getProteinsIgnoredDueToFilter() != 4 ) {
5318                 return false;
5319             }
5320             if ( proteins.size() != 0 ) {
5321                 return false;
5322             }
5323             //
5324             filter = new TreeSet<DomainId>();
5325             filter.add( new DomainId( "UIM" ) );
5326             parser = new HmmPfamOutputParser( new File( test_dir + ForesterUtil.getFileSeparator() + "hmmpfam_output3" ),
5327                                               "human",
5328                                               "ls",
5329                                               filter,
5330                                               HmmPfamOutputParser.FilterType.NEGATIVE_PROTEIN );
5331             parser.setEValueMaximum( 0.2 );
5332             parser.setIgnoreDufs( true );
5333             parser.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
5334             proteins = null;
5335             proteins = parser.parse();
5336             if ( parser.getProteinsIgnoredDueToFilter() != 1 ) {
5337                 return false;
5338             }
5339             if ( parser.getProteinsStored() != 3 ) {
5340                 return false;
5341             }
5342             if ( proteins.size() != 3 ) {
5343                 return false;
5344             }
5345             //
5346             filter = new TreeSet<DomainId>();
5347             filter.add( new DomainId( "UIM" ) );
5348             parser = new HmmPfamOutputParser( new File( test_dir + ForesterUtil.getFileSeparator() + "hmmpfam_output3" ),
5349                                               "human",
5350                                               "ls",
5351                                               filter,
5352                                               HmmPfamOutputParser.FilterType.POSITIVE_PROTEIN );
5353             parser.setEValueMaximum( 0.2 );
5354             parser.setIgnoreDufs( true );
5355             parser.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
5356             proteins = null;
5357             proteins = parser.parse();
5358             if ( parser.getProteinsIgnoredDueToFilter() != 3 ) {
5359                 return false;
5360             }
5361             if ( parser.getProteinsStored() != 1 ) {
5362                 return false;
5363             }
5364             if ( proteins.size() != 1 ) {
5365                 return false;
5366             }
5367             //
5368             filter = new TreeSet<DomainId>();
5369             filter.add( new DomainId( "A" ) );
5370             filter.add( new DomainId( "C" ) );
5371             parser = new HmmPfamOutputParser( new File( test_dir + ForesterUtil.getFileSeparator() + "hmmpfam_output3" ),
5372                                               "human",
5373                                               "ls",
5374                                               filter,
5375                                               HmmPfamOutputParser.FilterType.POSITIVE_PROTEIN );
5376             parser.setEValueMaximum( 0.2 );
5377             parser.setIgnoreDufs( true );
5378             parser.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
5379             proteins = null;
5380             proteins = parser.parse();
5381             if ( parser.getDomainsEncountered() != 11 ) {
5382                 return false;
5383             }
5384             if ( parser.getProteinsEncountered() != 4 ) {
5385                 return false;
5386             }
5387             if ( parser.getProteinsIgnoredDueToFilter() != 1 ) {
5388                 return false;
5389             }
5390             if ( parser.getProteinsStored() != 3 ) {
5391                 return false;
5392             }
5393             if ( proteins.size() != 3 ) {
5394                 return false;
5395             }
5396         }
5397         catch ( final Exception e ) {
5398             e.printStackTrace( System.out );
5399             return false;
5400         }
5401         return true;
5402     }
5403
5404     private static boolean testOverlapRemoval() {
5405         try {
5406             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
5407             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
5408             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
5409             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
5410             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
5411             final List<Boolean> covered = new ArrayList<Boolean>();
5412             covered.add( true ); // 0
5413             covered.add( false ); // 1
5414             covered.add( true ); // 2
5415             covered.add( false ); // 3
5416             covered.add( true ); // 4
5417             covered.add( true ); // 5
5418             covered.add( false ); // 6
5419             covered.add( true ); // 7
5420             covered.add( true ); // 8
5421             if ( SurfacingUtil.calculateOverlap( d0, covered ) != 3 ) {
5422                 return false;
5423             }
5424             if ( SurfacingUtil.calculateOverlap( d1, covered ) != 2 ) {
5425                 return false;
5426             }
5427             if ( SurfacingUtil.calculateOverlap( d2, covered ) != 6 ) {
5428                 return false;
5429             }
5430             if ( SurfacingUtil.calculateOverlap( d3, covered ) != 0 ) {
5431                 return false;
5432             }
5433             if ( SurfacingUtil.calculateOverlap( d4, covered ) != 2 ) {
5434                 return false;
5435             }
5436             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.01, 1 );
5437             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
5438             final Protein ab = new BasicProtein( "ab", "varanus" );
5439             ab.addProteinDomain( a );
5440             ab.addProteinDomain( b );
5441             final Protein ab_s0 = SurfacingUtil.removeOverlappingDomains( 3, false, ab );
5442             if ( ab.getNumberOfProteinDomains() != 2 ) {
5443                 return false;
5444             }
5445             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
5446                 return false;
5447             }
5448             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().getId().equals( "a" ) ) {
5449                 return false;
5450             }
5451             final Protein ab_s1 = SurfacingUtil.removeOverlappingDomains( 4, false, ab );
5452             if ( ab.getNumberOfProteinDomains() != 2 ) {
5453                 return false;
5454             }
5455             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
5456                 return false;
5457             }
5458             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
5459             final Domain d = new BasicDomain( "d",
5460                                               ( short ) 10000,
5461                                               ( short ) 10500,
5462                                               ( short ) 1,
5463                                               ( short ) 1,
5464                                               0.0000001,
5465                                               1 );
5466             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
5467             final Protein cde = new BasicProtein( "cde", "varanus" );
5468             cde.addProteinDomain( c );
5469             cde.addProteinDomain( d );
5470             cde.addProteinDomain( e );
5471             final Protein cde_s0 = SurfacingUtil.removeOverlappingDomains( 0, false, cde );
5472             if ( cde.getNumberOfProteinDomains() != 3 ) {
5473                 return false;
5474             }
5475             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
5476                 return false;
5477             }
5478             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
5479             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
5480             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
5481             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
5482             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
5483             final Protein fghi = new BasicProtein( "fghi", "varanus" );
5484             fghi.addProteinDomain( f );
5485             fghi.addProteinDomain( g );
5486             fghi.addProteinDomain( h );
5487             fghi.addProteinDomain( i );
5488             fghi.addProteinDomain( i );
5489             fghi.addProteinDomain( i );
5490             fghi.addProteinDomain( i2 );
5491             final Protein fghi_s0 = SurfacingUtil.removeOverlappingDomains( 10, false, fghi );
5492             if ( fghi.getNumberOfProteinDomains() != 7 ) {
5493                 return false;
5494             }
5495             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
5496                 return false;
5497             }
5498             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().getId().equals( "h" ) ) {
5499                 return false;
5500             }
5501             final Protein fghi_s1 = SurfacingUtil.removeOverlappingDomains( 11, false, fghi );
5502             if ( fghi.getNumberOfProteinDomains() != 7 ) {
5503                 return false;
5504             }
5505             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
5506                 return false;
5507             }
5508             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
5509             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
5510             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
5511             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
5512             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
5513             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
5514             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
5515             final Protein jklm = new BasicProtein( "jklm", "varanus" );
5516             jklm.addProteinDomain( j );
5517             jklm.addProteinDomain( k );
5518             jklm.addProteinDomain( l );
5519             jklm.addProteinDomain( m );
5520             jklm.addProteinDomain( m0 );
5521             jklm.addProteinDomain( m1 );
5522             jklm.addProteinDomain( m2 );
5523             final Protein jklm_s0 = SurfacingUtil.removeOverlappingDomains( 10, false, jklm );
5524             if ( jklm.getNumberOfProteinDomains() != 7 ) {
5525                 return false;
5526             }
5527             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
5528                 return false;
5529             }
5530             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().getId().equals( "l" ) ) {
5531                 return false;
5532             }
5533             final Protein jklm_s1 = SurfacingUtil.removeOverlappingDomains( 11, false, jklm );
5534             if ( jklm.getNumberOfProteinDomains() != 7 ) {
5535                 return false;
5536             }
5537             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
5538                 return false;
5539             }
5540             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
5541             final Protein od = new BasicProtein( "od", "varanus" );
5542             od.addProteinDomain( only );
5543             final Protein od_s0 = SurfacingUtil.removeOverlappingDomains( 0, false, od );
5544             if ( od.getNumberOfProteinDomains() != 1 ) {
5545                 return false;
5546             }
5547             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
5548                 return false;
5549             }
5550         }
5551         catch ( final Exception e ) {
5552             e.printStackTrace( System.out );
5553             return false;
5554         }
5555         return true;
5556     }
5557
5558     private static boolean testParsimony() {
5559         try {
5560             final BinaryStates X = BinaryStates.PRESENT;
5561             final BinaryStates O = BinaryStates.ABSENT;
5562             final GainLossStates G = GainLossStates.GAIN;
5563             final GainLossStates L = GainLossStates.LOSS;
5564             final GainLossStates A = GainLossStates.UNCHANGED_ABSENT;
5565             final GainLossStates P = GainLossStates.UNCHANGED_PRESENT;
5566             final Domain a = new BasicDomain( "A", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5567             final Domain b = new BasicDomain( "B", 2, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5568             final Domain c = new BasicDomain( "C", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5569             final Domain d = new BasicDomain( "D", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5570             final Domain e = new BasicDomain( "E", 2, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5571             final Domain f = new BasicDomain( "F", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5572             final Domain g = new BasicDomain( "G", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5573             final Domain h = new BasicDomain( "H", 2, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5574             final Domain i = new BasicDomain( "I", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5575             final Domain j = new BasicDomain( "J", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5576             final Domain l = new BasicDomain( "L", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5577             final Domain m = new BasicDomain( "M", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5578             final Domain n = new BasicDomain( "N", 2, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5579             final Domain o = new BasicDomain( "O", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5580             final Domain p = new BasicDomain( "P", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5581             final Domain q = new BasicDomain( "Q", 2, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5582             final Domain r = new BasicDomain( "R", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5583             // 1 a-a a-b a-c e-f-g-h l-m
5584             // 2 a-b a-c e-f-g-i n-o
5585             // 3 a-b a-d e-f-g-j p-q
5586             // 4 a-b a-d p-r
5587             // 1 a-a a-b a-c e-f e-g e-h f-g f-h g-h l-m
5588             // 2 a-b a-c e-f e-g e-i f-g f-i g-i n-o
5589             // 3 a-b a-d e-f e-g e-j f-g f-j g-j p-q
5590             // 4 a-b a-d p-r
5591             // 1 a b c e f g h l m
5592             // 2 a b c e f g i n o
5593             // 3 a b d e f g j p q
5594             // 4 a b d p r
5595             final Protein aa1 = new BasicProtein( "aa1", "one" );
5596             aa1.addProteinDomain( a );
5597             aa1.addProteinDomain( a );
5598             final Protein ab1 = new BasicProtein( "ab1", "one" );
5599             ab1.addProteinDomain( a );
5600             ab1.addProteinDomain( b );
5601             final Protein ac1 = new BasicProtein( "ac1", "one" );
5602             ac1.addProteinDomain( a );
5603             ac1.addProteinDomain( c );
5604             final Protein efgh1 = new BasicProtein( "efgh1", "one" );
5605             efgh1.addProteinDomain( e );
5606             efgh1.addProteinDomain( f );
5607             efgh1.addProteinDomain( g );
5608             efgh1.addProteinDomain( h );
5609             final Protein lm1 = new BasicProtein( "lm1", "one" );
5610             lm1.addProteinDomain( l );
5611             lm1.addProteinDomain( m );
5612             final Protein ab2 = new BasicProtein( "ab2", "two" );
5613             ab2.addProteinDomain( a );
5614             ab2.addProteinDomain( b );
5615             final Protein ac2 = new BasicProtein( "ac2", "two" );
5616             ac2.addProteinDomain( a );
5617             ac2.addProteinDomain( c );
5618             final Protein efgi2 = new BasicProtein( "efgi2", "two" );
5619             efgi2.addProteinDomain( e );
5620             efgi2.addProteinDomain( f );
5621             efgi2.addProteinDomain( g );
5622             efgi2.addProteinDomain( i );
5623             final Protein no2 = new BasicProtein( "no2", "two" );
5624             no2.addProteinDomain( n );
5625             no2.addProteinDomain( o );
5626             final Protein ab3 = new BasicProtein( "ab3", "three" );
5627             ab3.addProteinDomain( a );
5628             ab3.addProteinDomain( b );
5629             final Protein ad3 = new BasicProtein( "ad3", "three" );
5630             ad3.addProteinDomain( a );
5631             ad3.addProteinDomain( d );
5632             final Protein efgj3 = new BasicProtein( "efgj3", "three" );
5633             efgj3.addProteinDomain( e );
5634             efgj3.addProteinDomain( f );
5635             efgj3.addProteinDomain( g );
5636             efgj3.addProteinDomain( j );
5637             final Protein pq3 = new BasicProtein( "pq3", "three" );
5638             pq3.addProteinDomain( p );
5639             pq3.addProteinDomain( q );
5640             final Protein ab4 = new BasicProtein( "ab4", "four" );
5641             ab4.addProteinDomain( a );
5642             ab4.addProteinDomain( b );
5643             final Protein ad4 = new BasicProtein( "ad4", "four" );
5644             ad4.addProteinDomain( a );
5645             ad4.addProteinDomain( d );
5646             final Protein pr4 = new BasicProtein( "pr4", "four" );
5647             pr4.addProteinDomain( p );
5648             pr4.addProteinDomain( r );
5649             final List<Protein> one_list = new ArrayList<Protein>();
5650             one_list.add( aa1 );
5651             one_list.add( ab1 );
5652             one_list.add( ac1 );
5653             one_list.add( efgh1 );
5654             one_list.add( lm1 );
5655             final List<Protein> two_list = new ArrayList<Protein>();
5656             two_list.add( ab2 );
5657             two_list.add( ac2 );
5658             two_list.add( efgi2 );
5659             two_list.add( no2 );
5660             final List<Protein> three_list = new ArrayList<Protein>();
5661             three_list.add( ab3 );
5662             three_list.add( ad3 );
5663             three_list.add( efgj3 );
5664             three_list.add( pq3 );
5665             final List<Protein> four_list = new ArrayList<Protein>();
5666             four_list.add( ab4 );
5667             four_list.add( ad4 );
5668             four_list.add( pr4 );
5669             final GenomeWideCombinableDomains one = BasicGenomeWideCombinableDomains
5670                     .createInstance( one_list, false, new BasicSpecies( "one" ) );
5671             final GenomeWideCombinableDomains two = BasicGenomeWideCombinableDomains
5672                     .createInstance( two_list, false, new BasicSpecies( "two" ) );
5673             final GenomeWideCombinableDomains three = BasicGenomeWideCombinableDomains
5674                     .createInstance( three_list, false, new BasicSpecies( "three" ) );
5675             final GenomeWideCombinableDomains four = BasicGenomeWideCombinableDomains
5676                     .createInstance( four_list, false, new BasicSpecies( "four" ) );
5677             final List<GenomeWideCombinableDomains> gwcd_list = new ArrayList<GenomeWideCombinableDomains>();
5678             gwcd_list.add( one );
5679             gwcd_list.add( two );
5680             gwcd_list.add( three );
5681             gwcd_list.add( four );
5682             final CharacterStateMatrix<BinaryStates> matrix_d = DomainParsimonyCalculator
5683                     .createMatrixOfDomainPresenceOrAbsence( gwcd_list );
5684             final CharacterStateMatrix<BinaryStates> matrix_bc = DomainParsimonyCalculator
5685                     .createMatrixOfBinaryDomainCombinationPresenceOrAbsence( gwcd_list );
5686             // 1 a b c e f g h l m
5687             // 2 a b c e f g i n o
5688             // 3 a b d e f g j p q
5689             // 4 a b d p r
5690             if ( matrix_d.getState( 0, 0 ) != X ) {
5691                 return false;
5692             }
5693             if ( matrix_d.getState( 0, 1 ) != X ) {
5694                 return false;
5695             }
5696             if ( matrix_d.getState( 0, 2 ) != X ) {
5697                 return false;
5698             }
5699             if ( matrix_d.getState( 0, 3 ) != O ) {
5700                 return false;
5701             }
5702             if ( matrix_d.getState( 0, 4 ) != X ) {
5703                 return false;
5704             }
5705             if ( matrix_d.getState( 0, 5 ) != X ) {
5706                 return false;
5707             }
5708             if ( matrix_d.getState( 0, 6 ) != X ) {
5709                 return false;
5710             }
5711             if ( matrix_d.getState( 0, 7 ) != X ) {
5712                 return false;
5713             }
5714             if ( matrix_d.getState( 0, 8 ) != O ) {
5715                 return false;
5716             }
5717             // 1 a-a a-b a-c e-f e-g e-h f-g f-h g-h l-m
5718             // 2 a-b a-c e-f e-g e-i f-g f-i g-i n-o
5719             // 3 a-b a-d e-f e-g e-j f-g f-j g-j p-q
5720             // 4 a-b a-d p-r
5721             if ( matrix_bc.getState( 0, 0 ) != X ) {
5722                 return false;
5723             }
5724             if ( matrix_bc.getState( 0, 1 ) != X ) {
5725                 return false;
5726             }
5727             if ( matrix_bc.getState( 0, 2 ) != X ) {
5728                 return false;
5729             }
5730             if ( matrix_bc.getState( 0, 3 ) != O ) {
5731                 return false;
5732             }
5733             if ( matrix_bc.getState( 0, 4 ) != X ) {
5734                 return false;
5735             }
5736             if ( matrix_bc.getState( 1, 0 ) != O ) {
5737                 return false;
5738             }
5739             if ( matrix_bc.getState( 1, 1 ) != X ) {
5740                 return false;
5741             }
5742             if ( matrix_bc.getState( 1, 2 ) != X ) {
5743                 return false;
5744             }
5745             if ( matrix_bc.getState( 1, 3 ) != O ) {
5746                 return false;
5747             }
5748             if ( matrix_bc.getState( 1, 4 ) != X ) {
5749                 return false;
5750             }
5751             if ( matrix_bc.getState( 2, 0 ) != O ) {
5752                 return false;
5753             }
5754             if ( matrix_bc.getState( 2, 1 ) != X ) {
5755                 return false;
5756             }
5757             if ( matrix_bc.getState( 2, 2 ) != O ) {
5758                 return false;
5759             }
5760             if ( matrix_bc.getState( 2, 3 ) != X ) {
5761                 return false;
5762             }
5763             if ( matrix_bc.getState( 2, 4 ) != X ) {
5764                 return false;
5765             }
5766             final PhylogenyFactory factory0 = ParserBasedPhylogenyFactory.getInstance();
5767             final String p0_str = "((one,two)1-2,(three,four)3-4)root";
5768             final Phylogeny p0 = factory0.create( p0_str, new NHXParser() )[ 0 ];
5769             final DomainParsimonyCalculator dp0 = DomainParsimonyCalculator.createInstance( p0, gwcd_list );
5770             dp0.executeDolloParsimonyOnDomainPresence();
5771             final CharacterStateMatrix<GainLossStates> gl_matrix_d = dp0.getGainLossMatrix();
5772             final CharacterStateMatrix<BinaryStates> is_matrix_d = dp0.getInternalStatesMatrix();
5773             dp0.executeDolloParsimonyOnBinaryDomainCombintionPresence();
5774             final CharacterStateMatrix<GainLossStates> gl_matrix_bc = dp0.getGainLossMatrix();
5775             final CharacterStateMatrix<BinaryStates> is_matrix_bc = dp0.getInternalStatesMatrix();
5776             if ( is_matrix_d.getState( "root", "A" ) != X ) {
5777                 return false;
5778             }
5779             if ( is_matrix_d.getState( "root", "B" ) != X ) {
5780                 return false;
5781             }
5782             if ( is_matrix_d.getState( "root", "C" ) != O ) {
5783                 return false;
5784             }
5785             if ( is_matrix_d.getState( "root", "D" ) != O ) {
5786                 return false;
5787             }
5788             if ( is_matrix_d.getState( "root", "E" ) != X ) {
5789                 return false;
5790             }
5791             if ( is_matrix_bc.getState( "root", "A=A" ) != O ) {
5792                 return false;
5793             }
5794             if ( is_matrix_bc.getState( "root", "A=B" ) != X ) {
5795                 return false;
5796             }
5797             if ( is_matrix_bc.getState( "root", "A=C" ) != O ) {
5798                 return false;
5799             }
5800             if ( is_matrix_bc.getState( "root", "A=D" ) != O ) {
5801                 return false;
5802             }
5803             if ( is_matrix_bc.getState( "root", "G=H" ) != O ) {
5804                 return false;
5805             }
5806             if ( is_matrix_bc.getState( "1-2", "G=H" ) != O ) {
5807                 return false;
5808             }
5809             if ( is_matrix_bc.getState( "root", "E=F" ) != X ) {
5810                 return false;
5811             }
5812             if ( gl_matrix_bc.getState( "root", "E=F" ) != P ) {
5813                 return false;
5814             }
5815             if ( gl_matrix_bc.getState( "root", "A=A" ) != A ) {
5816                 return false;
5817             }
5818             if ( gl_matrix_bc.getState( "one", "A=A" ) != G ) {
5819                 return false;
5820             }
5821             if ( gl_matrix_bc.getState( "root", "A=B" ) != P ) {
5822                 return false;
5823             }
5824             if ( gl_matrix_bc.getState( "3-4", "A=D" ) != G ) {
5825                 return false;
5826             }
5827             if ( gl_matrix_bc.getState( "four", "E=F" ) != L ) {
5828                 return false;
5829             }
5830             if ( gl_matrix_d.getState( "3-4", "P" ) != G ) {
5831                 return false;
5832             }
5833         }
5834         catch ( final Exception e ) {
5835             e.printStackTrace( System.out );
5836             return false;
5837         }
5838         return true;
5839     }
5840
5841     private static boolean testParsimonyOnSecondaryFeatures() {
5842         try {
5843             final BinaryStates X = BinaryStates.PRESENT;
5844             final BinaryStates O = BinaryStates.ABSENT;
5845             final GainLossStates G = GainLossStates.GAIN;
5846             final GainLossStates L = GainLossStates.LOSS;
5847             final GainLossStates A = GainLossStates.UNCHANGED_ABSENT;
5848             final GainLossStates P = GainLossStates.UNCHANGED_PRESENT;
5849             final Domain a = new BasicDomain( "A", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5850             final Domain b = new BasicDomain( "B", 2, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5851             final Domain c = new BasicDomain( "C", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5852             final Domain d = new BasicDomain( "D", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5853             final Domain e = new BasicDomain( "E", 2, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5854             final Domain f = new BasicDomain( "F", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5855             final Domain g = new BasicDomain( "G", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5856             final Domain h = new BasicDomain( "H", 2, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5857             final Domain i = new BasicDomain( "I", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5858             final Domain j = new BasicDomain( "J", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5859             final Domain l = new BasicDomain( "L", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5860             final Domain m = new BasicDomain( "M", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5861             final Domain n = new BasicDomain( "N", 2, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5862             final Domain o = new BasicDomain( "O", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5863             final Domain p = new BasicDomain( "P", 1, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5864             final Domain q = new BasicDomain( "Q", 2, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5865             final Domain r = new BasicDomain( "R", 3, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
5866             // 1 a-a a-b a-c e-f-g-h l-m
5867             // 2 a-b a-c e-f-g-i n-o
5868             // 3 a-b a-d e-f-g-j p-q
5869             // 4 a-b a-d p-r
5870             // 1 a-a a-b a-c e-f e-g e-h f-g f-h g-h l-m
5871             // 2 a-b a-c e-f e-g e-i f-g f-i g-i n-o
5872             // 3 a-b a-d e-f e-g e-j f-g f-j g-j p-q
5873             // 4 a-b a-d p-r
5874             // 1 a b c e f g h l m
5875             // 2 a b c e f g i n o
5876             // 3 a b d e f g j p q
5877             // 4 a b d p r
5878             final Protein aa1 = new BasicProtein( "aa1", "one" );
5879             aa1.addProteinDomain( a );
5880             aa1.addProteinDomain( a );
5881             final Protein ab1 = new BasicProtein( "ab1", "one" );
5882             ab1.addProteinDomain( a );
5883             ab1.addProteinDomain( b );
5884             final Protein ac1 = new BasicProtein( "ac1", "one" );
5885             ac1.addProteinDomain( a );
5886             ac1.addProteinDomain( c );
5887             final Protein efgh1 = new BasicProtein( "efgh1", "one" );
5888             efgh1.addProteinDomain( e );
5889             efgh1.addProteinDomain( f );
5890             efgh1.addProteinDomain( g );
5891             efgh1.addProteinDomain( h );
5892             final Protein lm1 = new BasicProtein( "lm1", "one" );
5893             lm1.addProteinDomain( l );
5894             lm1.addProteinDomain( m );
5895             final Protein ab2 = new BasicProtein( "ab2", "two" );
5896             ab2.addProteinDomain( a );
5897             ab2.addProteinDomain( b );
5898             final Protein ac2 = new BasicProtein( "ac2", "two" );
5899             ac2.addProteinDomain( a );
5900             ac2.addProteinDomain( c );
5901             final Protein efgi2 = new BasicProtein( "efgi2", "two" );
5902             efgi2.addProteinDomain( e );
5903             efgi2.addProteinDomain( f );
5904             efgi2.addProteinDomain( g );
5905             efgi2.addProteinDomain( i );
5906             final Protein no2 = new BasicProtein( "no2", "two" );
5907             no2.addProteinDomain( n );
5908             no2.addProteinDomain( o );
5909             final Protein ab3 = new BasicProtein( "ab3", "three" );
5910             ab3.addProteinDomain( a );
5911             ab3.addProteinDomain( b );
5912             final Protein ad3 = new BasicProtein( "ad3", "three" );
5913             ad3.addProteinDomain( a );
5914             ad3.addProteinDomain( d );
5915             final Protein efgj3 = new BasicProtein( "efgj3", "three" );
5916             efgj3.addProteinDomain( e );
5917             efgj3.addProteinDomain( f );
5918             efgj3.addProteinDomain( g );
5919             efgj3.addProteinDomain( j );
5920             final Protein pq3 = new BasicProtein( "pq3", "three" );
5921             pq3.addProteinDomain( p );
5922             pq3.addProteinDomain( q );
5923             final Protein ab4 = new BasicProtein( "ab4", "four" );
5924             ab4.addProteinDomain( a );
5925             ab4.addProteinDomain( b );
5926             final Protein ad4 = new BasicProtein( "ad4", "four" );
5927             ad4.addProteinDomain( a );
5928             ad4.addProteinDomain( d );
5929             final Protein pr4 = new BasicProtein( "pr4", "four" );
5930             pr4.addProteinDomain( p );
5931             pr4.addProteinDomain( r );
5932             final List<Protein> one_list = new ArrayList<Protein>();
5933             one_list.add( aa1 );
5934             one_list.add( ab1 );
5935             one_list.add( ac1 );
5936             one_list.add( efgh1 );
5937             one_list.add( lm1 );
5938             final List<Protein> two_list = new ArrayList<Protein>();
5939             two_list.add( ab2 );
5940             two_list.add( ac2 );
5941             two_list.add( efgi2 );
5942             two_list.add( no2 );
5943             final List<Protein> three_list = new ArrayList<Protein>();
5944             three_list.add( ab3 );
5945             three_list.add( ad3 );
5946             three_list.add( efgj3 );
5947             three_list.add( pq3 );
5948             final List<Protein> four_list = new ArrayList<Protein>();
5949             four_list.add( ab4 );
5950             four_list.add( ad4 );
5951             four_list.add( pr4 );
5952             final GenomeWideCombinableDomains one = BasicGenomeWideCombinableDomains
5953                     .createInstance( one_list, false, new BasicSpecies( "one" ) );
5954             final GenomeWideCombinableDomains two = BasicGenomeWideCombinableDomains
5955                     .createInstance( two_list, false, new BasicSpecies( "two" ) );
5956             final GenomeWideCombinableDomains three = BasicGenomeWideCombinableDomains
5957                     .createInstance( three_list, false, new BasicSpecies( "three" ) );
5958             final GenomeWideCombinableDomains four = BasicGenomeWideCombinableDomains
5959                     .createInstance( four_list, false, new BasicSpecies( "four" ) );
5960             final List<GenomeWideCombinableDomains> gwcd_list = new ArrayList<GenomeWideCombinableDomains>();
5961             gwcd_list.add( one );
5962             gwcd_list.add( two );
5963             gwcd_list.add( three );
5964             gwcd_list.add( four );
5965             final Map<DomainId, Set<String>> map_same = new HashMap<DomainId, Set<String>>();
5966             final HashSet<String> a_s = new HashSet<String>();
5967             a_s.add( "AAA" );
5968             final HashSet<String> b_s = new HashSet<String>();
5969             b_s.add( "BBB" );
5970             final HashSet<String> c_s = new HashSet<String>();
5971             c_s.add( "CCC" );
5972             final HashSet<String> d_s = new HashSet<String>();
5973             d_s.add( "DDD" );
5974             final HashSet<String> e_s = new HashSet<String>();
5975             e_s.add( "EEE" );
5976             final HashSet<String> f_s = new HashSet<String>();
5977             f_s.add( "FFF" );
5978             final HashSet<String> g_s = new HashSet<String>();
5979             g_s.add( "GGG" );
5980             final HashSet<String> h_s = new HashSet<String>();
5981             h_s.add( "HHH" );
5982             final HashSet<String> i_s = new HashSet<String>();
5983             i_s.add( "III" );
5984             final HashSet<String> j_s = new HashSet<String>();
5985             j_s.add( "JJJ" );
5986             final HashSet<String> l_s = new HashSet<String>();
5987             l_s.add( "LLL" );
5988             final HashSet<String> m_s = new HashSet<String>();
5989             m_s.add( "MMM" );
5990             final HashSet<String> n_s = new HashSet<String>();
5991             n_s.add( "NNN" );
5992             final HashSet<String> o_s = new HashSet<String>();
5993             o_s.add( "OOO" );
5994             final HashSet<String> p_s = new HashSet<String>();
5995             p_s.add( "PPP" );
5996             final HashSet<String> q_s = new HashSet<String>();
5997             q_s.add( "QQQ" );
5998             final HashSet<String> r_s = new HashSet<String>();
5999             r_s.add( "RRR" );
6000             map_same.put( a.getDomainId(), a_s );
6001             map_same.put( b.getDomainId(), b_s );
6002             map_same.put( c.getDomainId(), c_s );
6003             map_same.put( d.getDomainId(), d_s );
6004             map_same.put( e.getDomainId(), e_s );
6005             map_same.put( f.getDomainId(), f_s );
6006             map_same.put( g.getDomainId(), g_s );
6007             map_same.put( h.getDomainId(), h_s );
6008             map_same.put( i.getDomainId(), i_s );
6009             map_same.put( j.getDomainId(), j_s );
6010             map_same.put( l.getDomainId(), l_s );
6011             map_same.put( m.getDomainId(), m_s );
6012             map_same.put( n.getDomainId(), n_s );
6013             map_same.put( o.getDomainId(), o_s );
6014             map_same.put( p.getDomainId(), p_s );
6015             map_same.put( q.getDomainId(), q_s );
6016             map_same.put( r.getDomainId(), r_s );
6017             final CharacterStateMatrix<BinaryStates> matrix_s = DomainParsimonyCalculator
6018                     .createMatrixOfSecondaryFeaturePresenceOrAbsence( gwcd_list, map_same, null );
6019             // 1 a b c e f g h l m
6020             // 2 a b c e f g i n o
6021             // 3 a b d e f g j p q
6022             // 4 a b d p r
6023             if ( matrix_s.getState( 0, 0 ) != X ) {
6024                 return false;
6025             }
6026             if ( matrix_s.getState( 0, 1 ) != X ) {
6027                 return false;
6028             }
6029             if ( matrix_s.getState( 0, 2 ) != X ) {
6030                 return false;
6031             }
6032             if ( matrix_s.getState( 0, 3 ) != O ) {
6033                 return false;
6034             }
6035             if ( matrix_s.getState( 0, 4 ) != X ) {
6036                 return false;
6037             }
6038             if ( matrix_s.getState( 0, 5 ) != X ) {
6039                 return false;
6040             }
6041             if ( matrix_s.getState( 0, 6 ) != X ) {
6042                 return false;
6043             }
6044             if ( matrix_s.getState( 0, 7 ) != X ) {
6045                 return false;
6046             }
6047             if ( matrix_s.getState( 0, 8 ) != O ) {
6048                 return false;
6049             }
6050             final PhylogenyFactory factory0 = ParserBasedPhylogenyFactory.getInstance();
6051             final String p0_str = "((one,two)1-2,(three,four)3-4)root";
6052             final Phylogeny p0 = factory0.create( p0_str, new NHXParser() )[ 0 ];
6053             final DomainParsimonyCalculator dp0 = DomainParsimonyCalculator.createInstance( p0, gwcd_list, map_same );
6054             dp0.executeDolloParsimonyOnSecondaryFeatures( null );
6055             final CharacterStateMatrix<GainLossStates> gl_matrix_d = dp0.getGainLossMatrix();
6056             final CharacterStateMatrix<BinaryStates> is_matrix_d = dp0.getInternalStatesMatrix();
6057             if ( is_matrix_d.getState( "root", "AAA" ) != X ) {
6058                 return false;
6059             }
6060             if ( is_matrix_d.getState( "root", "BBB" ) != X ) {
6061                 return false;
6062             }
6063             if ( is_matrix_d.getState( "root", "CCC" ) != O ) {
6064                 return false;
6065             }
6066             if ( is_matrix_d.getState( "root", "DDD" ) != O ) {
6067                 return false;
6068             }
6069             if ( is_matrix_d.getState( "root", "EEE" ) != X ) {
6070                 return false;
6071             }
6072             if ( gl_matrix_d.getState( "3-4", "PPP" ) != G ) {
6073                 return false;
6074             }
6075         }
6076         catch ( final Exception e ) {
6077             e.printStackTrace( System.out );
6078             return false;
6079         }
6080         return true;
6081     }
6082
6083     private static boolean testPaupLogParser( final File test_dir ) {
6084         try {
6085             final PaupLogParser parser = new PaupLogParser();
6086             parser.setSource( new File( test_dir + ForesterUtil.getFileSeparator() + "paup_log_test_1" ) );
6087             final CharacterStateMatrix<BinaryStates> matrix = parser.parse();
6088             if ( matrix.getNumberOfIdentifiers() != 8 ) {
6089                 return false;
6090             }
6091             if ( !matrix.getIdentifier( 0 ).equals( "MOUSE" ) ) {
6092                 return false;
6093             }
6094             if ( !matrix.getIdentifier( 1 ).equals( "NEMVE" ) ) {
6095                 return false;
6096             }
6097             if ( !matrix.getIdentifier( 2 ).equals( "MONBE" ) ) {
6098                 return false;
6099             }
6100             if ( !matrix.getIdentifier( 3 ).equals( "DICDI" ) ) {
6101                 return false;
6102             }
6103             if ( !matrix.getIdentifier( 4 ).equals( "ARATH" ) ) {
6104                 return false;
6105             }
6106             if ( !matrix.getIdentifier( 5 ).equals( "6" ) ) {
6107                 return false;
6108             }
6109             if ( !matrix.getIdentifier( 6 ).equals( "7" ) ) {
6110                 return false;
6111             }
6112             if ( !matrix.getIdentifier( 7 ).equals( "8" ) ) {
6113                 return false;
6114             }
6115             if ( matrix.getNumberOfCharacters() != ( 66 + 66 + 28 ) ) {
6116                 return false;
6117             }
6118             if ( matrix.getState( 0, 4 ) != BinaryStates.ABSENT ) {
6119                 return false;
6120             }
6121             if ( matrix.getState( 0, 5 ) != BinaryStates.PRESENT ) {
6122                 return false;
6123             }
6124             if ( matrix.getState( 1, 5 ) != BinaryStates.PRESENT ) {
6125                 return false;
6126             }
6127             if ( matrix.getState( 7, 154 ) != BinaryStates.ABSENT ) {
6128                 return false;
6129             }
6130             if ( matrix.getState( 7, 155 ) != BinaryStates.PRESENT ) {
6131                 return false;
6132             }
6133             if ( matrix.getState( 7, 156 ) != BinaryStates.PRESENT ) {
6134                 return false;
6135             }
6136             if ( matrix.getState( 7, 157 ) != BinaryStates.ABSENT ) {
6137                 return false;
6138             }
6139             if ( matrix.getState( 7, 158 ) != BinaryStates.PRESENT ) {
6140                 return false;
6141             }
6142             if ( matrix.getState( 7, 159 ) != BinaryStates.ABSENT ) {
6143                 return false;
6144             }
6145         }
6146         catch ( final Exception e ) {
6147             e.printStackTrace( System.out );
6148             return false;
6149         }
6150         return true;
6151     }
6152
6153     private static boolean testProteinId() {
6154         try {
6155             final ProteinId id1 = new ProteinId( "a" );
6156             final ProteinId id2 = new ProteinId( "a" );
6157             final ProteinId id3 = new ProteinId( "A" );
6158             final ProteinId id4 = new ProteinId( "b" );
6159             if ( !id1.equals( id1 ) ) {
6160                 return false;
6161             }
6162             if ( id1.getId().equals( "x" ) ) {
6163                 return false;
6164             }
6165             if ( id1.getId().equals( null ) ) {
6166                 return false;
6167             }
6168             if ( !id1.equals( id2 ) ) {
6169                 return false;
6170             }
6171             if ( id1.equals( id3 ) ) {
6172                 return false;
6173             }
6174             if ( id1.hashCode() != id1.hashCode() ) {
6175                 return false;
6176             }
6177             if ( id1.hashCode() != id2.hashCode() ) {
6178                 return false;
6179             }
6180             if ( id1.hashCode() == id3.hashCode() ) {
6181                 return false;
6182             }
6183             if ( id1.compareTo( id1 ) != 0 ) {
6184                 return false;
6185             }
6186             if ( id1.compareTo( id2 ) != 0 ) {
6187                 return false;
6188             }
6189             if ( id1.compareTo( id3 ) != 0 ) {
6190                 return false;
6191             }
6192             if ( id1.compareTo( id4 ) >= 0 ) {
6193                 return false;
6194             }
6195             if ( id4.compareTo( id1 ) <= 0 ) {
6196                 return false;
6197             }
6198             if ( !id4.getId().equals( "b" ) ) {
6199                 return false;
6200             }
6201             final ProteinId id5 = new ProteinId( " C " );
6202             if ( !id5.getId().equals( "C" ) ) {
6203                 return false;
6204             }
6205             if ( id5.equals( id1 ) ) {
6206                 return false;
6207             }
6208         }
6209         catch ( final Exception e ) {
6210             e.printStackTrace( System.out );
6211             return false;
6212         }
6213         return true;
6214     }
6215
6216     private static boolean testSpecies() {
6217         try {
6218             final Species s1 = new BasicSpecies( "a" );
6219             final Species s2 = new BasicSpecies( "a" );
6220             final Species s3 = new BasicSpecies( "A" );
6221             final Species s4 = new BasicSpecies( "b" );
6222             if ( !s1.equals( s1 ) ) {
6223                 return false;
6224             }
6225             if ( s1.getSpeciesId().equals( "x" ) ) {
6226                 return false;
6227             }
6228             if ( s1.getSpeciesId().equals( null ) ) {
6229                 return false;
6230             }
6231             if ( !s1.equals( s2 ) ) {
6232                 return false;
6233             }
6234             if ( s1.equals( s3 ) ) {
6235                 return false;
6236             }
6237             if ( s1.hashCode() != s1.hashCode() ) {
6238                 return false;
6239             }
6240             if ( s1.hashCode() != s2.hashCode() ) {
6241                 return false;
6242             }
6243             if ( s1.hashCode() == s3.hashCode() ) {
6244                 return false;
6245             }
6246             if ( s1.compareTo( s1 ) != 0 ) {
6247                 return false;
6248             }
6249             if ( s1.compareTo( s2 ) != 0 ) {
6250                 return false;
6251             }
6252             if ( s1.compareTo( s3 ) != 0 ) {
6253                 return false;
6254             }
6255             if ( s1.compareTo( s4 ) >= 0 ) {
6256                 return false;
6257             }
6258             if ( s4.compareTo( s1 ) <= 0 ) {
6259                 return false;
6260             }
6261             if ( !s4.getSpeciesId().equals( "b" ) ) {
6262                 return false;
6263             }
6264             final Species s5 = new BasicSpecies( " C " );
6265             if ( !s5.getSpeciesId().equals( "C" ) ) {
6266                 return false;
6267             }
6268             if ( s5.equals( s1 ) ) {
6269                 return false;
6270             }
6271         }
6272         catch ( final Exception e ) {
6273             e.printStackTrace( System.out );
6274             return false;
6275         }
6276         return true;
6277     }
6278 }