X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fmsa_compactor%2FMsaCompactor.java;h=58953a8dc70ce51b9f60d29f2e9b8e2e7f239923;hb=70da437f494b483dac92a488bd3500e5add2e34e;hp=4a078135d41b33e4f42b245328ee939e9d1207ae;hpb=3945d8f21a983506954bfa12295de6ab39b8ab92;p=jalview.git diff --git a/forester/java/src/org/forester/msa_compactor/MsaCompactor.java b/forester/java/src/org/forester/msa_compactor/MsaCompactor.java index 4a07813..58953a8 100644 --- a/forester/java/src/org/forester/msa_compactor/MsaCompactor.java +++ b/forester/java/src/org/forester/msa_compactor/MsaCompactor.java @@ -24,6 +24,7 @@ package org.forester.msa_compactor; +import java.awt.Color; import java.io.File; import java.io.IOException; import java.io.Writer; @@ -36,11 +37,16 @@ import java.util.List; import java.util.SortedSet; import java.util.TreeSet; +import org.forester.archaeopteryx.Archaeopteryx; +import org.forester.archaeopteryx.Configuration; import org.forester.evoinference.distance.NeighborJoiningF; 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.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION; +import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException; +import org.forester.io.parsers.util.ParserUtils; import org.forester.io.writers.SequenceWriter; import org.forester.io.writers.SequenceWriter.SEQ_FORMAT; import org.forester.msa.DeleteableMsa; @@ -52,6 +58,12 @@ import org.forester.msa.MsaMethods; import org.forester.msa.ResampleableMsa; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyMethods; +import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY; +import org.forester.phylogeny.PhylogenyNode; +import org.forester.phylogeny.data.NodeVisualData; +import org.forester.phylogeny.data.NodeVisualData.NodeFill; +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.ForesterUtil; @@ -66,6 +78,7 @@ public class MsaCompactor { private String _maffts_opts = "--auto"; private int _min_length = -1; // + private String _infile_name = null; private DeleteableMsa _msa = null; private boolean _norm = true; private File _out_file_base = null; @@ -79,6 +92,7 @@ public class MsaCompactor { private boolean _report_aln_mean_identity = false; private int _step = -1; private int _step_for_diagnostics = -1; + private boolean _phylogentic_inference = false; static { NF_4.setRoundingMode( RoundingMode.HALF_UP ); NF_3.setRoundingMode( RoundingMode.HALF_UP ); @@ -99,14 +113,21 @@ public class MsaCompactor { for( final GapContribution gap_gontribution : stats ) { to_remove_ids.add( gap_gontribution.getId() ); } - final boolean print_id = ( _step < 2 ) && ( _step_for_diagnostics < 2 ); - printTableHeader( print_id ); + if ( !_realign ) { + _step = -1; + } int x = ForesterUtil.roundToInt( _msa.getNumberOfSequences() / 20.0 ); if ( x < 1 ) { x = 1; } MsaProperties msa_prop = new MsaProperties( _msa, _report_aln_mean_identity ); msa_props.add( msa_prop ); + if ( _phylogentic_inference ) { + System.out.println( "calculating phylogentic tree..." ); + System.out.println(); + pi( to_remove_ids ); + } + printTableHeader(); printMsaProperties( "", msa_prop ); System.out.println(); int i = 0; @@ -134,6 +155,10 @@ public class MsaCompactor { return msa_props; } + final public void deleteGapColumns( final double max_allowed_gap_ratio ) { + _msa.deleteGapColumns( max_allowed_gap_ratio ); + } + final public Msa getMsa() { return _msa; } @@ -142,6 +167,15 @@ public class MsaCompactor { return _removed_seq_ids; } + public final void removeSequencesByMinimalLength( final int min_effective_length ) { + 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 ) ); + System.out.println(); + } + public final List removeViaGapAverage( final double mean_gapiness ) throws IOException, InterruptedException { final GapContribution stats[] = calcGapContribtionsStats( _norm ); @@ -150,8 +184,7 @@ public class MsaCompactor { for( final GapContribution gap_gontribution : stats ) { to_remove_ids.add( gap_gontribution.getId() ); } - final boolean print_id = ( _step < 2 ) || ( _step_for_diagnostics < 2 ); - printTableHeader( print_id ); + printTableHeader(); MsaProperties msa_prop = new MsaProperties( _msa, _report_aln_mean_identity ); msa_props.add( msa_prop ); printMsaProperties( "", msa_prop ); @@ -191,8 +224,7 @@ public class MsaCompactor { for( final GapContribution gap_gontribution : stats ) { to_remove_ids.add( gap_gontribution.getId() ); } - final boolean print_id = ( _step < 2 ) || ( _step_for_diagnostics < 2 ); - printTableHeader( print_id ); + printTableHeader(); MsaProperties msa_prop = new MsaProperties( _msa, _report_aln_mean_identity ); msa_props.add( msa_prop ); printMsaProperties( "", msa_prop ); @@ -225,15 +257,6 @@ public class MsaCompactor { return msa_props; } - public final void removeSequencesByMinimalLength( final int min_effective_length ) { - 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 ) ); - System.out.println(); - } - public final List removeWorstOffenders( final int to_remove ) throws IOException, InterruptedException { final GapContribution stats[] = calcGapContribtionsStats( _norm ); @@ -243,8 +266,7 @@ public class MsaCompactor { to_remove_ids.add( stats[ j ].getId() ); _removed_seq_ids.add( stats[ j ].getId() ); } - final boolean print_id = ( _step < 2 ) || ( _step_for_diagnostics < 2 ); - printTableHeader( print_id ); + printTableHeader(); MsaProperties msa_prop = new MsaProperties( _msa, _report_aln_mean_identity ); msa_props.add( msa_prop ); printMsaProperties( "", msa_prop ); @@ -275,10 +297,6 @@ public class MsaCompactor { return msa_props; } - final public void deleteGapColumns( final double max_allowed_gap_ratio ) { - _msa.deleteGapColumns( max_allowed_gap_ratio ); - } - public final void setGapRatio( final double gap_ratio ) { _gap_ratio = gap_ratio; } @@ -436,11 +454,11 @@ public class MsaCompactor { } private final boolean isPrintMsaStats( final int i ) { - return ( ( ( _step < 2 ) && ( _step_for_diagnostics < 2 ) ) || ( ( _step_for_diagnostics > 0 ) && ( ( ( i + 1 ) % _step_for_diagnostics ) == 0 ) ) ); + return ( ( ( _step == 1 ) && ( _step_for_diagnostics == 1 ) ) || ( ( _step_for_diagnostics > 0 ) && ( ( ( i + 1 ) % _step_for_diagnostics ) == 0 ) ) ); } private final boolean isPrintMsaStatsWriteOutfileAndRealign( final int i ) { - return ( ( ( _step < 2 ) && ( _step_for_diagnostics < 2 ) ) || ( ( _step > 0 ) && ( ( ( i + 1 ) % _step ) == 0 ) ) ); + return ( ( ( _step == 1 ) && ( _step_for_diagnostics == 1 ) ) || ( ( _step > 0 ) && ( ( ( i + 1 ) % _step ) == 0 ) ) ); } private final StringBuilder msaPropertiesAsSB( final MsaProperties msa_properties ) { @@ -467,7 +485,7 @@ public class MsaCompactor { return ""; } - private final Phylogeny pi( final String matrix ) { + private final Phylogeny pi( final String matrix, final int boostrap ) { final Phylogeny master_phy = inferNJphylogeny( PWD_DISTANCE_METHOD.KIMURA_DISTANCE, _msa, true, matrix ); final int seed = 15; final int n = 100; @@ -485,8 +503,56 @@ public class MsaCompactor { return master_phy; } + private final Phylogeny pi( final List to_remove_ids ) { + final Phylogeny phy = inferNJphylogeny( PWD_DISTANCE_METHOD.KIMURA_DISTANCE, _msa, false, "" ); + for( int i = 0; i < to_remove_ids.size(); ++i ) { + final String id = to_remove_ids.get( i ); + final PhylogenyNode n = phy.getNode( id ); + n.setName( n.getName() + " [" + ( i + 1 ) + "]" ); + final NodeVisualData vis = new NodeVisualData(); + vis.setFillType( NodeFill.SOLID ); + vis.setShape( NodeShape.RECTANGLE ); + vis.setSize( 6 ); + vis.setNodeColor( new Color( i > 255 ? 0 : 255 - i, 0, 0 ) ); + n.getNodeData().setNodeVisualData( vis ); + } + PhylogenyMethods.midpointRoot( phy ); + PhylogenyMethods.orderAppearance( phy.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME ); + final boolean x = PhylogenyMethods.extractFastaInformation( phy ); + if ( !x ) { + final PhylogenyNodeIterator it = phy.iteratorExternalForward(); + while ( it.hasNext() ) { + final PhylogenyNode n = it.next(); + final String name = n.getName().trim(); + if ( !ForesterUtil.isEmpty( name ) ) { + try { + ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ); + } + catch ( final PhyloXmlDataFormatException e ) { + // Ignore. + } + } + } + } + final Configuration config = new Configuration(); + config.setDisplayAsPhylogram( true ); + config.setUseStyle( true ); + config.setDisplayTaxonomyCode( false ); + config.setDisplayTaxonomyCommonNames( false ); + config.setDisplayTaxonomyScientificNames( false ); + config.setDisplaySequenceNames( false ); + config.setDisplaySequenceSymbols( false ); + config.setDisplayGeneNames( false ); + config.setShowScale( true ); + config.setAddTaxonomyImagesCB( false ); + 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 ) { - if ( ( _step < 2 ) || ( _step_for_diagnostics < 2 ) ) { + if ( ( _step == 1 ) || ( _step_for_diagnostics == 1 ) ) { System.out.print( ForesterUtil.pad( id, _longest_id_length, ' ', false ) ); System.out.print( "\t" ); } @@ -506,8 +572,8 @@ public class MsaCompactor { return msa_prop; } - private final void printTableHeader( final boolean print_id ) { - if ( print_id ) { + private final void printTableHeader() { + if ( ( _step == 1 ) || ( _step_for_diagnostics == 1 ) ) { System.out.print( ForesterUtil.pad( "Id", _longest_id_length, ' ', false ) ); System.out.print( "\t" ); } @@ -580,4 +646,12 @@ public class MsaCompactor { msa.write( w, format ); w.close(); } + + public void setPeformPhylogenticInference( final boolean phylogentic_inference ) { + _phylogentic_inference = phylogentic_inference; + } + + public void setInfileName( final String infile_name ) { + _infile_name = infile_name; + } }