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.HashMap;
30 import java.util.List;
33 import org.forester.util.ForesterUtil;
35 public final class UniProtTaxonomy {
37 public static final String ARCHAEA = "Archaea";
38 public static final String BACTERIA = "Bacteria";
39 public static final String EUKARYOTA = "Eukaryota";
40 private final List<String> _lineage;
41 private final String _code;
42 private final String _scientific_name;
43 private final String _common_name;
44 private final String _synonym;
45 private final String _rank;
46 private final String _id;
47 public final static String CELLULAR_ORGANISMS = "cellular organisms";
48 public final static String VIRUSES = "Viruses";
49 public static final String X = "x";
53 public UniProtTaxonomy( final String line ) {
54 final String[] items = line.split( "\t" );
55 if ( items.length < 5 ) {
56 throw new IllegalArgumentException( "cannot parse uniprot taxonomy from: " + line );
58 _id = items[ 0 ].trim();
59 _code = items[ 1 ].trim();
60 _scientific_name = items[ 2 ].trim();
61 _common_name = items[ 3 ].trim();
62 _synonym = items[ 4 ].trim();
63 if ( items.length > 6 ) {
64 _rank = items[ 7 ].trim();
70 if ( items.length > 8 ) {
71 lin = items[ 8 ].split( "; " );
73 _lineage = new ArrayList<String>();
74 if ( ( lin != null ) && ( lin.length > 0 ) ) {
75 final List<String> temp = new ArrayList<String>();
76 for( final String t : lin ) {
77 if ( !ForesterUtil.isEmpty( t ) ) {
81 for( int i = 0; i < temp.size(); ++i ) {
83 && ( temp.get( i ).equalsIgnoreCase( EUKARYOTA ) || temp.get( i ).equalsIgnoreCase( BACTERIA ) || temp
84 .get( i ).equalsIgnoreCase( ARCHAEA ) ) ) {
85 _lineage.add( CELLULAR_ORGANISMS );
87 _lineage.add( temp.get( i ) );
90 if ( _lineage.isEmpty()
91 && ( _scientific_name.equalsIgnoreCase( EUKARYOTA ) || _scientific_name.equalsIgnoreCase( BACTERIA ) || _scientific_name
92 .equalsIgnoreCase( ARCHAEA ) ) ) {
93 _lineage.add( CELLULAR_ORGANISMS );
95 _lineage.add( _scientific_name );
96 if ( _lineage.isEmpty() ) {
97 throw new IllegalArgumentException( "lineage in a UniProt taxonomy can not be empty\n: " + line );
101 public UniProtTaxonomy( final List<String> lineage,
103 final String common_name,
104 final String scientific_name,
105 final String synonym,
110 _scientific_name = scientific_name;
111 _common_name = common_name;
115 if ( ( ( _lineage != null ) && _lineage.isEmpty() )
116 || ( ( !ForesterUtil.isEmpty( _lineage ) ) && !_lineage.get( _lineage.size() - 1 )
117 .equalsIgnoreCase( _scientific_name ) ) ) {
118 _lineage.add( _scientific_name );
123 * Creates deep copy for all fields, except lineage.
127 public UniProtTaxonomy copy() {
128 return new UniProtTaxonomy( getLineage(),
129 getCode() != null ? new String( getCode() ) : null,
130 getCommonName() != null ? new String( getCommonName() ) : null,
131 getScientificName() != null ? new String( getScientificName() ) : null,
132 getSynonym() != null ? new String( getSynonym() ) : null,
133 getRank() != null ? new String( getRank() ) : null,
134 getId() != null ? new String( getId() ) : null );
137 public String getCode() {
141 public String getCommonName() {
145 public String getId() {
149 public List<String> getLineage() {
153 public String getRank() {
157 public String getScientificName() {
158 return _scientific_name;
161 public String getSynonym() {
170 public final static UniProtTaxonomy createSpecialFromScientificName( final String sn ) {
171 final List<String> lineage = new ArrayList<String>();
172 final String code = "";
173 final String common_name = "";
174 String scientific_name = "";
175 final String synonym = "";
178 if ( sn.equalsIgnoreCase( BACTERIA ) ) {
179 scientific_name = BACTERIA;
180 lineage.add( "cellular organisms" );
181 rank = "superkingdom";
184 else if ( sn.equalsIgnoreCase( ARCHAEA ) ) {
185 scientific_name = ARCHAEA;
186 lineage.add( "cellular organisms" );
187 rank = "superkingdom";
190 else if ( sn.equalsIgnoreCase( EUKARYOTA ) ) {
191 scientific_name = EUKARYOTA;
192 lineage.add( "cellular organisms" );
193 rank = "superkingdom";
196 else if ( sn.equalsIgnoreCase( VIRUSES ) ) {
197 scientific_name = VIRUSES;
198 rank = "superkingdom";
201 else if ( sn.equalsIgnoreCase( X ) ) {
205 throw new IllegalArgumentException( "illegal attempt to make UniProt taxonomy for :" + sn );
207 return new UniProtTaxonomy( lineage, code, common_name, scientific_name, synonym, rank, id );