2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2014 Christian M. Zmasek
6 // Copyright (C) 2014 Sanford-Burnham Medical Research Institute
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
25 package org.forester.msa_compactor;
27 import java.awt.Color;
29 import java.io.IOException;
30 import java.io.Writer;
31 import java.math.RoundingMode;
32 import java.text.DecimalFormat;
33 import java.text.NumberFormat;
34 import java.util.ArrayList;
35 import java.util.Arrays;
36 import java.util.List;
37 import java.util.SortedSet;
38 import java.util.TreeSet;
40 import org.forester.archaeopteryx.Archaeopteryx;
41 import org.forester.archaeopteryx.Configuration;
42 import org.forester.evoinference.distance.NeighborJoiningF;
43 import org.forester.evoinference.distance.PairwiseDistanceCalculator;
44 import org.forester.evoinference.distance.PairwiseDistanceCalculator.PWD_DISTANCE_METHOD;
45 import org.forester.evoinference.matrix.distance.BasicSymmetricalDistanceMatrix;
46 import org.forester.evoinference.tools.BootstrapResampler;
47 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
48 import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException;
49 import org.forester.io.parsers.util.ParserUtils;
50 import org.forester.io.writers.SequenceWriter;
51 import org.forester.io.writers.SequenceWriter.SEQ_FORMAT;
52 import org.forester.msa.DeleteableMsa;
53 import org.forester.msa.Mafft;
54 import org.forester.msa.Msa;
55 import org.forester.msa.Msa.MSA_FORMAT;
56 import org.forester.msa.MsaInferrer;
57 import org.forester.msa.MsaMethods;
58 import org.forester.msa.ResampleableMsa;
59 import org.forester.phylogeny.Phylogeny;
60 import org.forester.phylogeny.PhylogenyMethods;
61 import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
62 import org.forester.phylogeny.PhylogenyNode;
63 import org.forester.phylogeny.data.NodeVisualData;
64 import org.forester.phylogeny.data.NodeVisualData.NodeFill;
65 import org.forester.phylogeny.data.NodeVisualData.NodeShape;
66 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
67 import org.forester.sequence.Sequence;
68 import org.forester.tools.ConfidenceAssessor;
69 import org.forester.util.BasicDescriptiveStatistics;
70 import org.forester.util.DescriptiveStatistics;
71 import org.forester.util.ForesterUtil;
73 public class MsaCompactor {
75 final private static NumberFormat NF_1 = new DecimalFormat( "0.#" );
76 final private static NumberFormat NF_3 = new DecimalFormat( "0.###" );
77 final private static NumberFormat NF_4 = new DecimalFormat( "0.####" );
78 private boolean _calculate_shannon_entropy = false;
80 private String _infile_name = null;
81 private final short _longest_id_length;
83 private String _maffts_opts = "--auto";
84 private DeleteableMsa _msa = null;
85 private boolean _norm = true;
86 private File _out_file_base = null;
87 private MSA_FORMAT _output_format = MSA_FORMAT.FASTA;
88 private String _path_to_mafft = null;
89 private boolean _phylogentic_inference = false;
91 private boolean _realign = false;
92 private final SortedSet<String> _removed_seq_ids;
93 private final ArrayList<Sequence> _removed_seqs;
94 private File _removed_seqs_out_base = null;
95 private int _step = -1;
96 private int _step_for_diagnostics = -1;
98 NF_1.setRoundingMode( RoundingMode.HALF_UP );
99 NF_4.setRoundingMode( RoundingMode.HALF_UP );
100 NF_3.setRoundingMode( RoundingMode.HALF_UP );
103 public MsaCompactor( final DeleteableMsa msa ) {
105 _removed_seq_ids = new TreeSet<String>();
106 _longest_id_length = _msa.determineMaxIdLength();
107 _removed_seqs = new ArrayList<Sequence>();
110 public final Phylogeny calcTree() {
111 final Phylogeny phy = inferNJphylogeny( PWD_DISTANCE_METHOD.KIMURA_DISTANCE, _msa, false, "" );
112 PhylogenyMethods.midpointRoot( phy );
113 PhylogenyMethods.orderAppearance( phy.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
114 final boolean x = PhylogenyMethods.extractFastaInformation( phy );
116 final PhylogenyNodeIterator it = phy.iteratorExternalForward();
117 while ( it.hasNext() ) {
118 final PhylogenyNode n = it.next();
119 final String name = n.getName().trim();
120 if ( !ForesterUtil.isEmpty( name ) ) {
122 ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE );
124 catch ( final PhyloXmlDataFormatException e ) {
133 public final List<MsaProperties> chart( final int step, final boolean realign, final boolean norm )
134 throws IOException, InterruptedException {
135 final GapContribution stats[] = calcGapContribtionsStats( norm );
136 final List<String> to_remove_ids = new ArrayList<String>();
137 final List<MsaProperties> msa_props = new ArrayList<MsaProperties>();
138 for( final GapContribution gap_gontribution : stats ) {
139 to_remove_ids.add( gap_gontribution.getId() );
141 Phylogeny phy = null;
142 if ( _phylogentic_inference ) {
143 System.out.println( "calculating phylogentic tree..." );
144 System.out.println();
150 int x = ForesterUtil.roundToInt( _msa.getNumberOfSequences() / 10.0 );
154 MsaProperties msa_prop = new MsaProperties( _msa, "", _calculate_shannon_entropy );
155 msa_props.add( msa_prop );
157 printMsaProperties( msa_prop );
158 System.out.println();
160 while ( _msa.getNumberOfSequences() > x ) {
161 final String id = to_remove_ids.get( i );
162 _msa.deleteRow( id, false );
163 if ( realign && isPrintMsaStatsWriteOutfileAndRealign( i ) ) {
166 msa_prop = new MsaProperties( _msa, id, _calculate_shannon_entropy );
167 msa_props.add( msa_prop );
168 printMsaProperties( msa_prop );
169 System.out.print( "(realigned)" );
170 System.out.println();
172 else if ( isPrintMsaStats( i ) ) {
174 msa_prop = new MsaProperties( _msa, id, _calculate_shannon_entropy );
175 msa_props.add( msa_prop );
176 printMsaProperties( msa_prop );
177 System.out.println();
181 if ( _phylogentic_inference ) {
182 decorateTree( phy, msa_props, true );
188 public final void decorateTree( final Phylogeny phy, final List<MsaProperties> msa_props, final boolean chart_only ) {
189 final BasicDescriptiveStatistics length_stats = new BasicDescriptiveStatistics();
190 for( int i = 0; i < msa_props.size(); ++i ) {
191 final MsaProperties msa_prop = msa_props.get( i );
192 final String id = msa_prop.getRemovedSeq();
193 if ( !ForesterUtil.isEmpty( id ) ) {
194 length_stats.addValue( msa_prop.getLength() );
197 final double mean = length_stats.arithmeticMean();
198 final double min = length_stats.getMin();
199 final double max = length_stats.getMax();
200 final Color min_color = new Color( 0, 255, 0 );
201 final Color max_color = new Color( 255, 0, 0 );
202 final Color mean_color = new Color( 255, 255, 0 );
203 final PhylogenyNodeIterator it = phy.iteratorExternalForward();
205 while ( it.hasNext() ) {
206 final NodeVisualData vis = new NodeVisualData();
207 vis.setFillType( NodeFill.SOLID );
208 vis.setShape( NodeShape.RECTANGLE );
209 vis.setNodeColor( min_color );
210 it.next().getNodeData().setNodeVisualData( vis );
213 for( int i = 0; i < msa_props.size(); ++i ) {
214 final MsaProperties msa_prop = msa_props.get( i );
215 final String id = msa_prop.getRemovedSeq();
216 if ( !ForesterUtil.isEmpty( id ) ) {
217 final PhylogenyNode n = phy.getNode( id );
218 n.setName( n.getName() + " [" + i + "]" );
220 final NodeVisualData vis = new NodeVisualData();
221 vis.setFillType( NodeFill.SOLID );
222 vis.setShape( NodeShape.RECTANGLE );
223 vis.setNodeColor( ForesterUtil.calcColor( msa_prop.getLength(), min, max, mean_color, max_color ) );
224 n.getNodeData().setNodeVisualData( vis );
229 .setNodeColor( ForesterUtil.calcColor( msa_prop.getLength(),
241 final public void deleteGapColumns( final double max_allowed_gap_ratio ) {
242 _msa.deleteGapColumns( max_allowed_gap_ratio );
245 public final void displayTree( final Phylogeny phy ) {
246 final Configuration config = new Configuration();
247 config.setDisplayAsPhylogram( true );
248 config.setUseStyle( true );
249 config.setDisplayTaxonomyCode( false );
250 config.setDisplayTaxonomyCommonNames( false );
251 config.setDisplayTaxonomyScientificNames( false );
252 config.setDisplaySequenceNames( false );
253 config.setDisplaySequenceSymbols( false );
254 config.setDisplayGeneNames( false );
255 config.setShowScale( true );
256 config.setAddTaxonomyImagesCB( false );
257 config.setBaseFontSize( 9 );
258 config.setBaseFontFamilyName( "Arial" );
259 Archaeopteryx.createApplication( phy, config, _infile_name );
262 final public Msa getMsa() {
266 public final void removeSequencesByMinimalLength( final int min_effective_length ) throws IOException {
267 _msa = DeleteableMsa.createInstance( MsaMethods.removeSequencesByMinimalLength( _msa, min_effective_length ) );
269 final String s = writeOutfile();
270 final DescriptiveStatistics msa_stats = MsaMethods.calculateEffectiveLengthStatistics( _msa );
271 System.out.println( "Output MSA : " + s );
272 System.out.println( " MSA length : " + _msa.getLength() );
273 System.out.println( " Number of sequences : " + _msa.getNumberOfSequences() );
274 System.out.println( " Median sequence length : " + NF_1.format( msa_stats.median() ) );
275 System.out.println( " Mean sequence length : " + NF_1.format( msa_stats.arithmeticMean() ) );
276 System.out.println( " Max sequence length : " + ( ( int ) msa_stats.getMax() ) );
277 System.out.println( " Min sequence length : " + ( ( int ) msa_stats.getMin() ) );
278 System.out.println( " Gap ratio : " + NF_4.format( MsaMethods.calcGapRatio( _msa ) ) );
279 System.out.println( " Normalized Shannon Entropy (entn21): "
280 + NF_4.format( MsaMethods.calcNormalizedShannonsEntropy( 21, _msa ) ) );
281 System.out.println();
284 public final List<MsaProperties> removeViaGapAverage( final double mean_gapiness ) throws IOException,
285 InterruptedException {
286 final GapContribution stats[] = calcGapContribtionsStats( _norm );
287 final List<String> to_remove_ids = new ArrayList<String>();
288 final List<MsaProperties> msa_props = new ArrayList<MsaProperties>();
289 for( final GapContribution gap_gontribution : stats ) {
290 to_remove_ids.add( gap_gontribution.getId() );
292 Phylogeny phy = null;
293 if ( _phylogentic_inference ) {
294 System.out.println( "calculating phylogentic tree..." );
295 System.out.println();
299 MsaProperties msa_prop = new MsaProperties( _msa, "", _calculate_shannon_entropy );
300 msa_props.add( msa_prop );
301 printMsaProperties( msa_prop );
302 System.out.println();
304 while ( MsaMethods.calcGapRatio( _msa ) > mean_gapiness ) {
305 final String id = to_remove_ids.get( i );
306 _removed_seq_ids.add( id );
307 final Sequence deleted = _msa.deleteRow( id, true );
308 _removed_seqs.add( deleted );
310 if ( isPrintMsaStatsWriteOutfileAndRealign( i ) || ( MsaMethods.calcGapRatio( _msa ) <= mean_gapiness ) ) {
311 msa_prop = printMsaStatsWriteOutfileAndRealign( _realign, id );
312 msa_props.add( msa_prop );
313 System.out.println();
315 else if ( isPrintMsaStats( i ) ) {
316 msa_prop = new MsaProperties( _msa, id, _calculate_shannon_entropy );
317 msa_props.add( msa_prop );
318 printMsaProperties( msa_prop );
319 System.out.println();
323 if ( _removed_seqs_out_base != null ) {
324 final String msg = writeAndAlignRemovedSeqs();
325 System.out.println();
326 System.out.println( msg );
328 if ( _phylogentic_inference ) {
329 decorateTree( phy, msa_props, false );
335 public List<MsaProperties> removeViaLength( final int length ) throws IOException, InterruptedException {
336 final GapContribution stats[] = calcGapContribtionsStats( _norm );
337 final List<String> to_remove_ids = new ArrayList<String>();
338 final List<MsaProperties> msa_props = new ArrayList<MsaProperties>();
339 for( final GapContribution gap_gontribution : stats ) {
340 to_remove_ids.add( gap_gontribution.getId() );
342 Phylogeny phy = null;
343 if ( _phylogentic_inference ) {
344 System.out.println( "calculating phylogentic tree..." );
345 System.out.println();
349 MsaProperties msa_prop = new MsaProperties( _msa, "", _calculate_shannon_entropy );
350 msa_props.add( msa_prop );
351 printMsaProperties( msa_prop );
352 System.out.println();
354 while ( _msa.getLength() > length ) {
355 final String id = to_remove_ids.get( i );
356 _removed_seq_ids.add( id );
357 final Sequence deleted = _msa.deleteRow( id, true );
358 _removed_seqs.add( deleted );
360 if ( isPrintMsaStatsWriteOutfileAndRealign( i ) || ( _msa.getLength() <= length ) ) {
361 msa_prop = printMsaStatsWriteOutfileAndRealign( _realign, id );
362 msa_props.add( msa_prop );
363 System.out.println();
365 else if ( isPrintMsaStats( i ) ) {
366 msa_prop = new MsaProperties( _msa, id, _calculate_shannon_entropy );
367 printMsaProperties( msa_prop );
368 msa_props.add( msa_prop );
369 System.out.println();
373 if ( _removed_seqs_out_base != null ) {
374 final String msg = writeAndAlignRemovedSeqs();
375 System.out.println();
376 System.out.println( msg );
378 if ( _phylogentic_inference ) {
379 decorateTree( phy, msa_props, false );
385 public final List<MsaProperties> removeWorstOffenders( final int to_remove ) throws IOException,
386 InterruptedException {
387 final GapContribution stats[] = calcGapContribtionsStats( _norm );
388 final List<String> to_remove_ids = new ArrayList<String>();
389 final List<MsaProperties> msa_props = new ArrayList<MsaProperties>();
390 for( int j = 0; j < to_remove; ++j ) {
391 to_remove_ids.add( stats[ j ].getId() );
393 Phylogeny phy = null;
394 if ( _phylogentic_inference ) {
395 System.out.println( "calculating phylogentic tree..." );
396 System.out.println();
400 MsaProperties msa_prop = new MsaProperties( _msa, "", _calculate_shannon_entropy );
401 msa_props.add( msa_prop );
402 printMsaProperties( msa_prop );
403 System.out.println();
404 for( int i = 0; i < to_remove_ids.size(); ++i ) {
405 final String id = to_remove_ids.get( i );
406 _removed_seq_ids.add( id );
407 final Sequence deleted = _msa.deleteRow( id, true );
408 _removed_seqs.add( deleted );
410 if ( isPrintMsaStatsWriteOutfileAndRealign( i ) || ( i == ( to_remove_ids.size() - 1 ) ) ) {
411 msa_prop = printMsaStatsWriteOutfileAndRealign( _realign, id );
412 msa_props.add( msa_prop );
413 System.out.println();
415 else if ( isPrintMsaStats( i ) ) {
416 msa_prop = new MsaProperties( _msa, id, _calculate_shannon_entropy );
417 msa_props.add( msa_prop );
418 printMsaProperties( msa_prop );
419 System.out.println();
422 if ( _removed_seqs_out_base != null ) {
423 final String msg = writeAndAlignRemovedSeqs();
424 System.out.println();
425 System.out.println( msg );
427 if ( _phylogentic_inference ) {
428 decorateTree( phy, msa_props, false );
434 public final void setCalculateNormalizedShannonEntropy( final boolean calculate_shannon_entropy ) {
435 _calculate_shannon_entropy = calculate_shannon_entropy;
438 public void setInfileName( final String infile_name ) {
439 _infile_name = infile_name;
442 public final void setMafftOptions( final String maffts_opts ) {
443 _maffts_opts = maffts_opts;
446 public final void setNorm( final boolean norm ) {
450 final public void setOutFileBase( final File out_file_base ) {
451 _out_file_base = out_file_base;
454 public final void setOutputFormat( final MSA_FORMAT output_format ) {
455 _output_format = output_format;
458 public void setPathToMafft( final String path_to_mafft ) {
459 _path_to_mafft = path_to_mafft;
462 public void setPeformPhylogenticInference( final boolean phylogentic_inference ) {
463 _phylogentic_inference = phylogentic_inference;
466 public final void setRealign( final boolean realign ) {
470 public final void setRemovedSeqsOutBase( final File removed_seqs_out_base ) {
471 _removed_seqs_out_base = removed_seqs_out_base;
474 public final void setStep( final int step ) {
478 public final void setStepForDiagnostics( final int step_for_diagnostics ) {
479 _step_for_diagnostics = step_for_diagnostics;
482 final public String writeAndAlignRemovedSeqs() throws IOException, InterruptedException {
483 final StringBuilder msg = new StringBuilder();
484 final String n = _removed_seqs_out_base + "_" + _removed_seqs.size() + ".fasta";
485 SequenceWriter.writeSeqs( _removed_seqs, new File( n ), SEQ_FORMAT.FASTA, 100 );
486 msg.append( "wrote " + _removed_seqs.size() + " removed sequences to " + "\"" + n + "\"" );
488 final MsaInferrer mafft = Mafft.createInstance( _path_to_mafft );
489 final List<String> opts = new ArrayList<String>();
490 for( final String o : _maffts_opts.split( "\\s" ) ) {
493 final Msa removed_msa = mafft.infer( _removed_seqs, opts );
494 final Double gr = MsaMethods.calcGapRatio( removed_msa );
495 String s = _removed_seqs_out_base + "_" + removed_msa.getNumberOfSequences() + "_"
496 + removed_msa.getLength() + "_" + ForesterUtil.roundToInt( gr * 100 );
497 final String suffix = obtainSuffix();
499 writeMsa( removed_msa, s, _output_format );
500 msg.append( ", and as MSA of length " + removed_msa.getLength() + " to \"" + s + "\"" );
502 return msg.toString();
505 final public String writeMsa( final File outfile ) throws IOException {
506 final Double gr = MsaMethods.calcGapRatio( _msa );
507 final String s = outfile + "_" + _msa.getNumberOfSequences() + "_" + _msa.getLength() + "_"
508 + ForesterUtil.roundToInt( gr * 100 );
509 writeMsa( _msa, s + obtainSuffix(), _output_format );
513 final int calcNonGapResidues( final Sequence seq ) {
515 for( int i = 0; i < seq.getLength(); ++i ) {
516 if ( !seq.isGapAt( i ) ) {
523 private final GapContribution[] calcGapContribtions( final boolean normalize_for_effective_seq_length ) {
524 final double gappiness[] = calcGappiness();
525 final GapContribution stats[] = new GapContribution[ _msa.getNumberOfSequences() ];
526 for( int row = 0; row < _msa.getNumberOfSequences(); ++row ) {
527 stats[ row ] = new GapContribution( _msa.getIdentifier( row ) );
528 for( int col = 0; col < _msa.getLength(); ++col ) {
529 if ( !_msa.isGapAt( row, col ) ) {
530 stats[ row ].addToValue( gappiness[ col ] );
533 if ( normalize_for_effective_seq_length ) {
534 stats[ row ].divideValue( calcNonGapResidues( _msa.getSequence( row ) ) );
537 stats[ row ].divideValue( _msa.getLength() );
543 final private GapContribution[] calcGapContribtionsStats( final boolean norm ) {
544 final GapContribution stats[] = calcGapContribtions( norm );
545 Arrays.sort( stats );
549 private final double[] calcGappiness() {
550 final int l = _msa.getLength();
551 final double gappiness[] = new double[ l ];
552 final int seqs = _msa.getNumberOfSequences();
553 for( int i = 0; i < l; ++i ) {
554 gappiness[ i ] = ( double ) MsaMethods.calcGapSumPerColumn( _msa, i ) / seqs;
559 private final Phylogeny collapse( final Msa msa, final int threshold ) {
560 final BasicSymmetricalDistanceMatrix m = PairwiseDistanceCalculator.calcFractionalDissimilarities( msa );
565 private final Phylogeny inferNJphylogeny( final PWD_DISTANCE_METHOD pwd_distance_method,
567 final boolean write_matrix,
568 final String matrix_name ) {
569 BasicSymmetricalDistanceMatrix m = null;
570 switch ( pwd_distance_method ) {
571 case KIMURA_DISTANCE:
572 m = PairwiseDistanceCalculator.calcKimuraDistances( msa );
574 case POISSON_DISTANCE:
575 m = PairwiseDistanceCalculator.calcPoissonDistances( msa );
577 case FRACTIONAL_DISSIMILARITY:
578 m = PairwiseDistanceCalculator.calcFractionalDissimilarities( msa );
581 throw new IllegalArgumentException( "invalid pwd method" );
583 if ( write_matrix ) {
585 m.write( ForesterUtil.createBufferedWriter( matrix_name ) );
587 catch ( final IOException e ) {
591 final NeighborJoiningF nj = NeighborJoiningF.createInstance( false, 5 );
592 final Phylogeny phy = nj.execute( m );
596 private final boolean isPrintMsaStats( final int i ) {
597 return ( ( ( _step == 1 ) && ( _step_for_diagnostics == 1 ) ) || ( ( _step_for_diagnostics > 0 ) && ( ( ( i + 1 ) % _step_for_diagnostics ) == 0 ) ) );
600 private final boolean isPrintMsaStatsWriteOutfileAndRealign( final int i ) {
601 return ( ( ( _step == 1 ) && ( _step_for_diagnostics == 1 ) ) || ( ( _step > 0 ) && ( ( ( i + 1 ) % _step ) == 0 ) ) );
604 private final StringBuilder msaPropertiesAsSB( final MsaProperties msa_properties ) {
605 final StringBuilder sb = new StringBuilder();
606 sb.append( msa_properties.getNumberOfSequences() );
608 sb.append( msa_properties.getLength() );
610 sb.append( NF_4.format( msa_properties.getGapRatio() ) );
611 if ( _calculate_shannon_entropy ) {
613 sb.append( NF_4.format( msa_properties.getEntropy7() ) );
615 sb.append( NF_4.format( msa_properties.getEntropy21() ) );
620 private String obtainSuffix() {
621 if ( _output_format == MSA_FORMAT.FASTA ) {
624 else if ( _output_format == MSA_FORMAT.PHYLIP ) {
630 private final Phylogeny pi( final String matrix, final int boostrap ) {
631 final Phylogeny master_phy = inferNJphylogeny( PWD_DISTANCE_METHOD.KIMURA_DISTANCE, _msa, true, matrix );
634 final ResampleableMsa resampleable_msa = new ResampleableMsa( _msa );
635 final int[][] resampled_column_positions = BootstrapResampler.createResampledColumnPositions( _msa.getLength(),
638 final Phylogeny[] eval_phys = new Phylogeny[ n ];
639 for( int i = 0; i < n; ++i ) {
640 resampleable_msa.resample( resampled_column_positions[ i ] );
641 eval_phys[ i ] = inferNJphylogeny( PWD_DISTANCE_METHOD.KIMURA_DISTANCE, resampleable_msa, false, null );
643 ConfidenceAssessor.evaluate( "bootstrap", eval_phys, master_phy, true, 1 );
644 PhylogenyMethods.extractFastaInformation( master_phy );
648 private final void printMsaProperties( final MsaProperties msa_properties ) {
649 if ( ( _step == 1 ) || ( _step_for_diagnostics == 1 ) ) {
650 System.out.print( ForesterUtil.pad( msa_properties.getRemovedSeq(), _longest_id_length, ' ', false ) );
651 System.out.print( "\t" );
653 System.out.print( msaPropertiesAsSB( msa_properties ) );
654 System.out.print( "\t" );
657 final private MsaProperties printMsaStatsWriteOutfileAndRealign( final boolean realign, final String id )
658 throws IOException, InterruptedException {
662 final MsaProperties msa_prop = new MsaProperties( _msa, id, _calculate_shannon_entropy );
663 printMsaProperties( msa_prop );
664 final String s = writeOutfile();
665 System.out.print( "-> " + s + ( realign ? "\t(realigned)" : "" ) );
669 private final void printTableHeader() {
670 if ( ( _step == 1 ) || ( _step_for_diagnostics == 1 ) ) {
671 System.out.print( ForesterUtil.pad( "Id", _longest_id_length, ' ', false ) );
672 System.out.print( "\t" );
674 System.out.print( "Seqs" );
675 System.out.print( "\t" );
676 System.out.print( "Length" );
677 System.out.print( "\t" );
678 System.out.print( "Gaps" );
679 System.out.print( "\t" );
680 if ( _calculate_shannon_entropy ) {
681 System.out.print( "entn7" );
682 System.out.print( "\t" );
683 System.out.print( "entn21" );
684 System.out.print( "\t" );
686 System.out.println();
689 final private void realignWithMafft() throws IOException, InterruptedException {
690 final MsaInferrer mafft = Mafft.createInstance( _path_to_mafft );
691 final List<String> opts = new ArrayList<String>();
692 for( final String o : _maffts_opts.split( "\\s" ) ) {
695 _msa = DeleteableMsa.createInstance( mafft.infer( _msa.asSequenceList(), opts ) );
698 final private void removeGapColumns() {
699 _msa.deleteGapOnlyColumns();
702 private final String writeOutfile() throws IOException {
703 final String s = writeMsa( _out_file_base );
707 // Returns null if not path found.
708 final public static String guessPathToMafft() {
710 if ( ForesterUtil.OS_NAME.toLowerCase().indexOf( "win" ) >= 0 ) {
711 path = "C:\\Program Files\\mafft-win\\mafft.bat";
712 if ( MsaInferrer.isInstalled( path ) ) {
716 path = "/home/czmasek/SOFTWARE/MSA/MAFFT/mafft-7.130-without-extensions/scripts/mafft";
717 if ( MsaInferrer.isInstalled( path ) ) {
720 path = "/usr/local/bin/mafft";
721 if ( MsaInferrer.isInstalled( path ) ) {
724 path = "/usr/bin/mafft";
725 if ( MsaInferrer.isInstalled( path ) ) {
729 if ( MsaInferrer.isInstalled( path ) ) {
733 if ( MsaInferrer.isInstalled( path ) ) {
739 final private static void writeMsa( final Msa msa, final String outfile, final MSA_FORMAT format )
741 final Writer w = ForesterUtil.createBufferedWriter( outfile );
742 msa.write( w, format );