Changed map parser to ignore " in lines like "x y z" (at ComPhy 2012 Moscow)
[jalview.git] / forester / java / src / org / forester / tools / PhylogenyDecorator.java
index 24bbaf2..90959dc 100644 (file)
@@ -32,8 +32,9 @@ import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.forester.archaeopteryx.Util;
+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;
@@ -76,7 +77,7 @@ public final class PhylogenyDecorator {
                                  final Map<String, Map<String, String>> 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();
@@ -91,70 +92,70 @@ public final class PhylogenyDecorator {
                     }
                     if ( new_values != null ) {
                         if ( new_values.containsKey( TP_TAXONOMY_CODE ) ) {
-                            Util.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 ) ) {
-                            Util.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 ) ) {
-                            Util.ensurePresenceOfTaxonomy( node );
+                            AptxUtil.ensurePresenceOfTaxonomy( node );
                             node.getNodeData().getTaxonomy()
                                     .setIdentifier( new Identifier( new_values.get( TP_TAXONOMY_ID ) ) );
                         }
                         if ( new_values.containsKey( TP_TAXONOMY_SN ) ) {
-                            Util.ensurePresenceOfTaxonomy( node );
+                            AptxUtil.ensurePresenceOfTaxonomy( node );
                             node.getNodeData().getTaxonomy().setScientificName( new_values.get( TP_TAXONOMY_SN ) );
                         }
                         if ( new_values.containsKey( TP_TAXONOMY_CN ) ) {
-                            Util.ensurePresenceOfTaxonomy( node );
+                            AptxUtil.ensurePresenceOfTaxonomy( node );
                             node.getNodeData().getTaxonomy().setCommonName( new_values.get( TP_TAXONOMY_CN ) );
                         }
                         if ( new_values.containsKey( TP_TAXONOMY_SYN ) ) {
-                            Util.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 ) ) {
-                            Util.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 ) ) {
-                            Util.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 ) ) {
-                            Util.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 ) ) {
-                            Util.ensurePresenceOfSequence( node );
+                            AptxUtil.ensurePresenceOfSequence( node );
                             node.getNodeData().getSequence().setSymbol( new_values.get( TP_SEQ_SYMBOL ) );
                         }
                         if ( new_values.containsKey( TP_SEQ_NAME ) ) {
-                            Util.ensurePresenceOfSequence( node );
+                            AptxUtil.ensurePresenceOfSequence( node );
                             node.getNodeData().getSequence().setName( new_values.get( TP_SEQ_NAME ) );
                         }
                         if ( new_values.containsKey( TP_SEQ_MOL_SEQ ) ) {
-                            Util.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" );
                 }
@@ -175,6 +176,7 @@ public final class PhylogenyDecorator {
      * @param picky
      * @throws IllegalArgumentException
      * @throws NHXFormatException
+     * @throws PhyloXmlDataFormatException 
      */
     public static void decorate( final Phylogeny phylogeny,
                                  final Map<String, String> map,
@@ -186,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,
@@ -213,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<String, String> map,
@@ -224,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" );
         }
@@ -275,14 +279,14 @@ public final class PhylogenyDecorator {
                                 if ( PhylogenyDecorator.VERBOSE ) {
                                     System.out.println( name + ": " + new_value );
                                 }
-                                Util.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 );
                                 }
-                                Util.ensurePresenceOfTaxonomy( node );
+                                AptxUtil.ensurePresenceOfTaxonomy( node );
                                 node.getNodeData().getTaxonomy().setScientificName( new_value );
                                 break;
                             case SEQUENCE_NAME:
@@ -343,7 +347,7 @@ public final class PhylogenyDecorator {
                                  final Map<String, Map<String, String>> 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,
@@ -362,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,
@@ -388,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,
@@ -415,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 );
-        Util.ensurePresenceOfTaxonomy( node );
+        AptxUtil.ensurePresenceOfTaxonomy( node );
         node.getNodeData().getTaxonomy().setScientificName( scientific_name );
     }