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: https://sites.google.com/site/cmzmasek/home/software/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;
73 public StringBuffer asSimpleText() {
74 return new StringBuffer( getGoId().toString() );
78 public StringBuffer asText() {
79 return new StringBuffer( toString() );
83 * Compares based on GO id.
87 public int compareTo( final GoTerm go_term ) {
88 return getGoId().compareTo( go_term.getGoId() );
92 * Makes a shallow copy.
97 public PhylogenyData copy() {
98 final BasicGoTerm gt = new BasicGoTerm( getGoId(), getName(), getGoNameSpace(), isObsolete() );
99 gt.setGoXrefs( getGoXRefs() );
100 gt.setGoSubsets( getGoSubsets() );
101 gt.setSuperTerms( getSuperGoIds() );
102 gt.setAltIds( getAltIds() );
103 gt.setDefinition( getDefinition() );
108 * Return true if both GO id and namespace are equal.
112 public boolean equals( final Object o ) {
116 else if ( o == null ) {
117 throw new IllegalArgumentException( "attempt to check go term equality to null" );
119 else if ( o.getClass() != this.getClass() ) {
120 throw new IllegalArgumentException( "attempt to check go term equality to " + o + " [" + o.getClass() + "]" );
123 final GoTerm gt = ( GoTerm ) o;
124 return getGoNameSpace().equals( gt.getGoNameSpace() ) && getGoId().equals( gt.getGoId() );
129 public List<GoId> getAltIds() {
134 public String getComment() {
139 public String getDefinition() {
144 public GoId getGoId() {
149 public GoNameSpace getGoNameSpace() {
154 public List<GoRelationship> getGoRelationships() {
155 return _go_relationships;
159 public List<GoSubset> getGoSubsets() {
164 public List<GoXRef> getGoXRefs() {
169 public String getName() {
174 public List<GoId> getSuperGoIds() {
175 return _super_go_ids;
179 * Hashcode is based on hashcode of GO id.
184 public int hashCode() {
185 return getGoId().hashCode();
188 private void init() {
189 setGoXrefs( new ArrayList<GoXRef>() );
190 setSuperTerms( new ArrayList<GoId>() );
191 setAltIds( new ArrayList<GoId>() );
192 setGoRelationships( new ArrayList<GoRelationship>() );
193 setGoSubsets( new ArrayList<GoSubset>() );
199 public boolean isEqual( final PhylogenyData go_term ) {
200 return equals( go_term );
204 public boolean isObsolete() {
208 private void setAltIds( final List<GoId> alt_ids ) {
212 public void setComment( final String comment ) {
216 public void setDefinition( final String definition ) {
217 _definition = definition;
220 private void setGoRelationships( final List<GoRelationship> go_relationships ) {
221 _go_relationships = go_relationships;
224 public void setGoSubsets( final List<GoSubset> go_subsets ) {
225 _go_subsets = go_subsets;
228 private void setGoXrefs( final List<GoXRef> xrefs ) {
232 private void setSuperTerms( final List<GoId> super_terms ) {
233 _super_go_ids = super_terms;
237 public StringBuffer toNHX() {
238 throw new UnsupportedOperationException();
242 public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
243 throw new UnsupportedOperationException();
247 public String toString() {
248 final StringBuffer sb = new StringBuffer();
249 sb.append( getGoId() );
251 sb.append( getName() );
253 sb.append( getGoNameSpace() );
255 if ( isObsolete() ) {
256 sb.append( " [is obsolete]" );
258 return sb.toString();