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";
}
}
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;
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,
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() + "]" );
+ 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 ) {
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 ) {
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;
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 ) );
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;
}
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;
}
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:",
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();
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:
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;
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 );
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,
}
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,
&& ( !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() );
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() );
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 {