+
+ public final static String extractTaxonomyCodeFromNodeName( final String name,
+ final TAXONOMY_EXTRACTION taxonomy_extraction ) {
+ if ( ( name.indexOf( "_" ) > 0 )
+ && ( ( taxonomy_extraction != TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ) || ( name.indexOf( "/" ) > 4 ) ) ) {
+ final String[] s = name.split( "[_\\s]" );
+ if ( s.length > 1 ) {
+ final String str = s[ 1 ];
+ if ( !ForesterUtil.isEmpty( str ) ) {
+ if ( taxonomy_extraction == TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ) {
+ final Matcher m = TAXOMONY_CODE_PATTERN_PF.matcher( str );
+ if ( m.matches() ) {
+ return m.group( 1 );
+ }
+ }
+ else {
+ final Matcher m1 = TAXOMONY_CODE_PATTERN_1.matcher( str );
+ if ( m1.matches() ) {
+ return m1.group();
+ }
+ final Matcher m2 = TAXOMONY_CODE_PATTERN_2.matcher( str );
+ if ( m2.matches() ) {
+ return m2.group( 1 );
+ }
+ }
+ }
+ }
+ }
+ else if ( taxonomy_extraction == TAXONOMY_EXTRACTION.YES ) {
+ final Matcher m1 = TAXOMONY_CODE_PATTERN_1.matcher( name );
+ if ( m1.matches() ) {
+ return name;
+ }
+ }
+ return null;
+ }
+
+ public final static String extractScientificNameFromNodeName( final String name ) {
+ final Matcher m1 = TAXOMONY_SN_PATTERN.matcher( name );
+ if ( m1.matches() ) {
+ return m1.group( 1 ).replace( '_', ' ' );
+ }
+ return null;
+ }
+
+ public final static String extractTaxonomyDataFromNodeName( final PhylogenyNode node,
+ final NHXParser.TAXONOMY_EXTRACTION taxonomy_extraction )
+ throws PhyloXmlDataFormatException {
+ final String id = extractUniprotTaxonomyIdFromNodeName( node.getName(), taxonomy_extraction );
+ if ( !ForesterUtil.isEmpty( id ) ) {
+ if ( !node.getNodeData().isHasTaxonomy() ) {
+ node.getNodeData().setTaxonomy( new Taxonomy() );
+ }
+ if ( ( node.getNodeData().getTaxonomy().getIdentifier() == null )
+ || ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getIdentifier().getValue() ) ) {
+ 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() );
+ }
+ if ( ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
+ node.getNodeData().getTaxonomy().setTaxonomyCode( code );
+ return code;
+ }
+ }
+ else if ( taxonomy_extraction == TAXONOMY_EXTRACTION.YES ) {
+ final String sn = extractScientificNameFromNodeName( node.getName() );
+ if ( !ForesterUtil.isEmpty( sn ) ) {
+ if ( !node.getNodeData().isHasTaxonomy() ) {
+ node.getNodeData().setTaxonomy( new Taxonomy() );
+ }
+ if ( ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getScientificName() ) ) {
+ node.getNodeData().getTaxonomy().setScientificName( sn );
+ return sn;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public final static String extractUniprotTaxonomyIdFromNodeName( final String name,
+ final TAXONOMY_EXTRACTION taxonomy_extraction ) {
+ if ( ( name.indexOf( "_" ) > 0 )
+ && ( ( taxonomy_extraction != TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ) || ( name.indexOf( "/" ) > 4 ) ) ) {
+ final String[] s = name.split( "[_\\s]" );
+ if ( s.length > 1 ) {
+ final String str = s[ 1 ];
+ if ( !ForesterUtil.isEmpty( str ) ) {
+ if ( taxonomy_extraction == TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ) {
+ final Matcher m = TAXOMONY_UNIPROT_ID_PATTERN_PF.matcher( str );
+ if ( m.matches() ) {
+ return m.group( 1 );
+ }
+ }
+ else {
+ final Matcher m1 = TAXOMONY_UNIPROT_ID_PATTERN_1.matcher( str );
+ if ( m1.matches() ) {
+ return m1.group();
+ }
+ final Matcher m2 = TAXOMONY_UNIPROT_ID_PATTERN_2.matcher( str );
+ if ( m2.matches() ) {
+ return m2.group( 1 );
+ }
+ }
+ }
+ }
+ }
+ else if ( taxonomy_extraction == TAXONOMY_EXTRACTION.YES ) {
+ final Matcher m1 = TAXOMONY_UNIPROT_ID_PATTERN_1.matcher( name );
+ if ( m1.matches() ) {
+ return name;
+ }
+ }
+ return null;
+ }
+
+ public final static Phylogeny[] readPhylogenies( final File file ) throws FileNotFoundException, IOException {
+ return PhylogenyMethods.readPhylogenies( ParserUtils.createParserDependingOnFileType( file, true ), file );
+ }
+
+ public final static Phylogeny[] readPhylogenies( final String file_name ) throws FileNotFoundException, IOException {
+ return readPhylogenies( new File( file_name ) );
+ }