X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fsdi%2FSDI.java;h=b1258f0820f58c05707179be26936e4045ac8de7;hb=4acc1443d8c6c6f47c26a7c57357bdcdad27ecf8;hp=6f163cca704ca5ffc85198efe3b5f57c8dc45ae4;hpb=eee996a6476a1e3d84c07f8f690dcde3ff4b2ef5;p=jalview.git diff --git a/forester/java/src/org/forester/sdi/SDI.java b/forester/java/src/org/forester/sdi/SDI.java index 6f163cc..b1258f0 100644 --- a/forester/java/src/org/forester/sdi/SDI.java +++ b/forester/java/src/org/forester/sdi/SDI.java @@ -32,6 +32,7 @@ import java.util.Map; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyNode; +import org.forester.phylogeny.data.Identifier; import org.forester.phylogeny.data.Taxonomy; import org.forester.phylogeny.iterators.PhylogenyNodeIterator; import org.forester.util.ForesterUtil; @@ -131,7 +132,6 @@ public abstract class SDI { boolean all_have_id = true; boolean all_have_code = true; boolean all_have_sn = true; - boolean all_have_cn = true; for( final PhylogenyNodeIterator iter = _species_tree.iteratorExternalForward(); iter.hasNext(); ) { final PhylogenyNode n = iter.next(); if ( n.getNodeData().isHasTaxonomy() ) { @@ -145,9 +145,6 @@ public abstract class SDI { if ( ForesterUtil.isEmpty( tax.getScientificName() ) ) { all_have_sn = false; } - if ( ForesterUtil.isEmpty( tax.getCommonName() ) ) { - all_have_cn = false; - } } else { throw new IllegalArgumentException( "species tree node [" + n + "] has no taxonomic data" ); @@ -166,9 +163,6 @@ public abstract class SDI { if ( ForesterUtil.isEmpty( tax.getScientificName() ) ) { all_have_sn = false; } - if ( ForesterUtil.isEmpty( tax.getCommonName() ) ) { - all_have_cn = false; - } } else { throw new IllegalArgumentException( "gene tree node [" + n + "] has no taxonomic data" ); @@ -183,9 +177,6 @@ public abstract class SDI { else if ( all_have_sn ) { base = TaxonomyComparisonBase.SCIENTIFIC_NAME; } - else if ( all_have_cn ) { - base = TaxonomyComparisonBase.COMMON_NAME; - } else { throw new IllegalArgumentException( "gene tree and species tree have incomparable taxonomies" ); } @@ -224,8 +215,9 @@ public abstract class SDI { * links (sets the field "link" of PhylogenyNode) each external * PhylogenyNode of gene_tree to the external PhylogenyNode of species_tree * which has the same species name. + * @throws SDIException */ - void linkNodesOfG() { + void linkNodesOfG() throws SDIException { final Map speciestree_ext_nodes = new HashMap(); final TaxonomyComparisonBase tax_comp_base = determineTaxonomyComparisonBase(); // Put references to all external nodes of the species tree into a map. @@ -296,23 +288,44 @@ public abstract class SDI { return sb.toString(); } - private static String taxonomyToString( final PhylogenyNode n, final TaxonomyComparisonBase base ) { - final Taxonomy tax = n.getNodeData().getTaxonomy(); + static String taxonomyToString( final PhylogenyNode n, final TaxonomyComparisonBase base ) { switch ( base ) { case ID: - return tax.getIdentifier().getValue(); + final Identifier id = n.getNodeData().getTaxonomy().getIdentifier(); + if ( id == null ) { + return null; + } + return id.getValuePlusProvider(); case CODE: - return tax.getTaxonomyCode(); + return n.getNodeData().getTaxonomy().getTaxonomyCode(); case SCIENTIFIC_NAME: - return tax.getScientificName(); - case COMMON_NAME: - return tax.getCommonName(); + return n.getNodeData().getTaxonomy().getScientificName(); default: throw new IllegalArgumentException( "unknown comparison base for taxonomies: " + base ); } } - enum TaxonomyComparisonBase { - ID, CODE, SCIENTIFIC_NAME, COMMON_NAME; + public enum TaxonomyComparisonBase { + ID { + + @Override + public String toString() { + return "taxonomy id"; + } + }, + CODE { + + @Override + public String toString() { + return "taxonomy code/mnemonic"; + } + }, + SCIENTIFIC_NAME { + + @Override + public String toString() { + return "scientific name"; + } + } } }