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 public class BasicGoXRef implements GoXRef {
30 private final String _xref;
31 private final Type _type;
33 public BasicGoXRef( final String s ) {
34 final String[] sa = s.split( ":" );
35 if ( sa.length < 2 ) {
36 throw new IllegalArgumentException( "unexpected format for GO xref: " + s );
38 final String type = sa[ 0 ].trim();
39 if ( type.equals( EC_STR ) ) {
42 else if ( type.equals( META_CYC_STR ) ) {
43 _type = Type.META_CYC;
45 else if ( type.equals( REACTOME_STR ) ) {
46 _type = Type.REACTOME;
48 else if ( type.equals( RESID_STR ) ) {
51 else if ( type.equals( UM_BBD_ENZYME_ID_STR ) ) {
52 _type = Type.UM_BBD_ENZYME_ID;
54 else if ( type.equals( UM_BBD_PATHWAY_ID_STR ) ) {
55 _type = Type.UM_BBD_PATHWAY_ID;
57 else if ( type.equals( UM_BBD_REACTIONID_STR ) ) {
58 _type = Type.UM_BBD_REACTIONID;
60 else if ( type.equals( TC_STR ) ) {
63 else if ( type.equals( ARACYC_STR ) ) {
66 else if ( type.equals( XX_STR ) ) {
69 else if ( type.equals( PMID_STR ) ) {
72 else if ( type.equals( IMG_STR ) ) {
75 else if ( type.equals( GOC_STR ) ) {
78 else if ( type.equals( KEGG_STR ) ) {
81 else if ( type.equals( WIKIPEDIA_STR ) ) {
82 _type = Type.WIKIPEDIA;
84 else if ( type.equals( RHEA_STR ) ) {
87 else if ( type.equals( NIF_SUBCELLULAR_STR ) ) {
88 _type = Type.NIF_SUBCELLULAR;
90 else if ( type.equals( CORUM_STR ) ) {
93 else if ( type.equals( UNIPATHWAY_STR ) ) {
94 _type = Type.UNIPATHWAY;
96 else if ( type.equals( PO_STR ) ) {
100 throw new IllegalArgumentException( "unknown GO xref type: " + type );
102 _xref = sa[ 1 ].trim();
105 public BasicGoXRef( final Type type, final String xref ) {
111 public int compareTo( final GoXRef xref ) {
112 return getXRef().compareTo( xref.getXRef() );
116 * Based on value and type.
121 public boolean equals( final Object o ) {
125 else if ( o == null ) {
126 throw new IllegalArgumentException( "attempt to check go xref equality to null" );
128 else if ( o.getClass() != this.getClass() ) {
129 throw new IllegalArgumentException( "attempt to check go xref equality to " + o + " [" + o.getClass() + "]" );
132 return getXRef().equals( ( ( GoXRef ) o ).getXRef() ) && getType().equals( ( ( GoXRef ) o ).getType() );
137 public Type getType() {
142 public String getXRef() {
147 public String toString() {
148 final StringBuffer sb = new StringBuffer();
149 switch ( getType() ) {
154 sb.append( META_CYC_STR );
157 sb.append( REACTOME_STR );
160 sb.append( RESID_STR );
162 case UM_BBD_ENZYME_ID:
163 sb.append( UM_BBD_ENZYME_ID_STR );
165 case UM_BBD_PATHWAY_ID:
166 sb.append( UM_BBD_PATHWAY_ID_STR );
168 case UM_BBD_REACTIONID:
169 sb.append( UM_BBD_REACTIONID_STR );
175 sb.append( ARACYC_STR );
181 sb.append( GOC_STR );
184 sb.append( IMG_STR );
187 sb.append( PMID_STR );
190 sb.append( WIKIPEDIA_STR );
193 new AssertionError( "unknown type: " + getType() );
196 sb.append( getXRef() );
197 return sb.toString();