fixed issue with cutting off of long names in pdf export + minor changes
[jalview.git] / forester / java / src / org / forester / msa / DeleteableMsa.java
index 05bf074..5126e47 100644 (file)
@@ -27,7 +27,7 @@ package org.forester.msa;
 import java.util.List;
 
 import org.forester.sequence.BasicSequence;
-import org.forester.sequence.Sequence;
+import org.forester.sequence.MolecularSequence;
 
 public final class DeleteableMsa extends BasicMsa {
 
@@ -50,6 +50,27 @@ 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 ) {
@@ -60,7 +81,7 @@ public final class DeleteableMsa extends BasicMsa {
         }
         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 );
@@ -81,7 +102,7 @@ public final class DeleteableMsa extends BasicMsa {
         }
     }
 
-    final public Sequence deleteRow( final String id ) {
+    final public MolecularSequence deleteRow( final String id, final boolean return_removed_seq ) {
         int row = -1;
         for( int r = 0; r < getNumberOfSequences(); ++r ) {
             if ( getIdentifier( r ).equals( id ) ) {
@@ -92,9 +113,25 @@ public final class DeleteableMsa extends BasicMsa {
         if ( row < 0 ) {
             throw new IllegalArgumentException( "id [" + id + "] not found" );
         }
-        final Sequence s = getSequence( row );
+        MolecularSequence s = null;
+        StringBuilder sb = null;
+        if ( return_removed_seq ) {
+            s = getSequence( row );
+            final char[] x = s.getMolecularSequence();
+            sb = new StringBuilder( x.length );
+            for( final char element : x ) {
+                if ( element != MolecularSequence.GAP ) {
+                    sb.append( element );
+                }
+            }
+        }
         deleteRow( row );
-        return s;
+        if ( return_removed_seq ) {
+            return new BasicSequence( new String( s.getIdentifier() ), sb.toString(), s.getType() );
+        }
+        else {
+            return null;
+        }
     }
 
     @Override
@@ -121,7 +158,7 @@ public final class DeleteableMsa extends BasicMsa {
     }
 
     @Override
-    public Sequence getSequence( final int row ) {
+    public MolecularSequence getSequence( final int row ) {
         checkRow( row );
         return new BasicSequence( getIdentifier( row ), getSequenceAsString( row ).toString(), getType() );
     }
@@ -129,7 +166,7 @@ public final class DeleteableMsa extends BasicMsa {
     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 ) {
+            if ( super.getResidueAt( _mapped_row_positions[ j ], m_col ) != MolecularSequence.GAP ) {
                 return false;
             }
         }
@@ -163,7 +200,7 @@ public final class DeleteableMsa extends BasicMsa {
 
     final private void deleteColumn( final int col ) {
         checkColumn( col );
-        for( int c = col; c < _length - 1; ++c ) {
+        for( int c = col; c < ( _length - 1 ); ++c ) {
             _mapped_col_positions[ c ] = _mapped_col_positions[ c + 1 ];
         }
         --_length;
@@ -171,13 +208,13 @@ public final class DeleteableMsa extends BasicMsa {
 
     final private void deleteRow( final int row ) {
         checkRow( row );
-        for( int r = row; r < _seqs - 1; ++r ) {
+        for( int r = row; r < ( _seqs - 1 ); ++r ) {
             _mapped_row_positions[ r ] = _mapped_row_positions[ r + 1 ];
         }
         --_seqs;
     }
 
-    public final static DeleteableMsa createInstance( final List<Sequence> seqs ) {
+    public final static DeleteableMsa createInstance( final List<MolecularSequence> seqs ) {
         return new DeleteableMsa( ( BasicMsa ) BasicMsa.createInstance( seqs ) );
     }