X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Ftools%2FPhylogenyDecorator.java;h=90959dc836e4a419fccdf7b022c2024761c3fb2e;hb=87b28d6eed75bbb88b52b526126cc3e71921139d;hp=ebc1a6ac959fa1b1c0abc8d1fd8d16e08c6ae5aa;hpb=eee996a6476a1e3d84c07f8f690dcde3ff4b2ef5;p=jalview.git diff --git a/forester/java/src/org/forester/tools/PhylogenyDecorator.java b/forester/java/src/org/forester/tools/PhylogenyDecorator.java index ebc1a6a..90959dc 100644 --- a/forester/java/src/org/forester/tools/PhylogenyDecorator.java +++ b/forester/java/src/org/forester/tools/PhylogenyDecorator.java @@ -32,7 +32,9 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.forester.archaeopteryx.AptxUtil; import org.forester.io.parsers.nhx.NHXFormatException; +import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyNode; import org.forester.phylogeny.data.Accession; @@ -75,7 +77,7 @@ public final class PhylogenyDecorator { final Map> map, final boolean picky, final int numbers_of_chars_allowed_to_remove_if_not_found_in_map ) - throws IllegalArgumentException { + throws IllegalArgumentException, PhyloXmlDataFormatException { for( final PhylogenyNodeIterator iter = phylogeny.iteratorPostorder(); iter.hasNext(); ) { final PhylogenyNode node = iter.next(); final String name = node.getName(); @@ -90,70 +92,70 @@ public final class PhylogenyDecorator { } if ( new_values != null ) { if ( new_values.containsKey( TP_TAXONOMY_CODE ) ) { - ForesterUtil.ensurePresenceOfTaxonomy( node ); + AptxUtil.ensurePresenceOfTaxonomy( node ); node.getNodeData().getTaxonomy().setTaxonomyCode( new_values.get( TP_TAXONOMY_CODE ) ); } if ( new_values.containsKey( TP_TAXONOMY_ID ) && new_values.containsKey( TP_TAXONOMY_ID_PROVIDER ) ) { - ForesterUtil.ensurePresenceOfTaxonomy( node ); + AptxUtil.ensurePresenceOfTaxonomy( node ); node.getNodeData() .getTaxonomy() .setIdentifier( new Identifier( new_values.get( TP_TAXONOMY_ID ), new_values.get( TP_TAXONOMY_ID_PROVIDER ) ) ); } else if ( new_values.containsKey( TP_TAXONOMY_ID ) ) { - ForesterUtil.ensurePresenceOfTaxonomy( node ); + AptxUtil.ensurePresenceOfTaxonomy( node ); node.getNodeData().getTaxonomy() .setIdentifier( new Identifier( new_values.get( TP_TAXONOMY_ID ) ) ); } if ( new_values.containsKey( TP_TAXONOMY_SN ) ) { - ForesterUtil.ensurePresenceOfTaxonomy( node ); + AptxUtil.ensurePresenceOfTaxonomy( node ); node.getNodeData().getTaxonomy().setScientificName( new_values.get( TP_TAXONOMY_SN ) ); } if ( new_values.containsKey( TP_TAXONOMY_CN ) ) { - ForesterUtil.ensurePresenceOfTaxonomy( node ); + AptxUtil.ensurePresenceOfTaxonomy( node ); node.getNodeData().getTaxonomy().setCommonName( new_values.get( TP_TAXONOMY_CN ) ); } if ( new_values.containsKey( TP_TAXONOMY_SYN ) ) { - ForesterUtil.ensurePresenceOfTaxonomy( node ); + AptxUtil.ensurePresenceOfTaxonomy( node ); node.getNodeData().getTaxonomy().getSynonyms().add( new_values.get( TP_TAXONOMY_SYN ) ); } if ( new_values.containsKey( TP_SEQ_ACCESSION ) && new_values.containsKey( TP_SEQ_ACCESSION_SOURCE ) ) { - ForesterUtil.ensurePresenceOfSequence( node ); + AptxUtil.ensurePresenceOfSequence( node ); node.getNodeData() .getSequence() .setAccession( new Accession( new_values.get( TP_SEQ_ACCESSION ), new_values.get( TP_SEQ_ACCESSION_SOURCE ) ) ); } if ( new_values.containsKey( TP_SEQ_ANNOTATION_DESC ) ) { - ForesterUtil.ensurePresenceOfSequence( node ); + AptxUtil.ensurePresenceOfSequence( node ); final Annotation ann = new Annotation( "?" ); ann.setDesc( new_values.get( TP_SEQ_ANNOTATION_DESC ) ); node.getNodeData().getSequence().addAnnotation( ann ); } if ( new_values.containsKey( TP_SEQ_ANNOTATION_REF ) ) { - ForesterUtil.ensurePresenceOfSequence( node ); + AptxUtil.ensurePresenceOfSequence( node ); final Annotation ann = new Annotation( new_values.get( TP_SEQ_ANNOTATION_REF ) ); node.getNodeData().getSequence().addAnnotation( ann ); } if ( new_values.containsKey( TP_SEQ_SYMBOL ) ) { - ForesterUtil.ensurePresenceOfSequence( node ); + AptxUtil.ensurePresenceOfSequence( node ); node.getNodeData().getSequence().setSymbol( new_values.get( TP_SEQ_SYMBOL ) ); } if ( new_values.containsKey( TP_SEQ_NAME ) ) { - ForesterUtil.ensurePresenceOfSequence( node ); + AptxUtil.ensurePresenceOfSequence( node ); node.getNodeData().getSequence().setName( new_values.get( TP_SEQ_NAME ) ); } if ( new_values.containsKey( TP_SEQ_MOL_SEQ ) ) { - ForesterUtil.ensurePresenceOfSequence( node ); + AptxUtil.ensurePresenceOfSequence( node ); node.getNodeData().getSequence().setMolecularSequence( new_values.get( TP_SEQ_MOL_SEQ ) ); } if ( new_values.containsKey( TP_NODE_NAME ) ) { node.setName( new_values.get( TP_NODE_NAME ) ); } - } - } + } // if ( new_values != null ) + } // if ( map.containsKey( name ) || ( numbers_of_chars_allowed_to_remove_if_not_found_in_map > 0 ) ) else if ( picky ) { throw new IllegalArgumentException( "\"" + name + "\" not found in name map" ); } @@ -174,6 +176,7 @@ public final class PhylogenyDecorator { * @param picky * @throws IllegalArgumentException * @throws NHXFormatException + * @throws PhyloXmlDataFormatException */ public static void decorate( final Phylogeny phylogeny, final Map map, @@ -185,7 +188,7 @@ public final class PhylogenyDecorator { final boolean process_similar_to, final int numbers_of_chars_allowed_to_remove_if_not_found_in_map, final boolean move_domain_numbers_at_end_to_middle ) throws IllegalArgumentException, - NHXFormatException { + NHXFormatException, PhyloXmlDataFormatException { PhylogenyDecorator.decorate( phylogeny, map, field, @@ -212,6 +215,7 @@ public final class PhylogenyDecorator { * @param intermediate_map * maps name (in phylogeny) to a intermediate value * @throws IllegalArgumentException + * @throws PhyloXmlDataFormatException */ public static void decorate( final Phylogeny phylogeny, final Map map, @@ -223,7 +227,8 @@ public final class PhylogenyDecorator { final boolean process_name_intelligently, final boolean process_similar_to, final int numbers_of_chars_allowed_to_remove_if_not_found_in_map, - final boolean move_domain_numbers_at_end_to_middle ) throws IllegalArgumentException { + final boolean move_domain_numbers_at_end_to_middle ) throws IllegalArgumentException, + PhyloXmlDataFormatException { if ( extract_bracketed_scientific_name && ( field == FIELD.TAXONOMY_SCIENTIFIC_NAME ) ) { throw new IllegalArgumentException( "Attempt to extract bracketed scientific name together with data field pointing to scientific name" ); } @@ -274,14 +279,14 @@ public final class PhylogenyDecorator { if ( PhylogenyDecorator.VERBOSE ) { System.out.println( name + ": " + new_value ); } - ForesterUtil.ensurePresenceOfTaxonomy( node ); + AptxUtil.ensurePresenceOfTaxonomy( node ); node.getNodeData().getTaxonomy().setTaxonomyCode( new_value ); break; case TAXONOMY_SCIENTIFIC_NAME: if ( PhylogenyDecorator.VERBOSE ) { System.out.println( name + ": " + new_value ); } - ForesterUtil.ensurePresenceOfTaxonomy( node ); + AptxUtil.ensurePresenceOfTaxonomy( node ); node.getNodeData().getTaxonomy().setScientificName( new_value ); break; case SEQUENCE_NAME: @@ -342,7 +347,7 @@ public final class PhylogenyDecorator { final Map> map, final boolean picky, final int numbers_of_chars_allowed_to_remove_if_not_found_in_map ) - throws IllegalArgumentException, NHXFormatException { + throws IllegalArgumentException, NHXFormatException, PhyloXmlDataFormatException { for( int i = 0; i < phylogenies.length; ++i ) { PhylogenyDecorator.decorate( phylogenies[ i ], map, @@ -361,7 +366,7 @@ public final class PhylogenyDecorator { final boolean process_similar_to, final int numbers_of_chars_allowed_to_remove_if_not_found_in_map, final boolean move_domain_numbers_at_end_to_middle ) throws IllegalArgumentException, - NHXFormatException { + NHXFormatException, PhyloXmlDataFormatException { for( int i = 0; i < phylogenies.length; ++i ) { PhylogenyDecorator.decorate( phylogenies[ i ], map, @@ -387,7 +392,7 @@ public final class PhylogenyDecorator { final boolean process_similar_to, final int numbers_of_chars_allowed_to_remove_if_not_found_in_map, final boolean move_domain_numbers_at_end_to_middle ) throws IllegalArgumentException, - NHXFormatException { + NHXFormatException, PhyloXmlDataFormatException { for( int i = 0; i < phylogenies.length; ++i ) { PhylogenyDecorator.decorate( phylogenies[ i ], map, @@ -414,7 +419,7 @@ public final class PhylogenyDecorator { private static void extractBracketedScientificNames( final PhylogenyNode node, final String new_value ) { final int i = new_value.lastIndexOf( "[" ); final String scientific_name = new_value.substring( i + 1, new_value.length() - 1 ); - ForesterUtil.ensurePresenceOfTaxonomy( node ); + AptxUtil.ensurePresenceOfTaxonomy( node ); node.getNodeData().getTaxonomy().setScientificName( scientific_name ); }