compactor work
[jalview.git] / forester / java / src / org / forester / msa_compactor / MsaCompactor.java
index 494b771..b4d2fe7 100644 (file)
@@ -143,6 +143,7 @@ public class MsaCompactor {
             System.out.println( "calculating phylogentic tree..." );
             System.out.println();
             phy = calcTree();
+            addSeqs2Tree( _msa, phy );
         }
         if ( !_realign ) {
             _step = -1;
@@ -178,6 +179,7 @@ public class MsaCompactor {
             }
             ++i;
         }
+        
         if ( _phylogentic_inference ) {
             decorateTree( phy, msa_props, true );
             displayTree( phy );
@@ -185,7 +187,26 @@ public class MsaCompactor {
         return msa_props;
     }
 
-    public final void decorateTree( final Phylogeny phy, final List<MsaProperties> msa_props, final boolean chart_only ) {
+    private final static void addSeqs2Tree( final Msa msa, final Phylogeny phy ) {
+        for( int i = 0; i < msa.getNumberOfSequences(); ++i ) {
+            final MolecularSequence seq = msa.getSequence( i );
+            final String seq_name = seq.getIdentifier();
+            final PhylogenyNode n = phy.getNode( seq_name );
+            if ( !n.getNodeData().isHasSequence() ) {
+                n.getNodeData().addSequence( new org.forester.phylogeny.data.Sequence() );
+            }
+            else {
+                throw new IllegalArgumentException( "this should not have happened" );
+            }
+            n.getNodeData().getSequence().setMolecularSequence( seq.getMolecularSequenceAsString() );
+            n.getNodeData().getSequence().setMolecularSequenceAligned( true );
+            n.getNodeData().getSequence().setName( seq_name );
+        }
+    }
+
+    private final static void decorateTree( final Phylogeny phy,
+                                            final List<MsaProperties> msa_props,
+                                            final boolean chart_only ) {
         final BasicDescriptiveStatistics length_stats = new BasicDescriptiveStatistics();
         for( int i = 0; i < msa_props.size(); ++i ) {
             final MsaProperties msa_prop = msa_props.get( i );
@@ -252,6 +273,7 @@ public class MsaCompactor {
         config.setDisplaySequenceNames( false );
         config.setDisplaySequenceSymbols( false );
         config.setDisplayGeneNames( false );
+        config.setDisplayMultipleSequenceAlignment( true );
         config.setShowScale( true );
         config.setAddTaxonomyImagesCB( false );
         config.setBaseFontSize( 9 );
@@ -294,6 +316,7 @@ public class MsaCompactor {
             System.out.println( "calculating phylogentic tree..." );
             System.out.println();
             phy = calcTree();
+            addSeqs2Tree( _msa, phy );
         }
         printTableHeader();
         MsaProperties msa_prop = new MsaProperties( _msa, "", _calculate_shannon_entropy );
@@ -328,7 +351,14 @@ public class MsaCompactor {
         if ( _phylogentic_inference ) {
             decorateTree( phy, msa_props, false );
             displayTree( phy );
-        }
+            System.out.println( "calculating phylogentic tree..." );
+            System.out.println();
+            final Phylogeny phy2 = calcTree();
+            addSeqs2Tree( _msa, phy2 );
+            displayTree( phy2 );
+        }   
+      
+       
         return msa_props;
     }
 
@@ -344,6 +374,7 @@ public class MsaCompactor {
             System.out.println( "calculating phylogentic tree..." );
             System.out.println();
             phy = calcTree();
+            addSeqs2Tree( _msa, phy );
         }
         printTableHeader();
         MsaProperties msa_prop = new MsaProperties( _msa, "", _calculate_shannon_entropy );
@@ -378,7 +409,13 @@ public class MsaCompactor {
         if ( _phylogentic_inference ) {
             decorateTree( phy, msa_props, false );
             displayTree( phy );
-        }
+            System.out.println( "calculating phylogentic tree..." );
+            System.out.println();
+            final Phylogeny phy2 = calcTree();
+            addSeqs2Tree( _msa, phy2 );
+            displayTree( phy2 );
+        }   
+       
         return msa_props;
     }
 
@@ -395,6 +432,7 @@ public class MsaCompactor {
             System.out.println( "calculating phylogentic tree..." );
             System.out.println();
             phy = calcTree();
+            addSeqs2Tree( _msa, phy );
         }
         printTableHeader();
         MsaProperties msa_prop = new MsaProperties( _msa, "", _calculate_shannon_entropy );
@@ -427,7 +465,13 @@ public class MsaCompactor {
         if ( _phylogentic_inference ) {
             decorateTree( phy, msa_props, false );
             displayTree( phy );
-        }
+            System.out.println( "calculating phylogentic tree..." );
+            System.out.println();
+            final Phylogeny phy2 = calcTree();
+            addSeqs2Tree( _msa, phy2 );
+            displayTree( phy2 );
+        }   
+       
         return msa_props;
     }
 
@@ -608,6 +652,8 @@ public class MsaCompactor {
         sb.append( msa_properties.getLength() );
         sb.append( "\t" );
         sb.append( NF_4.format( msa_properties.getGapRatio() ) );
+        sb.append( "\t" );
+        sb.append( NF_1.format( msa_properties.getAvgNumberOfGaps() ) );
         if ( _calculate_shannon_entropy ) {
             sb.append( "\t" );
             sb.append( NF_4.format( msa_properties.getEntropy7() ) );
@@ -675,6 +721,8 @@ public class MsaCompactor {
         System.out.print( "\t" );
         System.out.print( "Length" );
         System.out.print( "\t" );
+        System.out.print( "Gap R" );
+        System.out.print( "\t" );
         System.out.print( "Gaps" );
         System.out.print( "\t" );
         if ( _calculate_shannon_entropy ) {