2 package org.forester.sdi;
4 import org.forester.phylogeny.Phylogeny;
5 import org.forester.phylogeny.PhylogenyNode;
6 import org.forester.phylogeny.data.Identifier;
7 import org.forester.phylogeny.data.Taxonomy;
8 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
9 import org.forester.util.ForesterUtil;
11 public class SDIutil {
13 static String taxonomyToString( final PhylogenyNode n, final TaxonomyComparisonBase base ) {
16 final Identifier id = n.getNodeData().getTaxonomy().getIdentifier();
20 return id.getValuePlusProvider();
22 return n.getNodeData().getTaxonomy().getTaxonomyCode();
24 return n.getNodeData().getTaxonomy().getScientificName();
26 throw new IllegalArgumentException( "unknown comparison base for taxonomies: " + base );
30 public enum ALGORITHM {
31 GSDIR, GSDI, SDI, SDIR
34 public enum TaxonomyComparisonBase {
38 public String toString() {
45 public String toString() {
46 return "taxonomy code/mnemonic";
52 public String toString() {
53 return "scientific name";
58 public final static TaxonomyComparisonBase determineTaxonomyComparisonBase( final Phylogeny gene_tree ) {
59 int with_id_count = 0;
60 int with_code_count = 0;
61 int with_sn_count = 0;
63 for( final PhylogenyNodeIterator iter = gene_tree.iteratorExternalForward(); iter.hasNext(); ) {
64 final PhylogenyNode g = iter.next();
65 if ( g.getNodeData().isHasTaxonomy() ) {
66 final Taxonomy tax = g.getNodeData().getTaxonomy();
67 if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) ) {
68 if ( ++with_id_count > max ) {
72 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
73 if ( ++with_code_count > max ) {
74 max = with_code_count;
77 if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
78 if ( ++with_sn_count > max ) {
85 throw new IllegalArgumentException( "gene tree has no taxonomic data" );
87 else if ( max == 1 ) {
88 throw new IllegalArgumentException( "gene tree has only one node with taxonomic data" );
90 else if ( max == with_id_count ) {
91 return TaxonomyComparisonBase.ID;
93 else if ( max == with_sn_count ) {
94 return TaxonomyComparisonBase.SCIENTIFIC_NAME;
97 return TaxonomyComparisonBase.CODE;