3 // FORESTER -- software libraries and applications
4 // for evolutionary biology research and applications.
6 // Copyright (C) 2008-2009 Christian M. Zmasek
7 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 // Contact: phylosoft @ gmail . com
25 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
27 package org.forester.protein;
29 import org.forester.util.ForesterUtil;
31 public class BasicDomain implements Domain {
33 final private String _id;
34 final private int _from;
35 final private int _to;
36 final private short _number;
37 final private short _total_count;
38 final private double _per_sequence_evalue;
39 final private double _per_sequence_score;
40 final private double _per_domain_evalue;
41 final private double _per_domain_score;
43 public BasicDomain( final String id ) {
44 if ( ForesterUtil.isEmpty( id ) ) {
45 throw new IllegalArgumentException( "attempt to create protein domain with null or empty id" );
52 _per_sequence_evalue = -1;
53 _per_sequence_score = -1;
54 _per_domain_evalue = -1;
55 _per_domain_score = -1;
58 public BasicDomain( final String id,
62 final short total_count,
63 final double per_sequence_evalue,
64 final double per_sequence_score ) {
65 this( id, from, to, number, total_count, per_sequence_evalue, per_sequence_score, 0, 0 );
68 public BasicDomain( final String id,
72 final short total_count,
73 final double per_sequence_evalue,
74 final double per_sequence_score,
75 final double per_domain_evalue,
76 final double per_domain_score ) {
77 if ( ( from >= to ) || ( from < 0 ) ) {
78 throw new IllegalArgumentException( "attempt to create protein domain from " + from + " to " + to );
80 if ( ForesterUtil.isEmpty( id ) ) {
81 throw new IllegalArgumentException( "attempt to create protein domain with null or empty id" );
83 if ( ( number > total_count ) || ( number < 0 ) ) {
84 throw new IllegalArgumentException( "attempt to create protein domain number " + number + " out of "
87 if ( ( per_sequence_evalue < 0.0 ) || ( per_domain_evalue < 0.0 ) ) {
88 throw new IllegalArgumentException( "attempt to create protein domain with negative E-value" );
94 _total_count = total_count;
95 _per_sequence_evalue = per_sequence_evalue;
96 _per_sequence_score = per_sequence_score;
97 _per_domain_evalue = per_domain_evalue;
98 _per_domain_score = per_domain_score;
102 // ^^ public void addGoId( final GoId go_id ) {
103 // ^^ getDomainId().getGoIds().add( go_id );
106 * Basic domains are compared/sorted based upon their identifiers (case
107 * insensitive) and their numbers.
111 public int compareTo( final Domain domain ) {
112 if ( domain.getClass() != this.getClass() ) {
113 throw new IllegalArgumentException( "attempt to compare [" + domain.getClass() + "] to " + "["
114 + this.getClass() + "]" );
116 if ( this == domain ) {
119 return getDomainId().compareTo( domain.getDomainId() );
123 * Basic domains are considered equal if they have the same identifier (case
128 public boolean equals( final Object o ) {
132 else if ( o == null ) {
133 throw new IllegalArgumentException( "attempt to check [" + this.getClass() + "] equality to null" );
135 else if ( o.getClass() != this.getClass() ) {
136 throw new IllegalArgumentException( "attempt to check [" + this.getClass() + "] equality to " + o + " ["
137 + o.getClass() + "]" );
140 return getDomainId().equals( ( ( Domain ) o ).getDomainId() );
145 public String getDomainId() {
150 public int getFrom() {
155 // ^^ public GoId getGoId( final int i ) {
156 // ^^ return getDomainId().getGoIds().get( i );
159 public short getNumber() {
164 // ^^ public int getNumberOfGoIds() {
165 // ^^ return getDomainId().getGoIds().size();
168 public double getPerDomainEvalue() {
169 return _per_domain_evalue;
173 public double getPerDomainScore() {
174 return _per_domain_score;
178 public double getPerSequenceEvalue() {
179 return _per_sequence_evalue;
183 public double getPerSequenceScore() {
184 return _per_sequence_score;
193 public short getTotalCount() {
198 public int hashCode() {
199 return getDomainId().hashCode();
203 public String toString() {
204 return getDomainId();
207 public StringBuffer toStringBuffer() {
208 return new StringBuffer( getDomainId() );
212 public int getLength() {
213 return ( 1 + getTo() ) - getFrom();