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.uniprot;
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 UniProtTaxonomy DROSOPHILA_GENUS = new UniProtTaxonomy( new String[] {
47 CELLULAR_ORGANISMS, EUKARYOTA, "Metazoa", "Arthropoda", "Hexapoda", "Insecta", "Pterygota", "Neoptera",
48 "Endopterygota", "Diptera", "Brachycera", "Muscomorpha", "Ephydroidea", "Drosophilidae" },
55 public final static UniProtTaxonomy XENOPUS_GENUS = new UniProtTaxonomy( new String[] {
56 CELLULAR_ORGANISMS, EUKARYOTA, "Metazoa", "Chordata", "Craniata", "Vertebrata", "Euteleostomi", "Amphibia",
57 "Batrachia", "Anura", "Mesobatrachia", "Pipoidea", "Pipidae", "Xenopodinae" },
64 public final static UniProtTaxonomy CAPITELLA_TELATA_SPECIES = new UniProtTaxonomy( new String[] {
65 CELLULAR_ORGANISMS, EUKARYOTA, "Metazoa", "Annelida", "Polychaeta", "Scolecida", "Capitellida",
66 "Capitellidae", "Capitella" },
74 public UniProtTaxonomy( final String line ) {
75 final String[] items = line.split( "\t" );
76 if ( items.length < 5 ) {
77 throw new IllegalArgumentException( "cannot parse uniprot taxonomy from: " + line );
79 _id = items[ 0 ].trim();
80 _code = items[ 1 ].trim();
81 _scientific_name = items[ 2 ].trim();
82 _common_name = items[ 3 ].trim();
83 _synonym = items[ 4 ].trim();
84 if ( items.length > 6 ) {
85 _rank = items[ 7 ].trim();
91 if ( items.length > 7 ) {
92 lin = items[ 8 ].split( "; " );
94 _lineage = new ArrayList<String>();
95 if ( ( lin != null ) && ( lin.length > 0 ) ) {
96 final List<String> temp = new ArrayList<String>();
97 for( final String t : lin ) {
98 if ( !ForesterUtil.isEmpty( t ) ) {
102 for( int i = 0; i < temp.size(); ++i ) {
104 && ( temp.get( i ).equalsIgnoreCase( EUKARYOTA ) || temp.get( i ).equalsIgnoreCase( BACTERIA ) || temp
105 .get( i ).equalsIgnoreCase( ARCHAEA ) ) ) {
106 _lineage.add( CELLULAR_ORGANISMS );
108 _lineage.add( temp.get( i ) );
111 if ( _lineage.isEmpty()
112 && ( _scientific_name.equalsIgnoreCase( EUKARYOTA ) || _scientific_name.equalsIgnoreCase( BACTERIA ) || _scientific_name
113 .equalsIgnoreCase( ARCHAEA ) ) ) {
114 System.out.println( " >>>>>>>>>>>>>>>>>>>>>>>>> did it!" );
115 _lineage.add( CELLULAR_ORGANISMS );
117 _lineage.add( _scientific_name );
118 if ( _lineage.isEmpty() ) {
119 throw new IllegalArgumentException( "lineage in a UniProt Taxonomy can not be empty\n: " + line );
123 public UniProtTaxonomy( final List<String> lineage,
125 final String common_name,
126 final String scientific_name,
127 final String synonym,
132 _scientific_name = scientific_name;
133 _common_name = common_name;
139 public UniProtTaxonomy( final String[] lineage,
141 final String common_name,
142 final String scientific_name,
143 final String synonym,
146 _lineage = new ArrayList<String>();
147 for( String l : lineage ) {
151 _scientific_name = scientific_name;
152 _common_name = common_name;
159 * Creates deep copy for all fields, except lineage.
163 public UniProtTaxonomy copy() {
164 return new UniProtTaxonomy( getLineage(),
165 getCode() != null ? new String( getCode() ) : null,
166 getCommonName() != null ? new String( getCommonName() ) : null,
167 getScientificName() != null ? new String( getScientificName() ) : null,
168 getSynonym() != null ? new String( getSynonym() ) : null,
169 getRank() != null ? new String( getRank() ) : null,
170 getId() != null ? new String( getId() ) : null );
173 public String getCode() {
177 public String getCommonName() {
181 public String getId() {
185 public List<String> getLineage() {
189 public String[] getLineageAsArray() {
190 String[] str = new String[ _lineage.size() ];
192 for( String l : _lineage ) {
198 public String getRank() {
202 public String getScientificName() {
203 return _scientific_name;
206 public String getSynonym() {