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.seqdb;
28 import java.util.ArrayList;
29 import java.util.List;
31 import org.forester.util.ForesterUtil;
33 public final class UniProtTaxonomy {
35 private static final String ARCHAEA = "Archaea";
36 private static final String BACTERIA = "Bacteria";
37 private static final String EUKARYOTA = "Eukaryota";
38 private final List<String> _lineage;
39 private final String _code;
40 private final String _scientific_name;
41 private final String _common_name;
42 private final String _synonym;
43 private final String _rank;
44 private final String _id;
45 public final static String CELLULAR_ORGANISMS = "cellular organisms";
46 public final static String VIRUSES = "Viruses";
48 public UniProtTaxonomy( final String line ) {
49 final String[] items = line.split( "\t" );
50 if ( items.length < 5 ) {
51 throw new IllegalArgumentException( "cannot parse uniprot taxonomy from: " + line );
53 _id = items[ 0 ].trim();
54 _code = items[ 1 ].trim();
55 _scientific_name = items[ 2 ].trim();
56 _common_name = items[ 3 ].trim();
57 _synonym = items[ 4 ].trim();
58 if ( items.length > 6 ) {
59 _rank = items[ 7 ].trim();
65 if ( items.length > 8 ) {
66 lin = items[ 8 ].split( "; " );
68 _lineage = new ArrayList<String>();
69 if ( ( lin != null ) && ( lin.length > 0 ) ) {
70 final List<String> temp = new ArrayList<String>();
71 for( final String t : lin ) {
72 if ( !ForesterUtil.isEmpty( t ) ) {
76 for( int i = 0; i < temp.size(); ++i ) {
78 && ( temp.get( i ).equalsIgnoreCase( EUKARYOTA ) || temp.get( i ).equalsIgnoreCase( BACTERIA ) || temp
79 .get( i ).equalsIgnoreCase( ARCHAEA ) ) ) {
80 _lineage.add( CELLULAR_ORGANISMS );
82 _lineage.add( temp.get( i ) );
85 if ( _lineage.isEmpty()
86 && ( _scientific_name.equalsIgnoreCase( EUKARYOTA ) || _scientific_name.equalsIgnoreCase( BACTERIA ) || _scientific_name
87 .equalsIgnoreCase( ARCHAEA ) ) ) {
88 _lineage.add( CELLULAR_ORGANISMS );
90 _lineage.add( _scientific_name );
91 if ( _lineage.isEmpty() ) {
92 throw new IllegalArgumentException( "lineage in a UniProt taxonomy can not be empty\n: " + line );
96 public UniProtTaxonomy( final List<String> lineage,
98 final String common_name,
99 final String scientific_name,
100 final String synonym,
105 _scientific_name = scientific_name;
106 _common_name = common_name;
110 if ( ( _lineage != null ) && !_lineage.get( _lineage.size() - 1 ).equalsIgnoreCase( _scientific_name ) ) {
111 _lineage.add( _scientific_name );
115 public UniProtTaxonomy( final String[] lineage,
117 final String common_name,
118 final String scientific_name,
119 final String synonym,
122 _lineage = new ArrayList<String>();
123 if ( lineage != null ) {
124 for( final String l : lineage ) {
129 _scientific_name = scientific_name;
130 _common_name = common_name;
134 if ( ( _lineage != null ) && !_lineage.get( _lineage.size() - 1 ).equalsIgnoreCase( _scientific_name ) ) {
135 _lineage.add( _scientific_name );
140 * Creates deep copy for all fields, except lineage.
144 public UniProtTaxonomy copy() {
145 return new UniProtTaxonomy( getLineage(),
146 getCode() != null ? new String( getCode() ) : null,
147 getCommonName() != null ? new String( getCommonName() ) : null,
148 getScientificName() != null ? new String( getScientificName() ) : null,
149 getSynonym() != null ? new String( getSynonym() ) : null,
150 getRank() != null ? new String( getRank() ) : null,
151 getId() != null ? new String( getId() ) : null );
154 public String getCode() {
158 public String getCommonName() {
162 public String getId() {
166 public List<String> getLineage() {
170 public String getRank() {
174 public String getScientificName() {
175 return _scientific_name;
178 public String getSynonym() {