// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
//
// Contact: phylosoft @ gmail . com
-// WWW: www.phylosoft.org/forester
+// WWW: https://sites.google.com/site/cmzmasek/home/software/forester
package org.forester.surfacing;
import java.util.SortedSet;
import java.util.TreeSet;
+import org.forester.application.surfacing;
import org.forester.evoinference.matrix.character.BasicCharacterStateMatrix;
import org.forester.evoinference.matrix.character.CharacterStateMatrix;
import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
import org.forester.phylogeny.PhylogenyNode;
import org.forester.phylogeny.data.BinaryCharacters;
import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
-import org.forester.surfacing.BinaryDomainCombination.DomainCombinationType;
+import org.forester.protein.BinaryDomainCombination;
+import org.forester.protein.BinaryDomainCombination.DomainCombinationType;
+import org.forester.protein.DomainId;
+import org.forester.species.Species;
import org.forester.util.ForesterUtil;
public final class DomainParsimonyCalculator {
setTotalLosses( fitch.getTotalLosses() );
setTotalUnchanged( fitch.getTotalUnchanged() );
}
-
- private void executeFitchParsimonyOnSecondaryFeatures(
- final boolean use_last,
- final boolean randomize,
- final long random_number_seed ) {
+
+ private void executeFitchParsimonyOnSecondaryFeatures( final boolean use_last,
+ final boolean randomize,
+ final long random_number_seed ) {
reset();
if ( use_last ) {
System.out.println( " Fitch parsimony: use_last = true" );
fitch.setUseLast( use_last );
fitch.setReturnGainLossMatrix( true );
fitch.setReturnInternalStates( true );
-
final Map<DomainId, Set<String>> map = getDomainIdToSecondaryFeaturesMap();
final Map<DomainId, String> newmap = new HashMap<DomainId, String>();
final Iterator<Entry<DomainId, Set<String>>> it = map.entrySet().iterator();
- while (it.hasNext()) {
- final Map.Entry<DomainId, Set<String>> pair = (Map.Entry<DomainId, Set<String>>)it.next();
+ while ( it.hasNext() ) {
+ final Map.Entry<DomainId, Set<String>> pair = it.next();
if ( pair.getValue().size() != 1 ) {
- throw new IllegalArgumentException( pair.getKey().getId() + " mapps to " + pair.getValue().size() + " items" );
+ throw new IllegalArgumentException( pair.getKey().getId() + " mapps to " + pair.getValue().size()
+ + " items" );
}
newmap.put( pair.getKey(), ( String ) pair.getValue().toArray()[ 0 ] );
}
-
- CharacterStateMatrix<BinaryStates> states =createMatrixOfSecondaryFeatureBinaryDomainCombinationPresenceOrAbsence( getGenomeWideCombinableDomainsList(),
- newmap );
-
+ final CharacterStateMatrix<BinaryStates> states = createMatrixOfSecondaryFeatureBinaryDomainCombinationPresenceOrAbsence( getGenomeWideCombinableDomainsList(),
+ newmap );
fitch.execute( getPhylogeny(), states );
setGainLossMatrix( fitch.getGainLossMatrix() );
setBinaryInternalStatesMatrix( fitch.getInternalStatesMatrix() );
public void executeFitchParsimonyOnBinaryDomainCombintion( final boolean use_last ) {
executeFitchParsimony( false, use_last, false, 0 );
}
-
+
public void executeFitchParsimonyOnBinaryDomainCombintionOnSecondaryFeatures( final boolean use_last ) {
executeFitchParsimonyOnSecondaryFeatures( use_last, false, 0 );
}
return new DomainParsimonyCalculator( phylogeny, gwcd_list, domain_id_to_secondary_features_map );
}
-
/**
* For folds instead of Pfam-domains, for example
*
}
return matrix;
}
-
-
+
public static CharacterStateMatrix<BinaryStates> createMatrixOfSecondaryFeatureBinaryDomainCombinationPresenceOrAbsence( final List<GenomeWideCombinableDomains> gwcd_list,
- final Map<DomainId, String> domain_id_to_second_features_map) {
+ final Map<DomainId, String> domain_id_to_second_features_map ) {
if ( gwcd_list.isEmpty() ) {
throw new IllegalArgumentException( "genome wide combinable domains list is empty" );
}
final SortedSet<BinaryDomainCombination> all_binary_combinations_mapped = new TreeSet<BinaryDomainCombination>();
final Set<BinaryDomainCombination>[] binary_combinations_per_genome_mapped = new HashSet[ number_of_identifiers ];
int identifier_index = 0;
+ final SortedSet<String> no_mappings = new TreeSet<String>();
for( final GenomeWideCombinableDomains gwcd : gwcd_list ) {
binary_combinations_per_genome_mapped[ identifier_index ] = new HashSet<BinaryDomainCombination>();
for( final BinaryDomainCombination bc : gwcd.toBinaryDomainCombinations() ) {
-
- if ( !domain_id_to_second_features_map.containsKey( bc.getId0() ) ) {
- throw new IllegalArgumentException( "no mapping found for " + bc.getId0() );
- }
- if ( !domain_id_to_second_features_map.containsKey( bc.getId1() ) ) {
- throw new IllegalArgumentException( "no mapping found for " + bc.getId1() );
- }
-
-
- final BinaryDomainCombination mapped_bc = new BasicBinaryDomainCombination( domain_id_to_second_features_map.get( bc.getId0()) ,
- domain_id_to_second_features_map.get( bc.getId1()) );
+ final BinaryDomainCombination mapped_bc = mapBinaryDomainCombination( domain_id_to_second_features_map,
+ bc,
+ no_mappings );
all_binary_combinations_mapped.add( mapped_bc );
binary_combinations_per_genome_mapped[ identifier_index ].add( mapped_bc );
}
++identifier_index;
}
-
+ if ( !no_mappings.isEmpty() ) {
+ ForesterUtil.programMessage( surfacing.PRG_NAME, "No mappings for the following (" + no_mappings.size()
+ + "):" );
+ for( final String id : no_mappings ) {
+ ForesterUtil.programMessage( surfacing.PRG_NAME, id );
+ }
+ }
final int number_of_characters = all_binary_combinations_mapped.size();
final CharacterStateMatrix<CharacterStateMatrix.BinaryStates> matrix = new BasicCharacterStateMatrix<CharacterStateMatrix.BinaryStates>( number_of_identifiers,
number_of_characters );
}
return matrix;
}
-
-
-
-
+
+ private static BinaryDomainCombination mapBinaryDomainCombination( final Map<DomainId, String> domain_id_to_second_features_map,
+ final BinaryDomainCombination bc,
+ final SortedSet<String> no_mappings ) {
+ String id0 = "";
+ String id1 = "";
+ if ( !domain_id_to_second_features_map.containsKey( bc.getId0() ) ) {
+ no_mappings.add( bc.getId0().getId() );
+ id0 = bc.getId0().getId();
+ }
+ else {
+ id0 = domain_id_to_second_features_map.get( bc.getId0() );
+ }
+ if ( !domain_id_to_second_features_map.containsKey( bc.getId1() ) ) {
+ no_mappings.add( bc.getId1().getId() );
+ id1 = bc.getId1().getId();
+ }
+ else {
+ id1 = domain_id_to_second_features_map.get( bc.getId1() );
+ }
+ return new BasicBinaryDomainCombination( id0, id1 );
+ }
+
public static CharacterStateMatrix<BinaryStates> createMatrixOfBinaryDomainCombinationPresenceOrAbsence( final List<GenomeWideCombinableDomains> gwcd_list ) {
if ( gwcd_list.isEmpty() ) {
throw new IllegalArgumentException( "genome wide combinable domains list is empty" );
return matrix;
}
-
-
private static int getStateSumDeltaOnNode( final String node_identifier,
final CharacterStateMatrix<GainLossStates> gain_loss_matrix,
final GainLossStates state ) {