X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fprotein%2FBasicProtein.java;h=edece19a8b9ee8119dd2fdb878c277b8b1edbfab;hb=b5fe992f707cdad84255eb85040effbee97d61b3;hp=b9c8cbe5f5934040ec57f55e9f791f11e62ee8e4;hpb=ce9e2773527fda17dcd058c8432a3bffbfadecdc;p=jalview.git diff --git a/forester/java/src/org/forester/protein/BasicProtein.java b/forester/java/src/org/forester/protein/BasicProtein.java index b9c8cbe..edece19 100644 --- a/forester/java/src/org/forester/protein/BasicProtein.java +++ b/forester/java/src/org/forester/protein/BasicProtein.java @@ -55,9 +55,11 @@ public class BasicProtein implements Protein { final Domain d2 ) { final int m1 = ( d1.getTo() + d1.getFrom() ); final int m2 = ( d2.getTo() + d2.getFrom() ); - return m1 < m2 ? -1 : m1 > m2 ? 1 : d1 - .getDomainId().getId() - .compareTo( d2.getDomainId().getId() ); + return m1 < m2 ? -1 + : m1 > m2 ? 1 + : d1.getDomainId() + .compareTo( d2 + .getDomainId() ); } }; @@ -88,17 +90,17 @@ public class BasicProtein implements Protein { * If in_nc_order is set to true, this returns true only and only if * the order in List 'domains' and this protein (as determined by the start positions * of the domains of this proteins, _not_ by their index) are the same - * (interspersing, 'other', domains in this are ignored). + * (interspersing, 'other', domains in this are ignored). * If in_nc_order is set to false, this returns true only and only if * this contains all domains listed in 'domains' (order and count do not matter). - * + * * @param domains a list of domain ids in a certain order. * @param in_nc_order to consider order * @return */ - public boolean contains( final List query_domain_ids, final boolean in_nc_order ) { + public boolean contains( final List query_domain_ids, final boolean in_nc_order ) { if ( !in_nc_order ) { - for( final DomainId query_domain_id : query_domain_ids ) { + for( final String query_domain_id : query_domain_ids ) { if ( !getProteinDomainIds().contains( query_domain_id ) ) { return false; } @@ -107,7 +109,7 @@ public class BasicProtein implements Protein { } else { int current_start_position = -1; - I: for( final DomainId query_domain_id : query_domain_ids ) { + I: for( final String query_domain_id : query_domain_ids ) { if ( getProteinDomainIds().contains( query_domain_id ) ) { final List found_domains = getProteinDomains( query_domain_id ); final SortedSet ordered_start_positions = new TreeSet(); @@ -171,7 +173,7 @@ public class BasicProtein implements Protein { } @Override - public int getProteinDomainCount( final DomainId domain_id ) { + public int getProteinDomainCount( final String domain_id ) { return getProteinDomains( domain_id ).size(); } @@ -181,7 +183,7 @@ public class BasicProtein implements Protein { } @Override - public List getProteinDomains( final DomainId domain_id ) { + public List getProteinDomains( final String domain_id ) { final List domains = new ArrayList(); for( final Domain domain : getProteinDomains() ) { if ( domain.getDomainId().equals( domain_id ) ) { @@ -213,23 +215,74 @@ public class BasicProtein implements Protein { _name = name; } - public String toDomainArchitectureString( final String separator ) { + @Override + public final String toDomainArchitectureString( final String separator, final double ie_cutoff ) { final StringBuilder sb = new StringBuilder(); boolean first = true; for( final Domain d : getDomainsSortedByPosition() ) { - if ( first ) { - first = false; + if ( ( ie_cutoff <= -1 ) || ( d.getPerDomainEvalue() <= ie_cutoff ) ) { + if ( first ) { + first = false; + } + else { + sb.append( separator ); + } + sb.append( d.getDomainId() ); + } + } + return sb.toString(); + } + + public final String toDomainArchitectureString( final String separator ) { + return toDomainArchitectureString( separator, -1 ); + } + + public String toDomainArchitectureString( final String separator, + final int repeats_limit, + final String repeat_separator ) { + if ( repeats_limit < 3 ) { + throw new IllegalArgumentException( "repeats limit cannot be smaller than 3" ); + } + final StringBuilder sb = new StringBuilder(); + StringBuilder buffer = new StringBuilder(); + String prev_id = ""; + int counter = 1; + for( final Domain d : getDomainsSortedByPosition() ) { + final String id = d.getDomainId(); + if ( prev_id.equals( id ) ) { + counter++; } else { - sb.append( separator ); + counter = 1; + sb.append( buffer ); + buffer = new StringBuilder(); + } + if ( counter < repeats_limit ) { + buffer.append( id ); + buffer.append( separator ); } - sb.append( d.getDomainId().getId() ); + else if ( counter == repeats_limit ) { + buffer = new StringBuilder(); + buffer.append( id ); + buffer.append( repeat_separator ); + buffer.append( id ); + buffer.append( repeat_separator ); + buffer.append( id ); + buffer.append( separator ); + } + prev_id = id; } + sb.append( buffer.substring( 0, buffer.length() - 1 ) ); return sb.toString(); } - private List getProteinDomainIds() { - final List ids = new ArrayList( getProteinDomains().size() ); + @Override + public String toString() { + return toDomainArchitectureString( "--", 1 ); + } + + private List getProteinDomainIds() { + final List ids = new ArrayList( getProteinDomains().size() ); for( final Domain domain : getProteinDomains() ) { ids.add( domain.getDomainId() ); }