- /**
- * Extracts a code if and only if:
- * one and only one _,
- * shorter than 25,
- * no |,
- * no .,
- * if / present it has to be after the _,
- * if PFAM_STYLE_ONLY: / must be present,
- * tax code can only contain uppercase letters and numbers,
- * and must contain at least one uppercase letter.
- * Return null if no code extractable.
- *
- * @param name
- * @return
- */
- public static String extractTaxonomyCodeFromNodeName( final String name,
- final NHXParser.TAXONOMY_EXTRACTION taxonomy_extraction ) {
- if ( ( name.indexOf( "_" ) > 0 )
- && ( name.length() < 31 )
- // && ( name.lastIndexOf( "_" ) == name.indexOf( "_" ) )
- && ( name.indexOf( "|" ) < 0 )
- && ( name.indexOf( "." ) < 0 )
- && ( ( taxonomy_extraction != NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ) || ( name.indexOf( "/" ) >= 0 ) )
- && ( ( ( name.indexOf( "/" ) ) < 0 ) || ( name.indexOf( "/" ) > name.indexOf( "_" ) ) ) ) {
- final String[] s = name.split( "[_/]" );
- if ( s.length > 1 ) {
- final String str = s[ 1 ];
- // if ( str.length() < 6 ) {
- if ( ( str.length() < 5 )
- && ( str.startsWith( "RAT" ) || str.startsWith( "PIG" ) || str.startsWith( "CAP" ) ) ) {
- return str.substring( 0, 3 );
+ public final static String extractScientificNameFromNodeName( final String name ) {
+ final Matcher m = TAXOMONY_SN_PATTERN.matcher( name );
+ if ( m.find() ) {
+ return m.group( 1 ).replace( '_', ' ' );
+ }
+ return null;
+ }
+
+ public final static String extractTaxonomyCodeFromNodeName( final String name,
+ final TAXONOMY_EXTRACTION taxonomy_extraction ) {
+ Matcher m = TAXOMONY_CODE_PATTERN_PFS.matcher( name );
+ if ( m.find() ) {
+ return m.group( 1 );
+ }
+ else if ( ( taxonomy_extraction == TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
+ || ( taxonomy_extraction == TAXONOMY_EXTRACTION.AGGRESSIVE ) ) {
+ m = TAXOMONY_CODE_PATTERN_PFR.matcher( name );
+ if ( m.find() ) {
+ return m.group( 1 );
+ }
+ else if ( taxonomy_extraction == TAXONOMY_EXTRACTION.AGGRESSIVE ) {
+ m = TAXOMONY_CODE_PATTERN_A.matcher( name );
+ if ( m.find() ) {
+ return m.group( 1 );
+ }
+ }
+ }
+ return null;
+ }
+
+ public final static String extractTaxonomyDataFromNodeName( final PhylogenyNode node,
+ final NHXParser.TAXONOMY_EXTRACTION taxonomy_extraction )
+ throws PhyloXmlDataFormatException {
+ if ( taxonomy_extraction == TAXONOMY_EXTRACTION.NO ) {
+ throw new IllegalArgumentException();
+ }
+ final String id = extractUniprotTaxonomyIdFromNodeName( node.getName(), taxonomy_extraction );
+ if ( !ForesterUtil.isEmpty( id ) ) {
+ if ( !node.getNodeData().isHasTaxonomy() ) {
+ node.getNodeData().setTaxonomy( new Taxonomy() );
+ }
+ node.getNodeData().getTaxonomy().setIdentifier( new Identifier( id, "uniprot" ) );
+ return id;
+ }
+ else {
+ final String code = extractTaxonomyCodeFromNodeName( node.getName(), taxonomy_extraction );
+ if ( !ForesterUtil.isEmpty( code ) ) {
+ if ( !node.getNodeData().isHasTaxonomy() ) {
+ node.getNodeData().setTaxonomy( new Taxonomy() );