inprogress
authorcmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Fri, 22 Mar 2013 03:52:08 +0000 (03:52 +0000)
committercmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Fri, 22 Mar 2013 03:52:08 +0000 (03:52 +0000)
forester/java/src/org/forester/application/decorator.java
forester/java/src/org/forester/application/pccx.java
forester/java/src/org/forester/application/surfacing.java
forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java
forester/java/src/org/forester/io/parsers/SymmetricalDistanceMatrixParser.java
forester/java/src/org/forester/surfacing/SurfacingUtil.java
forester/java/src/org/forester/test/Test.java
forester/java/src/org/forester/tools/PhylogenyDecorator.java
forester/java/src/org/forester/util/BasicTableParser.java
forester/java/src/org/forester/util/CommandLineArguments.java

index d0197aa..acf8c50 100644 (file)
@@ -69,7 +69,7 @@ public final class decorator {
     final static private String KEY_COLUMN                              = "k";
     final static private String VALUE_COLUMN                            = "v";
     final static private String MAPPING_FILE_SEPARATOR_OPTION           = "s";
-    final static private String MAPPING_FILE_SEPARATOR_DEFAULT          = ": ";
+    final static private char   MAPPING_FILE_SEPARATOR_DEFAULT          = '\t';
     final static private String PRG_NAME                                = "decorator";
     final static private String PRG_VERSION                             = "1.13";
     final static private String PRG_DATE                                = "2013.01.19";
@@ -126,12 +126,12 @@ public final class decorator {
             }
         }
         final boolean picky = cla.isOptionSet( decorator.PICKY_OPTION );
-        String separator = decorator.MAPPING_FILE_SEPARATOR_DEFAULT;
+        char separator = decorator.MAPPING_FILE_SEPARATOR_DEFAULT;
         if ( cla.isOptionSet( decorator.MAPPING_FILE_SEPARATOR_OPTION ) ) {
             if ( advanced_table ) {
                 argumentsError();
             }
-            separator = cla.getOptionValue( decorator.MAPPING_FILE_SEPARATOR_OPTION );
+            separator = cla.getOptionValueAsChar( decorator.MAPPING_FILE_SEPARATOR_OPTION );
         }
         int key_column = 0;
         int value_column = 1;
@@ -277,7 +277,7 @@ public final class decorator {
         if ( !advanced_table ) {
             BasicTable<String> mapping_table = null;
             try {
-                mapping_table = BasicTableParser.parse( mapping_infile, separator, false, true );
+                mapping_table = BasicTableParser.parse( mapping_infile, separator, true, false );
             }
             catch ( final Exception e ) {
                 ForesterUtil.fatalError( decorator.PRG_NAME,
index 48ca75a..369d514 100644 (file)
@@ -176,7 +176,7 @@ public class pccx {
                 if ( !ForesterUtil.isEmpty( error ) ) {
                     ForesterUtil.fatalError( pccx.PRG_NAME, error );
                 }
-                intable = BasicTableParser.parse( infile, " ", false, false );
+                intable = BasicTableParser.parse( infile, ' ', false, false );
             }
             catch ( final IOException e ) {
                 ForesterUtil.fatalError( pccx.PRG_NAME, "failed to read \"" + infile + "\" [" + e.getMessage() + "]" );
index 5bc8173..155f958 100644 (file)
@@ -697,7 +697,7 @@ public class surfacing {
                         + error );
             }
             try {
-                final BasicTable<String> scores_table = BasicTableParser.parse( cutoff_scores_file, " " );
+                final BasicTable<String> scores_table = BasicTableParser.parse( cutoff_scores_file, ' ' );
                 individual_score_cutoffs = scores_table.getColumnsAsMapDouble( 0, 1 );
             }
             catch ( final IOException e ) {
index f414cd7..ebb8fd1 100644 (file)
@@ -1308,12 +1308,12 @@ public final class MainFrameApplication extends MainFrame {
         if ( ( file != null ) && ( file.length() > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
             BasicTable<String> t = null;
             try {
-                t = BasicTableParser.parse( file, "\t" );
+                t = BasicTableParser.parse( file, '\t' );
                 if ( t.getNumberOfColumns() < 2 ) {
-                    t = BasicTableParser.parse( file, "," );
+                    t = BasicTableParser.parse( file, ',' );
                 }
                 if ( t.getNumberOfColumns() < 2 ) {
-                    t = BasicTableParser.parse( file, " " );
+                    t = BasicTableParser.parse( file, ' ' );
                 }
             }
             catch ( final IOException e ) {
index 78b9fcd..0bdafe1 100644 (file)
@@ -55,7 +55,7 @@ public class SymmetricalDistanceMatrixParser {
 
     private final static InputMatrixType INPUT_MATRIX_TYPE_DEFAULT = InputMatrixType.LOWER_TRIANGLE;
     private final static String          COMMENT                   = "#";
-    private final static String          VALUE_SEPARATOR           = " ";
+    private final static char            VALUE_SEPARATOR           = ' ';
     private int                          _matrix_size;
     private InputMatrixType              _input_matrix_type;
 
index 06c8ca0..5067bc2 100644 (file)
@@ -627,7 +627,7 @@ public final class SurfacingUtil {
 
     public static Map<DomainId, Set<String>> createDomainIdToSecondaryFeaturesMap( final File secondary_features_map_file )
             throws IOException {
-        final BasicTable<String> primary_table = BasicTableParser.parse( secondary_features_map_file, "\t" );
+        final BasicTable<String> primary_table = BasicTableParser.parse( secondary_features_map_file, '\t' );
         final Map<DomainId, Set<String>> map = new TreeMap<DomainId, Set<String>>();
         for( int r = 0; r < primary_table.getNumberOfRows(); ++r ) {
             final DomainId domain_id = new DomainId( primary_table.getValue( 0, r ) );
index 93a623e..4ba7758 100644 (file)
@@ -1897,7 +1897,7 @@ public final class Test {
             source.append( "40 41 42 43" + l );
             source.append( "  # 1 1 1 1 1 " + l );
             source.append( "50 51 52 53 54" + l );
-            final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), " " );
+            final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
             if ( t1.getNumberOfColumns() != 5 ) {
                 return false;
             }
@@ -1926,7 +1926,7 @@ public final class Test {
             source1.append( "40;41;42;43" + l );
             source1.append( "  # 1 1 1 1 1 " + l );
             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
-            final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ";" );
+            final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
             if ( t2.getNumberOfColumns() != 5 ) {
                 return false;
             }
@@ -1963,7 +1963,7 @@ public final class Test {
             source2.append( "  comment: 1 1 1 1 1 " + l );
             source2.append( ";;;50  ;   52; 53;;54   " + l );
             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
-                                                                        ";",
+                                                                        ';',
                                                                         false,
                                                                         false,
                                                                         "comment:",
index f1d6e24..9d865e1 100644 (file)
@@ -217,6 +217,9 @@ public final class PhylogenyDecorator {
         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" );
         }
+        if ( map.isEmpty() ) {
+            throw new IllegalArgumentException( "map is empty" );
+        }
         for( final PhylogenyNodeIterator iter = phylogeny.iteratorPostorder(); iter.hasNext(); ) {
             final PhylogenyNode node = iter.next();
             String name = node.getName();
@@ -244,9 +247,14 @@ public final class PhylogenyDecorator {
                         if ( extract_bracketed_scientific_name && new_value.endsWith( "]" ) ) {
                             new_value = extractBracketedScientificNames( node, new_value );
                         }
-                        else if ( extract_bracketed_tax_code
-                                && ParserUtils.TAXOMONY_CODE_PATTERN_4.matcher( new_value ).matches() ) {
-                            new_value = extractBracketedTaxCodes( node, new_value );
+                        else if ( extract_bracketed_tax_code ) {
+                            if ( ParserUtils.TAXOMONY_CODE_PATTERN_4.matcher( new_value ).find() ) {
+                                new_value = extractBracketedTaxCodes( node, new_value );
+                            }
+                            else if ( picky ) {
+                                throw new IllegalArgumentException( " could not get taxonomy from \"" + new_value
+                                        + "\"" );
+                            }
                         }
                         switch ( field ) {
                             case SEQUENCE_ANNOTATION_DESC:
@@ -419,7 +427,7 @@ public final class PhylogenyDecorator {
             throws IOException {
         final Map<String, Map<String, String>> map = new HashMap<String, Map<String, String>>();
         BasicTable<String> mapping_table = null;
-        mapping_table = BasicTableParser.parse( mapping_table_file, "\t", false, false );
+        mapping_table = BasicTableParser.parse( mapping_table_file, '\t', false, false );
         for( int row = 0; row < mapping_table.getNumberOfRows(); ++row ) {
             final Map<String, String> row_map = new HashMap<String, String>();
             String name = null;
@@ -457,8 +465,8 @@ public final class PhylogenyDecorator {
 
     private static String extractBracketedTaxCodes( final PhylogenyNode node, final String new_value ) {
         final Matcher m = ParserUtils.TAXOMONY_CODE_PATTERN_4.matcher( new_value );
-        String tc = null;
-        if ( m.matches() ) {
+        String tc = "?";
+        if ( m.find() ) {
             tc = m.group( 1 );
         }
         ForesterUtil.ensurePresenceOfTaxonomy( node );
index aaa5781..4e5f4b3 100644 (file)
@@ -38,13 +38,13 @@ public class BasicTableParser {
     private BasicTableParser() {
     }
 
-    public static BasicTable<String> parse( final Object source, final String column_delimiter ) throws IOException {
+    public static BasicTable<String> parse( final Object source, final char column_delimiter ) throws IOException {
         return BasicTableParser.parse( source, column_delimiter, false, false, START_OF_COMMENT_LINE_DEFAULT, false )
                 .get( 0 );
     }
 
     public static BasicTable<String> parse( final Object source,
-                                            final String column_delimiter,
+                                            final char column_delimiter,
                                             final boolean use_first_separator_only,
                                             final boolean use_last_separator_only ) throws IOException {
         return BasicTableParser.parse( source,
@@ -56,7 +56,7 @@ public class BasicTableParser {
     }
 
     public static List<BasicTable<String>> parse( final Object source,
-                                                  final String column_delimiter,
+                                                  final char column_delimiter,
                                                   final boolean use_first_separator_only,
                                                   final boolean use_last_separator_only,
                                                   final String start_of_comment_line,
@@ -93,7 +93,7 @@ public class BasicTableParser {
                     && ( !use_start_of_comment_line || !line.startsWith( start_of_comment_line ) ) ) {
                 saw_first_table = true;
                 if ( use_last_separator_only ) {
-                    final String e[] = line.split( column_delimiter );
+                    final String e[] = line.split( column_delimiter + "" );
                     final StringBuffer rest = new StringBuffer();
                     for( int i = 0; i < ( e.length - 1 ); ++i ) {
                         rest.append( e[ i ].trim() );
@@ -102,7 +102,7 @@ public class BasicTableParser {
                     table.setValue( 1, row, e[ e.length - 1 ] );
                 }
                 else {
-                    final StringTokenizer st = new StringTokenizer( line, column_delimiter );
+                    final StringTokenizer st = new StringTokenizer( line, column_delimiter + "" );
                     int col = 0;
                     if ( st.hasMoreTokens() ) {
                         table.setValue( col++, row, st.nextToken().trim() );
index 7e2a167..31a50c9 100644 (file)
@@ -112,6 +112,10 @@ public final class CommandLineArguments {
         return getOptionValue( option_name ).replaceAll( "\"", "" ).replaceAll( "\'", "" );
     }
 
+    public char getOptionValueAsChar( final String option_name ) throws IllegalArgumentException {
+        return getOptionValue( option_name ).charAt( 0 );
+    }
+
     public double getOptionValueAsDouble( final String option_name ) throws IOException {
         double d = -Double.MAX_VALUE;
         try {