2 // forester -- software libraries and applications
3 // for genomics and evolutionary biology research.
5 // Copyright (C) 2010 Christian M Zmasek
6 // Copyright (C) 2010 Sanford-Burnham Medical Research Institute
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
26 package org.forester.ws.wabi;
28 import java.io.IOException;
30 import org.forester.phylogeny.PhylogenyMethods;
31 import org.forester.phylogeny.data.Taxonomy;
32 import org.forester.util.ForesterUtil;
33 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
34 import org.forester.ws.wabi.TxSearch.TAX_RANK;
36 public final class WabiTools {
38 private static String getATxName( final Taxonomy tax ) throws IOException {
40 if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
41 name = tax.getScientificName();
43 else if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
44 name = tax.getCommonName();
46 if ( ForesterUtil.isEmpty( name ) ) {
47 String id_value = null;
48 if ( PhylogenyMethods.isTaxonomyHasIdentifierOfGivenProvider( tax, new String[] { "uniprot", "ncbi" } ) ) {
49 id_value = tax.getIdentifier().getValue();
51 if ( !ForesterUtil.isEmpty( id_value ) ) {
52 name = TxSearch.getTxName( id_value );
58 public static String[] obtainLineage( final Taxonomy tax ) throws IOException {
59 final String name = getATxName( tax );
61 if ( !ForesterUtil.isEmpty( name ) ) {
62 result = TxSearch.searchParam( name, TAX_NAME_CLASS.ALL, TAX_RANK.ALL, 2, true );
64 if ( !ForesterUtil.isEmpty( result ) ) {
65 final String[] lin = TxSearch.getLineage( result );
67 final String[] lin_plus_self = new String[ lin.length + 1 ];
68 for( int i = 0; i < lin.length; ++i ) {
69 lin_plus_self[ i ] = lin[ i ];
71 lin_plus_self[ lin.length ] = name;
78 public static String obtainRank( final Taxonomy tax ) throws IOException {
79 final String result = searchParam( tax );
80 if ( !ForesterUtil.isEmpty( result ) ) {
81 return TxSearch.getTaxonomicRank( result );
86 private static String searchParam( final Taxonomy tax ) throws IOException {
87 final String name = getATxName( tax );
89 if ( !ForesterUtil.isEmpty( name ) ) {
90 result = TxSearch.searchParam( name, TAX_NAME_CLASS.ALL, TAX_RANK.ALL, 2, true );