package org.forester.surfacing;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
return sb;
}
+
+
+ private StringBuffer getTaxonomyGroupDistribution( Phylogeny tol ) {
+ //TODO work on me
+
+ final SortedMap<String, SortedSet<String>> m = new TreeMap<String, SortedSet<String>>();
+ for( final Species species : getSpeciesData().keySet() ) {
+ for( final String combable_dom : getCombinableDomainIds( species ) ) {
+ if ( !m.containsKey( combable_dom ) ) {
+ m.put( combable_dom, new TreeSet<String>() );
+ }
+ m.get( combable_dom ).add( species.getSpeciesId() );
+ }
+ }
+ Map<String,Integer> countz = new HashMap<String,Integer>();
+ for( final Map.Entry<String, SortedSet<String>> e : m.entrySet() ) {
+ for( final String tax_code : e.getValue() ) {
+ final String group = SurfacingUtil.obtainTaxonomyGroup( tax_code, tol );
+ if ( !ForesterUtil.isEmpty( group ) ) {
+ if ( !countz.containsKey( group ) ) {
+ countz.put( group, 1 );
+ }
+ else {
+ countz.put( group, countz.get( group) + 1 );
+ }
+
+ }
+ else {
+ return null;
+ }
+
+ }
+
+ }
+ final StringBuffer sb = new StringBuffer();
+
+ // i am just a template and need to be modified for "printout" TODO
+ for( final Map.Entry<String, SortedSet<String>> e : m.entrySet() ) {
+ sb.append( "<a href=\"" + SurfacingConstants.PFAM_FAMILY_ID_LINK + e.getKey() + "\">" + e.getKey() + "</a>" );
+ sb.append( ": " );
+ sb.append( "<span style=\"font-size:8px\">" );
+ for( final String tax : e.getValue() ) {
+ final String hex = SurfacingUtil.obtainHexColorStringDependingOnTaxonomyGroup( tax, null );
+ if ( !ForesterUtil.isEmpty( hex ) ) {
+ sb.append( "<span style=\"color:" );
+ sb.append( hex );
+ sb.append( "\">" );
+ sb.append( tax );
+ sb.append( "</span>" );
+ }
+ else {
+ sb.append( tax );
+ }
+ sb.append( " " );
+ }
+ sb.append( "</span>" );
+ sb.append( "<br>\n" );
+ }
+ return sb;
+ }
+
+
private StringBuffer getSpeciesDataInAlphabeticalOrder( final boolean html,
final Map<String, Integer> tax_code_to_id_map,
final Phylogeny phy ) {
public final static Pattern PATTERN_SP_STYLE_TAXONOMY = Pattern.compile( "^[A-Z0-9]{3,5}$" );
private final static Map<String, String> _TAXCODE_HEXCOLORSTRING_MAP = new HashMap<String, String>();
+
+
+ private final static Map<String, String> _TAXCODE_TAXGROUP_MAP = new HashMap<String, String>();
+
+
private static final Comparator<Domain> ASCENDING_CONFIDENCE_VALUE_ORDER = new Comparator<Domain>() {
@Override
}
return _TAXCODE_HEXCOLORSTRING_MAP.get( tax_code );
}
+
+
+ public static String obtainTaxonomyGroup( final String tax_code, final Phylogeny phy )
+ throws IllegalArgumentException {
+ if ( !_TAXCODE_TAXGROUP_MAP.containsKey( tax_code ) ) {
+ if ( ( phy != null ) && !phy.isEmpty() ) {
+ final List<PhylogenyNode> nodes = phy.getNodesViaTaxonomyCode( tax_code );
+
+ if ( ( nodes == null ) || nodes.isEmpty() ) {
+ throw new IllegalArgumentException( "code " + tax_code + " is not found" );
+ }
+ if ( nodes.size() != 1 ) {
+ throw new IllegalArgumentException( "code " + tax_code + " is not unique" );
+ }
+ PhylogenyNode n = nodes.get( 0 );
+ String group = null;
+ Color c = null;
+ while ( n != null ) {
+ if ( n.getNodeData().isHasTaxonomy()
+ && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
+ c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( n.getNodeData().getTaxonomy()
+ .getScientificName(), tax_code );
+
+ group = n.getNodeData().getTaxonomy()
+ .getScientificName();
+ }
+ if ( ( c == null ) && !ForesterUtil.isEmpty( n.getName() ) ) {
+ c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( n.getName(), tax_code );
+ group = n.getName();
+ }
+ if ( c != null ) {
+ break;
+ }
+ group = null;
+ n = n.getParent();
+ }
+ if ( c == null ) {
+ throw new IllegalArgumentException( "no group found for taxonomy code \"" + tax_code + "\"" );
+ }
+
+ _TAXCODE_TAXGROUP_MAP.put( tax_code, group );
+ }
+ else {
+ throw new IllegalArgumentException( "unable to obtain group for code " + tax_code
+ + " (tree is null or empty and code is not in map)" );
+ }
+ }
+ return _TAXCODE_TAXGROUP_MAP.get( tax_code );
+ }
+
+
+
public static void performDomainArchitectureAnalysis( final SortedMap<String, Set<String>> domain_architecutures,
final SortedMap<String, Integer> domain_architecuture_counts,
@SuppressWarnings( "unused")
public final class Test {
- private final static boolean PERFORM_DB_TESTS = false;
+ private final static boolean PERFORM_DB_TESTS = true;
private final static double ZERO_DIFF = 1.0E-9;
private final static String PATH_TO_TEST_DATA = System.getProperty( "user.dir" )
+ ForesterUtil.getFileSeparator() + "test_data"
failed++;
}
}
- ///////////////////////////////////////// System.exit( 0 );
+ System.exit( 0 );
System.out.print( "UniProtKB id extraction: " );
if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
System.out.println( "OK." );
System.out.println( entry4.getGeneName() );
return false;
}
- // if ( !entry4.getChromosome().equals( "ras" ) ) {
- // System.out.println( entry4.getChromosome() );
- // return false;
- // }
- // if ( !entry4.getMap().equals( "ras" ) ) {
- // System.out.println( entry4.getMap() );
- // return false;
- // }
+ if ( !entry4.getChromosome().equals( "ras" ) ) {
+ System.out.println( entry4.getChromosome() );
+ return false;
+ }
+ if ( !entry4.getMap().equals( "ras" ) ) {
+ System.out.println( entry4.getMap() );
+ return false;
+ }
//
//TODO fails:
// final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "M30539" );
seq.addCrossReference( x );
}
}
+ if ( !ForesterUtil.isEmpty( db_entry.getChromosome() ) && !ForesterUtil.isEmpty( db_entry.getMap() ) ) {
+ seq.setLocation( "chr " + db_entry.getChromosome() + ", " + db_entry.getMap() );
+ }
+ else if ( !ForesterUtil.isEmpty( db_entry.getChromosome() ) ) {
+ seq.setLocation( "chr " + db_entry.getChromosome() );
+ }
+ else if ( !ForesterUtil.isEmpty( db_entry.getMap() ) ) {
+ seq.setLocation( db_entry.getMap() );
+ }
final Taxonomy tax = node.getNodeData().isHasTaxonomy() ? node.getNodeData().getTaxonomy() : new Taxonomy();
if ( !ForesterUtil.isEmpty( db_entry.getTaxonomyScientificName() ) ) {
tax.setScientificName( db_entry.getTaxonomyScientificName() );