X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fprotein%2FBasicDomain.java;h=b1328987768593d50f4bffb584ec4b288ea29a32;hb=e572f0142daf64409db0461f15215288137603f8;hp=c6c528878a4aba6cf6510c4ab48a1ab6e840f8e0;hpb=03e51d179caedf757b09e2872f9500318bd85a53;p=jalview.git diff --git a/forester/java/src/org/forester/protein/BasicDomain.java b/forester/java/src/org/forester/protein/BasicDomain.java index c6c5288..b132898 100644 --- a/forester/java/src/org/forester/protein/BasicDomain.java +++ b/forester/java/src/org/forester/protein/BasicDomain.java @@ -22,92 +22,74 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA // // Contact: phylosoft @ gmail . com -// WWW: www.phylosoft.org/forester +// WWW: https://sites.google.com/site/cmzmasek/home/software/forester package org.forester.protein; -import org.forester.go.GoId; +import java.util.HashMap; +import java.util.Map; + import org.forester.util.ForesterUtil; public class BasicDomain implements Domain { - final private DomainId _id; - final private int _from; - final private int _to; - final private short _number; - final private short _total_count; - final private double _per_sequence_evalue; - final private double _per_sequence_score; - final private double _per_domain_evalue; - final private double _per_domain_score; - - public BasicDomain( final String id_str ) { - if ( ForesterUtil.isEmpty( id_str ) ) { + private static short COUNT = 0; + private final static Map ID_TO_STRING = new HashMap(); + private final static Map STRING_TO_ID = new HashMap(); + final private int _from; + final private short _id; + final private short _number; + final private double _per_domain_evalue; + final private double _per_domain_score; + final private int _to; + final private short _total_count; + + public BasicDomain( final String id ) { + if ( ForesterUtil.isEmpty( id ) ) { throw new IllegalArgumentException( "attempt to create protein domain with null or empty id" ); } - _id = new DomainId( id_str ); + _id = obtainIdAsShort( id ); _from = -1; _to = -1; _number = -1; _total_count = -1; - _per_sequence_evalue = -1; - _per_sequence_score = -1; _per_domain_evalue = -1; _per_domain_score = -1; } - public BasicDomain( final String id_str, - final int from, - final int to, - final short number, - final short total_count, - final double per_sequence_evalue, - final double per_sequence_score ) { - this( id_str, from, to, number, total_count, per_sequence_evalue, per_sequence_score, 0, 0 ); - } - - public BasicDomain( final String id_str, + public BasicDomain( final String id, final int from, final int to, final short number, final short total_count, - final double per_sequence_evalue, - final double per_sequence_score, final double per_domain_evalue, final double per_domain_score ) { if ( ( from >= to ) || ( from < 0 ) ) { throw new IllegalArgumentException( "attempt to create protein domain from " + from + " to " + to ); } - if ( ForesterUtil.isEmpty( id_str ) ) { + if ( ForesterUtil.isEmpty( id ) ) { throw new IllegalArgumentException( "attempt to create protein domain with null or empty id" ); } if ( ( number > total_count ) || ( number < 0 ) ) { throw new IllegalArgumentException( "attempt to create protein domain number " + number + " out of " + total_count ); } - if ( ( per_sequence_evalue < 0.0 ) || ( per_domain_evalue < 0.0 ) ) { + if ( per_domain_evalue < 0.0 ) { throw new IllegalArgumentException( "attempt to create protein domain with negative E-value" ); } - _id = new DomainId( id_str ); + _id = obtainIdAsShort( id ); _from = from; _to = to; _number = number; _total_count = total_count; - _per_sequence_evalue = per_sequence_evalue; - _per_sequence_score = per_sequence_score; _per_domain_evalue = per_domain_evalue; _per_domain_score = per_domain_score; } - @Override - public void addGoId( final GoId go_id ) { - getDomainId().getGoIds().add( go_id ); - } - /** * Basic domains are compared/sorted based upon their identifiers (case * insensitive) and their numbers. - * + * */ @Override public int compareTo( final Domain domain ) { @@ -124,7 +106,7 @@ public class BasicDomain implements Domain { /** * Basic domains are considered equal if they have the same identifier (case * sensitive). - * + * */ @Override public boolean equals( final Object o ) { @@ -144,8 +126,8 @@ public class BasicDomain implements Domain { } @Override - public DomainId getDomainId() { - return _id; + public String getDomainId() { + return obtainIdFromShort( _id ); } @Override @@ -154,8 +136,8 @@ public class BasicDomain implements Domain { } @Override - public GoId getGoId( final int i ) { - return getDomainId().getGoIds().get( i ); + public int getLength() { + return ( 1 + getTo() ) - getFrom(); } @Override @@ -164,11 +146,6 @@ public class BasicDomain implements Domain { } @Override - public int getNumberOfGoIds() { - return getDomainId().getGoIds().size(); - } - - @Override public double getPerDomainEvalue() { return _per_domain_evalue; } @@ -179,16 +156,6 @@ public class BasicDomain implements Domain { } @Override - public double getPerSequenceEvalue() { - return _per_sequence_evalue; - } - - @Override - public double getPerSequenceScore() { - return _per_sequence_score; - } - - @Override public int getTo() { return _to; } @@ -200,20 +167,31 @@ public class BasicDomain implements Domain { @Override public int hashCode() { - return getDomainId().getId().hashCode(); + return getDomainId().hashCode(); } @Override public String toString() { - return toStringBuffer().toString(); + return getDomainId(); } public StringBuffer toStringBuffer() { - return new StringBuffer( getDomainId().getId() ); + return new StringBuffer( getDomainId() ); } - @Override - public int getLength() { - return ( 1 + getTo() ) - getFrom(); + public final static short obtainIdAsShort( final String id ) { + if ( !STRING_TO_ID.containsKey( id ) ) { + if ( COUNT >= ( Short.MAX_VALUE - 2 ) ) { + throw new RuntimeException( "too many domain ids!" ); + } + ID_TO_STRING.put( COUNT, id ); + STRING_TO_ID.put( id, COUNT ); + ++COUNT; + } + return STRING_TO_ID.get( id ); + } + + public final static String obtainIdFromShort( final short id ) { + return ID_TO_STRING.get( id ); } }