2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
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.go;
28 import java.io.IOException;
29 import java.io.Writer;
30 import java.util.ArrayList;
31 import java.util.List;
33 import org.forester.phylogeny.data.PhylogenyData;
34 import org.forester.util.ForesterUtil;
36 public class BasicGoTerm implements GoTerm {
38 private final GoId _id;
39 private final String _name;
40 private final boolean _is_obsolete;
41 private final GoNameSpace _namespace;
42 private String _definition;
43 private List<GoId> _alt_ids;
44 private List<GoId> _super_go_ids;
45 private List<GoXRef> _go_xrefs;
46 private List<GoSubset> _go_subsets;
47 private String _comment;
48 private List<GoRelationship> _go_relationships;
50 public BasicGoTerm( final GoId id, final String name, final GoNameSpace namespace, final boolean is_obsolete ) {
51 if ( ( id == null ) || ForesterUtil.isEmpty( name ) || ( namespace == null ) ) {
52 throw new IllegalArgumentException( "attempt to create GO term with empty id, name, or namespace" );
56 _namespace = namespace;
57 _is_obsolete = is_obsolete;
61 public BasicGoTerm( final String id, final String name, final String namespace, final boolean is_obsolete ) {
62 if ( ForesterUtil.isEmpty( id ) || ForesterUtil.isEmpty( name ) || ForesterUtil.isEmpty( namespace ) ) {
63 throw new IllegalArgumentException( "attempt to create GO term with empty id, name, or namespace" );
67 _namespace = new GoNameSpace( namespace );
68 _is_obsolete = is_obsolete;
72 public StringBuffer asSimpleText() {
73 return new StringBuffer( getGoId().toString() );
76 public StringBuffer asText() {
77 return new StringBuffer( toString() );
81 * Compares based on GO id.
84 public int compareTo( final GoTerm go_term ) {
85 return getGoId().compareTo( go_term.getGoId() );
89 * Makes a shallow copy.
93 public PhylogenyData copy() {
94 final BasicGoTerm gt = new BasicGoTerm( getGoId(), getName(), getGoNameSpace(), isObsolete() );
95 gt.setGoXrefs( getGoXRefs() );
96 gt.setGoSubsets( getGoSubsets() );
97 gt.setSuperTerms( getSuperGoIds() );
98 gt.setAltIds( getAltIds() );
99 gt.setDefinition( getDefinition() );
104 * Return true if both GO id and namespace are equal.
108 public boolean equals( final Object o ) {
112 else if ( o == null ) {
113 throw new IllegalArgumentException( "attempt to check go term equality to null" );
115 else if ( o.getClass() != this.getClass() ) {
116 throw new IllegalArgumentException( "attempt to check go term equality to " + o + " [" + o.getClass() + "]" );
119 final GoTerm gt = ( GoTerm ) o;
120 return getGoNameSpace().equals( gt.getGoNameSpace() ) && getGoId().equals( gt.getGoId() );
124 public List<GoId> getAltIds() {
129 public String getComment() {
134 public String getDefinition() {
138 public GoId getGoId() {
142 public GoNameSpace getGoNameSpace() {
147 public List<GoRelationship> getGoRelationships() {
148 return _go_relationships;
152 public List<GoSubset> getGoSubsets() {
156 public List<GoXRef> getGoXRefs() {
160 public String getName() {
164 public List<GoId> getSuperGoIds() {
165 return _super_go_ids;
169 * Hashcode is based on hashcode of GO id.
174 public int hashCode() {
175 return getGoId().hashCode();
178 private void init() {
179 setGoXrefs( new ArrayList<GoXRef>() );
180 setSuperTerms( new ArrayList<GoId>() );
181 setAltIds( new ArrayList<GoId>() );
182 setGoRelationships( new ArrayList<GoRelationship>() );
183 setGoSubsets( new ArrayList<GoSubset>() );
188 public boolean isEqual( final PhylogenyData go_term ) {
189 return equals( go_term );
192 public boolean isObsolete() {
196 private void setAltIds( final List<GoId> alt_ids ) {
200 public void setComment( final String comment ) {
204 public void setDefinition( final String definition ) {
205 _definition = definition;
208 private void setGoRelationships( final List<GoRelationship> go_relationships ) {
209 _go_relationships = go_relationships;
212 public void setGoSubsets( final List<GoSubset> go_subsets ) {
213 _go_subsets = go_subsets;
216 private void setGoXrefs( final List<GoXRef> xrefs ) {
220 private void setSuperTerms( final List<GoId> super_terms ) {
221 _super_go_ids = super_terms;
224 public StringBuffer toNHX() {
225 throw new UnsupportedOperationException();
228 public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
229 throw new UnsupportedOperationException();
233 public String toString() {
234 final StringBuffer sb = new StringBuffer();
235 sb.append( getGoId() );
237 sb.append( getName() );
239 sb.append( getGoNameSpace() );
241 if ( isObsolete() ) {
242 sb.append( " [is obsolete]" );
244 return sb.toString();