inprogress
[jalview.git] / forester / java / src / org / forester / msa / DeleteableMsa.java
index da781b8..350aae2 100644 (file)
@@ -50,6 +50,17 @@ public final class DeleteableMsa extends BasicMsa {
         _seqs = msa.getNumberOfSequences();
     }
 
+    public short determineMaxIdLength() {
+        short max = 0;
+        for( int row = 0; row < getNumberOfSequences(); ++row ) {
+            final short l = ( short ) getIdentifier( row ).length();
+            if ( l > max ) {
+                max = l;
+            }
+        }
+        return max;
+    }
+
     final public void deleteGapColumns( final double max_allowed_gap_ratio ) {
         if ( ( max_allowed_gap_ratio < 0 ) || ( max_allowed_gap_ratio > 1 ) ) {
             throw new IllegalArgumentException( "max allowed gap ration is out of range: " + max_allowed_gap_ratio );
@@ -64,13 +75,13 @@ public final class DeleteableMsa extends BasicMsa {
 
     final public void deleteGapOnlyColumns() {
         for( int col = getLength() - 1; col >= 0; --col ) {
-            if ( MsaMethods.calcGapSumPerColumn( this, col ) == getNumberOfSequences() ) {
+            if ( isAllGap( col ) ) {
                 deleteColumn( col );
             }
         }
     }
 
-    final public void deleteRow( final String id ) {
+    final public Sequence deleteRow( final String id, final boolean return_removed_seq ) {
         int row = -1;
         for( int r = 0; r < getNumberOfSequences(); ++r ) {
             if ( getIdentifier( r ).equals( id ) ) {
@@ -81,7 +92,25 @@ public final class DeleteableMsa extends BasicMsa {
         if ( row < 0 ) {
             throw new IllegalArgumentException( "id [" + id + "] not found" );
         }
+        Sequence s = null;
+        StringBuilder sb = null;
+        if ( return_removed_seq ) {
+            s = getSequence( row );
+            final char[] x = s.getMolecularSequence();
+            sb = new StringBuilder( x.length );
+            for( int i = 0; i < x.length; ++i ) {
+                if ( x[ i ] != Sequence.GAP ) {
+                    sb.append( x[ i ] );
+                }
+            }
+        }
         deleteRow( row );
+        if ( return_removed_seq ) {
+            return new BasicSequence( new String( s.getIdentifier() ), sb.toString(), s.getType() );
+        }
+        else {
+            return null;
+        }
     }
 
     @Override
@@ -113,6 +142,16 @@ public final class DeleteableMsa extends BasicMsa {
         return new BasicSequence( getIdentifier( row ), getSequenceAsString( row ).toString(), getType() );
     }
 
+    final public boolean isAllGap( final int col ) {
+        final int m_col = _mapped_col_positions[ col ];
+        for( int j = 0; j < getNumberOfSequences(); ++j ) {
+            if ( super.getResidueAt( _mapped_row_positions[ j ], m_col ) != Sequence.GAP ) {
+                return false;
+            }
+        }
+        return true;
+    }
+
     @Override
     final public void setIdentifier( final int row, final String id ) {
         checkRow( row );