From db8b10baefc3e1b5fee9b8192657ecc97ca5b86d Mon Sep 17 00:00:00 2001 From: "cmzmasek@gmail.com" Date: Tue, 22 Apr 2014 19:32:18 +0000 Subject: [PATCH] inprogress --- .../org/forester/application/msa_compactor.java | 5 +- .../archaeopteryx/tools/PhylogeneticInferrer.java | 2 +- .../org/forester/io/writers/SequenceWriter.java | 2 +- forester/java/src/org/forester/msa/BasicMsa.java | 42 +++------ .../java/src/org/forester/msa/DeleteableMsa.java | 92 ++++++++++++------- forester/java/src/org/forester/msa/Msa.java | 2 - forester/java/src/org/forester/msa/MsaMethods.java | 17 +--- .../java/src/org/forester/msa/ResampleableMsa.java | 24 +++-- .../org/forester/msa_compactor/MsaCompactor.java | 5 +- .../src/org/forester/sequence/BasicSequence.java | 11 ++- forester/java/src/org/forester/test/Test.java | 95 ++++++++++++++------ 11 files changed, 173 insertions(+), 124 deletions(-) diff --git a/forester/java/src/org/forester/application/msa_compactor.java b/forester/java/src/org/forester/application/msa_compactor.java index 4b2aaa2..4c50028 100644 --- a/forester/java/src/org/forester/application/msa_compactor.java +++ b/forester/java/src/org/forester/application/msa_compactor.java @@ -31,7 +31,6 @@ import java.util.List; import org.forester.io.parsers.FastaParser; import org.forester.io.parsers.GeneralMsaParser; -import org.forester.msa.BasicMsa; import org.forester.msa.DeleteableMsa; import org.forester.msa.MsaInferrer; import org.forester.msa_compactor.MsaCompactor; @@ -91,10 +90,10 @@ public class msa_compactor { DeleteableMsa msa = null; final FileInputStream is = new FileInputStream( in ); if ( FastaParser.isLikelyFasta( in ) ) { - msa = new DeleteableMsa( ( BasicMsa ) FastaParser.parseMsa( is ) ); + msa = DeleteableMsa.createInstance( FastaParser.parseMsa( is ) ); } else { - msa = new DeleteableMsa( ( BasicMsa ) GeneralMsaParser.parse( is ) ); + msa = DeleteableMsa.createInstance( GeneralMsaParser.parse( is ) ); } if ( cla.isOptionSet( REMOVE_WORST_OFFENDERS_OPTION ) ) { worst_remove = cla.getOptionValueAsInt( REMOVE_WORST_OFFENDERS_OPTION ); diff --git a/forester/java/src/org/forester/archaeopteryx/tools/PhylogeneticInferrer.java b/forester/java/src/org/forester/archaeopteryx/tools/PhylogeneticInferrer.java index 20da0c3..f972745 100644 --- a/forester/java/src/org/forester/archaeopteryx/tools/PhylogeneticInferrer.java +++ b/forester/java/src/org/forester/archaeopteryx/tools/PhylogeneticInferrer.java @@ -203,7 +203,7 @@ public class PhylogeneticInferrer extends RunnableProcess { } final MsaMethods msa_tools = MsaMethods.createInstance(); if ( _options.isExecuteMsaProcessing() ) { - msa = msa_tools.removeGapColumns( _options.getMsaProcessingMaxAllowedGapRatio(), + msa = msa_tools.deleteGapColumns( _options.getMsaProcessingMaxAllowedGapRatio(), _options.getMsaProcessingMinAllowedLength(), msa ); if ( msa == null ) { diff --git a/forester/java/src/org/forester/io/writers/SequenceWriter.java b/forester/java/src/org/forester/io/writers/SequenceWriter.java index ddcb378..0829eb7 100644 --- a/forester/java/src/org/forester/io/writers/SequenceWriter.java +++ b/forester/java/src/org/forester/io/writers/SequenceWriter.java @@ -46,7 +46,7 @@ public class SequenceWriter { public static void toFasta( final Sequence seq, final Writer w, final int width ) throws IOException { w.write( ">" ); - w.write( seq.getIdentifier().toString() ); + w.write( seq.getIdentifier() ); w.write( ForesterUtil.LINE_SEPARATOR ); if ( ( width < 1 ) || ( width >= seq.getLength() ) ) { w.write( seq.getMolecularSequence() ); diff --git a/forester/java/src/org/forester/msa/BasicMsa.java b/forester/java/src/org/forester/msa/BasicMsa.java index 7d90c3c..4c00a30 100644 --- a/forester/java/src/org/forester/msa/BasicMsa.java +++ b/forester/java/src/org/forester/msa/BasicMsa.java @@ -26,6 +26,7 @@ package org.forester.msa; import java.io.IOException; +import java.io.StringWriter; import java.io.Writer; import java.util.ArrayList; import java.util.HashSet; @@ -72,7 +73,7 @@ public class BasicMsa implements Msa { private int determineMaxIdLength() { int max = 0; for( int row = 0; row < getNumberOfSequences(); ++row ) { - final int l = getIdentifier(row).length(); + final int l = getIdentifier( row ).length(); if ( l > max ) { max = l; } @@ -112,22 +113,17 @@ public class BasicMsa implements Msa { @Override public Sequence getSequence( final int row ) { - return new BasicSequence( getIdentifier( row ), getSequenceAsArray( row ), getType() ); + return new BasicSequence( getIdentifier( row ), _data[ row ], getType() ); } @Override public StringBuffer getSequenceAsString( final int row ) { - final StringBuffer sb = new StringBuffer(getLength() ); + final StringBuffer sb = new StringBuffer( getLength() ); for( int col = 0; col < getLength(); ++col ) { sb.append( getResidueAt( row, col ) ); } return sb; } - - @Override - public char[] getSequenceAsArray( final int row ) { - return _data[ row ]; - } @Override public TYPE getType() { @@ -146,16 +142,14 @@ public class BasicMsa implements Msa { @Override public String toString() { - final int max = determineMaxIdLength() + 1; - final StringBuffer sb = new StringBuffer(); - for( int row = 0; row < getNumberOfSequences(); ++row ) { - sb.append( ForesterUtil.pad( getIdentifier( row ).toString(), max, ' ', false ) ); - for( int col = 0; col < getLength(); ++col ) { - sb.append( getResidueAt( row, col ) ); - } - sb.append( ForesterUtil.LINE_SEPARATOR ); + final Writer w = new StringWriter(); + try { + write( w, MSA_FORMAT.PHYLIP ); + } + catch ( final IOException e ) { + e.printStackTrace(); } - return sb.toString(); + return w.toString(); } @Override @@ -196,20 +190,6 @@ public class BasicMsa implements Msa { final BasicMsa msa = new BasicMsa( seqs.size(), length, seqs.get( 0 ).getType() ); for( int row = 0; row < seqs.size(); ++row ) { final Sequence seq = seqs.get( row ); - // - // int x = length - seq.getLength(); - // if ( x > 0 ) { - // String a = ""; - // for( int i = 0; i < x; i++ ) { - // a += "-"; - // } - // seq = BasicSequence.createAaSequence( seq.getIdentifier(), seq.getMolecularSequenceAsString() + a ); - // } - // else { - // seq = BasicSequence.createAaSequence( seq.getIdentifier(), seq.getMolecularSequenceAsString() - // .substring( 0, length ) ); - // } - // if ( seq.getLength() != length ) { throw new IllegalArgumentException( "illegal attempt to build msa from sequences of unequal length [" + seq.getIdentifier() + "]" ); diff --git a/forester/java/src/org/forester/msa/DeleteableMsa.java b/forester/java/src/org/forester/msa/DeleteableMsa.java index 392f239..17f72bb 100644 --- a/forester/java/src/org/forester/msa/DeleteableMsa.java +++ b/forester/java/src/org/forester/msa/DeleteableMsa.java @@ -25,18 +25,20 @@ package org.forester.msa; import java.util.HashMap; +import java.util.List; -import org.forester.util.ForesterUtil; +import org.forester.sequence.BasicSequence; +import org.forester.sequence.Sequence; public final class DeleteableMsa extends BasicMsa { private int _length = 0; private int _mapped_col_positions[] = null; private int _mapped_row_positions[] = null; - private int _seqs = 0; private HashMap _seq_id_to_row_map = null; + private int _seqs = 0; - public DeleteableMsa( final BasicMsa msa ) { + private DeleteableMsa( final BasicMsa msa ) { super( msa ); _mapped_col_positions = new int[ msa.getLength() ]; _mapped_row_positions = new int[ msa.getNumberOfSequences() ]; @@ -53,36 +55,28 @@ public final class DeleteableMsa extends BasicMsa { _length = msa.getLength(); _seqs = msa.getNumberOfSequences(); } - - - @Override - public char[] getSequenceAsArray( final int row ) { - return super.getSequenceAsArray( _mapped_row_positions[ row ] ); - } - public void deleteColumn( final int col ) { - if ( col >= _length || col < 0 ) { - throw new IllegalArgumentException( "column " + col + " is out of range" ); + 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 ); } - for( int c = col; c < _length - 1; ++c ) { - _mapped_col_positions[ c ] = _mapped_col_positions[ c + 1 ]; + for( int col = getLength() - 1; col >= 0; --col ) { + final boolean delete = ( ( double ) MsaMethods.calcGapSumPerColumn( this, col ) / getNumberOfSequences() ) > max_allowed_gap_ratio; + if ( delete ) { + deleteColumn( col ); + } } - --_length; } - - - private void deleteRow( final int row ) { - if ( row >= _seqs || row < 0 ) { - throw new IllegalArgumentException( "row " + row + " is out of range" ); - } - for( int r = row; r < _seqs - 1; ++r ) { - _mapped_row_positions[ r ] = _mapped_row_positions[ r + 1 ]; + final public void deleteGapOnlyColumns() { + for( int col = getLength() - 1; col >= 0; --col ) { + if ( MsaMethods.calcGapSumPerColumn( this, col ) == getNumberOfSequences() ) { + deleteColumn( col ); + } } - --_seqs; } - public void deleteRow( final String id ) { + final public void deleteRow( final String id ) { int row = -1; for( int r = 0; r < getNumberOfSequences(); ++r ) { if ( getIdentifier( r ).equals( id ) ) { @@ -97,33 +91,65 @@ public final class DeleteableMsa extends BasicMsa { } @Override - public String getIdentifier( final int row ) { + final public String getIdentifier( final int row ) { return super.getIdentifier( _mapped_row_positions[ row ] ); } @Override - public int getLength() { + final public int getLength() { return _length; } @Override - public int getNumberOfSequences() { + final public int getNumberOfSequences() { return _seqs; } - @Override - public char getResidueAt( final int row, final int col ) { - return super.getResidueAt( _mapped_row_positions[ row ], _mapped_col_positions[ col ] ); + final public char getResidueAt( final int row, final int col ) { + return super.getResidueAt( _mapped_row_positions[ row ], _mapped_col_positions[ col ] ); } @Override - public void setIdentifier( final int row, final String id ) { + public Sequence getSequence( final int row ) { + return new BasicSequence( getIdentifier( row ), getSequenceAsString( row ).toString(), getType() ); + } + + @Override + final public void setIdentifier( final int row, final String id ) { super.setIdentifier( _mapped_row_positions[ row ], id ); } @Override - public void setResidueAt( final int row, final int col, final char residue ) { + final public void setResidueAt( final int row, final int col, final char residue ) { super.setResidueAt( _mapped_row_positions[ row ], _mapped_col_positions[ col ], residue ); } + + final private void deleteColumn( final int col ) { + if ( ( col >= _length ) || ( col < 0 ) ) { + throw new IllegalArgumentException( "column " + col + " is out of range" ); + } + for( int c = col; c < _length - 1; ++c ) { + _mapped_col_positions[ c ] = _mapped_col_positions[ c + 1 ]; + } + --_length; + } + + final private void deleteRow( final int row ) { + if ( ( row >= _seqs ) || ( row < 0 ) ) { + throw new IllegalArgumentException( "row " + row + " is out of range" ); + } + 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 seqs ) { + return new DeleteableMsa( ( BasicMsa ) BasicMsa.createInstance( seqs ) ); + } + + public final static DeleteableMsa createInstance( final Msa msa ) { + return new DeleteableMsa( ( BasicMsa ) msa ); + } } diff --git a/forester/java/src/org/forester/msa/Msa.java b/forester/java/src/org/forester/msa/Msa.java index ff2b110..648006a 100644 --- a/forester/java/src/org/forester/msa/Msa.java +++ b/forester/java/src/org/forester/msa/Msa.java @@ -65,6 +65,4 @@ public interface Msa { public void setResidueAt( final int row, final int col, final char residue ); public void write( Writer w, MSA_FORMAT format ) throws IOException; - - char[] getSequenceAsArray( int row ); } diff --git a/forester/java/src/org/forester/msa/MsaMethods.java b/forester/java/src/org/forester/msa/MsaMethods.java index 9975ab2..6499d92 100644 --- a/forester/java/src/org/forester/msa/MsaMethods.java +++ b/forester/java/src/org/forester/msa/MsaMethods.java @@ -111,7 +111,7 @@ public final class MsaMethods { return BasicMsa.createInstance( seqs ); } - synchronized final public Msa removeGapColumns( final double max_allowed_gap_ratio, + synchronized final public Msa deleteGapColumns( final double max_allowed_gap_ratio, final int min_allowed_length, final Msa msa ) { init(); @@ -122,7 +122,7 @@ public final class MsaMethods { final boolean[] delete_cols = new boolean[ msa.getLength() ]; int new_length = 0; for( int col = 0; col < msa.getLength(); ++col ) { - delete_cols[ col ] = ( ( double ) calcGapSumPerColumn( msa, col ) / msa.getNumberOfSequences() ) >= max_allowed_gap_ratio; + delete_cols[ col ] = ( ( double ) calcGapSumPerColumn( msa, col ) / msa.getNumberOfSequences() ) > max_allowed_gap_ratio; if ( !delete_cols[ col ] ) { ++new_length; } @@ -159,19 +159,6 @@ public final class MsaMethods { return BasicMsa.createInstance( seqs ); } - synchronized final public static void removeGapColumns( final double max_allowed_gap_ratio, final DeleteableMsa msa ) { - 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 ); - } - // final boolean ignore_too_short_seqs = min_allowed_length > 0; - for( int col = msa.getLength() - 1; col >= 0 ; --col ) { - final boolean delete = ( ( double ) calcGapSumPerColumn( msa, col ) / msa.getNumberOfSequences() ) >= max_allowed_gap_ratio; - if ( delete ) { - msa.deleteColumn( col ); - } - } - } - public static DescriptiveStatistics calculateIdentityRatio( final int from, final int to, final Msa msa ) { final DescriptiveStatistics stats = new BasicDescriptiveStatistics(); for( int c = from; c <= to; ++c ) { diff --git a/forester/java/src/org/forester/msa/ResampleableMsa.java b/forester/java/src/org/forester/msa/ResampleableMsa.java index 3823241..4427ea7 100644 --- a/forester/java/src/org/forester/msa/ResampleableMsa.java +++ b/forester/java/src/org/forester/msa/ResampleableMsa.java @@ -25,6 +25,9 @@ package org.forester.msa; +import org.forester.sequence.BasicSequence; +import org.forester.sequence.Sequence; + public final class ResampleableMsa extends BasicMsa { private int[] _resampled_column_positions = null; @@ -33,7 +36,15 @@ public final class ResampleableMsa extends BasicMsa { super( msa ); } - public void resample( final int[] resampled_column_positions ) { + @Override + final public char getResidueAt( final int row, final int col ) { + if ( _resampled_column_positions != null ) { + return super.getResidueAt( row, _resampled_column_positions[ col ] ); + } + return super.getResidueAt( row, col ); + } + + final public void resample( final int[] resampled_column_positions ) { if ( resampled_column_positions.length != getLength() ) { throw new IllegalArgumentException( "illegal attempt to use " + resampled_column_positions.length + " resampled column positions on msa of length " + getLength() ); @@ -42,15 +53,12 @@ public final class ResampleableMsa extends BasicMsa { } @Override - public char getResidueAt( final int row, final int col ) { - if ( _resampled_column_positions != null ) { - return super.getResidueAt( row, _resampled_column_positions[ col ] ); - } - return super.getResidueAt( row, col ); + final public void setResidueAt( final int row, final int col, final char residue ) { + throw new NoSuchMethodError( "illegal attempt to set residue in resampleable msa" ); } @Override - public void setResidueAt( final int row, final int col, final char residue ) { - throw new NoSuchMethodError( "illegal attempt to set residue in resampleable msa" ); + public Sequence getSequence( final int row ) { + return new BasicSequence( getIdentifier( row ), getSequenceAsString( row ).toString(), getType() ); } } diff --git a/forester/java/src/org/forester/msa_compactor/MsaCompactor.java b/forester/java/src/org/forester/msa_compactor/MsaCompactor.java index 689eb1c..a4d71da 100644 --- a/forester/java/src/org/forester/msa_compactor/MsaCompactor.java +++ b/forester/java/src/org/forester/msa_compactor/MsaCompactor.java @@ -41,7 +41,6 @@ import org.forester.evoinference.distance.PairwiseDistanceCalculator; import org.forester.evoinference.distance.PairwiseDistanceCalculator.PWD_DISTANCE_METHOD; import org.forester.evoinference.matrix.distance.BasicSymmetricalDistanceMatrix; import org.forester.evoinference.tools.BootstrapResampler; -import org.forester.msa.BasicMsa; import org.forester.msa.DeleteableMsa; import org.forester.msa.Mafft; import org.forester.msa.Msa; @@ -284,12 +283,12 @@ public class MsaCompactor { //opts.add( "1000" ); //opts.add( "--localpair" ); //opts.add( "--quiet" ); - _msa = new DeleteableMsa( ( BasicMsa ) mafft.infer( _msa.asSequenceList(), opts ) ); + _msa = DeleteableMsa.createInstance( mafft.infer( _msa.asSequenceList(), opts ) ); } final private void removeGapColumns() { //~ _msa = MsaMethods.createInstance().removeGapColumns( 1, 0, _msa ); - MsaMethods.removeGapColumns( 1, _msa ); + _msa.deleteGapOnlyColumns(); } final private void removeViaGapAverage( final double mean_gapiness, diff --git a/forester/java/src/org/forester/sequence/BasicSequence.java b/forester/java/src/org/forester/sequence/BasicSequence.java index a172221..dccc191 100644 --- a/forester/java/src/org/forester/sequence/BasicSequence.java +++ b/forester/java/src/org/forester/sequence/BasicSequence.java @@ -34,7 +34,11 @@ public class BasicSequence implements Sequence { private String _identifier; private final TYPE _type; - private BasicSequence( final String identifier, final String mol_sequence, final TYPE type ) { + /** + * Only use if you know what you are doing! + * + */ + public BasicSequence( final String identifier, final String mol_sequence, final TYPE type ) { if ( ForesterUtil.isEmpty( identifier ) ) { throw new IllegalArgumentException( "identifier of sequence cannot be empty" ); } @@ -46,7 +50,10 @@ public class BasicSequence implements Sequence { _type = type; } - // Only use if you know what you are doing! + /** + * Only use if you know what you are doing! + * + */ public BasicSequence( final String identifier, final char[] mol_sequence, final TYPE type ) { if ( ForesterUtil.isEmpty( identifier ) ) { throw new IllegalArgumentException( "identifier of sequence cannot be empty" ); diff --git a/forester/java/src/org/forester/test/Test.java b/forester/java/src/org/forester/test/Test.java index bd332ee..73c1c1f 100644 --- a/forester/java/src/org/forester/test/Test.java +++ b/forester/java/src/org/forester/test/Test.java @@ -28,6 +28,8 @@ import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; import java.net.URL; import java.util.ArrayList; import java.util.Date; @@ -64,6 +66,7 @@ import org.forester.msa.BasicMsa; import org.forester.msa.DeleteableMsa; import org.forester.msa.Mafft; import org.forester.msa.Msa; +import org.forester.msa.Msa.MSA_FORMAT; import org.forester.msa.MsaInferrer; import org.forester.msa.MsaMethods; import org.forester.pccx.TestPccx; @@ -909,7 +912,7 @@ public final class Test { System.out.println( "failed." ); failed++; } - System.exit( 0 ); + System.exit( 0 ); if ( PERFORM_DB_TESTS ) { System.out.print( "Uniprot Entry Retrieval: " ); if ( Test.testUniprotEntryRetrieval() ) { @@ -6085,7 +6088,7 @@ public final class Test { } return true; } - + private static boolean testDeleteableMsa() { try { final Sequence s0 = BasicSequence.createAaSequence( "a", "AAAA" ); @@ -6101,44 +6104,41 @@ public final class Test { l0.add( s3 ); l0.add( s4 ); l0.add( s5 ); - final Msa msa0 = BasicMsa.createInstance( l0 ); - final DeleteableMsa dmsa0 = new DeleteableMsa( ( BasicMsa ) msa0 ); + final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 ); dmsa0.deleteRow( "b" ); if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) { return false; } System.out.println(); - System.out.println( dmsa0.toString() ); + System.out.println( dmsa0.toString() ); dmsa0.deleteRow( "e" ); System.out.println(); - System.out.println( dmsa0.toString() ); + System.out.println( dmsa0.toString() ); dmsa0.deleteRow( "a" ); System.out.println(); - System.out.println( dmsa0.toString() ); + System.out.println( dmsa0.toString() ); dmsa0.deleteRow( "f" ); System.out.println(); - System.out.println( dmsa0.toString() ); - + System.out.println( dmsa0.toString() ); if ( dmsa0.getLength() != 4 ) { return false; } if ( dmsa0.getNumberOfSequences() != 2 ) { return false; } - if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) { return false; } if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) { return false; } - if ( dmsa0.getResidueAt( 0, 0 ) != 'C') { + if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) { return false; } - if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" )) { + if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) { return false; } - if ( dmsa0.getColumnAt( 0 ).size() !=2 ) { + if ( dmsa0.getColumnAt( 0 ).size() != 2 ) { return false; } dmsa0.deleteRow( "c" ); @@ -6147,12 +6147,12 @@ public final class Test { return false; } // - final Sequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C---" ); - final Sequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C---" ); - final Sequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C---" ); - final Sequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C---" ); - final Sequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C---" ); - final Sequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--" ); + final Sequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" ); + final Sequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" ); + final Sequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" ); + final Sequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" ); + final Sequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" ); + final Sequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" ); final List l1 = new ArrayList(); l1.add( s_0 ); l1.add( s_1 ); @@ -6160,12 +6160,57 @@ public final class Test { l1.add( s_3 ); l1.add( s_4 ); l1.add( s_5 ); - final Msa msa1 = BasicMsa.createInstance( l1 ); - final DeleteableMsa dmsa1 = new DeleteableMsa( ( BasicMsa ) msa1 ); - System.out.println( dmsa1.toString() ); - MsaMethods.removeGapColumns( 1, dmsa1 ); - System.out.println( dmsa1.toString() ); - + final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 ); + System.out.println( dmsa1.toString() ); + dmsa1.deleteGapOnlyColumns(); + System.out.println( dmsa1.toString() ); + dmsa1.deleteRow( "a" ); + dmsa1.deleteRow( "f" ); + dmsa1.deleteRow( "d" ); + System.out.println( dmsa1.toString() ); + dmsa1.deleteGapOnlyColumns(); + System.out.println( dmsa1.toString() ); + if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) { + return false; + } + if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) { + return false; + } + if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) { + return false; + } + dmsa1.deleteRow( "c" ); + dmsa1.deleteGapOnlyColumns(); + final Writer w0 = new StringWriter(); + dmsa1.write( w0, MSA_FORMAT.FASTA ); + System.out.println( w0.toString() ); + final Writer w1 = new StringWriter(); + dmsa1.write( w1, MSA_FORMAT.PHYLIP ); + System.out.println( w1.toString() ); + if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) { + return false; + } + if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) { + return false; + } + // + final Sequence s__0 = BasicSequence.createAaSequence( "a", "A------" ); + final Sequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" ); + final Sequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" ); + final Sequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" ); + final Sequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" ); + final Sequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" ); + final List l2 = new ArrayList(); + l2.add( s__0 ); + l2.add( s__1 ); + l2.add( s__2 ); + l2.add( s__3 ); + l2.add( s__4 ); + l2.add( s__5 ); + final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 ); + System.out.println( dmsa2.toString() ); + dmsa2.deleteGapColumns( 0.5 ); + System.out.println( dmsa2.toString() ); } catch ( final Exception e ) { e.printStackTrace( System.out ); -- 1.7.10.2