X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fapplication%2Fdecorator.java;h=d0197aae03f837b94e0ffce2c4eed6ef5f9bb4df;hb=a29d5642b2f9a3db526f35ca5971c08700963503;hp=be44f67ae430aa431c90dd985d7a50d0561a317e;hpb=0cbfc79c69ccbfca7ac42a1381d62d449bf1adf6;p=jalview.git diff --git a/forester/java/src/org/forester/application/decorator.java b/forester/java/src/org/forester/application/decorator.java index be44f67..d0197aa 100644 --- a/forester/java/src/org/forester/application/decorator.java +++ b/forester/java/src/org/forester/application/decorator.java @@ -21,7 +21,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA // // Contact: phylosoft @ gmail . com -// WWW: www.phylosoft.org/forester +// WWW: https://sites.google.com/site/cmzmasek/home/software/forester package org.forester.application; @@ -47,74 +47,32 @@ import org.forester.util.ForesterUtil; public final class decorator { - private static final String SEQUENCE_NAME_FIELD = "s"; - private static final String TAXONOMY_CODE_FIELD = "c"; - private static final String TAXONOMY_SCIENTIFIC_NAME_FIELD = "sn"; - private static final String DS_FILED = "d"; - private static final String SEQUENCE_ANNOTATION_DESC = "a"; - private static final String NODE_NAME_FIELD = "n"; - final static private String PICKY_OPTION = "p"; - final static private String FIELD_OPTION = "f"; - final static private String MOVE_DOMAIN_NUMBER_OPTION = "mdn"; // Hidden expert option. - final static private String TREE_NAME_OPTION = "pn"; - final static private String TREE_ID_OPTION = "pi"; - final static private String TREE_DESC_OPTION = "pd"; - final static private String EXTRACT_BRACKETED_SCIENTIC_NAME_OPTION = "sn"; - final static private String PROCESS_NAME_INTELLIGENTLY_OPTION = "x"; - final static private String PROCESS_SIMILAR_TO_OPTION = "xs"; - final static private String CUT_NAME_AFTER_FIRST_SPACE_OPTION = "c"; - final static private String ALLOW_REMOVAL_OF_CHARS_OPTION = "r"; - final static private String ADVANCED_TABLE_OPTION = "table"; - 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 boolean USE_FIRST_SEPARATOR_ONLY = true; - final static private String PRG_NAME = "decorator"; - final static private String PRG_VERSION = "1.11"; - final static private String PRG_DATE = "2012.08.08"; - - private static void argumentsError() { - System.out.println(); - System.out.println( decorator.PRG_NAME + " -" + ADVANCED_TABLE_OPTION + " | -f= " - + "[mapping table file] " ); - System.out.println(); - System.out.println( "options:" ); - System.out.println(); - System.out.println( " -" + ADVANCED_TABLE_OPTION + " : table instead of one to one map (-f=)" ); - System.out.println( " -r= : allow to remove up to n characters from the end of the names" ); - System.out.println( " in phylogenies infile if not found (in map) otherwise" ); - System.out.println( " -p : for picky, fails if node name not found in mapping table, default is off" ); - System.out.println( " -" + TREE_NAME_OPTION + "=: name for the phylogeny" ); - System.out.println( " -" + TREE_ID_OPTION + "=: identifier for the phylogeny (in the form provider:value)" ); - System.out.println( " -" + TREE_DESC_OPTION + "=: description for phylogenies" ); - System.out.println(); - System.out.println(); - System.out.println( "advanced options, only available if -" + ADVANCED_TABLE_OPTION + " is not used:" ); - System.out.println(); - System.out.println( " -f= : field to be replaced: " + NODE_NAME_FIELD + " : node name" ); - System.out.println( " " + SEQUENCE_ANNOTATION_DESC - + " : sequence annotation description" ); - System.out.println( " " + DS_FILED + " : domain structure" ); - System.out.println( " " + TAXONOMY_CODE_FIELD + " : taxonomy code" ); - System.out.println( " " + TAXONOMY_SCIENTIFIC_NAME_FIELD - + ": taxonomy scientific name" ); - System.out.println( " " + SEQUENCE_NAME_FIELD + " : sequence name" ); - System.out.println( " -k= : key column in mapping table (0 based)," ); - System.out.println( " names of the node to be decorated - default is 0" ); - System.out.println( " -v= : value column in mapping table (0 based)," ); - System.out.println( " data which with to decorate - default is 1" ); - System.out.println( " -" + EXTRACT_BRACKETED_SCIENTIC_NAME_OPTION - + " : to extract bracketed scientific names" ); - System.out.println( " -s= : column separator in mapping file, default is \"" - + decorator.MAPPING_FILE_SEPARATOR_DEFAULT + "\"" ); - System.out.println( " -x : process name \"intelligently\" (only for -f=n)" ); - System.out.println( " -" + decorator.PROCESS_SIMILAR_TO_OPTION - + " : process name \"intelligently\" and process information after \"similar to\" (only for -f=n)" ); - System.out.println( " -c : cut name after first space (only for -f=n)" ); - System.out.println(); - System.exit( -1 ); - } + private static final String SEQUENCE_NAME_FIELD = "s"; + private static final String TAXONOMY_CODE_FIELD = "c"; + private static final String TAXONOMY_SCIENTIFIC_NAME_FIELD = "sn"; + private static final String DS_FILED = "d"; + private static final String SEQUENCE_ANNOTATION_DESC = "a"; + private static final String NODE_NAME_FIELD = "n"; + final static private String PICKY_OPTION = "p"; + final static private String FIELD_OPTION = "f"; + final static private String TRIM_AFTER_TILDE_OPTION = "t"; + final static private String TREE_NAME_OPTION = "pn"; + final static private String TREE_ID_OPTION = "pi"; + final static private String TREE_DESC_OPTION = "pd"; + final static private String EXTRACT_BRACKETED_SCIENTIC_NAME_OPTION = "sn"; + final static private String EXTRACT_BRACKETED_TAXONOMIC_CODE_OPTION = "tc"; + final static private String PROCESS_NAME_INTELLIGENTLY_OPTION = "x"; + final static private String PROCESS_SIMILAR_TO_OPTION = "xs"; + final static private String CUT_NAME_AFTER_FIRST_SPACE_OPTION = "c"; + final static private String ALLOW_REMOVAL_OF_CHARS_OPTION = "r"; + final static private String ADVANCED_TABLE_OPTION = "table"; + 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 String PRG_NAME = "decorator"; + final static private String PRG_VERSION = "1.13"; + final static private String PRG_DATE = "2013.01.19"; public static void main( final String args[] ) { ForesterUtil.printProgramInformation( decorator.PRG_NAME, decorator.PRG_VERSION, decorator.PRG_DATE ); @@ -149,10 +107,11 @@ public final class decorator { allowed_options.add( decorator.VALUE_COLUMN ); allowed_options.add( decorator.MAPPING_FILE_SEPARATOR_OPTION ); allowed_options.add( decorator.EXTRACT_BRACKETED_SCIENTIC_NAME_OPTION ); + allowed_options.add( decorator.EXTRACT_BRACKETED_TAXONOMIC_CODE_OPTION ); allowed_options.add( decorator.TREE_NAME_OPTION ); allowed_options.add( decorator.TREE_ID_OPTION ); allowed_options.add( decorator.TREE_DESC_OPTION ); - allowed_options.add( decorator.MOVE_DOMAIN_NUMBER_OPTION ); + allowed_options.add( decorator.TRIM_AFTER_TILDE_OPTION ); final String dissallowed_options = cla.validateAllowedOptionsAsString( allowed_options ); if ( dissallowed_options.length() > 0 ) { ForesterUtil.fatalError( decorator.PRG_NAME, "unknown option(s): " + dissallowed_options ); @@ -183,7 +142,8 @@ public final class decorator { boolean process_name_intelligently = false; boolean process_similar_to = false; boolean extract_bracketed_scientific_name = false; - boolean move_domain_numbers_at_end_to_middle = false; + boolean extract_bracketed_tax_code = false; + boolean trim_after_tilde = false; String tree_name = ""; String tree_id = ""; String tree_desc = ""; @@ -203,6 +163,12 @@ public final class decorator { } extract_bracketed_scientific_name = true; } + if ( cla.isOptionSet( decorator.EXTRACT_BRACKETED_TAXONOMIC_CODE_OPTION ) ) { + if ( advanced_table ) { + argumentsError(); + } + extract_bracketed_tax_code = true; + } if ( cla.isOptionSet( decorator.KEY_COLUMN ) ) { if ( advanced_table ) { argumentsError(); @@ -233,13 +199,16 @@ public final class decorator { } process_similar_to = true; } + if ( cla.isOptionSet( decorator.TRIM_AFTER_TILDE_OPTION ) ) { + if ( advanced_table ) { + argumentsError(); + } + trim_after_tilde = true; + } if ( cla.isOptionSet( decorator.ALLOW_REMOVAL_OF_CHARS_OPTION ) ) { numbers_of_chars_allowed_to_remove_if_not_found_in_map = cla .getOptionValueAsInt( decorator.ALLOW_REMOVAL_OF_CHARS_OPTION ); } - if ( cla.isOptionSet( decorator.MOVE_DOMAIN_NUMBER_OPTION ) ) { - move_domain_numbers_at_end_to_middle = true; - } if ( cla.isOptionSet( decorator.FIELD_OPTION ) ) { field_str = cla.getOptionValue( decorator.FIELD_OPTION ); if ( field_str.equals( NODE_NAME_FIELD ) ) { @@ -251,6 +220,7 @@ public final class decorator { else if ( field_str.equals( DS_FILED ) ) { field = FIELD.DOMAIN_STRUCTURE; extract_bracketed_scientific_name = false; + extract_bracketed_tax_code = false; } else if ( field_str.equals( TAXONOMY_CODE_FIELD ) ) { field = FIELD.TAXONOMY_CODE; @@ -261,6 +231,7 @@ public final class decorator { else if ( field_str.equals( TAXONOMY_SCIENTIFIC_NAME_FIELD ) ) { field = FIELD.TAXONOMY_SCIENTIFIC_NAME; extract_bracketed_scientific_name = false; + extract_bracketed_tax_code = false; } else { ForesterUtil.fatalError( decorator.PRG_NAME, "unknown value for \"" + decorator.FIELD_OPTION @@ -289,6 +260,9 @@ public final class decorator { ForesterUtil.fatalError( decorator.PRG_NAME, "attempt to use -" + decorator.PROCESS_SIMILAR_TO_OPTION + " and -c option together" ); } + if ( extract_bracketed_scientific_name && extract_bracketed_tax_code ) { + argumentsError(); + } Phylogeny[] phylogenies = null; try { final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); @@ -303,7 +277,7 @@ public final class decorator { if ( !advanced_table ) { BasicTable mapping_table = null; try { - mapping_table = BasicTableParser.parse( mapping_infile, separator, decorator.USE_FIRST_SEPARATOR_ONLY ); + mapping_table = BasicTableParser.parse( mapping_infile, separator, false, true ); } catch ( final Exception e ) { ForesterUtil.fatalError( decorator.PRG_NAME, @@ -332,8 +306,8 @@ public final class decorator { phylogenies[ 0 ].setIdentifier( new Identifier( s_ary[ 1 ], s_ary[ 0 ] ) ); } if ( !ForesterUtil.isEmpty( tree_desc ) ) { - for( int i = 0; i < phylogenies.length; ++i ) { - phylogenies[ i ].setDescription( tree_desc ); + for( final Phylogeny phylogenie : phylogenies ) { + phylogenie.setDescription( tree_desc ); } } } @@ -357,19 +331,20 @@ public final class decorator { map, field, extract_bracketed_scientific_name, + extract_bracketed_tax_code, picky, cut_name_after_space, process_name_intelligently, process_similar_to, numbers_of_chars_allowed_to_remove_if_not_found_in_map, - move_domain_numbers_at_end_to_middle ); + trim_after_tilde ); } } catch ( final NullPointerException e ) { ForesterUtil.unexpectedFatalError( decorator.PRG_NAME, e ); } catch ( final Exception e ) { - ForesterUtil.fatalError( decorator.PRG_NAME, e.getLocalizedMessage() ); + ForesterUtil.fatalError( decorator.PRG_NAME, e.getLocalizedMessage() ); } try { final PhylogenyWriter w = new PhylogenyWriter(); @@ -382,4 +357,50 @@ public final class decorator { ForesterUtil.programMessage( PRG_NAME, "wrote: " + phylogenies_outfile ); ForesterUtil.programMessage( PRG_NAME, "OK." ); } + + private static void argumentsError() { + System.out.println(); + System.out.println( decorator.PRG_NAME + " -" + ADVANCED_TABLE_OPTION + " | -f= " + + "[mapping table file] " ); + System.out.println(); + System.out.println( "options:" ); + System.out.println(); + System.out.println( " -" + ADVANCED_TABLE_OPTION + " : table instead of one to one map (-f=)" ); + System.out.println( " -r= : allow to remove up to n characters from the end of the names" ); + System.out.println( " in phylogenies infile if not found (in map) otherwise" ); + System.out.println( " -p : picky, fails if node name not found in mapping table" ); + System.out.println( " -" + TREE_NAME_OPTION + "=: name for the phylogeny" ); + System.out.println( " -" + TREE_ID_OPTION + "=: identifier for the phylogeny (in the form provider:value)" ); + System.out.println( " -" + TREE_DESC_OPTION + "=: description for phylogenies" ); + System.out.println(); + System.out.println(); + System.out.println( "advanced options, only available if -" + ADVANCED_TABLE_OPTION + " is not used:" ); + System.out.println(); + System.out.println( " -f= : field to be replaced: " + NODE_NAME_FIELD + " : node name" ); + System.out.println( " " + SEQUENCE_ANNOTATION_DESC + + " : sequence annotation description" ); + System.out.println( " " + DS_FILED + " : domain structure" ); + System.out.println( " " + TAXONOMY_CODE_FIELD + " : taxonomy code" ); + System.out.println( " " + TAXONOMY_SCIENTIFIC_NAME_FIELD + + ": taxonomy scientific name" ); + System.out.println( " " + SEQUENCE_NAME_FIELD + " : sequence name" ); + System.out.println( " -k= : key column in mapping table (0 based)," ); + System.out.println( " names of the node to be decorated - default is 0" ); + System.out.println( " -v= : value column in mapping table (0 based)," ); + System.out.println( " data which with to decorate - default is 1" ); + System.out.println( " -" + EXTRACT_BRACKETED_SCIENTIC_NAME_OPTION + + " : to extract bracketed scientific names, e.g. [Nematostella vectensis]" ); + System.out.println( " -" + EXTRACT_BRACKETED_TAXONOMIC_CODE_OPTION + + " : to extract bracketed taxonomic codes, e.g. [NEMVE]" ); + System.out.println( " -s= : column separator in mapping file, default is \"" + + decorator.MAPPING_FILE_SEPARATOR_DEFAULT + "\"" ); + System.out.println( " -x : process name \"intelligently\" (only for -f=n)" ); + System.out.println( " -" + decorator.PROCESS_SIMILAR_TO_OPTION + + " : process name \"intelligently\" and process information after \"similar to\" (only for -f=n)" ); + System.out.println( " -c : cut name after first space (only for -f=n)" ); + System.out.println( " -" + decorator.TRIM_AFTER_TILDE_OPTION + + " : trim node name to be replaced after tilde" ); + System.out.println(); + System.exit( -1 ); + } }