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