in progress...
[jalview.git] / forester / java / src / org / forester / protein / BasicProtein.java
index b33082c..91f5eb4 100644 (file)
@@ -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<DomainId> query_domain_ids, final boolean in_nc_order ) {
+    public boolean contains( final List<String> 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<Domain> found_domains = getProteinDomains( query_domain_id );
                     final SortedSet<Integer> ordered_start_positions = new TreeSet<Integer>();
@@ -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<Domain> getProteinDomains( final DomainId domain_id ) {
+    public List<Domain> getProteinDomains( final String domain_id ) {
         final List<Domain> domains = new ArrayList<Domain>();
         for( final Domain domain : getProteinDomains() ) {
             if ( domain.getDomainId().equals( domain_id ) ) {
@@ -213,52 +215,76 @@ 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;
-            }
-            else {
-                sb.append( separator );
+            if ( ( ie_cutoff <= -1 ) || ( d.getPerDomainEvalue() <= ie_cutoff ) ) {
+                if ( first ) {
+                    first = false;
+                }
+                else {
+                    sb.append( separator );
+                }
+                sb.append( d.getDomainId() );
             }
-            sb.append( d.getDomainId().getId() );
         }
         return sb.toString();
     }
+    
+    
+    
+    public final String toDomainArchitectureString( final String separator ) {
+        return toDomainArchitectureString( separator, -1 );
+    }
 
-    public String toDomainArchitectureString( final String separator, int max_repeats ) {
-        if ( max_repeats < 2 ) {
-            throw new IllegalArgumentException( "max repeats cannot be smaller than 2" );
+    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();
-        boolean first = true;
+        StringBuilder buffer = new StringBuilder();
         String prev_id = "";
-        int counter = 0;
+        int counter = 1;
         for( final Domain d : getDomainsSortedByPosition() ) {
-            if ( first ) {
-                first = false;
-            }
-            else {
-                sb.append( separator );
-            }
-            if ( prev_id.equals( d.getDomainId().getId() ) ) {
+            final String id = d.getDomainId();
+            if ( prev_id.equals( id ) ) {
                 counter++;
             }
             else {
-                counter = 0;
+                counter = 1;
+                sb.append( buffer );
+                buffer = new StringBuilder();
+            }
+            if ( counter < repeats_limit ) {
+                buffer.append( id );
+                buffer.append( separator );
             }
-            if ( counter >= max_repeats ) {
+            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 );
             }
-            sb.append( d.getDomainId().getId() );
-            prev_id = d.getDomainId().getId();
+            prev_id = id;
         }
+        sb.append( buffer.substring( 0, buffer.length() - 1 ) );
         return sb.toString();
     }
 
-    private List<DomainId> getProteinDomainIds() {
-        final List<DomainId> ids = new ArrayList<DomainId>( getProteinDomains().size() );
+    @Override
+    public String toString() {
+        return toDomainArchitectureString( "--", 1 );
+    }
+
+    private List<String> getProteinDomainIds() {
+        final List<String> ids = new ArrayList<String>( getProteinDomains().size() );
         for( final Domain domain : getProteinDomains() ) {
             ids.add( domain.getDomainId() );
         }