X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fsurfacing%2FDomainArchitectureBasedGenomeSimilarityCalculator.java;h=a61ba305a8bce02ff46b0666e5e21bdc9238997e;hb=bf4f34e0511813622f68e54ffb783e4e6d92bfa4;hp=cdc9416369471d8f281e587cead369accbdbfcc4;hpb=656be28debec520e0e35a8b311114398a40ea366;p=jalview.git diff --git a/forester/java/src/org/forester/surfacing/DomainArchitectureBasedGenomeSimilarityCalculator.java b/forester/java/src/org/forester/surfacing/DomainArchitectureBasedGenomeSimilarityCalculator.java index cdc9416..a61ba30 100644 --- a/forester/java/src/org/forester/surfacing/DomainArchitectureBasedGenomeSimilarityCalculator.java +++ b/forester/java/src/org/forester/surfacing/DomainArchitectureBasedGenomeSimilarityCalculator.java @@ -30,24 +30,23 @@ import java.util.HashSet; import java.util.Set; import org.forester.protein.BinaryDomainCombination; -import org.forester.protein.DomainId; public class DomainArchitectureBasedGenomeSimilarityCalculator { public static final double MAX_SIMILARITY_SCORE = 1.0; public static final double MIN_SIMILARITY_SCORE = 0.0; - final private GenomeWideCombinableDomains _combinable_domains_genome_0; - final private GenomeWideCombinableDomains _combinable_domains_genome_1; - private Set _domain_ids_to_ignore; - private boolean _allow_domains_to_be_ignored; - private Set _all_domains; - private Set _shared_domains; - private Set _domains_specific_to_0; - private Set _domains_specific_to_1; private Set _all_binary_domain_combinations; - private Set _shared_binary_domain_combinations; + private Set _all_domains; + private boolean _allow_domains_to_be_ignored; private Set _binary_domain_combinations_specific_to_0; private Set _binary_domain_combinations_specific_to_1; + final private GenomeWideCombinableDomains _combinable_domains_genome_0; + final private GenomeWideCombinableDomains _combinable_domains_genome_1; + private Set _domain_ids_to_ignore; + private Set _domains_specific_to_0; + private Set _domains_specific_to_1; + private Set _shared_binary_domain_combinations; + private Set _shared_domains; public DomainArchitectureBasedGenomeSimilarityCalculator( final GenomeWideCombinableDomains combinable_domains_genome_0, final GenomeWideCombinableDomains combinable_domains_genome_1 ) { @@ -64,7 +63,7 @@ public class DomainArchitectureBasedGenomeSimilarityCalculator { forceRecalculation(); } - public void addDomainIdToIgnore( final DomainId domain_id_to_ignore ) { + public void addDomainIdToIgnore( final String domain_id_to_ignore ) { forceRecalculation(); getDomainIdsToIgnore().add( domain_id_to_ignore ); } @@ -113,18 +112,7 @@ public class DomainArchitectureBasedGenomeSimilarityCalculator { public void deleteAllDomainIdsToIgnore() { forceRecalculation(); - setDomainIdsToIgnore( new HashSet() ); - } - - private void forceRecalculation() { - _all_domains = null; - _shared_domains = null; - _domains_specific_to_0 = null; - _domains_specific_to_1 = null; - _all_binary_domain_combinations = null; - _shared_binary_domain_combinations = null; - _binary_domain_combinations_specific_to_0 = null; - _binary_domain_combinations_specific_to_1 = null; + setDomainIdsToIgnore( new HashSet() ); } /** @@ -155,9 +143,9 @@ public class DomainArchitectureBasedGenomeSimilarityCalculator { * * @return */ - public Set getAllDomains() { + public Set getAllDomains() { if ( _all_domains == null ) { - final Set all = new HashSet(); + final Set all = new HashSet(); all.addAll( getCombinableDomainsGenome0().getAllDomainIds() ); all.addAll( getCombinableDomainsGenome1().getAllDomainIds() ); if ( isAllowDomainsToBeIgnored() && !getDomainIdsToIgnore().isEmpty() ) { @@ -170,30 +158,6 @@ public class DomainArchitectureBasedGenomeSimilarityCalculator { return _all_domains; } - private Set getBinaryDomainCombinationsSpecificToGenome( final boolean specific_to_genome_0 ) { - final Set specific = new HashSet(); - final Set bc0 = getCombinableDomainsGenome0().toBinaryDomainCombinations(); - final Set bc1 = getCombinableDomainsGenome1().toBinaryDomainCombinations(); - if ( specific_to_genome_0 ) { - for( final BinaryDomainCombination binary_domain_combination0 : bc0 ) { - if ( !bc1.contains( binary_domain_combination0 ) ) { - specific.add( binary_domain_combination0 ); - } - } - } - else { - for( final BinaryDomainCombination binary_domain_combination1 : bc1 ) { - if ( !bc0.contains( binary_domain_combination1 ) ) { - specific.add( binary_domain_combination1 ); - } - } - } - if ( isAllowDomainsToBeIgnored() && !getDomainIdsToIgnore().isEmpty() ) { - return pruneBinaryCombinations( specific ); - } - return specific; - } - public Set getBinaryDomainCombinationsSpecificToGenome0() { if ( _binary_domain_combinations_specific_to_0 == null ) { _binary_domain_combinations_specific_to_0 = getBinaryDomainCombinationsSpecificToGenome( true ); @@ -208,50 +172,14 @@ public class DomainArchitectureBasedGenomeSimilarityCalculator { return _binary_domain_combinations_specific_to_1; } - private GenomeWideCombinableDomains getCombinableDomainsGenome0() { - return _combinable_domains_genome_0; - } - - private GenomeWideCombinableDomains getCombinableDomainsGenome1() { - return _combinable_domains_genome_1; - } - - private Set getDomainIdsToIgnore() { - return _domain_ids_to_ignore; - } - - private Set getDomainsSpecificToGenome( final boolean specific_to_genome_0 ) { - final Set specific = new HashSet(); - final Set d0 = getCombinableDomainsGenome0().getAllDomainIds(); - final Set d1 = getCombinableDomainsGenome1().getAllDomainIds(); - if ( specific_to_genome_0 ) { - for( final DomainId domain0 : d0 ) { - if ( !d1.contains( domain0 ) ) { - specific.add( domain0 ); - } - } - } - else { - for( final DomainId domain1 : d1 ) { - if ( !d0.contains( domain1 ) ) { - specific.add( domain1 ); - } - } - } - if ( isAllowDomainsToBeIgnored() && !getDomainIdsToIgnore().isEmpty() ) { - return pruneDomains( specific ); - } - return specific; - } - - public Set getDomainsSpecificToGenome0() { + public Set getDomainsSpecificToGenome0() { if ( _domains_specific_to_0 == null ) { _domains_specific_to_0 = getDomainsSpecificToGenome( true ); } return _domains_specific_to_0; } - public Set getDomainsSpecificToGenome1() { + public Set getDomainsSpecificToGenome1() { if ( _domains_specific_to_1 == null ) { _domains_specific_to_1 = getDomainsSpecificToGenome( false ); } @@ -276,12 +204,12 @@ public class DomainArchitectureBasedGenomeSimilarityCalculator { return _shared_binary_domain_combinations; } - public Set getSharedDomains() { + public Set getSharedDomains() { if ( _shared_domains == null ) { - final Set shared = new HashSet(); - final Set d0 = getCombinableDomainsGenome0().getAllDomainIds(); - final Set d1 = getCombinableDomainsGenome1().getAllDomainIds(); - for( final DomainId domain0 : d0 ) { + final Set shared = new HashSet(); + final Set d0 = getCombinableDomainsGenome0().getAllDomainIds(); + final Set d1 = getCombinableDomainsGenome1().getAllDomainIds(); + for( final String domain0 : d0 ) { if ( d1.contains( domain0 ) ) { shared.add( domain0 ); } @@ -294,6 +222,87 @@ public class DomainArchitectureBasedGenomeSimilarityCalculator { return _shared_domains; } + public void setAllowDomainsToBeIgnored( final boolean allow_domains_to_be_ignored ) { + forceRecalculation(); + _allow_domains_to_be_ignored = allow_domains_to_be_ignored; + } + + void setDomainIdsToIgnore( final Set domain_ids_to_ignore ) { + forceRecalculation(); + _domain_ids_to_ignore = domain_ids_to_ignore; + } + + private void forceRecalculation() { + _all_domains = null; + _shared_domains = null; + _domains_specific_to_0 = null; + _domains_specific_to_1 = null; + _all_binary_domain_combinations = null; + _shared_binary_domain_combinations = null; + _binary_domain_combinations_specific_to_0 = null; + _binary_domain_combinations_specific_to_1 = null; + } + + private Set getBinaryDomainCombinationsSpecificToGenome( final boolean specific_to_genome_0 ) { + final Set specific = new HashSet(); + final Set bc0 = getCombinableDomainsGenome0().toBinaryDomainCombinations(); + final Set bc1 = getCombinableDomainsGenome1().toBinaryDomainCombinations(); + if ( specific_to_genome_0 ) { + for( final BinaryDomainCombination binary_domain_combination0 : bc0 ) { + if ( !bc1.contains( binary_domain_combination0 ) ) { + specific.add( binary_domain_combination0 ); + } + } + } + else { + for( final BinaryDomainCombination binary_domain_combination1 : bc1 ) { + if ( !bc0.contains( binary_domain_combination1 ) ) { + specific.add( binary_domain_combination1 ); + } + } + } + if ( isAllowDomainsToBeIgnored() && !getDomainIdsToIgnore().isEmpty() ) { + return pruneBinaryCombinations( specific ); + } + return specific; + } + + private GenomeWideCombinableDomains getCombinableDomainsGenome0() { + return _combinable_domains_genome_0; + } + + private GenomeWideCombinableDomains getCombinableDomainsGenome1() { + return _combinable_domains_genome_1; + } + + private Set getDomainIdsToIgnore() { + return _domain_ids_to_ignore; + } + + private Set getDomainsSpecificToGenome( final boolean specific_to_genome_0 ) { + final Set specific = new HashSet(); + final Set d0 = getCombinableDomainsGenome0().getAllDomainIds(); + final Set d1 = getCombinableDomainsGenome1().getAllDomainIds(); + if ( specific_to_genome_0 ) { + for( final String domain0 : d0 ) { + if ( !d1.contains( domain0 ) ) { + specific.add( domain0 ); + } + } + } + else { + for( final String domain1 : d1 ) { + if ( !d0.contains( domain1 ) ) { + specific.add( domain1 ); + } + } + } + if ( isAllowDomainsToBeIgnored() && !getDomainIdsToIgnore().isEmpty() ) { + return pruneDomains( specific ); + } + return specific; + } + private void init() { deleteAllDomainIdsToIgnore(); setAllowDomainsToBeIgnored( false ); @@ -314,23 +323,13 @@ public class DomainArchitectureBasedGenomeSimilarityCalculator { return pruned; } - private Set pruneDomains( final Set all ) { - final Set pruned = new HashSet(); - for( final DomainId d : all ) { + private Set pruneDomains( final Set all ) { + final Set pruned = new HashSet(); + for( final String d : all ) { if ( !getDomainIdsToIgnore().contains( d ) ) { pruned.add( d ); } } return pruned; } - - public void setAllowDomainsToBeIgnored( final boolean allow_domains_to_be_ignored ) { - forceRecalculation(); - _allow_domains_to_be_ignored = allow_domains_to_be_ignored; - } - - void setDomainIdsToIgnore( final Set domain_ids_to_ignore ) { - forceRecalculation(); - _domain_ids_to_ignore = domain_ids_to_ignore; - } } \ No newline at end of file