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: www.phylosoft.org/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";
47 public final static UniProtTaxonomy DROSOPHILA_GENUS = new UniProtTaxonomy( new String[] {
48 CELLULAR_ORGANISMS, EUKARYOTA, "Metazoa", "Ecdysozoa", "Arthropoda", "Hexapoda", "Insecta", "Pterygota",
49 "Neoptera", "Endopterygota", "Diptera", "Brachycera", "Muscomorpha", "Ephydroidea", "Drosophilidae",
57 public final static UniProtTaxonomy XENOPUS_GENUS = new UniProtTaxonomy( new String[] {
58 CELLULAR_ORGANISMS, EUKARYOTA, "Metazoa", "Chordata", "Craniata", "Vertebrata", "Euteleostomi", "Amphibia",
59 "Batrachia", "Anura", "Mesobatrachia", "Pipoidea", "Pipidae", "Xenopodinae", "Xenopus" },
66 public final static UniProtTaxonomy CAPITELLA_TELATA_SPECIES = new UniProtTaxonomy( new String[] {
67 CELLULAR_ORGANISMS, EUKARYOTA, "Metazoa", "Annelida", "Polychaeta", "Scolecida", "Capitellida",
68 "Capitellidae", "Capitella", "Capitella teleta" },
76 public UniProtTaxonomy( final String line ) {
77 final String[] items = line.split( "\t" );
78 if ( items.length < 5 ) {
79 throw new IllegalArgumentException( "cannot parse uniprot taxonomy from: " + line );
81 _id = items[ 0 ].trim();
82 _code = items[ 1 ].trim();
83 _scientific_name = items[ 2 ].trim();
84 _common_name = items[ 3 ].trim();
85 _synonym = items[ 4 ].trim();
86 if ( items.length > 6 ) {
87 _rank = items[ 7 ].trim();
93 if ( items.length > 8 ) {
94 lin = items[ 8 ].split( "; " );
96 _lineage = new ArrayList<String>();
97 if ( ( lin != null ) && ( lin.length > 0 ) ) {
98 final List<String> temp = new ArrayList<String>();
99 for( final String t : lin ) {
100 if ( !ForesterUtil.isEmpty( t ) ) {
101 temp.add( t.trim() );
104 for( int i = 0; i < temp.size(); ++i ) {
106 && ( temp.get( i ).equalsIgnoreCase( EUKARYOTA ) || temp.get( i ).equalsIgnoreCase( BACTERIA ) || temp
107 .get( i ).equalsIgnoreCase( ARCHAEA ) ) ) {
108 _lineage.add( CELLULAR_ORGANISMS );
110 _lineage.add( temp.get( i ) );
113 if ( _lineage.isEmpty()
114 && ( _scientific_name.equalsIgnoreCase( EUKARYOTA ) || _scientific_name.equalsIgnoreCase( BACTERIA ) || _scientific_name
115 .equalsIgnoreCase( ARCHAEA ) ) ) {
116 _lineage.add( CELLULAR_ORGANISMS );
118 _lineage.add( _scientific_name );
119 if ( _lineage.isEmpty() ) {
120 throw new IllegalArgumentException( "lineage in a UniProt taxonomy can not be empty\n: " + line );
124 public UniProtTaxonomy( final List<String> lineage,
126 final String common_name,
127 final String scientific_name,
128 final String synonym,
133 _scientific_name = scientific_name;
134 _common_name = common_name;
138 if ( ( _lineage != null ) && !_lineage.get( _lineage.size() - 1 ).equalsIgnoreCase( _scientific_name ) ) {
139 _lineage.add( _scientific_name );
143 public UniProtTaxonomy( final String[] lineage,
145 final String common_name,
146 final String scientific_name,
147 final String synonym,
150 _lineage = new ArrayList<String>();
151 if ( lineage != null ) {
152 for( final String l : lineage ) {
157 _scientific_name = scientific_name;
158 _common_name = common_name;
162 if ( ( _lineage != null ) && !_lineage.get( _lineage.size() - 1 ).equalsIgnoreCase( _scientific_name ) ) {
163 _lineage.add( _scientific_name );
168 * Creates deep copy for all fields, except lineage.
172 public UniProtTaxonomy copy() {
173 return new UniProtTaxonomy( getLineage(),
174 getCode() != null ? new String( getCode() ) : null,
175 getCommonName() != null ? new String( getCommonName() ) : null,
176 getScientificName() != null ? new String( getScientificName() ) : null,
177 getSynonym() != null ? new String( getSynonym() ) : null,
178 getRank() != null ? new String( getRank() ) : null,
179 getId() != null ? new String( getId() ) : null );
182 public String getCode() {
186 public String getCommonName() {
190 public String getId() {
194 public List<String> getLineage() {
198 public String getRank() {
202 public String getScientificName() {
203 return _scientific_name;
206 public String getSynonym() {