inprogress
[jalview.git] / forester / java / src / org / forester / msa / DeleteableMsa.java
index 9f18924..172ce4d 100644 (file)
@@ -50,6 +50,38 @@ public final class DeleteableMsa extends BasicMsa {
         _seqs = msa.getNumberOfSequences();
     }
 
+    public final double[] calcGappiness() {
+        final int length = getLength();
+        final double gappiness[] = new double[ length ];
+        final int seqs = getNumberOfSequences();
+        for( int row = 0; row < seqs; ++row ) {
+            for( int col = 0; col < length; ++col ) {
+            }
+        }
+        return gappiness;
+    }
+
+    public static int calcGapSumPerColumn( final Msa msa, final int col ) {
+        int gap_rows = 0;
+        for( int j = 0; j < msa.getNumberOfSequences(); ++j ) {
+            if ( msa.isGapAt( j, col ) ) {
+                gap_rows++;
+            }
+        }
+        return gap_rows;
+    }
+
+    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 );
@@ -70,7 +102,7 @@ public final class DeleteableMsa extends BasicMsa {
         }
     }
 
-    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 +113,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