inprogress
[jalview.git] / forester / java / src / org / forester / protein / BasicProtein.java
index b9c8cbe..e17862f 100644 (file)
@@ -228,6 +228,50 @@ public class BasicProtein implements Protein {
         return sb.toString();
     }
 
+    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().getId();
+            if ( prev_id.equals( id ) ) {
+                counter++;
+            }
+            else {
+                counter = 1;
+                sb.append( buffer );
+                buffer = new StringBuilder();
+            }
+            if ( counter < repeats_limit ) {
+                buffer.append( id );
+                buffer.append( separator );
+            }
+            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();
+    }
+
+    @Override
+    public String toString() {
+        return toDomainArchitectureString( "~" );
+    }
+
     private List<DomainId> getProteinDomainIds() {
         final List<DomainId> ids = new ArrayList<DomainId>( getProteinDomains().size() );
         for( final Domain domain : getProteinDomains() ) {