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