- /**
- * 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 PhylogenyMethods.TAXONOMY_EXTRACTION taxonomy_extraction ) {
+ public final static String extractTaxonomyCodeFromNodeName( final String name,
+ final TAXONOMY_EXTRACTION taxonomy_extraction ) {
+ if ( taxonomy_extraction == TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ) {
+ final Matcher m = TAXOMONY_CODE_PATTERN_PF.matcher( name );
+ if ( m.find() ) {
+ return m.group( 1 );
+ }
+ }
+ else if ( ( taxonomy_extraction == TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
+ || ( taxonomy_extraction == TAXONOMY_EXTRACTION.AGGRESSIVE ) ) {
+ final Matcher m1 = TAXOMONY_CODE_PATTERN_R1.matcher( name );
+ if ( m1.find() ) {
+ return m1.group( 1 );
+ }
+ final Matcher m2 = TAXOMONY_CODE_PATTERN_R2.matcher( name );
+ if ( m2.find() ) {
+ return m2.group( 1 );
+ }
+ }
+ return null;
+ }
+
+ public final static String extractScientificNameFromNodeName( final String name ) {
+ final Matcher m1 = TAXOMONY_SN_PATTERN.matcher( name );
+ if ( m1.find() ) {
+ return m1.group( 1 ).replace( '_', ' ' );
+ }
+ 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() );
+ }
+ node.getNodeData().getTaxonomy().setTaxonomyCode( code );
+ return code;
+ }
+ else if ( ( taxonomy_extraction == TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED || taxonomy_extraction == TAXONOMY_EXTRACTION.AGGRESSIVE ) ) {
+ final String sn = extractScientificNameFromNodeName( node.getName() );
+ if ( !ForesterUtil.isEmpty( sn ) ) {
+ if ( !node.getNodeData().isHasTaxonomy() ) {
+ node.getNodeData().setTaxonomy( new Taxonomy() );
+ }
+ node.getNodeData().getTaxonomy().setScientificName( sn );
+ return sn;
+ }
+ }
+ }
+ return null;
+ }
+
+ public final static String extractUniprotTaxonomyIdFromNodeName( final String name,
+ final TAXONOMY_EXTRACTION taxonomy_extraction ) {