From: cmzmasek@gmail.com Date: Tue, 6 May 2014 23:45:47 +0000 (+0000) Subject: inprogress X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=861cf1ba9d6eb76eeb499fa59d7ffc961e5288e1;p=jalview.git inprogress --- diff --git a/forester/java/src/org/forester/msa_compactor/Chart.java b/forester/java/src/org/forester/msa_compactor/Chart.java index ccb6a0b..2f0607c 100644 --- a/forester/java/src/org/forester/msa_compactor/Chart.java +++ b/forester/java/src/org/forester/msa_compactor/Chart.java @@ -93,10 +93,10 @@ public final class Chart extends JDialog implements ActionListener { final MultiScatterDataModel model = new MultiScatterDataModel(); if ( ( _msa_props == null ) || _msa_props.isEmpty() ) { _msa_props = new ArrayList(); - final MsaProperties p0 = new MsaProperties( 10, 200, 0.5, 0.1 ); - final MsaProperties p1 = new MsaProperties( 9, 190, 0.49, 0.2 ); - final MsaProperties p2 = new MsaProperties( 8, 150, 0.2, 0.3 ); - final MsaProperties p3 = new MsaProperties( 7, 145, 0.2, 0.4 ); + final MsaProperties p0 = new MsaProperties( 10, 200, 0.5, 0.1, "" ); + final MsaProperties p1 = new MsaProperties( 9, 190, 0.49, 0.2, "" ); + final MsaProperties p2 = new MsaProperties( 8, 150, 0.2, 0.3, "" ); + final MsaProperties p3 = new MsaProperties( 7, 145, 0.2, 0.4, "" ); _msa_props.add( p0 ); _msa_props.add( p1 ); _msa_props.add( p2 ); diff --git a/forester/java/src/org/forester/msa_compactor/MsaCompactor.java b/forester/java/src/org/forester/msa_compactor/MsaCompactor.java index 37de654..0b7f8ed 100644 --- a/forester/java/src/org/forester/msa_compactor/MsaCompactor.java +++ b/forester/java/src/org/forester/msa_compactor/MsaCompactor.java @@ -66,6 +66,7 @@ import org.forester.phylogeny.data.NodeVisualData.NodeShape; import org.forester.phylogeny.iterators.PhylogenyNodeIterator; import org.forester.sequence.Sequence; import org.forester.tools.ConfidenceAssessor; +import org.forester.util.BasicDescriptiveStatistics; import org.forester.util.ForesterUtil; public class MsaCompactor { @@ -120,12 +121,13 @@ public class MsaCompactor { if ( x < 1 ) { x = 1; } - MsaProperties msa_prop = new MsaProperties( _msa, _report_aln_mean_identity ); + MsaProperties msa_prop = new MsaProperties( _msa, "", _report_aln_mean_identity ); msa_props.add( msa_prop ); + Phylogeny phy = null; if ( _phylogentic_inference ) { System.out.println( "calculating phylogentic tree..." ); System.out.println(); - pi( to_remove_ids ); + phy = calcTree(); } printTableHeader(); printMsaProperties( "", msa_prop ); @@ -137,7 +139,7 @@ public class MsaCompactor { if ( realign && isPrintMsaStatsWriteOutfileAndRealign( i ) ) { removeGapColumns(); realignWithMafft(); - msa_prop = new MsaProperties( _msa, _report_aln_mean_identity ); + msa_prop = new MsaProperties( _msa, id, _report_aln_mean_identity ); msa_props.add( msa_prop ); printMsaProperties( id, msa_prop ); System.out.print( "(realigned)" ); @@ -145,13 +147,20 @@ public class MsaCompactor { } else if ( isPrintMsaStats( i ) ) { removeGapColumns(); - msa_prop = new MsaProperties( _msa, _report_aln_mean_identity ); + msa_prop = new MsaProperties( _msa, id, _report_aln_mean_identity ); msa_props.add( msa_prop ); printMsaProperties( id, msa_prop ); System.out.println(); } ++i; } + if ( _phylogentic_inference ) { + final Phylogeny p2 = phy.copy(); + decorateTree( p2, to_remove_ids ); + decorateTree2( phy, msa_props ); + displayTree( p2 ); + displayTree( phy ); + } return msa_props; } @@ -168,11 +177,11 @@ public class MsaCompactor { } public final void removeSequencesByMinimalLength( final int min_effective_length ) { - printMsaProperties( "", new MsaProperties( _msa, _report_aln_mean_identity ) ); + printMsaProperties( "", new MsaProperties( _msa, "", _report_aln_mean_identity ) ); System.out.println(); _msa = DeleteableMsa.createInstance( MsaMethods.removeSequencesByMinimalLength( _msa, min_effective_length ) ); removeGapColumns(); - printMsaProperties( "", new MsaProperties( _msa, _report_aln_mean_identity ) ); + printMsaProperties( "", new MsaProperties( _msa, "", _report_aln_mean_identity ) ); System.out.println(); } @@ -185,7 +194,7 @@ public class MsaCompactor { to_remove_ids.add( gap_gontribution.getId() ); } printTableHeader(); - MsaProperties msa_prop = new MsaProperties( _msa, _report_aln_mean_identity ); + MsaProperties msa_prop = new MsaProperties( _msa, "", _report_aln_mean_identity ); msa_props.add( msa_prop ); printMsaProperties( "", msa_prop ); System.out.println(); @@ -202,7 +211,7 @@ public class MsaCompactor { System.out.println(); } else if ( isPrintMsaStats( i ) ) { - msa_prop = new MsaProperties( _msa, _report_aln_mean_identity ); + msa_prop = new MsaProperties( _msa, id, _report_aln_mean_identity ); msa_props.add( msa_prop ); printMsaProperties( id, msa_prop ); System.out.println(); @@ -225,7 +234,7 @@ public class MsaCompactor { to_remove_ids.add( gap_gontribution.getId() ); } printTableHeader(); - MsaProperties msa_prop = new MsaProperties( _msa, _report_aln_mean_identity ); + MsaProperties msa_prop = new MsaProperties( _msa, "", _report_aln_mean_identity ); msa_props.add( msa_prop ); printMsaProperties( "", msa_prop ); System.out.println(); @@ -242,7 +251,7 @@ public class MsaCompactor { System.out.println(); } else if ( isPrintMsaStats( i ) ) { - msa_prop = new MsaProperties( _msa, _report_aln_mean_identity ); + msa_prop = new MsaProperties( _msa, id, _report_aln_mean_identity ); printMsaProperties( id, msa_prop ); msa_props.add( msa_prop ); System.out.println(); @@ -267,7 +276,7 @@ public class MsaCompactor { _removed_seq_ids.add( stats[ j ].getId() ); } printTableHeader(); - MsaProperties msa_prop = new MsaProperties( _msa, _report_aln_mean_identity ); + MsaProperties msa_prop = new MsaProperties( _msa, "", _report_aln_mean_identity ); msa_props.add( msa_prop ); printMsaProperties( "", msa_prop ); System.out.println(); @@ -283,7 +292,7 @@ public class MsaCompactor { System.out.println(); } else if ( isPrintMsaStats( i ) ) { - msa_prop = new MsaProperties( _msa, _report_aln_mean_identity ); + msa_prop = new MsaProperties( _msa, id, _report_aln_mean_identity ); msa_props.add( msa_prop ); printMsaProperties( id, msa_prop ); System.out.println(); @@ -503,7 +512,7 @@ public class MsaCompactor { return master_phy; } - private final Phylogeny calcTree( final List to_remove_ids ) { + public final Phylogeny calcTree() { final Phylogeny phy = inferNJphylogeny( PWD_DISTANCE_METHOD.KIMURA_DISTANCE, _msa, false, "" ); PhylogenyMethods.midpointRoot( phy ); PhylogenyMethods.orderAppearance( phy.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME ); @@ -526,7 +535,7 @@ public class MsaCompactor { return phy; } - private final Phylogeny pi( Phylogeny phy, final List to_remove_ids ) { + public final void decorateTree( final Phylogeny phy, final List to_remove_ids ) { for( int i = 0; i < to_remove_ids.size(); ++i ) { final String id = to_remove_ids.get( i ); final PhylogenyNode n = phy.getNode( id ); @@ -538,6 +547,52 @@ public class MsaCompactor { vis.setNodeColor( new Color( i > 255 ? 0 : 255 - i, 0, 0 ) ); n.getNodeData().setNodeVisualData( vis ); } + } + + public final void decorateTree2( final Phylogeny phy, final List msa_props ) { + final BasicDescriptiveStatistics length_stats = new BasicDescriptiveStatistics(); + for( int i = 0; i < msa_props.size(); ++i ) { + final MsaProperties msa_prop = msa_props.get( i ); + final String id = msa_prop.getRemovedSeq(); + if ( !ForesterUtil.isEmpty( id ) ) { + length_stats.addValue( msa_prop.getLength() ); + } + } + final double mean = length_stats.arithmeticMean(); + final double min = length_stats.getMin(); + final double max = length_stats.getMax(); + final Color min_color = new Color( 0, 255, 0 ); + final Color max_color = new Color( 255, 0, 0 ); + final Color mean_color = new Color( 255, 255, 0 ); + final PhylogenyNodeIterator it = phy.iteratorExternalForward(); + while ( it.hasNext() ) { + final NodeVisualData vis = new NodeVisualData(); + vis.setFillType( NodeFill.SOLID ); + vis.setShape( NodeShape.RECTANGLE ); + vis.setSize( 6 ); + vis.setNodeColor( min_color ); + it.next().getNodeData().setNodeVisualData( vis ); + } + for( int i = 0; i < msa_props.size(); ++i ) { + final MsaProperties msa_prop = msa_props.get( i ); + final String id = msa_prop.getRemovedSeq(); + if ( !ForesterUtil.isEmpty( id ) ) { + final PhylogenyNode n = phy.getNode( id ); + n.setName( n.getName() + " [" + i + "]" ); + n.getNodeData() + .getNodeVisualData() + .setNodeColor( ForesterUtil.calcColor( msa_prop.getLength(), + min, + max, + mean, + min_color, + max_color, + mean_color ) ); + } + } + } + + public final void displayTree( final Phylogeny phy ) { final Configuration config = new Configuration(); config.setDisplayAsPhylogram( true ); config.setUseStyle( true ); @@ -552,7 +607,6 @@ public class MsaCompactor { config.setBaseFontSize( 9 ); config.setBaseFontFamilyName( "Arial" ); Archaeopteryx.createApplication( phy, config, _infile_name ); - return phy; } private final void printMsaProperties( final String id, final MsaProperties msa_properties ) { @@ -569,7 +623,7 @@ public class MsaCompactor { if ( realign ) { realignWithMafft(); } - final MsaProperties msa_prop = new MsaProperties( _msa, _report_aln_mean_identity ); + final MsaProperties msa_prop = new MsaProperties( _msa, id, _report_aln_mean_identity ); printMsaProperties( id, msa_prop ); final String s = writeOutfile(); System.out.print( "-> " + s + ( realign ? "\t(realigned)" : "" ) ); diff --git a/forester/java/src/org/forester/msa_compactor/MsaProperties.java b/forester/java/src/org/forester/msa_compactor/MsaProperties.java index deccb79..f24f60f 100644 --- a/forester/java/src/org/forester/msa_compactor/MsaProperties.java +++ b/forester/java/src/org/forester/msa_compactor/MsaProperties.java @@ -33,21 +33,25 @@ public final class MsaProperties { final private double _gap_ratio; final private int _length; final private int _number_of_sequences; + final private String _removed_seq; public MsaProperties( final int number_of_sequences, final int length, final double gap_ratio, - final double average_identity_ratio ) { + final double average_identity_ratio, + final String removed_seq ) { _number_of_sequences = number_of_sequences; _length = length; _gap_ratio = gap_ratio; _average_identity_ratio = average_identity_ratio; + _removed_seq = removed_seq; } - public MsaProperties( final Msa msa, final boolean calculate_aln_mean_identity ) { + public MsaProperties( final Msa msa, final String removed_seq, final boolean calculate_aln_mean_identity ) { _number_of_sequences = msa.getNumberOfSequences(); _length = msa.getLength(); _gap_ratio = MsaMethods.calcGapRatio( msa ); + _removed_seq = removed_seq; if ( calculate_aln_mean_identity ) { _average_identity_ratio = MsaMethods.calculateIdentityRatio( 0, msa.getLength() - 1, msa ).arithmeticMean(); } @@ -71,4 +75,8 @@ public final class MsaProperties { public final int getNumberOfSequences() { return _number_of_sequences; } + + public final String getRemovedSeq() { + return _removed_seq; + } }