X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fprotein%2FBasicDomain.java;h=b7ab1d8cc26dfce4b7f66205037f329b803660d4;hb=2320da44a171273ec44c0adcaf991687a4780b6e;hp=0232b912370f4a21defffde13f1d56e2f1ed78ec;hpb=656be28debec520e0e35a8b311114398a40ea366;p=jalview.git diff --git a/forester/java/src/org/forester/protein/BasicDomain.java b/forester/java/src/org/forester/protein/BasicDomain.java index 0232b91..b7ab1d8 100644 --- a/forester/java/src/org/forester/protein/BasicDomain.java +++ b/forester/java/src/org/forester/protein/BasicDomain.java @@ -26,88 +26,121 @@ 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; + final private short _hmm_len; + final private short _hmm_from; + final private short _hmm_to; + + 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; + _hmm_len = -1; + _hmm_from= -1; + _hmm_to= -1; + } - 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 ) { - this( id_str, from, to, number, total_count, per_sequence_evalue, per_sequence_score, 0, 0 ); + 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 ) ) { + 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_domain_evalue < 0.0 ) { + throw new IllegalArgumentException( "attempt to create protein domain with negative E-value" ); + } + _id = obtainIdAsShort( id ); + _from = from; + _to = to; + _number = number; + _total_count = total_count; + _per_domain_evalue = per_domain_evalue; + _per_domain_score = per_domain_score; + _hmm_len = -1; + _hmm_from= -1; + _hmm_to= -1; } - - 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 ) { + final double per_domain_score, + final short hmm_len, + final short hmm_from, + final short hmm_to) { 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 ); + if ( ( hmm_from >= hmm_to ) || ( hmm_from < 0 ) ) { + throw new IllegalArgumentException( "attempt to create protein domain matching hmm from " + from + " to " + to ); + } + if ( hmm_len <= 0 ) { + throw new IllegalArgumentException( "attempt to create protein domain with zero or negative hmm length" ); + } + _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 ); + _hmm_len = hmm_len; + _hmm_from= hmm_from; + _hmm_to= hmm_to; } /** * Basic domains are compared/sorted based upon their identifiers (case * insensitive) and their numbers. - * + * */ @Override public int compareTo( final Domain domain ) { @@ -124,7 +157,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 +177,8 @@ public class BasicDomain implements Domain { } @Override - public DomainId getDomainId() { - return _id; + public String getDomainId() { + return obtainIdFromShort( _id ); } @Override @@ -154,8 +187,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 +197,6 @@ public class BasicDomain implements Domain { } @Override - public int getNumberOfGoIds() { - return getDomainId().getGoIds().size(); - } - - @Override public double getPerDomainEvalue() { return _per_domain_evalue; } @@ -179,41 +207,59 @@ public class BasicDomain implements Domain { } @Override - public double getPerSequenceEvalue() { - return _per_sequence_evalue; + public int getTo() { + return _to; } @Override - public double getPerSequenceScore() { - return _per_sequence_score; + public short getTotalCount() { + return _total_count; } @Override - public int getTo() { - return _to; + public final short getHmmLen() { + return _hmm_len; } @Override - public short getTotalCount() { - return _total_count; + public final short getHmmFrom() { + return _hmm_from; } @Override + public final short getHmmTo() { + return _hmm_to; + } + + @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 ); + } + + }