initial commit
[jalview.git] / forester / java / src / org / forester / ws / uniprot / UniProtTaxonomy.java
1 // $Id:
2 // forester -- software libraries and applications
3 // for genomics and evolutionary biology research.
4 //
5 // Copyright (C) 2010 Christian M Zmasek
6 // Copyright (C) 2010 Sanford-Burnham Medical Research Institute
7 // All rights reserved
8 // 
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.
13 //
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.
18 // 
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
22 //
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org/forester
25
26 package org.forester.ws.uniprot;
27
28 import java.util.ArrayList;
29 import java.util.List;
30
31 import org.forester.util.ForesterUtil;
32
33 public final class UniProtTaxonomy {
34
35     private final String[]              _lineage;
36     private final String                _code;
37     private final String                _scientific_name;
38     private final String                _common_name;
39     private final String                _synonym;
40     private final String                _rank;
41     private final String                _id;
42     public final static UniProtTaxonomy DROSOPHILA_GENUS         = new UniProtTaxonomy( new String[] { "Eukaryota",
43             "Metazoa", "Arthropoda", "Hexapoda", "Insecta", "Pterygota", "Neoptera", "Endopterygota", "Diptera",
44             "Brachycera", "Muscomorpha", "Ephydroidea", "Drosophilidae"                },
45                                                                                         "",
46                                                                                         "fruit flies",
47                                                                                         "Drosophila",
48                                                                                         "",
49                                                                                         "genus",
50                                                                                         "7215" );
51     public final static UniProtTaxonomy XENOPUS_GENUS            = new UniProtTaxonomy( new String[] { "Eukaryota",
52             "Metazoa", "Chordata", "Craniata", "Vertebrata", "Euteleostomi", "Amphibia", "Batrachia", "Anura",
53             "Mesobatrachia", "Pipoidea", "Pipidae", "Xenopodinae" }, "", "", "Xenopus", "", "genus", "8353" );
54     public final static UniProtTaxonomy CAPITELLA_TELATA_SPECIES = new UniProtTaxonomy( new String[] { "Eukaryota",
55             "Metazoa", "Annelida", "Polychaeta", "Scolecida", "Capitellida", "Capitellidae", "Capitella" },
56                                                                                         "",
57                                                                                         "",
58                                                                                         "Capitella teleta",
59                                                                                         "Capitella sp. I",
60                                                                                         "species",
61                                                                                         "283909" );
62
63     public UniProtTaxonomy( final String line ) {
64         final String[] items = line.split( "\t" );
65         if ( items.length < 5 ) {
66             throw new IllegalArgumentException( "cannot parse uniprot taxonomy from: " + line );
67         }
68         _id = items[ 0 ].trim();
69         _code = items[ 1 ].trim();
70         _scientific_name = items[ 2 ].trim();
71         _common_name = items[ 3 ].trim();
72         _synonym = items[ 4 ].trim();
73         if ( items.length > 6 ) {
74             _rank = items[ 7 ].trim();
75         }
76         else {
77             _rank = "";
78         }
79         String[] lin = null;
80         if ( items.length > 7 ) {
81             lin = items[ 8 ].split( "; " );
82         }
83         if ( ( lin != null ) && ( lin.length > 0 ) ) {
84             final List<String> temp = new ArrayList<String>();
85             for( final String t : lin ) {
86                 if ( !ForesterUtil.isEmpty( t ) ) {
87                     temp.add( t.trim() );
88                 }
89             }
90             _lineage = new String[ temp.size() ];
91             for( int i = 0; i < temp.size(); ++i ) {
92                 _lineage[ i ] = temp.get( i );
93             }
94         }
95         else {
96             _lineage = new String[ 0 ];
97         }
98     }
99
100     public UniProtTaxonomy( final String[] lineage,
101                             final String code,
102                             final String common_name,
103                             final String scientific_name,
104                             final String synonym,
105                             final String rank,
106                             final String id ) {
107         _lineage = lineage;
108         _code = code;
109         _scientific_name = scientific_name;
110         _common_name = common_name;
111         _synonym = synonym;
112         _rank = rank;
113         _id = id;
114     }
115
116     /**
117      * Creates deep copy for all fields, except lineage.
118      * 
119      * @return
120      */
121     public UniProtTaxonomy copy() {
122         return new UniProtTaxonomy( getLineage(),
123                                     getCode() != null ? new String( getCode() ) : null,
124                                     getCommonName() != null ? new String( getCommonName() ) : null,
125                                     getScientificName() != null ? new String( getScientificName() ) : null,
126                                     getSynonym() != null ? new String( getSynonym() ) : null,
127                                     getRank() != null ? new String( getRank() ) : null,
128                                     getId() != null ? new String( getId() ) : null );
129     }
130
131     public String getCode() {
132         return _code;
133     }
134
135     public String getCommonName() {
136         return _common_name;
137     }
138
139     public String getId() {
140         return _id;
141     }
142
143     public String[] getLineage() {
144         return _lineage;
145     }
146
147     public String getRank() {
148         return _rank;
149     }
150
151     public String getScientificName() {
152         return _scientific_name;
153     }
154
155     public String getSynonym() {
156         return _synonym;
157     }
158 }