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";
+ final static private String PRG_DATE = "2012.09.15";
private static void argumentsError() {
System.out.println();
System.out.println( " -" + ADVANCED_TABLE_OPTION + " : table instead of one to one map (-f=<c>)" );
System.out.println( " -r=<n> : 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( " -p : picky, fails if node name not found in mapping table" );
System.out.println( " -" + TREE_NAME_OPTION + "=<s>: name for the phylogeny" );
System.out.println( " -" + TREE_ID_OPTION + "=<s>: identifier for the phylogeny (in the form provider:value)" );
System.out.println( " -" + TREE_DESC_OPTION + "=<s>: description for phylogenies" );
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 after tilde" );
+ System.out.println( " -" + decorator.TRIM_AFTER_TILDE_OPTION
+ + " : trim node name to be replaced after tilde" );
System.out.println();
System.exit( -1 );
}
if ( !advanced_table ) {
BasicTable<String> 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,
"failed to read [" + mapping_infile + "] [" + e.getMessage() + "]" );
}
+ System.out.println( mapping_table.toString() );
if ( ( key_column < 0 ) || ( key_column >= mapping_table.getNumberOfColumns() ) ) {
ForesterUtil.fatalError( decorator.PRG_NAME, "illegal value for key column" );
}
if ( !ForesterUtil.isEmpty( error ) ) {
ForesterUtil.fatalError( pccx.PRG_NAME, error );
}
- intable = BasicTableParser.parse( infile, " ", false );
+ intable = BasicTableParser.parse( infile, " ", false, false );
}
catch ( final IOException e ) {
ForesterUtil.fatalError( pccx.PRG_NAME, "failed to read \"" + infile + "\" [" + e.getMessage() + "]" );
public DistanceMatrix[] parse( final Object source ) throws IOException {
reset();
- final List<BasicTable<String>> tables = BasicTableParser.parse( source, VALUE_SEPARATOR, false, COMMENT, true );
+ final List<BasicTable<String>> tables = BasicTableParser.parse( source,
+ VALUE_SEPARATOR,
+ false,
+ false,
+ COMMENT,
+ true );
final DistanceMatrix[] distance_matrices = new DistanceMatrix[ tables.size() ];
int i = 0;
for( final BasicTable<String> table : tables ) {
final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
";",
false,
+ false,
"comment:",
false );
if ( tl.size() != 2 ) {
final boolean trim_after_tilde ) 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" );
+ throw new IllegalArgumentException( "attempt to extract bracketed scientific name together with data field pointing to scientific name" );
}
for( final PhylogenyNodeIterator iter = phylogeny.iteratorPostorder(); iter.hasNext(); ) {
final PhylogenyNode node = iter.next();
new_value = new_value.trim();
new_value.replaceAll( "/\\s+/", " " );
if ( extract_bracketed_scientific_name && new_value.endsWith( "]" ) ) {
- extractBracketedScientificNames( node, new_value );
+ new_value = extractBracketedScientificNames( node, new_value );
}
switch ( field ) {
case SEQUENCE_ANNOTATION_DESC:
return name;
}
- private static void extractBracketedScientificNames( final PhylogenyNode node, final String new_value ) {
+ private static String 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 );
AptxUtil.ensurePresenceOfTaxonomy( node );
node.getNodeData().getTaxonomy().setScientificName( scientific_name );
+ return new_value.substring( 0, i - 1 ).trim();
}
private static String extractIntermediate( final Map<String, String> intermediate_map, final String name ) {
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 );
+ 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;
}
public static BasicTable<String> parse( final Object source, final String column_delimiter ) throws IOException {
- return BasicTableParser.parse( source, column_delimiter, false, START_OF_COMMENT_LINE_DEFAULT, false ).get( 0 );
+ 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 boolean use_first_separator_only ) throws IOException {
+ final boolean use_first_separator_only,
+ final boolean use_last_separator_only ) throws IOException {
return BasicTableParser.parse( source,
column_delimiter,
use_first_separator_only,
+ use_last_separator_only,
START_OF_COMMENT_LINE_DEFAULT,
false ).get( 0 );
}
public static List<BasicTable<String>> parse( final Object source,
final String column_delimiter,
final boolean use_first_separator_only,
+ final boolean use_last_separator_only,
final String start_of_comment_line,
final boolean tables_separated_by_single_string_line )
throws IOException {
else if ( !ForesterUtil.isEmpty( line )
&& ( !use_start_of_comment_line || !line.startsWith( start_of_comment_line ) ) ) {
saw_first_table = true;
- final StringTokenizer st = new StringTokenizer( line, column_delimiter );
- int col = 0;
- if ( st.hasMoreTokens() ) {
- table.setValue( col++, row, st.nextToken().trim() );
- }
- if ( !use_first_separator_only ) {
- while ( st.hasMoreTokens() ) {
- table.setValue( col++, row, st.nextToken().trim() );
+ if ( use_last_separator_only ) {
+ 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() );
}
+ table.setValue( 0, row, e[ e.length - 1 ] );
+ table.setValue( 1, row, rest.toString() );
}
else {
- final StringBuffer rest = new StringBuffer();
- while ( st.hasMoreTokens() ) {
- rest.append( st.nextToken() );
+ final StringTokenizer st = new StringTokenizer( line, column_delimiter );
+ int col = 0;
+ if ( st.hasMoreTokens() ) {
+ table.setValue( col++, row, st.nextToken().trim() );
+ }
+ if ( use_first_separator_only ) {
+ final StringBuffer rest = new StringBuffer();
+ while ( st.hasMoreTokens() ) {
+ rest.append( st.nextToken() );
+ }
+ table.setValue( col++, row, rest.toString() );
+ }
+ else {
+ while ( st.hasMoreTokens() ) {
+ table.setValue( col++, row, st.nextToken().trim() );
+ }
}
- table.setValue( col++, row, rest.toString().trim() );
}
- ++row;
}
+ ++row;
}
if ( !table.isEmpty() ) {
tables.add( table );