X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Ftools%2FPhylogenyDecorator.java;h=57ef9f04a7acb3a10f76eb8abaff32ba904150b7;hb=41ea5973f93687513d29e5b7cad1abff8f3adb4b;hp=f1d6e241639dc1f925a7102b8be43cfa3883b16c;hpb=9f15c8c3415681ea197bf9d629ee3f2c126fc5b7;p=jalview.git diff --git a/forester/java/src/org/forester/tools/PhylogenyDecorator.java b/forester/java/src/org/forester/tools/PhylogenyDecorator.java index f1d6e24..57ef9f0 100644 --- a/forester/java/src/org/forester/tools/PhylogenyDecorator.java +++ b/forester/java/src/org/forester/tools/PhylogenyDecorator.java @@ -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,17 @@ 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 ( ParserUtils.TAXOMONY_CODE_PATTERN_6.matcher( new_value ).find() ) { + new_value = extractBracketedTaxCodes6( node, new_value ); + } + else if ( picky ) { + throw new IllegalArgumentException( " could not get taxonomy from \"" + new_value + + "\"" ); + } } switch ( field ) { case SEQUENCE_ANNOTATION_DESC: @@ -256,7 +267,7 @@ public final class PhylogenyDecorator { if ( !node.getNodeData().isHasSequence() ) { node.getNodeData().setSequence( new Sequence() ); } - final Annotation annotation = new Annotation( "?" ); + final Annotation annotation = new Annotation(); annotation.setDesc( new_value ); node.getNodeData().getSequence().addAnnotation( annotation ); break; @@ -419,7 +430,7 @@ public final class PhylogenyDecorator { throws IOException { final Map> map = new HashMap>(); BasicTable 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 row_map = new HashMap(); String name = null; @@ -457,8 +468,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 ); @@ -471,6 +482,30 @@ public final class PhylogenyDecorator { return new_value; //TODO //FIXME } + private static String extractBracketedTaxCodes6( final PhylogenyNode node, final String new_value ) { + final Matcher m = ParserUtils.TAXOMONY_CODE_PATTERN_6.matcher( new_value ); + String tc = "?"; + if ( m.find() ) { + tc = m.group( 1 ); + } + ForesterUtil.ensurePresenceOfTaxonomy( node ); + try { + if ( tc.length() == 6 ) { + final String t = tc.substring( 0, 5 ); + System.out.println( "WARNING: taxonomy code " + tc + " -> " + t ); + tc = t; + } + else { + throw new IllegalArgumentException(); + } + node.getNodeData().getTaxonomy().setTaxonomyCode( tc ); + } + catch ( final PhyloXmlDataFormatException e ) { + throw new IllegalArgumentException( "illegal format for taxonomy code: " + tc ); + } + return new_value; //TODO //FIXME + } + private static String extractIntermediate( final Map intermediate_map, final String name ) { String new_name = null; if ( PhylogenyDecorator.VERBOSE ) {