import org.forester.io.parsers.FastaParser;
import org.forester.io.parsers.GeneralMsaParser;
import org.forester.msa.Msa;
-import org.forester.msa.MsaInferrer;
import org.forester.msa.Msa.MSA_FORMAT;
-import org.forester.msa.MsaMethods;
+import org.forester.msa.MsaInferrer;
import org.forester.msa_compactor.MsaCompactor;
import org.forester.util.CommandLineArguments;
import org.forester.util.ForesterUtil;
final static private String HELP_OPTION_1 = "help";
final static private String HELP_OPTION_2 = "h";
- final static private String REMOVE_WORST_OFFENDERS_OPTION = "w";
- final static private String AV_GAPINESS_OPTION = "a";
+ final static private String REMOVE_WORST_OFFENDERS_OPTION = "r";
+ final static private String AV_GAPINESS_OPTION = "g";
final static private String STEP_OPTION = "s";
final static private String LENGTH_OPTION = "l";
- final static private String REALIGN_OPTION = "r";
+ final static private String REALIGN_OPTION = "a";
final static private String PATH_TO_MAFFT_OPTION = "mafft";
final static private String DO_NOT_NORMALIZE_FOR_EFF_LENGTH_OPTION = "nn";
final static private String PRG_NAME = "msa_compactor";
// printHelp();
// System.exit( 0 );
// }
-
if ( realign ) {
if ( ForesterUtil.isEmpty( path_to_mafft ) ) {
path_to_mafft = MsaCompactor.guessPathToMafft();
}
checkPathToMafft( path_to_mafft );
}
-
-
Msa msa = null;
final FileInputStream is = new FileInputStream( in );
if ( FastaParser.isLikelyFasta( in ) ) {
else {
msa = GeneralMsaParser.parse( is );
}
-
-
-
MsaCompactor mc = null;
if ( worst_remove > 0 ) {
mc = MsaCompactor.removeWorstOffenders( msa, worst_remove, realign, norm, path_to_mafft );
else if ( length > 0 ) {
mc = MsaCompactor.reduceLength( msa, length, step, realign, path_to_mafft );
}
- System.out.println( MsaMethods.calcGapRatio( mc.getMsa() ) );
- for( final String id : mc.getRemovedSeqIds() ) {
- System.out.println( id );
- }
+ //System.out.println( MsaMethods.calcGapRatio( mc.getMsa() ) );
+ // for( final String id : mc.getRemovedSeqIds() ) {
+ // System.out.println( id );
+ //}
mc.writeMsa( out, MSA_FORMAT.PHYLIP, ".aln" );
}
catch ( final Exception e ) {
}
}
- private static void checkPathToMafft( String path_to_mafft ) {
+ private static void checkPathToMafft( final String path_to_mafft ) {
if ( !ForesterUtil.isEmpty( path_to_mafft ) && MsaInferrer.isInstalled( path_to_mafft ) ) {
- ForesterUtil.programMessage( PRG_NAME, "using MAFFT at \"" + path_to_mafft + "\"" );
+ ForesterUtil.programMessage( PRG_NAME, "using MAFFT at \"" + path_to_mafft + "\"" );
}
else {
if ( ForesterUtil.isEmpty( path_to_mafft ) ) {
- ForesterUtil.fatalError( PRG_NAME, "no MAFFT executable found, use -\"" + PATH_TO_MAFFT_OPTION + "=<path to MAFFT>\" option" );
+ ForesterUtil.fatalError( PRG_NAME, "no MAFFT executable found, use -\"" + PATH_TO_MAFFT_OPTION
+ + "=<path to MAFFT>\" option" );
}
else {
- ForesterUtil.fatalError( PRG_NAME, "no MAFFT executable at \"" + path_to_mafft + "\"" );
+ ForesterUtil.fatalError( PRG_NAME, "no MAFFT executable at \"" + path_to_mafft + "\"" );
}
}
}
final String path_to_mafft = MsaCompactor.guessPathToMafft();
String mafft_comment;
if ( !ForesterUtil.isEmpty( path_to_mafft ) ) {
- mafft_comment = " (" + path_to_mafft + ")";
+ mafft_comment = " (using " + path_to_mafft + ")";
}
else {
mafft_comment = " (no path to MAFFT found, use -\"" + PATH_TO_MAFFT_OPTION + "=<path to MAFFT>\" option";
}
-
System.out.println( "Usage:" );
System.out.println();
- System.out.println( PRG_NAME + " <options> <msa input file>" );
+ System.out.println( PRG_NAME + " <options> <msa input file> <output file>" );
System.out.println();
System.out.println( " options: " );
System.out.println();
- System.out.println( " -" + REMOVE_WORST_OFFENDERS_OPTION + "=<integer> number of sequences to remove" );
- System.out.println( " -" + REALIGN_OPTION + " to realign using MAFFT" + mafft_comment );
+ System.out.println( " -" + REMOVE_WORST_OFFENDERS_OPTION
+ + "=<integer> number of worst offender sequences to remove" );
+ System.out.println( " -" + REALIGN_OPTION + " to realign using MAFFT" + mafft_comment );
System.out.println();
System.out.println();
System.out.println();
import java.util.SortedSet;
import java.util.TreeSet;
-import org.forester.archaeopteryx.Archaeopteryx;
import org.forester.evoinference.distance.NeighborJoiningF;
import org.forester.evoinference.distance.PairwiseDistanceCalculator;
import org.forester.evoinference.distance.PairwiseDistanceCalculator.PWD_DISTANCE_METHOD;
import org.forester.phylogeny.PhylogenyMethods;
import org.forester.sequence.Sequence;
import org.forester.tools.ConfidenceAssessor;
+import org.forester.util.BasicDescriptiveStatistics;
+import org.forester.util.DescriptiveStatistics;
import org.forester.util.ForesterUtil;
public class MsaCompactor {
private static final boolean VERBOSE = true;
private Msa _msa;
private final SortedSet<String> _removed_seq_ids;
- private String _path_to_mafft;
+ private String _path_to_mafft;
static {
NF_4.setRoundingMode( RoundingMode.HALF_UP );
NF_3.setRoundingMode( RoundingMode.HALF_UP );
final private GapContribution[] calcGapContribtionsStats( final boolean norm ) {
final GapContribution stats[] = calcGapContribtions( norm );
Arrays.sort( stats );
- for( final GapContribution stat : stats ) {
- final StringBuilder sb = new StringBuilder();
- sb.append( stat.getId() );
- sb.append( "\t" );
- sb.append( NF_4.format( stat.getValue() ) );
- sb.append( "\t" );
- // sb.append( NF_4.format( stat.median() ) );
- // sb.append( "\t" );
- // sb.append( NF_4.format( stat.getMin() ) );
- // sb.append( "\t" );
- // sb.append( NF_4.format( stat.getMax() ) );
- //sb.append( "\t" );
- System.out.println( sb );
+ // for( final GapContribution stat : stats ) {
+ // final StringBuilder sb = new StringBuilder();
+ // sb.append( stat.getId() );
+ // sb.append( "\t" );
+ // sb.append( NF_4.format( stat.getValue() ) );
+ // sb.append( "\t" );
+ // sb.append( NF_4.format( stat.median() ) );
+ // sb.append( "\t" );
+ // sb.append( NF_4.format( stat.getMin() ) );
+ // sb.append( "\t" );
+ // sb.append( NF_4.format( stat.getMax() ) );
+ //sb.append( "\t" );
+ //System.out.println( sb );
+ // }
+ return stats;
+ }
+
+ private static DescriptiveStatistics calculateIdentityRatio( final int from, final int to, final Msa msa ) {
+ final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
+ for( int c = from; c <= to; ++c ) {
+ stats.addValue( MsaMethods.calculateIdentityRatio( msa, c ) );
}
return stats;
}
}
return gappiness;
}
-
+
// Returns null if not path found.
final public static String guessPathToMafft() {
String path;
if ( MsaInferrer.isInstalled( path ) ) {
return path;
}
-
}
path = "/usr/local/bin/mafft";
if ( MsaInferrer.isInstalled( path ) ) {
}
return null;
}
-
final private void mafft() throws IOException, InterruptedException {
- // final MsaInferrer mafft = Mafft
+ // final MsaInferrer mafft = Mafft
// .createInstance( "/home/czmasek/SOFTWARE/MSA/MAFFT/mafft-7.130-without-extensions/scripts/mafft" );
-
- final MsaInferrer mafft = Mafft
- .createInstance( _path_to_mafft );
-
-
+ final MsaInferrer mafft = Mafft.createInstance( _path_to_mafft );
final List<String> opts = new ArrayList<String>();
opts.add( "--maxiterate" );
opts.add( "1000" );
sb.append( _msa.getLength() );
sb.append( "\t" );
sb.append( NF_3.format( MsaMethods.calcGapRatio( _msa ) ) );
+ sb.append( "\t" );
+ sb.append( NF_3.format( calculateIdentityRatio( 0, _msa.getLength() - 1, _msa ).arithmeticMean() ) );
return sb;
}
final int step,
final boolean realign,
final boolean norm ) throws IOException, InterruptedException {
- final Phylogeny a = pi( "a.pwd" );
- Archaeopteryx.createApplication( a );
+ //final Phylogeny a = pi( "a.pwd" );
+ //Archaeopteryx.createApplication( a );
final GapContribution stats[] = calcGapContribtionsStats( norm );
final List<String> to_remove_ids = new ArrayList<String>();
for( int j = 0; j < to_remove; ++j ) {
to_remove_ids.add( stats[ j ].getId() );
_removed_seq_ids.add( stats[ j ].getId() );
}
- //TODO if verbose/interactve
+ //TODO if verbose/interactive
for( final String id : to_remove_ids ) {
_msa = MsaMethods.removeSequence( _msa, id );
removeGapColumns();
- System.out.print( id );
+ //System.out.print( id );
+ System.out.print( ForesterUtil.pad( id, 20, ' ', false ) );
System.out.print( "\t" );
final StringBuilder sb = msaStatsAsSB();
System.out.println( sb );
if ( realign ) {
mafft();
}
- final Phylogeny b = pi( "b.pwd" );
- Archaeopteryx.createApplication( b );
+ //final Phylogeny b = pi( "b.pwd" );
+ //Archaeopteryx.createApplication( b );
}
final private void writeMsa( final String outfile, final MSA_FORMAT format ) throws IOException {
final String path_to_mafft ) throws IOException,
InterruptedException {
final MsaCompactor mc = new MsaCompactor( msa );
- if ( realign) {
+ if ( realign ) {
mc.setPathToMafft( path_to_mafft );
}
mc.removeViaGapAverage( max_gap_average, step, realign, out, minimal_effective_length );
final int length,
final int step,
final boolean realign,
- final String path_to_mafft ) throws IOException, InterruptedException {
+ final String path_to_mafft ) throws IOException,
+ InterruptedException {
final MsaCompactor mc = new MsaCompactor( msa );
- if ( realign) {
+ if ( realign ) {
mc.setPathToMafft( path_to_mafft );
}
mc.removeViaLength( length, step, realign );
final String path_to_mafft ) throws IOException,
InterruptedException {
final MsaCompactor mc = new MsaCompactor( msa );
- if ( realign) {
+ if ( realign ) {
mc.setPathToMafft( path_to_mafft );
}
mc.removeWorstOffenders( worst_offenders_to_remove, 1, realign, norm );
private void setPathToMafft( final String path_to_mafft ) {
_path_to_mafft = path_to_mafft;
-
}
}
private static boolean testMsaQualityMethod() {
try {
- final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
- final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
- final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
- final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
+ final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
+ final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
+ final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
+ final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
final List<Sequence> l = new ArrayList<Sequence>();
l.add( s0 );
l.add( s1 );
if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
return false;
}
+ if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
+ return false;
+ }
+ if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
+ return false;
+ }
+ if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
+ return false;
+ }
}
catch ( final Exception e ) {
e.printStackTrace( System.out );