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 public static final String ARCHAEA = "Archaea";
36 public static final String BACTERIA = "Bacteria";
37 public 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";
47 public static final String X = "x";
49 public UniProtTaxonomy( final String line ) {
50 final String[] items = line.split( "\t" );
51 if ( items.length < 5 ) {
52 throw new IllegalArgumentException( "cannot parse uniprot taxonomy from: " + line );
54 _id = items[ 0 ].trim();
55 _code = items[ 1 ].trim();
56 _scientific_name = items[ 2 ].trim();
57 _common_name = items[ 3 ].trim();
58 _synonym = items[ 4 ].trim();
59 if ( items.length > 6 ) {
60 _rank = items[ 7 ].trim();
66 if ( items.length > 8 ) {
67 lin = items[ 8 ].split( "; " );
69 _lineage = new ArrayList<String>();
70 if ( ( lin != null ) && ( lin.length > 0 ) ) {
71 final List<String> temp = new ArrayList<String>();
72 for( final String t : lin ) {
73 if ( !ForesterUtil.isEmpty( t ) ) {
77 for( int i = 0; i < temp.size(); ++i ) {
79 && ( temp.get( i ).equalsIgnoreCase( EUKARYOTA ) || temp.get( i ).equalsIgnoreCase( BACTERIA ) || temp
80 .get( i ).equalsIgnoreCase( ARCHAEA ) ) ) {
81 _lineage.add( CELLULAR_ORGANISMS );
83 _lineage.add( temp.get( i ) );
86 if ( _lineage.isEmpty()
87 && ( _scientific_name.equalsIgnoreCase( EUKARYOTA ) || _scientific_name.equalsIgnoreCase( BACTERIA ) || _scientific_name
88 .equalsIgnoreCase( ARCHAEA ) ) ) {
89 _lineage.add( CELLULAR_ORGANISMS );
91 _lineage.add( _scientific_name );
92 if ( _lineage.isEmpty() ) {
93 throw new IllegalArgumentException( "lineage in a UniProt taxonomy can not be empty\n: " + line );
97 public UniProtTaxonomy( final List<String> lineage,
99 final String common_name,
100 final String scientific_name,
101 final String synonym,
106 _scientific_name = scientific_name;
107 _common_name = common_name;
111 if ( ( ( _lineage != null ) && _lineage.isEmpty() )
112 || ( ( !ForesterUtil.isEmpty( _lineage ) ) && !_lineage.get( _lineage.size() - 1 )
113 .equalsIgnoreCase( _scientific_name ) ) ) {
114 _lineage.add( _scientific_name );
119 * Creates deep copy for all fields, except lineage.
123 public UniProtTaxonomy copy() {
124 return new UniProtTaxonomy( getLineage(),
125 getCode() != null ? new String( getCode() ) : null,
126 getCommonName() != null ? new String( getCommonName() ) : null,
127 getScientificName() != null ? new String( getScientificName() ) : null,
128 getSynonym() != null ? new String( getSynonym() ) : null,
129 getRank() != null ? new String( getRank() ) : null,
130 getId() != null ? new String( getId() ) : null );
133 public String getCode() {
137 public String getCommonName() {
141 public String getId() {
145 public List<String> getLineage() {
149 public String getRank() {
153 public String getScientificName() {
154 return _scientific_name;
157 public String getSynonym() {
161 public final static UniProtTaxonomy createSpecialFromScientificName( final String sn ) {
162 final List<String> lineage = new ArrayList<String>();
163 final String code = "";
164 final String common_name = "";
165 String scientific_name = "";
166 final String synonym = "";
169 if ( sn.equalsIgnoreCase( BACTERIA ) ) {
170 scientific_name = BACTERIA;
171 lineage.add( "cellular organisms" );
172 rank = "superkingdom";
175 else if ( sn.equalsIgnoreCase( ARCHAEA ) ) {
176 scientific_name = ARCHAEA;
177 lineage.add( "cellular organisms" );
178 rank = "superkingdom";
181 else if ( sn.equalsIgnoreCase( EUKARYOTA ) ) {
182 scientific_name = EUKARYOTA;
183 lineage.add( "cellular organisms" );
184 rank = "superkingdom";
187 else if ( sn.equalsIgnoreCase( VIRUSES ) ) {
188 scientific_name = VIRUSES;
189 rank = "superkingdom";
192 else if ( sn.equalsIgnoreCase( X ) ) {
196 throw new IllegalArgumentException( "illegal attempt to make UniProt taxonomy for :" + sn );
198 return new UniProtTaxonomy( lineage, code, common_name, scientific_name, synonym, rank, id );