in progress
[jalview.git] / forester / java / src / org / forester / msa / BasicMsa.java
index bda6424..7d90c3c 100644 (file)
@@ -71,8 +71,8 @@ public class BasicMsa implements Msa {
 
     private int determineMaxIdLength() {
         int max = 0;
-        for( int row = 0; row < _data.length; ++row ) {
-            final int l = _identifiers[ row ].toString().length();
+        for( int row = 0; row < getNumberOfSequences(); ++row ) {
+            final int l = getIdentifier(row).length();
             if ( l > max ) {
                 max = l;
             }
@@ -112,17 +112,22 @@ public class BasicMsa implements Msa {
 
     @Override
     public Sequence getSequence( final int row ) {
-        return new BasicSequence( getIdentifier( row ), _data[ row ], getType() );
+        return new BasicSequence( getIdentifier( row ),  getSequenceAsArray( row ), getType() );
     }
 
     @Override
     public StringBuffer getSequenceAsString( final int row ) {
-        final StringBuffer sb = new StringBuffer( _data[ 0 ].length );
-        for( int col = 0; col < _data[ 0 ].length; ++col ) {
+        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() {
@@ -143,9 +148,9 @@ public class BasicMsa implements Msa {
     public String toString() {
         final int max = determineMaxIdLength() + 1;
         final StringBuffer sb = new StringBuffer();
-        for( int row = 0; row < _data.length; ++row ) {
-            sb.append( ForesterUtil.pad( _identifiers[ row ].toString(), max, ' ', false ) );
-            for( int col = 0; col < _data[ 0 ].length; ++col ) {
+        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 );
@@ -173,9 +178,9 @@ public class BasicMsa implements Msa {
 
     private void writeToPhylip( final Writer w ) throws IOException {
         final int max = determineMaxIdLength() + 1;
-        for( int row = 0; row < _data.length; ++row ) {
-            w.write( ForesterUtil.pad( _identifiers[ row ].toString(), max, ' ', false ).toString() );
-            for( int col = 0; col < _data[ 0 ].length; ++col ) {
+        for( int row = 0; row < getNumberOfSequences(); ++row ) {
+            w.write( ForesterUtil.pad( getIdentifier( row ), max, ' ', false ).toString() );
+            for( int col = 0; col < getLength(); ++col ) {
                 w.write( getResidueAt( row, col ) );
             }
             w.write( ForesterUtil.LINE_SEPARATOR );
@@ -191,6 +196,20 @@ 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() + "]" );