import java.util.List;
import java.util.Set;
+import org.forester.io.parsers.util.ParserUtils;
import org.forester.io.writers.PhylogenyWriter;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.PhylogenyNode;
Phylogeny[] evaluators = null;
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
try {
- targets = factory.create( target_file, ForesterUtil.createParserDependingOnFileType( target_file, true ) );
+ targets = factory.create( target_file, ParserUtils.createParserDependingOnFileType( target_file, true ) );
}
catch ( final IOException e ) {
ForesterUtil.fatalError( PRG_NAME,
}
try {
evaluators = factory.create( evaluators_file,
- ForesterUtil.createParserDependingOnFileType( evaluators_file, true ) );
+ ParserUtils.createParserDependingOnFileType( evaluators_file, true ) );
}
catch ( final IOException e ) {
ForesterUtil.fatalError( PRG_NAME, "failed to read evaluator topologies from [" + evaluators_file + "]: "
import java.util.List;
import org.forester.io.parsers.PhylogenyParser;
+import org.forester.io.parsers.util.ParserUtils;
import org.forester.io.writers.PhylogenyWriter;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.PhylogenyMethods;
Phylogeny[] ev = null;
try {
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
- final PhylogenyParser pp = ForesterUtil.createParserDependingOnFileType( phylogeny_infile, true );
+ final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( phylogeny_infile, true );
p = factory.create( phylogeny_infile, pp )[ 0 ];
}
catch ( final Exception e ) {
}
try {
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
- final PhylogenyParser pp = ForesterUtil.createParserDependingOnFileType( evaluators_infile, true );
+ final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( evaluators_infile, true );
ev = factory.create( evaluators_infile, pp );
}
catch ( final Exception e ) {
import java.util.Map;
import org.forester.io.parsers.PhylogenyParser;
+import org.forester.io.parsers.util.ParserUtils;
import org.forester.io.writers.PhylogenyWriter;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.data.Identifier;
Phylogeny[] phylogenies = null;
try {
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
- final PhylogenyParser pp = ForesterUtil.createParserDependingOnFileType( phylogenies_infile, true );
+ final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( phylogenies_infile, true );
phylogenies = factory.create( phylogenies_infile, pp );
}
catch ( final Exception e ) {
import java.util.List;
import org.forester.io.parsers.PhylogenyParser;
+import org.forester.io.parsers.util.ParserUtils;
import org.forester.io.writers.PhylogenyWriter;
import org.forester.phylogeny.Phylogeny;
+import org.forester.phylogeny.PhylogenyMethods;
import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
import org.forester.phylogeny.factories.PhylogenyFactory;
import org.forester.util.CommandLineArguments;
Phylogeny p = null;
try {
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
- final PhylogenyParser pp = ForesterUtil.createParserDependingOnFileType( phylogeny_infile, true );
+ final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( phylogeny_infile, true );
p = factory.create( phylogeny_infile, pp )[ 0 ];
}
catch ( final Exception e ) {
}
if ( int_node_name_is_support ) {
try {
- ForesterUtil.transferInternalNodeNamesToConfidence( p );
+ PhylogenyMethods.transferInternalNodeNamesToConfidence( p );
}
catch ( final Exception e ) {
ForesterUtil.unexpectedFatalError( nhx_too.PRG_NAME,
import java.util.List;
import org.forester.io.parsers.PhylogenyParser;
+import org.forester.io.parsers.util.ParserUtils;
import org.forester.io.writers.PhylogenyWriter;
import org.forester.pccx.BasicExternalNodeBasedCoverageExtender;
import org.forester.pccx.Coverage;
Phylogeny[] phylogenies = null;
try {
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
- final PhylogenyParser pp = ForesterUtil.createParserDependingOnFileType( phylogenies_infile, true );
+ final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( phylogenies_infile, true );
phylogenies = factory.create( phylogenies_infile, pp );
}
catch ( final IOException e ) {
import org.forester.io.parsers.PhylogenyParser;
import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
import org.forester.io.parsers.nhx.NHXParser;
+import org.forester.io.parsers.util.ParserUtils;
import org.forester.io.writers.PhylogenyWriter;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.PhylogenyMethods;
import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
import org.forester.util.CommandLineArguments;
import org.forester.util.ForesterUtil;
-import org.forester.util.ForesterUtil.PhylogenyNodeField;
public class phyloxml_converter {
System.exit( -1 );
}
final String field_option_value = cla.getOptionValue( FIELD_OPTION );
- PhylogenyNodeField field = null;
+ PhylogenyMethods.PhylogenyNodeField field = null;
if ( field_option_value.equals( FIELD_CLADE_NAME ) ) {
- field = PhylogenyNodeField.CLADE_NAME;
+ field = PhylogenyMethods.PhylogenyNodeField.CLADE_NAME;
}
else if ( field_option_value.equals( FIELD_TAXONOMY_CODE ) ) {
- field = PhylogenyNodeField.TAXONOMY_CODE;
+ field = PhylogenyMethods.PhylogenyNodeField.TAXONOMY_CODE;
}
else if ( field_option_value.equals( FIELD_TAXONOMY_SCI_NAME ) ) {
- field = PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME;
+ field = PhylogenyMethods.PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME;
}
else if ( field_option_value.equals( FIELD_TAXONOMY_COMM_NAME ) ) {
- field = PhylogenyNodeField.TAXONOMY_COMMON_NAME;
+ field = PhylogenyMethods.PhylogenyNodeField.TAXONOMY_COMMON_NAME;
}
else if ( field_option_value.equals( FIELD_SEQUENCE_GENE_NAME ) ) {
- field = PhylogenyNodeField.SEQUENCE_NAME;
+ field = PhylogenyMethods.PhylogenyNodeField.SEQUENCE_NAME;
}
else if ( field_option_value.equals( FIELD_SEQUENCE_SYMBOL ) ) {
- field = PhylogenyNodeField.SEQUENCE_SYMBOL;
+ field = PhylogenyMethods.PhylogenyNodeField.SEQUENCE_SYMBOL;
}
else if ( field_option_value.equals( FIELD_UNIPROT_TAXONOMY_ID_SPLIT_1 ) ) {
- field = PhylogenyNodeField.TAXONOMY_ID_UNIPROT_1;
+ field = PhylogenyMethods.PhylogenyNodeField.TAXONOMY_ID_UNIPROT_1;
}
else if ( field_option_value.equals( FIELD_UNIPROT_TAXONOMY_ID_SPLIT_2 ) ) {
- field = PhylogenyNodeField.TAXONOMY_ID_UNIPROT_2;
+ field = PhylogenyMethods.PhylogenyNodeField.TAXONOMY_ID_UNIPROT_2;
}
else if ( field_option_value.equals( FIELD_DUMMY ) ) {
}
Phylogeny[] phys = null;
try {
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
- final PhylogenyParser parser = ForesterUtil.createParserDependingOnFileType( infile, true );
+ final PhylogenyParser parser = ParserUtils.createParserDependingOnFileType( infile, true );
if ( parser instanceof NHXParser ) {
- if ( ( field != PhylogenyNodeField.TAXONOMY_CODE )
- && ( field != PhylogenyNodeField.TAXONOMY_COMMON_NAME )
- && ( field != PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME ) ) {
+ if ( ( field != PhylogenyMethods.PhylogenyNodeField.TAXONOMY_CODE )
+ && ( field != PhylogenyMethods.PhylogenyNodeField.TAXONOMY_COMMON_NAME )
+ && ( field != PhylogenyMethods.PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME ) ) {
if ( extr_taxonomy_pf_only ) {
( ( NHXParser ) parser )
- .setTaxonomyExtraction( ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ .setTaxonomyExtraction( PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
replace_underscores = false;
}
else if ( extr_taxonomy ) {
- ( ( NHXParser ) parser ).setTaxonomyExtraction( ForesterUtil.TAXONOMY_EXTRACTION.YES );
+ ( ( NHXParser ) parser ).setTaxonomyExtraction( PhylogenyMethods.TAXONOMY_EXTRACTION.YES );
replace_underscores = false;
}
}
else {
- ( ( NHXParser ) parser ).setTaxonomyExtraction( ForesterUtil.TAXONOMY_EXTRACTION.NO );
+ ( ( NHXParser ) parser ).setTaxonomyExtraction( PhylogenyMethods.TAXONOMY_EXTRACTION.NO );
}
( ( NHXParser ) parser ).setReplaceUnderscores( replace_underscores );
( ( NHXParser ) parser ).setIgnoreQuotes( false );
}
if ( int_values_are_boots ) {
for( final Phylogeny phy : phys ) {
- ForesterUtil.transferInternalNamesToBootstrapSupport( phy );
+ PhylogenyMethods.transferInternalNamesToBootstrapSupport( phy );
}
}
if ( field != null ) {
for( final Phylogeny phy : phys ) {
- ForesterUtil.transferNodeNameToField( phy, field );
+ PhylogenyMethods.transferNodeNameToField( phy, field );
}
}
if ( midpoint_reroot ) {
import java.io.PrintWriter;
import org.forester.io.parsers.PhylogenyParser;
+import org.forester.io.parsers.util.ParserUtils;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.PhylogenyMethods;
import org.forester.phylogeny.PhylogenyNode;
import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
import org.forester.phylogeny.factories.PhylogenyFactory;
-import org.forester.util.ForesterUtil;
public class printAllSpecies {
outfile = new File( args[ 1 ] );
try {
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
- final PhylogenyParser pp = ForesterUtil.createParserDependingOnFileType( infile, true );
+ final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( infile, true );
tree = factory.create( infile, pp )[ 0 ];
}
catch ( final Exception e ) {
import java.io.PrintWriter;
import org.forester.io.parsers.PhylogenyParser;
+import org.forester.io.parsers.util.ParserUtils;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.PhylogenyNode;
import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
import org.forester.phylogeny.factories.PhylogenyFactory;
-import org.forester.util.ForesterUtil;
public class printSameOrder {
outfile = new File( args[ 1 ] );
try {
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
- final PhylogenyParser pp = ForesterUtil.createParserDependingOnFileType( infile, true );
+ final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( infile, true );
tree = factory.create( infile, pp )[ 0 ];
}
catch ( final Exception e ) {
import java.io.IOException;
import org.forester.io.parsers.PhylogenyParser;
+import org.forester.io.parsers.util.ParserUtils;
import org.forester.io.writers.PhylogenyWriter;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.PhylogenyMethods;
import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
import org.forester.phylogeny.factories.PhylogenyFactory;
-import org.forester.util.ForesterUtil;
public class strip {
Phylogeny p = null;
try {
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
- final PhylogenyParser pp = ForesterUtil.createParserDependingOnFileType( infile, true );
+ final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( infile, true );
p = factory.create( infile, pp )[ 0 ];
}
catch ( final Exception e ) {
try {
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
final File f = new File( file );
- final PhylogenyParser pp = ForesterUtil.createParserDependingOnFileType( f, true );
+ final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( f, true );
p0 = factory.create( f, pp )[ 0 ];
}
catch ( final Exception e ) {
import java.util.List;
import org.forester.io.parsers.PhylogenyParser;
+import org.forester.io.parsers.util.ParserUtils;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.PhylogenyMethods;
import org.forester.phylogeny.PhylogenyNode;
for( int i = 0; i < phylogenies_infiles.length; i++ ) {
try {
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
- final PhylogenyParser pp = ForesterUtil
- .createParserDependingOnFileType( phylogenies_infiles[ i ], true );
+ final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( phylogenies_infiles[ i ], true );
phylogenies[ i ] = factory.create( phylogenies_infiles[ i ], pp )[ 0 ];
}
catch ( final IOException e ) {
import org.forester.io.parsers.PhylogenyParser;
import org.forester.io.parsers.nhx.NHXParser;
+import org.forester.io.parsers.util.ParserUtils;
import org.forester.io.writers.PhylogenyWriter;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.PhylogenyMethods;
import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
import org.forester.phylogeny.factories.PhylogenyFactory;
import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
-import org.forester.util.ForesterUtil;
public final class support_transfer {
System.exit( -1 );
}
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
- final PhylogenyParser pp_bl = ForesterUtil.createParserDependingOnFileType( infile_bl, true );
- final PhylogenyParser pp_s = ForesterUtil.createParserDependingOnFileType( infile_support_vals, true );
+ final PhylogenyParser pp_bl = ParserUtils.createParserDependingOnFileType( infile_bl, true );
+ final PhylogenyParser pp_s = ParserUtils.createParserDependingOnFileType( infile_support_vals, true );
if ( pp_bl instanceof NHXParser ) {
- ( ( NHXParser ) pp_bl ).setTaxonomyExtraction( ForesterUtil.TAXONOMY_EXTRACTION.YES );
+ ( ( NHXParser ) pp_bl ).setTaxonomyExtraction( PhylogenyMethods.TAXONOMY_EXTRACTION.YES );
}
phylogeny_w_bl = factory.create( infile_bl, pp_bl )[ index_of_tree_w_bl ];
phylogeny_w_support_vals = factory.create( infile_support_vals, pp_s )[ 0 ];
import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
import org.forester.io.parsers.nexus.PaupLogParser;
import org.forester.phylogeny.Phylogeny;
+import org.forester.phylogeny.PhylogenyNode;
import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
import org.forester.phylogeny.factories.PhylogenyFactory;
+import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
import org.forester.surfacing.DomainParsimonyCalculator;
import org.forester.surfacing.SurfacingUtil;
import org.forester.util.CommandLineArguments;
if ( !phylogeny.isRooted() ) {
ForesterUtil.fatalError( PRG_NAME, "phylogeny from [" + surfacing_nexus_outfile + "] is not rooted" );
}
- ForesterUtil.postOrderRelabelInternalNodes( phylogeny, phylogeny.getNumberOfExternalNodes() + 1 );
+ postOrderRelabelInternalNodes( phylogeny, phylogeny.getNumberOfExternalNodes() + 1 );
CharacterStateMatrix<BinaryStates> matrix = null;
final PaupLogParser paup_log_parser = new PaupLogParser();
try {
ForesterUtil.programMessage( PRG_NAME, "OK" );
}
+ final private static void postOrderRelabelInternalNodes( final Phylogeny phylogeny, final int starting_number ) {
+ int i = starting_number;
+ for( final PhylogenyNodeIterator it = phylogeny.iteratorPostorder(); it.hasNext(); ) {
+ final PhylogenyNode node = it.next();
+ if ( !node.isExternal() ) {
+ node.setName( String.valueOf( i++ ) );
+ }
+ }
+ }
+
private static void printHelp() {
System.out.println();
System.out.println( "Usage:" );
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import org.forester.go.PfamToGoParser;
import org.forester.io.parsers.HmmscanPerDomainTableParser;
import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
+import org.forester.io.parsers.util.ParserUtils;
import org.forester.io.writers.PhylogenyWriter;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.PhylogenyMethods;
import org.forester.surfacing.ProteinCountsBasedPairwiseDomainSimilarityCalculator;
import org.forester.surfacing.Species;
import org.forester.surfacing.SurfacingUtil;
+import org.forester.util.BasicDescriptiveStatistics;
import org.forester.util.BasicTable;
import org.forester.util.BasicTableParser;
import org.forester.util.CommandLineArguments;
}
try {
final Phylogeny[] p_array = ParserBasedPhylogenyFactory.getInstance()
- .create( intree_file, ForesterUtil.createParserDependingOnFileType( intree_file, true ) );
+ .create( intree_file, ParserUtils.createParserDependingOnFileType( intree_file, true ) );
if ( p_array.length < 1 ) {
ForesterUtil.fatalError( surfacing.PRG_NAME, "file [" + intree_file
+ "] does not contain any phylogeny in phyloXML format" );
}
} // if ( perform_pwc ) {
System.out.println();
- html_desc.append( "<tr><td>Command line:</td><td>" + cla.getCommandLineArgsAsString() + "</td></tr>" + nl );
+ html_desc.append( "<tr><td>Command line:</td><td>\n" + cla.getCommandLineArgsAsString() + "\n</td></tr>" + nl );
System.out.println( "Command line : " + cla.getCommandLineArgsAsString() );
BufferedWriter[] query_domains_writer_ary = null;
List<DomainId>[] query_domain_ids_array = null;
catch ( final IOException e2 ) {
ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getMessage() );
}
+ final DescriptiveStatistics all_genomes_domains_per_potein_stats = new BasicDescriptiveStatistics();
+ final SortedMap<Integer, Integer> all_genomes_domains_per_potein_histo = new TreeMap<Integer, Integer>();
+ final SortedSet<String> domains_which_are_always_single = new TreeSet<String>();
+ final SortedSet<String> domains_which_are_sometimes_single_sometimes_not = new TreeSet<String>();
+ final SortedSet<String> domains_which_never_single = new TreeSet<String>();
+ final BufferedWriter domains_which_are_always_single_writer = null;
+ final BufferedWriter domains_which_are_sometimes_single_sometimes_not_writer = null;
+ final BufferedWriter domains_which_never_single_writer = null;
+ BufferedWriter all_genomes_domains_per_potein_histo_writer = null;
+ BufferedWriter domains_per_potein_stats_writer = null;
+ try {
+ all_genomes_domains_per_potein_histo_writer = new BufferedWriter( new FileWriter( out_dir
+ + ForesterUtil.FILE_SEPARATOR + output_file + "__all_genomes_domains_per_potein_histo.txt" ) );
+ domains_per_potein_stats_writer = new BufferedWriter( new FileWriter( out_dir + ForesterUtil.FILE_SEPARATOR
+ + output_file + "__domains_per_potein_stats.txt" ) );
+ domains_per_potein_stats_writer.write( "Genome" );
+ domains_per_potein_stats_writer.write( "\t" );
+ domains_per_potein_stats_writer.write( "Mean" );
+ domains_per_potein_stats_writer.write( "\t" );
+ domains_per_potein_stats_writer.write( "SD" );
+ domains_per_potein_stats_writer.write( "\t" );
+ domains_per_potein_stats_writer.write( "Median" );
+ domains_per_potein_stats_writer.write( "\t" );
+ domains_per_potein_stats_writer.write( "N" );
+ domains_per_potein_stats_writer.write( "\t" );
+ domains_per_potein_stats_writer.write( "Min" );
+ domains_per_potein_stats_writer.write( "\t" );
+ domains_per_potein_stats_writer.write( "Max" );
+ domains_per_potein_stats_writer.write( "\n" );
+ }
+ catch ( final IOException e3 ) {
+ e3.printStackTrace();
+ }
for( int i = 0; i < number_of_genomes; ++i ) {
System.out.println();
System.out.println( ( i + 1 ) + "/" + number_of_genomes );
catch ( final IOException e ) {
ForesterUtil.fatalError( surfacing.PRG_NAME, e.toString() );
}
+ SurfacingUtil.domainsPerProteinsStatistics( input_file_properties[ i ][ 0 ],
+ protein_list,
+ all_genomes_domains_per_potein_stats,
+ all_genomes_domains_per_potein_histo,
+ domains_which_are_always_single,
+ domains_which_are_sometimes_single_sometimes_not,
+ domains_which_never_single,
+ domains_per_potein_stats_writer );
gwcd_list.add( BasicGenomeWideCombinableDomains
.createInstance( protein_list,
ignore_combination_with_same,
}
ForesterUtil.programMessage( PRG_NAME, "Wrote domain promiscuities to: "
+ per_genome_domain_promiscuity_statistics_file );
+ //
+ try {
+ domains_per_potein_stats_writer.write( "ALL" );
+ domains_per_potein_stats_writer.write( "\t" );
+ domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.arithmeticMean() + "" );
+ domains_per_potein_stats_writer.write( "\t" );
+ domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.sampleStandardDeviation() + "" );
+ domains_per_potein_stats_writer.write( "\t" );
+ domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.median() + "" );
+ domains_per_potein_stats_writer.write( "\t" );
+ domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.getN() + "" );
+ domains_per_potein_stats_writer.write( "\t" );
+ domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.getMin() + "" );
+ domains_per_potein_stats_writer.write( "\t" );
+ domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.getMax() + "" );
+ domains_per_potein_stats_writer.write( "\n" );
+ domains_per_potein_stats_writer.flush();
+ domains_per_potein_stats_writer.close();
+ for( final Entry<Integer, Integer> entry : all_genomes_domains_per_potein_histo.entrySet() ) {
+ all_genomes_domains_per_potein_histo_writer.write( entry.getKey() + "\t" + entry.getValue() + "\n" );
+ }
+ all_genomes_domains_per_potein_histo_writer.flush();
+ all_genomes_domains_per_potein_histo_writer.close();
+ }
+ catch ( final IOException e2 ) {
+ ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getLocalizedMessage() );
+ }
+ //
if ( query_domains_writer_ary != null ) {
for( int j = 0; j < query_domain_ids_array.length; j++ ) {
try {
import org.forester.go.PfamToGoMapping;
import org.forester.go.PfamToGoParser;
import org.forester.io.parsers.HmmPfamOutputParser;
+import org.forester.io.parsers.util.ParserUtils;
import org.forester.io.writers.PhylogenyWriter;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.PhylogenyMethods;
}
try {
final Phylogeny[] p_array = ParserBasedPhylogenyFactory.getInstance()
- .create( intree_file, ForesterUtil.createParserDependingOnFileType( intree_file, true ) );
+ .create( intree_file, ParserUtils.createParserDependingOnFileType( intree_file, true ) );
if ( p_array.length < 1 ) {
ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "file [" + intree_file
+ "] does not contain any phylogeny in phyloXML format" );
import java.util.List;
import org.forester.io.parsers.PhylogenyParser;
+import org.forester.io.parsers.util.ParserUtils;
import org.forester.io.writers.PhylogenyWriter;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
}
try {
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
- final PhylogenyParser pp = ForesterUtil.createParserDependingOnFileType( species_tree_file, true );
+ final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( species_tree_file, true );
species_tree = factory.create( species_tree_file, pp )[ 0 ];
}
catch ( final IOException e ) {
}
try {
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
- final PhylogenyParser pp = ForesterUtil.createParserDependingOnFileType( gene_tree_file, true );
+ final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( gene_tree_file, true );
gene_tree = factory.create( gene_tree_file, pp )[ 0 ];
}
catch ( final IOException e ) {
import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
import org.forester.io.parsers.nhx.NHXParser;
import org.forester.io.parsers.phyloxml.PhyloXmlParser;
+import org.forester.io.parsers.util.ParserUtils;
import org.forester.phylogeny.Phylogeny;
+import org.forester.phylogeny.PhylogenyMethods;
import org.forester.util.ForesterUtil;
//
ForesterUtil.fatalError( Constants.PRG_NAME, err );
}
boolean nhx_or_nexus = false;
- final PhylogenyParser p = ForesterUtil.createParserDependingOnFileType( f, conf
+ final PhylogenyParser p = ParserUtils.createParserDependingOnFileType( f, conf
.isValidatePhyloXmlAgainstSchema() );
if ( p instanceof NHXParser ) {
nhx_or_nexus = true;
final NHXParser nhx = ( NHXParser ) p;
nhx.setReplaceUnderscores( conf.isReplaceUnderscoresInNhParsing() );
nhx.setIgnoreQuotes( false );
- ForesterUtil.TAXONOMY_EXTRACTION te = ForesterUtil.TAXONOMY_EXTRACTION.NO;
+ PhylogenyMethods.TAXONOMY_EXTRACTION te = PhylogenyMethods.TAXONOMY_EXTRACTION.NO;
if ( conf.isExtractPfamTaxonomyCodesInNhParsing() ) {
- te = ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY;
+ te = PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY;
}
nhx.setTaxonomyExtraction( te );
}
else if ( p instanceof PhyloXmlParser ) {
MainFrameApplication.warnIfNotPhyloXmlValidation( conf );
}
- phylogenies = ForesterUtil.readPhylogenies( p, f );
+ phylogenies = PhylogenyMethods.readPhylogenies( p, f );
if ( nhx_or_nexus && conf.isInternalNumberAreConfidenceForNhParsing() ) {
for( final Phylogeny phy : phylogenies ) {
- ForesterUtil.transferInternalNodeNamesToConfidence( phy );
+ PhylogenyMethods.transferInternalNodeNamesToConfidence( phy );
}
}
}
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
+import org.apache.commons.codec.binary.Base64;
import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
import org.forester.phylogeny.data.SequenceRelation;
import org.forester.util.ForesterConstants;
import org.forester.util.ForesterUtil;
-import org.apache.commons.codec.binary.Base64;
// Use like this:
// <applet archive="forester.jar"
* @author Herve Menager
*/
public String getCurrentPhylogenyGraphicsAsBase64EncodedString( final String format ) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- try{
- Util.writePhylogenyToGraphicsByteArrayOutputStream( baos,
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try {
+ Util.writePhylogenyToGraphicsByteArrayOutputStream( baos,
_main_panel.getWidth(),
_main_panel.getHeight(),
- this.getCurrentTreePanel(),
+ getCurrentTreePanel(),
getCurrentTreePanel().getControlPanel(),
- GraphicsExportType.valueOf(format),
- getOptions());
- }catch(IOException ioe){
+ GraphicsExportType.valueOf( format ),
+ getOptions() );
+ }
+ catch ( final IOException ioe ) {
ForesterUtil.printErrorMessage( NAME, ioe.toString() );
ioe.printStackTrace();
JOptionPane.showMessageDialog( this,
JOptionPane.ERROR_MESSAGE );
return null;
}
- byte[] bytes = baos.toByteArray();
- String dataImg = Base64.encodeBase64String(bytes);
+ final byte[] bytes = baos.toByteArray();
+ final String dataImg = Base64.encodeBase64String( bytes );
return dataImg;
}
-
+
void buildFontSizeMenu() {
_font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
_font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
if ( ( current_tree_panel == null ) || ( current_tree_panel.getPhylogeny() == null ) ) {
mi.setEnabled( true );
}
- else if ( ForesterUtil.isHasAtLeastOneBranchWithSupportValues( current_tree_panel.getPhylogeny() ) ) {
+ else if ( Util.isHasAtLeastOneBranchWithSupportValues( current_tree_panel.getPhylogeny() ) ) {
mi.setEnabled( true );
}
else {
import org.forester.io.parsers.phyloxml.PhyloXmlParser;
import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
import org.forester.io.parsers.tol.TolParser;
+import org.forester.io.parsers.util.ParserUtils;
import org.forester.io.writers.PhylogenyWriter;
import org.forester.io.writers.SequenceWriter;
import org.forester.msa.Msa;
import org.forester.util.BasicTableParser;
import org.forester.util.DescriptiveStatistics;
import org.forester.util.ForesterUtil;
-import org.forester.util.ForesterUtil.PhylogenyNodeField;
-import org.forester.util.ForesterUtil.TAXONOMY_EXTRACTION;
import org.forester.util.WindowsUtils;
class DefaultFilter extends FileFilter {
final PhylogenyNode n = it.next();
final String name = n.getName().trim();
if ( !ForesterUtil.isEmpty( name ) ) {
- final String code = ForesterUtil.extractTaxonomyCodeFromNodeName( name,
- false,
- TAXONOMY_EXTRACTION.YES );
+ final String code = ParserUtils
+ .extractTaxonomyCodeFromNodeName( name, false, PhylogenyMethods.TAXONOMY_EXTRACTION.YES );
if ( !ForesterUtil.isEmpty( code ) ) {
PhylogenyMethods.setTaxonomyCode( n, code );
}
if ( getCurrentTreePanel() != null ) {
final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
if ( ( phy != null ) && !phy.isEmpty() ) {
- ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.SEQUENCE_NAME );
+ PhylogenyMethods.transferNodeNameToField( phy, PhylogenyMethods.PhylogenyNodeField.SEQUENCE_NAME );
}
}
}
if ( getCurrentTreePanel() != null ) {
final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
if ( ( phy != null ) && !phy.isEmpty() ) {
- ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME );
+ PhylogenyMethods.transferNodeNameToField( phy,
+ PhylogenyMethods.PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME );
}
}
}
try {
final NHXParser nhx = new NHXParser();
setSpecialOptionsForNhxParser( nhx );
- phys = ForesterUtil.readPhylogenies( nhx, file );
+ phys = PhylogenyMethods.readPhylogenies( nhx, file );
nhx_or_nexus = true;
}
catch ( final Exception e ) {
warnIfNotPhyloXmlValidation( getConfiguration() );
try {
final PhyloXmlParser xml_parser = createPhyloXmlParser();
- phys = ForesterUtil.readPhylogenies( xml_parser, file );
+ phys = PhylogenyMethods.readPhylogenies( xml_parser, file );
}
catch ( final Exception e ) {
exception = true;
}
else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) {
try {
- phys = ForesterUtil.readPhylogenies( new TolParser(), file );
+ phys = PhylogenyMethods.readPhylogenies( new TolParser(), file );
}
catch ( final Exception e ) {
exception = true;
try {
final NexusPhylogeniesParser nex = new NexusPhylogeniesParser();
setSpecialOptionsForNexParser( nex );
- phys = ForesterUtil.readPhylogenies( nex, file );
+ phys = PhylogenyMethods.readPhylogenies( nex, file );
nhx_or_nexus = true;
}
catch ( final Exception e ) {
// "*.*":
else {
try {
- final PhylogenyParser parser = ForesterUtil
+ final PhylogenyParser parser = ParserUtils
.createParserDependingOnFileType( file, getConfiguration()
.isValidatePhyloXmlAgainstSchema() );
if ( parser instanceof NexusPhylogeniesParser ) {
else if ( parser instanceof PhyloXmlParser ) {
warnIfNotPhyloXmlValidation( getConfiguration() );
}
- phys = ForesterUtil.readPhylogenies( parser, file );
+ phys = PhylogenyMethods.readPhylogenies( parser, file );
}
catch ( final Exception e ) {
exception = true;
if ( nhx_or_nexus ) {
for( final Phylogeny phy : phys ) {
if ( getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
- ForesterUtil.transferInternalNodeNamesToConfidence( phy );
+ PhylogenyMethods.transferInternalNodeNamesToConfidence( phy );
}
if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) {
one_desc = true;
parser = new TolParser();
}
else {
- parser = ForesterUtil.createParserDependingOnUrlContents( url, getConfiguration()
+ parser = ParserUtils.createParserDependingOnUrlContents( url, getConfiguration()
.isValidatePhyloXmlAgainstSchema() );
}
if ( parser instanceof NexusPhylogeniesParser ) {
if ( ( phys != null ) && ( phys.length > 0 ) ) {
if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
for( final Phylogeny phy : phys ) {
- ForesterUtil.transferInternalNodeNamesToConfidence( phy );
+ PhylogenyMethods.transferInternalNodeNamesToConfidence( phy );
}
}
Util.addPhylogeniesToTabs( phys,
if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.xmlfilter ) {
try {
- final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
+ final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new PhyloXmlParser(), file );
t = trees[ 0 ];
}
catch ( final Exception e ) {
}
else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.tolfilter ) {
try {
- final Phylogeny[] trees = ForesterUtil.readPhylogenies( new TolParser(), file );
+ final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new TolParser(), file );
t = trees[ 0 ];
}
catch ( final Exception e ) {
// "*.*":
else {
try {
- final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
+ final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new PhyloXmlParser(), file );
t = trees[ 0 ];
}
catch ( final Exception e ) {
private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {
nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
- ForesterUtil.TAXONOMY_EXTRACTION te = ForesterUtil.TAXONOMY_EXTRACTION.NO;
+ PhylogenyMethods.TAXONOMY_EXTRACTION te = PhylogenyMethods.TAXONOMY_EXTRACTION.NO;
if ( getOptions().isExtractPfamTaxonomyCodesInNhParsing() ) {
- te = ForesterUtil.TAXONOMY_EXTRACTION.YES;
+ te = PhylogenyMethods.TAXONOMY_EXTRACTION.YES;
}
nhx.setTaxonomyExtraction( te );
}
}
private List<Point> obtainPoints() {
- ForesterUtil.ensurePresenceOfDistribution( getMyNode() );
+ Util.ensurePresenceOfDistribution( getMyNode() );
Distribution d = getMyNode().getNodeData().getDistribution();
if ( d.getPoints() == null ) {
d = new Distribution( d.getDesc(), new ArrayList<Point>(), d.getPolygons() );
}
break;
case TAXONOMY_CODE:
- ForesterUtil.ensurePresenceOfTaxonomy( getMyNode() );
+ Util.ensurePresenceOfTaxonomy( getMyNode() );
try {
getMyNode().getNodeData().getTaxonomy().setTaxonomyCode( value );
}
}
break;
case TAXONOMY_SCIENTIFIC_NAME:
- ForesterUtil.ensurePresenceOfTaxonomy( getMyNode() );
+ Util.ensurePresenceOfTaxonomy( getMyNode() );
getMyNode().getNodeData().getTaxonomy().setScientificName( value );
break;
case TAXONOMY_COMMON_NAME:
- ForesterUtil.ensurePresenceOfTaxonomy( getMyNode() );
+ Util.ensurePresenceOfTaxonomy( getMyNode() );
getMyNode().getNodeData().getTaxonomy().setCommonName( value );
break;
case TAXONOMY_RANK:
- ForesterUtil.ensurePresenceOfTaxonomy( getMyNode() );
+ Util.ensurePresenceOfTaxonomy( getMyNode() );
try {
getMyNode().getNodeData().getTaxonomy().setRank( value.toLowerCase() );
}
}
break;
case TAXONOMY_AUTHORITY:
- ForesterUtil.ensurePresenceOfTaxonomy( getMyNode() );
+ Util.ensurePresenceOfTaxonomy( getMyNode() );
getMyNode().getNodeData().getTaxonomy().setAuthority( value );
break;
case TAXONOMY_URI: {
}
}
if ( uri != null ) {
- ForesterUtil.ensurePresenceOfTaxonomy( getMyNode() );
+ Util.ensurePresenceOfTaxonomy( getMyNode() );
}
addUri( mtn, uri, number, getMyNode().getNodeData().getTaxonomy() );
break;
}
else if ( getMyNode().getNodeData().getTaxonomy().getSynonyms().size() == number ) {
if ( !ForesterUtil.isEmpty( value ) ) {
- ForesterUtil.ensurePresenceOfTaxonomy( getMyNode() );
+ Util.ensurePresenceOfTaxonomy( getMyNode() );
getMyNode().getNodeData().getTaxonomy().getSynonyms().add( value );
}
}
}
break;
case TAXONOMY_ID_VALUE:
- ForesterUtil.ensurePresenceOfTaxonomy( getMyNode() );
+ Util.ensurePresenceOfTaxonomy( getMyNode() );
if ( getMyNode().getNodeData().getTaxonomy().getIdentifier() == null ) {
getMyNode().getNodeData().getTaxonomy().setIdentifier( new Identifier( value ) );
}
}
break;
case TAXONOMY_ID_PROVIDER:
- ForesterUtil.ensurePresenceOfTaxonomy( getMyNode() );
+ Util.ensurePresenceOfTaxonomy( getMyNode() );
if ( getMyNode().getNodeData().getTaxonomy().getIdentifier() == null ) {
getMyNode().getNodeData().getTaxonomy().setIdentifier( new Identifier( "", value ) );
}
}
break;
case SEQ_LOCATION:
- ForesterUtil.ensurePresenceOfSequence( getMyNode() );
+ Util.ensurePresenceOfSequence( getMyNode() );
getMyNode().getNodeData().getSequence().setLocation( value );
break;
case SEQ_MOL_SEQ:
- ForesterUtil.ensurePresenceOfSequence( getMyNode() );
+ Util.ensurePresenceOfSequence( getMyNode() );
getMyNode().getNodeData().getSequence().setMolecularSequence( value );
break;
case SEQ_NAME:
- ForesterUtil.ensurePresenceOfSequence( getMyNode() );
+ Util.ensurePresenceOfSequence( getMyNode() );
getMyNode().getNodeData().getSequence().setName( value );
break;
case SEQ_SYMBOL:
- ForesterUtil.ensurePresenceOfSequence( getMyNode() );
+ Util.ensurePresenceOfSequence( getMyNode() );
try {
getMyNode().getNodeData().getSequence().setSymbol( value );
}
}
break;
case SEQ_TYPE:
- ForesterUtil.ensurePresenceOfSequence( getMyNode() );
+ Util.ensurePresenceOfSequence( getMyNode() );
try {
getMyNode().getNodeData().getSequence().setType( value.toLowerCase() );
}
}
break;
case SEQ_ACC_SOURCE:
- ForesterUtil.ensurePresenceOfSequence( getMyNode() );
+ Util.ensurePresenceOfSequence( getMyNode() );
if ( getMyNode().getNodeData().getSequence().getAccession() == null ) {
getMyNode().getNodeData().getSequence().setAccession( new Accession( "", value ) );
}
}
break;
case SEQ_ACC_VALUE:
- ForesterUtil.ensurePresenceOfSequence( getMyNode() );
+ Util.ensurePresenceOfSequence( getMyNode() );
if ( getMyNode().getNodeData().getSequence().getAccession() == null ) {
getMyNode().getNodeData().getSequence().setAccession( new Accession( value, "" ) );
}
}
}
if ( uri != null ) {
- ForesterUtil.ensurePresenceOfSequence( getMyNode() );
+ Util.ensurePresenceOfSequence( getMyNode() );
}
addUri( mtn, uri, number, getMyNode().getNodeData().getSequence() );
break;
getMyNode().getNodeData().getEvent().setGeneLosses( parsePositiveInt( mtn, value ) );
break;
case DATE_DESCRIPTION:
- ForesterUtil.ensurePresenceOfDate( getMyNode() );
+ Util.ensurePresenceOfDate( getMyNode() );
getMyNode().getNodeData().getDate().setDesc( value );
break;
case DATE_MAX:
- ForesterUtil.ensurePresenceOfDate( getMyNode() );
+ Util.ensurePresenceOfDate( getMyNode() );
getMyNode().getNodeData().getDate().setMax( parseBigDecimal( mtn, value ) );
break;
case DATE_MIN:
- ForesterUtil.ensurePresenceOfDate( getMyNode() );
+ Util.ensurePresenceOfDate( getMyNode() );
getMyNode().getNodeData().getDate().setMin( parseBigDecimal( mtn, value ) );
break;
case DATE_UNIT:
- ForesterUtil.ensurePresenceOfDate( getMyNode() );
+ Util.ensurePresenceOfDate( getMyNode() );
getMyNode().getNodeData().getDate().setUnit( value );
break;
case DATE_VALUE:
- ForesterUtil.ensurePresenceOfDate( getMyNode() );
+ Util.ensurePresenceOfDate( getMyNode() );
getMyNode().getNodeData().getDate().setValue( parseBigDecimal( mtn, value ) );
break;
case DIST_ALT: {
break;
}
case DIST_DESC: {
- ForesterUtil.ensurePresenceOfDistribution( getMyNode() );
+ Util.ensurePresenceOfDistribution( getMyNode() );
final Distribution d = getMyNode().getNodeData().getDistribution();
getMyNode().getNodeData().setDistribution( new Distribution( value, d.getPoints(), d.getPolygons() ) );
break;
_main_panel = tjp;
_configuration = configuration;
_phylogeny = t;
- _phy_has_branch_lengths = ForesterUtil.isHasAtLeastOneBranchLengthLargerThanZero( _phylogeny );
+ _phy_has_branch_lengths = Util.isHasAtLeastOneBranchLengthLargerThanZero( _phylogeny );
init();
// if ( !_phylogeny.isEmpty() ) {
_phylogeny.recalculateNumberOfExternalDescendants( true );
import org.forester.io.parsers.phyloxml.PhyloXmlParser;
import org.forester.io.parsers.tol.TolParser;
import org.forester.phylogeny.Phylogeny;
+import org.forester.phylogeny.PhylogenyMethods;
import org.forester.phylogeny.data.Identifier;
import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
import org.forester.phylogeny.factories.PhylogenyFactory;
break;
case NH:
parser = new NHXParser();
- ( ( NHXParser ) parser ).setTaxonomyExtraction( ForesterUtil.TAXONOMY_EXTRACTION.NO );
+ ( ( NHXParser ) parser ).setTaxonomyExtraction( PhylogenyMethods.TAXONOMY_EXTRACTION.NO );
( ( NHXParser ) parser ).setReplaceUnderscores( true );
( ( NHXParser ) parser ).setGuessRootedness( true );
break;
case NH_EXTRACT_TAXONOMY:
parser = new NHXParser();
( ( NHXParser ) parser )
- .setTaxonomyExtraction( ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ .setTaxonomyExtraction( PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
( ( NHXParser ) parser ).setReplaceUnderscores( false );
( ( NHXParser ) parser ).setGuessRootedness( true );
break;
case PFAM:
parser = new NHXParser();
( ( NHXParser ) parser )
- .setTaxonomyExtraction( ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ .setTaxonomyExtraction( PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
( ( NHXParser ) parser ).setReplaceUnderscores( false );
( ( NHXParser ) parser ).setGuessRootedness( true );
break;
case NHX:
parser = new NHXParser();
- ( ( NHXParser ) parser ).setTaxonomyExtraction( ForesterUtil.TAXONOMY_EXTRACTION.NO );
+ ( ( NHXParser ) parser ).setTaxonomyExtraction( PhylogenyMethods.TAXONOMY_EXTRACTION.NO );
( ( NHXParser ) parser ).setReplaceUnderscores( false );
( ( NHXParser ) parser ).setGuessRootedness( true );
break;
if ( client.getName().equals( WebserviceUtil.PFAM_NAME ) ) {
phylogeny.setRerootable( false );
phylogeny.setRooted( true );
- ForesterUtil.transferInternalNodeNamesToConfidence( phylogeny );
+ PhylogenyMethods.transferInternalNodeNamesToConfidence( phylogeny );
}
if ( client.getProcessingInstructions() != null ) {
WebserviceUtil.processInstructions( client, phylogeny );
}
if ( client.getNodeField() != null ) {
- ForesterUtil.transferNodeNameToField( phylogeny, client.getNodeField() );
+ PhylogenyMethods.transferNodeNameToField( phylogeny, client.getNodeField() );
}
phylogeny.setIdentifier( new Identifier( identifier, client.getName() ) );
_main_frame.getJMenuBar().remove( _main_frame.getHelpMenu() );
import org.forester.io.parsers.PhylogenyParser;
import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
import org.forester.io.parsers.tol.TolParser;
+import org.forester.io.parsers.util.ParserUtils;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.PhylogenyMethods;
import org.forester.phylogeny.PhylogenyNode;
import org.forester.phylogeny.data.BranchColor;
+import org.forester.phylogeny.data.Distribution;
+import org.forester.phylogeny.data.Sequence;
import org.forester.phylogeny.data.Taxonomy;
import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
import org.forester.phylogeny.factories.PhylogenyFactory;
Arrays.sort( AVAILABLE_FONT_FAMILIES_SORTED );
}
+ public static void ensurePresenceOfTaxonomy( final PhylogenyNode node ) {
+ if ( !node.getNodeData().isHasTaxonomy() ) {
+ node.getNodeData().setTaxonomy( new Taxonomy() );
+ }
+ }
+
+ public static void ensurePresenceOfSequence( final PhylogenyNode node ) {
+ if ( !node.getNodeData().isHasSequence() ) {
+ node.getNodeData().setSequence( new Sequence() );
+ }
+ }
+
+ final public static void ensurePresenceOfDistribution( final PhylogenyNode node ) {
+ if ( !node.getNodeData().isHasDistribution() ) {
+ node.getNodeData().setDistribution( new Distribution( "" ) );
+ }
+ }
+
+ final public static void ensurePresenceOfDate( final PhylogenyNode node ) {
+ if ( !node.getNodeData().isHasDate() ) {
+ node.getNodeData().setDate( new org.forester.phylogeny.data.Date() );
+ }
+ }
+
+ final static public boolean isHasAtLeastOneBranchWithSupportValues( final Phylogeny phy ) {
+ final PhylogenyNodeIterator it = phy.iteratorPostorder();
+ while ( it.hasNext() ) {
+ if ( it.next().getBranchData().isHasConfidences() ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns true if at least one branch has a length larger than zero.
+ *
+ *
+ * @param phy
+ */
+ final static public boolean isHasAtLeastOneBranchLengthLargerThanZero( final Phylogeny phy ) {
+ final PhylogenyNodeIterator it = phy.iteratorPostorder();
+ while ( it.hasNext() ) {
+ if ( it.next().getDistanceToParent() > 0.0 ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ final static public boolean isHasAtLeastNodeWithEvent( final Phylogeny phy ) {
+ final PhylogenyNodeIterator it = phy.iteratorPostorder();
+ while ( it.hasNext() ) {
+ if ( it.next().getNodeData().isHasEvent() ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
public static MaskFormatter createMaskFormatter( final String s ) {
MaskFormatter formatter = null;
try {
final ControlPanel atv_control,
final Configuration configuration ) {
if ( ( t != null ) && !t.isEmpty() ) {
- if ( !ForesterUtil.isHasAtLeastOneBranchLengthLargerThanZero( t ) ) {
+ if ( !Util.isHasAtLeastOneBranchLengthLargerThanZero( t ) ) {
atv_control.setDrawPhylogram( false );
atv_control.setDrawPhylogramEnabled( false );
}
if ( configuration.doGuessCheckOption( Configuration.display_as_phylogram ) ) {
if ( atv_control.getDisplayAsPhylogramCb() != null ) {
- if ( ForesterUtil.isHasAtLeastOneBranchLengthLargerThanZero( t ) ) {
+ if ( Util.isHasAtLeastOneBranchLengthLargerThanZero( t ) ) {
atv_control.setDrawPhylogram( true );
atv_control.setDrawPhylogramEnabled( true );
}
}
if ( configuration.doGuessCheckOption( Configuration.write_confidence_values ) ) {
if ( atv_control.getWriteConfidenceCb() != null ) {
- if ( ForesterUtil.isHasAtLeastOneBranchWithSupportValues( t ) ) {
+ if ( Util.isHasAtLeastOneBranchWithSupportValues( t ) ) {
atv_control.setCheckbox( Configuration.write_confidence_values, true );
}
else {
}
if ( configuration.doGuessCheckOption( Configuration.write_events ) ) {
if ( atv_control.getShowEventsCb() != null ) {
- if ( ForesterUtil.isHasAtLeastNodeWithEvent( t ) ) {
+ if ( Util.isHasAtLeastNodeWithEvent( t ) ) {
atv_control.setCheckbox( Configuration.write_events, true );
}
else {
parser = new TolParser();
}
else {
- parser = ForesterUtil.createParserDependingOnUrlContents( url, phyloxml_validate_against_xsd );
+ parser = ParserUtils.createParserDependingOnUrlContents( url, phyloxml_validate_against_xsd );
}
return factory.create( url.openStream(), parser );
}
final TreePanel tree_panel,
final ControlPanel ac,
final GraphicsExportType type,
- final Options options ) throws IOException{
+ final Options options ) throws IOException {
if ( !options.isGraphicsExportUsingActualSize() ) {
if ( options.isGraphicsExportVisibleOnly() ) {
throw new IllegalArgumentException( "cannot export visible rectangle only without exporting in actual size" );
}
return msg;
}
-
+
final static void writeToTiff( final File file, final BufferedImage image ) throws IOException {
// See: http://log.robmeek.com/2005/08/write-tiff-in-java.html
ImageWriter writer = null;
package org.forester.archaeopteryx.webservices;
import org.forester.archaeopteryx.webservices.WebservicesManager.WsPhylogenyFormat;
-import org.forester.util.ForesterUtil.PhylogenyNodeField;
+import org.forester.phylogeny.PhylogenyMethods;
public class BasicPhylogeniesWebserviceClient implements PhylogeniesWebserviceClient {
- private final String _desc;
- private final String _instructions;
- private final String _menu_name;
- private final String _name;
- private final WsPhylogenyFormat _format;
- private final String _url;
- private final boolean _integer;
- private final PhylogenyNodeField _node_field;
- private final Object _proc_inst;
- private final String _ref;
+ private final String _desc;
+ private final String _instructions;
+ private final String _menu_name;
+ private final String _name;
+ private final WsPhylogenyFormat _format;
+ private final String _url;
+ private final boolean _integer;
+ private final PhylogenyMethods.PhylogenyNodeField _node_field;
+ private final Object _proc_inst;
+ private final String _ref;
public BasicPhylogeniesWebserviceClient( final String name,
final String menu_name,
final String desc,
final String instructions,
final WsPhylogenyFormat format,
- final PhylogenyNodeField node_field,
+ final PhylogenyMethods.PhylogenyNodeField node_field,
final String url,
final boolean integer,
final String ref,
}
@Override
- public PhylogenyNodeField getNodeField() {
+ public PhylogenyMethods.PhylogenyNodeField getNodeField() {
return _node_field;
}
package org.forester.archaeopteryx.webservices;
import org.forester.archaeopteryx.webservices.WebservicesManager.WsPhylogenyFormat;
-import org.forester.util.ForesterUtil.PhylogenyNodeField;
+import org.forester.phylogeny.PhylogenyMethods;
/*
* Webservices which return phylogenies.
*
* @return the field code
*/
- public PhylogenyNodeField getNodeField();
+ public PhylogenyMethods.PhylogenyNodeField getNodeField();
/**
* This is used to indicate any kind of special processing.
import org.forester.archaeopteryx.webservices.WebservicesManager.WsPhylogenyFormat;
import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
import org.forester.phylogeny.Phylogeny;
+import org.forester.phylogeny.PhylogenyMethods;
import org.forester.phylogeny.PhylogenyNode;
import org.forester.phylogeny.data.Accession;
import org.forester.phylogeny.data.Identifier;
import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
import org.forester.phylogeny.iterators.PreorderTreeIterator;
import org.forester.util.ForesterUtil;
-import org.forester.util.ForesterUtil.PhylogenyNodeField;
public final class WebserviceUtil {
"Please enter a Tree of Life node identifier\n(Examples: "
+ "19386 for Cephalopoda, 2461 for Cnidaria, 2466 for Deuterostomia)",
WsPhylogenyFormat.TOL_XML_RESPONSE,
- PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME,
+ PhylogenyMethods.PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME,
WebserviceUtil.TOL_WEBSERVER,
true,
"http://tolweb.org",
"Use TreeBASE to obtain a phylogeny",
"Please enter a TreeBASE tree identifier\n(Examples: 2654, 825, 4931, 2518, 2406, 4934)",
WsPhylogenyFormat.NEXUS,
- PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME,
+ PhylogenyMethods.PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME,
"http://purl.org/phylo/treebase/phylows/tree/TB2:Tr"
+ PhylogeniesWebserviceClient.QUERY_PLACEHOLDER
+ "?format=nexus",
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.forester.archaeopteryx.Util;
import org.forester.msa.BasicMsa;
import org.forester.msa.Msa;
import org.forester.msa.MsaFormatException;
final String seq_name = name_m.group( 3 );
final String tax_sn = name_m.group( 4 );
if ( !ForesterUtil.isEmpty( acc_source ) && !ForesterUtil.isEmpty( acc ) ) {
- ForesterUtil.ensurePresenceOfSequence( node );
+ Util.ensurePresenceOfSequence( node );
node.getNodeData().getSequence( 0 ).setAccession( new Accession( acc, acc_source ) );
}
if ( !ForesterUtil.isEmpty( seq_name ) ) {
- ForesterUtil.ensurePresenceOfSequence( node );
+ Util.ensurePresenceOfSequence( node );
node.getNodeData().getSequence( 0 ).setName( seq_name );
}
if ( !ForesterUtil.isEmpty( tax_sn ) ) {
- ForesterUtil.ensurePresenceOfTaxonomy( node );
+ Util.ensurePresenceOfTaxonomy( node );
node.getNodeData().getTaxonomy( 0 ).setScientificName( tax_sn );
}
}
import org.forester.io.parsers.util.ParserUtils;
import org.forester.io.parsers.util.PhylogenyParserException;
import org.forester.phylogeny.Phylogeny;
+import org.forester.phylogeny.PhylogenyMethods;
import org.forester.phylogeny.PhylogenyNode;
import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
import org.forester.phylogeny.factories.PhylogenyFactory;
final boolean is_rooted ) throws IOException {
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
final NHXParser pars = new NHXParser();
- pars.setTaxonomyExtraction( ForesterUtil.TAXONOMY_EXTRACTION.NO );
+ pars.setTaxonomyExtraction( PhylogenyMethods.TAXONOMY_EXTRACTION.NO );
pars.setReplaceUnderscores( isReplaceUnderscores() );
pars.setIgnoreQuotes( isIgnoreQuotes() );
if ( rooted_info_present ) {
import java.util.regex.Pattern;
import org.forester.io.parsers.PhylogenyParser;
+import org.forester.io.parsers.util.ParserUtils;
import org.forester.io.parsers.util.PhylogenyParserException;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.PhylogenyMethods;
public final class NHXParser implements PhylogenyParser {
- public static final boolean LIMIT_SPECIES_NAMES_TO_FIVE_CHARS = true;
- public static final ForesterUtil.TAXONOMY_EXTRACTION TAXONOMY_EXTRACTION_DEFAULT = ForesterUtil.TAXONOMY_EXTRACTION.NO;
- final static private boolean GUESS_ROOTEDNESS_DEFAULT = true;
- final static private boolean GUESS_IF_SUPPORT_VALUES = true;
- final static private boolean IGNORE_QUOTES_DEFAULT = false;
- final static public boolean REPLACE_UNDERSCORES_DEFAULT = false;
- private boolean _saw_closing_paren;
- final static private byte STRING = 0;
- final static private byte STRING_BUFFER = 1;
- final static private byte CHAR_ARRAY = 2;
- final static private byte BUFFERED_READER = 3;
- private boolean _guess_rootedness;
- private boolean _has_next;
- private boolean _ignore_quotes;
- private byte _input_type;
- private int _source_length;
- private PhylogenyNode _current_node;
- private StringBuilder _current_anotation;
- private Object _nhx_source;
- private int _clade_level;
- private List<Phylogeny> _phylogenies;
- private Phylogeny _current_phylogeny;
- private ForesterUtil.TAXONOMY_EXTRACTION _taxonomy_extraction;
- private boolean _replace_underscores;
- public final static Pattern UC_LETTERS_NUMBERS_PATTERN = Pattern
- .compile( "^[A-Z0-9]+$" );
- public final static Pattern NUMBERS_ONLY_PATTERN = Pattern
- .compile( "^[0-9]+$" );
+ public static final boolean LIMIT_SPECIES_NAMES_TO_FIVE_CHARS = true;
+ public static final PhylogenyMethods.TAXONOMY_EXTRACTION TAXONOMY_EXTRACTION_DEFAULT = PhylogenyMethods.TAXONOMY_EXTRACTION.NO;
+ final static private boolean GUESS_ROOTEDNESS_DEFAULT = true;
+ final static private boolean GUESS_IF_SUPPORT_VALUES = true;
+ final static private boolean IGNORE_QUOTES_DEFAULT = false;
+ final static public boolean REPLACE_UNDERSCORES_DEFAULT = false;
+ private boolean _saw_closing_paren;
+ final static private byte STRING = 0;
+ final static private byte STRING_BUFFER = 1;
+ final static private byte CHAR_ARRAY = 2;
+ final static private byte BUFFERED_READER = 3;
+ private boolean _guess_rootedness;
+ private boolean _has_next;
+ private boolean _ignore_quotes;
+ private byte _input_type;
+ private int _source_length;
+ private PhylogenyNode _current_node;
+ private StringBuilder _current_anotation;
+ private Object _nhx_source;
+ private int _clade_level;
+ private List<Phylogeny> _phylogenies;
+ private Phylogeny _current_phylogeny;
+ private PhylogenyMethods.TAXONOMY_EXTRACTION _taxonomy_extraction;
+ private boolean _replace_underscores;
+ public final static Pattern UC_LETTERS_NUMBERS_PATTERN = Pattern
+ .compile( "^[A-Z0-9]+$" );
+ public final static Pattern NUMBERS_ONLY_PATTERN = Pattern
+ .compile( "^[0-9]+$" );
public NHXParser() {
init();
return _source_length;
}
- public ForesterUtil.TAXONOMY_EXTRACTION getTaxonomyExtraction() {
+ public PhylogenyMethods.TAXONOMY_EXTRACTION getTaxonomyExtraction() {
return _taxonomy_extraction;
}
_source_length = source_length;
}
- public void setTaxonomyExtraction( final ForesterUtil.TAXONOMY_EXTRACTION taxonomy_extraction ) {
+ public void setTaxonomyExtraction( final PhylogenyMethods.TAXONOMY_EXTRACTION taxonomy_extraction ) {
_taxonomy_extraction = taxonomy_extraction;
}
public static void parseNHX( String s,
final PhylogenyNode node_to_annotate,
- final ForesterUtil.TAXONOMY_EXTRACTION taxonomy_extraction,
+ final PhylogenyMethods.TAXONOMY_EXTRACTION taxonomy_extraction,
final boolean replace_underscores ) throws NHXFormatException {
- if ( ( taxonomy_extraction != ForesterUtil.TAXONOMY_EXTRACTION.NO ) && replace_underscores ) {
+ if ( ( taxonomy_extraction != PhylogenyMethods.TAXONOMY_EXTRACTION.NO ) && replace_underscores ) {
throw new IllegalArgumentException( "cannot extract taxonomies and replace under scores at the same time" );
}
if ( ( s != null ) && ( s.length() > 0 ) ) {
if ( !s.startsWith( ":" ) ) {
node_to_annotate.setName( t.nextToken() );
if ( !replace_underscores
- && ( !is_nhx && ( taxonomy_extraction != ForesterUtil.TAXONOMY_EXTRACTION.NO ) ) ) {
- final String tax = ForesterUtil
+ && ( !is_nhx && ( taxonomy_extraction != PhylogenyMethods.TAXONOMY_EXTRACTION.NO ) ) ) {
+ final String tax = ParserUtils
.extractTaxonomyCodeFromNodeName( node_to_annotate.getName(),
LIMIT_SPECIES_NAMES_TO_FIVE_CHARS,
taxonomy_extraction );
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
+import java.net.URL;
+import java.util.regex.Matcher;
+
+import org.forester.io.parsers.PhylogenyParser;
+import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
+import org.forester.io.parsers.nhx.NHXParser;
+import org.forester.io.parsers.phyloxml.PhyloXmlParser;
+import org.forester.io.parsers.tol.TolParser;
+import org.forester.phylogeny.PhylogenyMethods;
+import org.forester.util.ForesterConstants;
+import org.forester.util.ForesterUtil;
public final class ParserUtils {
+ final public static PhylogenyParser createParserDependingOnUrlContents( final URL url,
+ final boolean phyloxml_validate_against_xsd )
+ throws FileNotFoundException, IOException {
+ final String lc_filename = url.getFile().toString().toLowerCase();
+ PhylogenyParser parser = createParserDependingOnSuffix( lc_filename, phyloxml_validate_against_xsd );
+ if ( ( parser != null ) && lc_filename.endsWith( ".zip" ) ) {
+ if ( parser instanceof PhyloXmlParser ) {
+ ( ( PhyloXmlParser ) parser ).setZippedInputstream( true );
+ }
+ else if ( parser instanceof TolParser ) {
+ ( ( TolParser ) parser ).setZippedInputstream( true );
+ }
+ }
+ if ( parser == null ) {
+ final String first_line = ForesterUtil.getFirstLine( url ).trim().toLowerCase();
+ if ( first_line.startsWith( "<" ) ) {
+ parser = new PhyloXmlParser();
+ if ( phyloxml_validate_against_xsd ) {
+ final ClassLoader cl = PhyloXmlParser.class.getClassLoader();
+ final URL xsd_url = cl.getResource( ForesterConstants.LOCAL_PHYLOXML_XSD_RESOURCE );
+ if ( xsd_url != null ) {
+ ( ( PhyloXmlParser ) parser ).setValidateAgainstSchema( xsd_url.toString() );
+ }
+ else {
+ throw new RuntimeException( "failed to get URL for phyloXML XSD from jar file from ["
+ + ForesterConstants.LOCAL_PHYLOXML_XSD_RESOURCE + "]" );
+ }
+ }
+ }
+ else if ( ( first_line.startsWith( "nexus" ) ) || ( first_line.startsWith( "#nexus" ) )
+ || ( first_line.startsWith( "# nexus" ) ) || ( first_line.startsWith( "begin" ) ) ) {
+ parser = new NexusPhylogeniesParser();
+ }
+ else {
+ parser = new NHXParser();
+ }
+ }
+ return parser;
+ }
+
+ /**
+ * Return null if it can not guess the parser to use based on name suffix.
+ *
+ * @param filename
+ * @return
+ */
+ final public static PhylogenyParser createParserDependingOnSuffix( final String filename,
+ final boolean phyloxml_validate_against_xsd ) {
+ PhylogenyParser parser = null;
+ final String filename_lc = filename.toLowerCase();
+ if ( filename_lc.endsWith( ".tol" ) || filename_lc.endsWith( ".tolxml" ) || filename_lc.endsWith( ".tol.zip" ) ) {
+ parser = new TolParser();
+ }
+ else if ( filename_lc.endsWith( ".xml" ) || filename_lc.endsWith( ".px" ) || filename_lc.endsWith( "phyloxml" )
+ || filename_lc.endsWith( ".zip" ) ) {
+ parser = new PhyloXmlParser();
+ if ( phyloxml_validate_against_xsd ) {
+ final ClassLoader cl = PhyloXmlParser.class.getClassLoader();
+ final URL xsd_url = cl.getResource( ForesterConstants.LOCAL_PHYLOXML_XSD_RESOURCE );
+ if ( xsd_url != null ) {
+ ( ( PhyloXmlParser ) parser ).setValidateAgainstSchema( xsd_url.toString() );
+ }
+ else {
+ if ( ForesterConstants.RELEASE ) {
+ throw new RuntimeException( "failed to get URL for phyloXML XSD from jar file from ["
+ + ForesterConstants.LOCAL_PHYLOXML_XSD_RESOURCE + "]" );
+ }
+ }
+ }
+ }
+ else if ( filename_lc.endsWith( ".nexus" ) || filename_lc.endsWith( ".nex" ) || filename_lc.endsWith( ".nx" ) ) {
+ parser = new NexusPhylogeniesParser();
+ }
+ else if ( filename_lc.endsWith( ".nhx" ) || filename_lc.endsWith( ".nh" ) || filename_lc.endsWith( ".newick" ) ) {
+ parser = new NHXParser();
+ }
+ return parser;
+ }
+
+ final public static PhylogenyParser createParserDependingOnFileType( final File file,
+ final boolean phyloxml_validate_against_xsd )
+ throws FileNotFoundException, IOException {
+ PhylogenyParser parser = null;
+ parser = ParserUtils.createParserDependingOnSuffix( file.getName(), phyloxml_validate_against_xsd );
+ if ( parser == null ) {
+ parser = createParserDependingFileContents( file, phyloxml_validate_against_xsd );
+ }
+ return parser;
+ }
+
+ final public static PhylogenyParser createParserDependingFileContents( final File file,
+ final boolean phyloxml_validate_against_xsd )
+ throws FileNotFoundException, IOException {
+ PhylogenyParser parser = null;
+ final String first_line = ForesterUtil.getFirstLine( file ).trim().toLowerCase();
+ if ( first_line.startsWith( "<" ) ) {
+ parser = new PhyloXmlParser();
+ if ( phyloxml_validate_against_xsd ) {
+ final ClassLoader cl = PhyloXmlParser.class.getClassLoader();
+ final URL xsd_url = cl.getResource( ForesterConstants.LOCAL_PHYLOXML_XSD_RESOURCE );
+ if ( xsd_url != null ) {
+ ( ( PhyloXmlParser ) parser ).setValidateAgainstSchema( xsd_url.toString() );
+ }
+ else {
+ if ( ForesterConstants.RELEASE ) {
+ throw new RuntimeException( "failed to get URL for phyloXML XSD from jar file from ["
+ + ForesterConstants.LOCAL_PHYLOXML_XSD_RESOURCE + "]" );
+ }
+ }
+ }
+ }
+ else if ( ( first_line.startsWith( "nexus" ) ) || ( first_line.startsWith( "#nexus" ) )
+ || ( first_line.startsWith( "# nexus" ) ) || ( first_line.startsWith( "begin" ) ) ) {
+ parser = new NexusPhylogeniesParser();
+ }
+ else {
+ parser = new NHXParser();
+ }
+ return parser;
+ }
+
+ /**
+ * Extracts a code if and only if:
+ * one and only one _,
+ * shorter than 25,
+ * no |,
+ * no .,
+ * if / present it has to be after the _,
+ * if PFAM_STYLE_ONLY: / must be present,
+ * tax code can only contain uppercase letters and numbers,
+ * and must contain at least one uppercase letter.
+ * Return null if no code extractable.
+ *
+ * @param name
+ * @param limit_to_five
+ * @return
+ */
+ public static String extractTaxonomyCodeFromNodeName( final String name,
+ final boolean limit_to_five,
+ final PhylogenyMethods.TAXONOMY_EXTRACTION taxonomy_extraction ) {
+ if ( ( name.indexOf( "_" ) > 0 )
+ && ( name.length() < 25 )
+ && ( name.lastIndexOf( "_" ) == name.indexOf( "_" ) )
+ && ( name.indexOf( "|" ) < 0 )
+ && ( name.indexOf( "." ) < 0 )
+ && ( ( taxonomy_extraction != PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ) || ( name
+ .indexOf( "/" ) >= 0 ) )
+ && ( ( ( name.indexOf( "/" ) ) < 0 ) || ( name.indexOf( "/" ) > name.indexOf( "_" ) ) ) ) {
+ final String[] s = name.split( "[_/]" );
+ if ( s.length > 1 ) {
+ String str = s[ 1 ];
+ if ( limit_to_five ) {
+ if ( str.length() > 5 ) {
+ str = str.substring( 0, 5 );
+ }
+ else if ( ( str.length() < 5 ) && ( str.startsWith( "RAT" ) || str.startsWith( "PIG" ) ) ) {
+ str = str.substring( 0, 3 );
+ }
+ }
+ final Matcher letters_and_numbers = NHXParser.UC_LETTERS_NUMBERS_PATTERN.matcher( str );
+ if ( !letters_and_numbers.matches() ) {
+ return null;
+ }
+ final Matcher numbers_only = NHXParser.NUMBERS_ONLY_PATTERN.matcher( str );
+ if ( numbers_only.matches() ) {
+ return null;
+ }
+ return str;
+ }
+ }
+ return null;
+ }
+
public static BufferedReader createReader( final Object source ) throws IOException, FileNotFoundException {
BufferedReader reader = null;
if ( ( source instanceof File ) || ( source instanceof String ) ) {
package org.forester.phylogeny;
import java.awt.Color;
+import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.SortedMap;
import java.util.TreeMap;
+import org.forester.io.parsers.PhylogenyParser;
+import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
+import org.forester.io.parsers.util.PhylogenyParserException;
import org.forester.phylogeny.data.BranchColor;
import org.forester.phylogeny.data.BranchWidth;
import org.forester.phylogeny.data.Confidence;
import org.forester.phylogeny.data.DomainArchitecture;
+import org.forester.phylogeny.data.Identifier;
+import org.forester.phylogeny.data.Sequence;
import org.forester.phylogeny.data.Taxonomy;
+import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
+import org.forester.phylogeny.factories.PhylogenyFactory;
import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
import org.forester.util.BasicDescriptiveStatistics;
import org.forester.util.DescriptiveStatistics;
return !obtainLCA( node1, node2 ).isDuplication();
}
+ public final static Phylogeny[] readPhylogenies( final PhylogenyParser parser, final File file ) throws IOException {
+ final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
+ final Phylogeny[] trees = factory.create( file, parser );
+ if ( ( trees == null ) || ( trees.length == 0 ) ) {
+ throw new PhylogenyParserException( "Unable to parse phylogeny from file: " + file );
+ }
+ return trees;
+ }
+
+ final static public void transferInternalNodeNamesToConfidence( final Phylogeny phy ) {
+ final PhylogenyNodeIterator it = phy.iteratorPostorder();
+ while ( it.hasNext() ) {
+ final PhylogenyNode n = it.next();
+ if ( !n.isRoot() && !n.isExternal() && !n.getBranchData().isHasConfidences() ) {
+ if ( !ForesterUtil.isEmpty( n.getName() ) ) {
+ double d = -1.0;
+ try {
+ d = Double.parseDouble( n.getName() );
+ }
+ catch ( final Exception e ) {
+ d = -1.0;
+ }
+ if ( d >= 0.0 ) {
+ n.getBranchData().addConfidence( new Confidence( d, "" ) );
+ n.setName( "" );
+ }
+ }
+ }
+ }
+ }
+
+ final static public void transferInternalNamesToBootstrapSupport( final Phylogeny phy ) {
+ final PhylogenyNodeIterator it = phy.iteratorPostorder();
+ while ( it.hasNext() ) {
+ final PhylogenyNode n = it.next();
+ if ( !n.isExternal() && !ForesterUtil.isEmpty( n.getName() ) ) {
+ double value = -1;
+ try {
+ value = Double.parseDouble( n.getName() );
+ }
+ catch ( final NumberFormatException e ) {
+ throw new IllegalArgumentException( "failed to parse number from [" + n.getName() + "]: "
+ + e.getLocalizedMessage() );
+ }
+ if ( value >= 0.0 ) {
+ n.getBranchData().addConfidence( new Confidence( value, "bootstrap" ) );
+ n.setName( "" );
+ }
+ }
+ }
+ }
+
+ final static public void transferNodeNameToField( final Phylogeny phy,
+ final PhylogenyMethods.PhylogenyNodeField field ) {
+ final PhylogenyNodeIterator it = phy.iteratorPostorder();
+ while ( it.hasNext() ) {
+ final PhylogenyNode n = it.next();
+ final String name = n.getName().trim();
+ if ( !ForesterUtil.isEmpty( name ) ) {
+ switch ( field ) {
+ case TAXONOMY_CODE:
+ //temp hack
+ // if ( name.length() > 5 ) {
+ // n.setName( "" );
+ // if ( !n.getNodeData().isHasTaxonomy() ) {
+ // n.getNodeData().setTaxonomy( new Taxonomy() );
+ // }
+ // n.getNodeData().getTaxonomy().setScientificName( name );
+ // break;
+ // }
+ //
+ n.setName( "" );
+ setTaxonomyCode( n, name );
+ break;
+ case TAXONOMY_SCIENTIFIC_NAME:
+ n.setName( "" );
+ if ( !n.getNodeData().isHasTaxonomy() ) {
+ n.getNodeData().setTaxonomy( new Taxonomy() );
+ }
+ n.getNodeData().getTaxonomy().setScientificName( name );
+ break;
+ case TAXONOMY_COMMON_NAME:
+ n.setName( "" );
+ if ( !n.getNodeData().isHasTaxonomy() ) {
+ n.getNodeData().setTaxonomy( new Taxonomy() );
+ }
+ n.getNodeData().getTaxonomy().setCommonName( name );
+ break;
+ case SEQUENCE_SYMBOL:
+ n.setName( "" );
+ if ( !n.getNodeData().isHasSequence() ) {
+ n.getNodeData().setSequence( new Sequence() );
+ }
+ n.getNodeData().getSequence().setSymbol( name );
+ break;
+ case SEQUENCE_NAME:
+ n.setName( "" );
+ if ( !n.getNodeData().isHasSequence() ) {
+ n.getNodeData().setSequence( new Sequence() );
+ }
+ n.getNodeData().getSequence().setName( name );
+ break;
+ case TAXONOMY_ID_UNIPROT_1: {
+ if ( !n.getNodeData().isHasTaxonomy() ) {
+ n.getNodeData().setTaxonomy( new Taxonomy() );
+ }
+ String id = name;
+ final int i = name.indexOf( '_' );
+ if ( i > 0 ) {
+ id = name.substring( 0, i );
+ }
+ else {
+ n.setName( "" );
+ }
+ n.getNodeData().getTaxonomy()
+ .setIdentifier( new Identifier( id, PhyloXmlUtil.UNIPROT_TAX_PROVIDER ) );
+ break;
+ }
+ case TAXONOMY_ID_UNIPROT_2: {
+ if ( !n.getNodeData().isHasTaxonomy() ) {
+ n.getNodeData().setTaxonomy( new Taxonomy() );
+ }
+ String id = name;
+ final int i = name.indexOf( '_' );
+ if ( i > 0 ) {
+ id = name.substring( i + 1, name.length() );
+ }
+ else {
+ n.setName( "" );
+ }
+ n.getNodeData().getTaxonomy()
+ .setIdentifier( new Identifier( id, PhyloXmlUtil.UNIPROT_TAX_PROVIDER ) );
+ break;
+ }
+ }
+ }
+ }
+ }
+
static double addPhylogenyDistances( final double a, final double b ) {
if ( ( a >= 0.0 ) && ( b >= 0.0 ) ) {
return a + b;
}
return nodes_to_delete.size();
}
+
+ public static enum PhylogenyNodeField {
+ CLADE_NAME,
+ TAXONOMY_CODE,
+ TAXONOMY_SCIENTIFIC_NAME,
+ TAXONOMY_COMMON_NAME,
+ SEQUENCE_SYMBOL,
+ SEQUENCE_NAME,
+ TAXONOMY_ID_UNIPROT_1,
+ TAXONOMY_ID_UNIPROT_2;
+ }
+
+ public static enum TAXONOMY_EXTRACTION {
+ NO, YES, PFAM_STYLE_ONLY;
+ }
}
}
public static PhylogenyNode createInstanceFromNhxString( final String nhx ) throws NHXFormatException {
- return new PhylogenyNode( nhx, ForesterUtil.TAXONOMY_EXTRACTION.NO, false );
+ return new PhylogenyNode( nhx, PhylogenyMethods.TAXONOMY_EXTRACTION.NO, false );
}
public static PhylogenyNode createInstanceFromNhxString( final String nhx,
- final ForesterUtil.TAXONOMY_EXTRACTION taxonomy_extraction )
+ final PhylogenyMethods.TAXONOMY_EXTRACTION taxonomy_extraction )
throws NHXFormatException {
return new PhylogenyNode( nhx, taxonomy_extraction, false );
}
public static PhylogenyNode createInstanceFromNhxString( final String nhx,
- final ForesterUtil.TAXONOMY_EXTRACTION taxonomy_extraction,
+ final PhylogenyMethods.TAXONOMY_EXTRACTION taxonomy_extraction,
final boolean replace_underscores )
throws NHXFormatException {
return new PhylogenyNode( nhx, taxonomy_extraction, replace_underscores );
}
private PhylogenyNode( final String nhx,
- final ForesterUtil.TAXONOMY_EXTRACTION taxonomy_extraction,
+ final PhylogenyMethods.TAXONOMY_EXTRACTION taxonomy_extraction,
final boolean replace_underscores ) throws NHXFormatException {
init();
NHXParser.parseNHX( nhx, this, taxonomy_extraction, replace_underscores );
import java.util.Vector;
import org.forester.io.parsers.PhylogenyParser;
+import org.forester.io.parsers.util.ParserUtils;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.PhylogenyNode;
import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
import org.forester.phylogeny.factories.PhylogenyFactory;
-import org.forester.util.ForesterUtil;
/*
* @author Christian M. Zmasek
tree_file = new File( args[ 0 ] );
try {
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
- final PhylogenyParser pp = ForesterUtil.createParserDependingOnFileType( tree_file, true );
+ final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( tree_file, true );
tree = factory.create( tree_file, pp )[ 0 ];
}
catch ( final Exception e ) {
import java.util.List;
import org.forester.io.parsers.PhylogenyParser;
+import org.forester.io.parsers.util.ParserUtils;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.PhylogenyMethods;
import org.forester.phylogeny.PhylogenyNode;
for( int i = 0; i < trees.length; ++i ) {
try {
System.out.println( "Reading tree #" + i + " [" + args[ i ] + "]" );
- final PhylogenyParser pp = ForesterUtil.createParserDependingOnFileType( new File( args[ i ] ), true );
+ final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( new File( args[ i ] ), true );
trees[ i ] = factory.create( new File( args[ i ] ), pp )[ 0 ];
}
catch ( final Exception e ) {
domain_parsimony.createMatrixOfBinaryDomainCombinationPresenceOrAbsence(),
phylogeny );
}
+
+ public static void domainsPerProteinsStatistics( final String genome,
+ final List<Protein> protein_list,
+ final DescriptiveStatistics all_genomes_domains_per_potein_stats,
+ final SortedMap<Integer, Integer> all_genomes_domains_per_potein_histo,
+ final SortedSet<String> domains_which_are_always_single,
+ final SortedSet<String> domains_which_are_sometimes_single_sometimes_not,
+ final SortedSet<String> domains_which_never_single,
+ final Writer writer ) {
+ final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
+ for( final Protein protein : protein_list ) {
+ final int domains = protein.getNumberOfProteinDomains();
+ stats.addValue( domains );
+ all_genomes_domains_per_potein_stats.addValue( domains );
+ if ( !all_genomes_domains_per_potein_histo.containsKey( domains ) ) {
+ all_genomes_domains_per_potein_histo.put( domains, 1 );
+ }
+ else {
+ all_genomes_domains_per_potein_histo.put( domains,
+ 1 + all_genomes_domains_per_potein_histo.get( domains ) );
+ }
+ if ( domains == 1 ) {
+ final String domain = protein.getProteinDomain( 0 ).getDomainId().getId();
+ if ( !domains_which_are_sometimes_single_sometimes_not.contains( domain ) ) {
+ if ( domains_which_never_single.contains( domain ) ) {
+ domains_which_never_single.remove( domain );
+ domains_which_are_sometimes_single_sometimes_not.add( domain );
+ }
+ else {
+ domains_which_are_always_single.add( domain );
+ }
+ }
+ }
+ else if ( domains > 1 ) {
+ for( final Domain d : protein.getProteinDomains() ) {
+ final String domain = d.getDomainId().getId();
+ if ( !domains_which_are_sometimes_single_sometimes_not.contains( domain ) ) {
+ if ( domains_which_are_always_single.contains( domain ) ) {
+ domains_which_are_always_single.remove( domain );
+ domains_which_are_sometimes_single_sometimes_not.add( domain );
+ }
+ else {
+ domains_which_never_single.add( domain );
+ }
+ }
+ }
+ }
+ }
+ try {
+ writer.write( genome );
+ writer.write( "\t" );
+ writer.write( stats.arithmeticMean() + "" );
+ writer.write( "\t" );
+ writer.write( stats.sampleStandardDeviation() + "" );
+ writer.write( "\t" );
+ writer.write( stats.median() + "" );
+ writer.write( "\t" );
+ writer.write( stats.getN() + "" );
+ writer.write( "\t" );
+ writer.write( stats.getMin() + "" );
+ writer.write( "\t" );
+ writer.write( stats.getMax() + "" );
+ writer.write( "\n" );
+ }
+ catch ( final IOException e ) {
+ e.printStackTrace();
+ }
+ }
}
}
final PhylogenyNode n1 = new PhylogenyNode();
final PhylogenyNode n2 = PhylogenyNode
- .createInstanceFromNhxString( "", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ .createInstanceFromNhxString( "", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
final PhylogenyNode n3 = PhylogenyNode
- .createInstanceFromNhxString( "n3", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ .createInstanceFromNhxString( "n3", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
final PhylogenyNode n4 = PhylogenyNode
- .createInstanceFromNhxString( "n4:0.01", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ .createInstanceFromNhxString( "n4:0.01", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
if ( n1.isHasAssignedEvent() ) {
return false;
}
return false;
}
final NHXParser nhxp = new NHXParser();
- nhxp.setTaxonomyExtraction( ForesterUtil.TAXONOMY_EXTRACTION.NO );
+ nhxp.setTaxonomyExtraction( PhylogenyMethods.TAXONOMY_EXTRACTION.NO );
nhxp.setReplaceUnderscores( true );
final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
return false;
}
final PhylogenyNode n8 = PhylogenyNode
- .createInstanceFromNhxString( "n8_ECOLI/12:0.01", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ .createInstanceFromNhxString( "n8_ECOLI/12:0.01",
+ PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
if ( !n8.getName().equals( "n8_ECOLI/12" ) ) {
return false;
}
}
final PhylogenyNode n9 = PhylogenyNode
.createInstanceFromNhxString( "n9_ECOLI/12=12:0.01",
- ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
if ( !n9.getName().equals( "n9_ECOLI/12=12" ) ) {
return false;
}
return false;
}
final PhylogenyNode n10 = PhylogenyNode
- .createInstanceFromNhxString( "n10.ECOLI", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ .createInstanceFromNhxString( "n10.ECOLI", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
if ( !n10.getName().equals( "n10.ECOLI" ) ) {
return false;
}
final PhylogenyNode n20 = PhylogenyNode
- .createInstanceFromNhxString( "n20_ECOLI/1-2", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ .createInstanceFromNhxString( "n20_ECOLI/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
if ( !n20.getName().equals( "n20_ECOLI/1-2" ) ) {
return false;
}
if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
return false;
}
- final PhylogenyNode n20x = PhylogenyNode.createInstanceFromNhxString( "n20_ECOL1/1-2",
- ForesterUtil.TAXONOMY_EXTRACTION.YES );
+ final PhylogenyNode n20x = PhylogenyNode
+ .createInstanceFromNhxString( "n20_ECOL1/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.YES );
if ( !n20x.getName().equals( "n20_ECOL1/1-2" ) ) {
return false;
}
return false;
}
final PhylogenyNode n20xx = PhylogenyNode
- .createInstanceFromNhxString( "n20_eCOL1/1-2", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ .createInstanceFromNhxString( "n20_eCOL1/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
if ( !n20xx.getName().equals( "n20_eCOL1/1-2" ) ) {
return false;
}
return false;
}
final PhylogenyNode n20xxx = PhylogenyNode
- .createInstanceFromNhxString( "n20_ecoli/1-2", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ .createInstanceFromNhxString( "n20_ecoli/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
return false;
}
return false;
}
final PhylogenyNode n20xxxx = PhylogenyNode
- .createInstanceFromNhxString( "n20_Ecoli/1-2", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ .createInstanceFromNhxString( "n20_Ecoli/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
return false;
}
if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
return false;
}
- final PhylogenyNode n21 = PhylogenyNode.createInstanceFromNhxString( "n21_PIG",
- ForesterUtil.TAXONOMY_EXTRACTION.YES );
+ final PhylogenyNode n21 = PhylogenyNode
+ .createInstanceFromNhxString( "n21_PIG", PhylogenyMethods.TAXONOMY_EXTRACTION.YES );
if ( !n21.getName().equals( "n21_PIG" ) ) {
return false;
}
return false;
}
final PhylogenyNode n21x = PhylogenyNode
- .createInstanceFromNhxString( "n21_PIG", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ .createInstanceFromNhxString( "n21_PIG", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
if ( !n21x.getName().equals( "n21_PIG" ) ) {
return false;
}
return false;
}
final PhylogenyNode n22 = PhylogenyNode
- .createInstanceFromNhxString( "n22/PIG", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ .createInstanceFromNhxString( "n22/PIG", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
if ( !n22.getName().equals( "n22/PIG" ) ) {
return false;
}
return false;
}
final PhylogenyNode n23 = PhylogenyNode
- .createInstanceFromNhxString( "n23/PIG_1", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ .createInstanceFromNhxString( "n23/PIG_1", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
if ( !n23.getName().equals( "n23/PIG_1" ) ) {
return false;
}
}
if ( NHXParser.LIMIT_SPECIES_NAMES_TO_FIVE_CHARS ) {
final PhylogenyNode a = PhylogenyNode
- .createInstanceFromNhxString( "n10_ECOLI/1-2", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ .createInstanceFromNhxString( "n10_ECOLI/1-2",
+ PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
if ( !a.getName().equals( "n10_ECOLI/1-2" ) ) {
return false;
}
}
final PhylogenyNode b = PhylogenyNode
.createInstanceFromNhxString( "n10_ECOLI1/1-2",
- ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
if ( !b.getName().equals( "n10_ECOLI1/1-2" ) ) {
return false;
}
}
final PhylogenyNode c = PhylogenyNode
.createInstanceFromNhxString( "n10_RATAF12/1000-2000",
- ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
if ( !c.getName().equals( "n10_RATAF12/1000-2000" ) ) {
return false;
}
return false;
}
final PhylogenyNode d = PhylogenyNode
- .createInstanceFromNhxString( "n10_RAT1/1-2", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ .createInstanceFromNhxString( "n10_RAT1/1-2",
+ PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
if ( !d.getName().equals( "n10_RAT1/1-2" ) ) {
return false;
}
return false;
}
final PhylogenyNode e = PhylogenyNode
- .createInstanceFromNhxString( "n10_RAT1", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ .createInstanceFromNhxString( "n10_RAT1", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
if ( !e.getName().equals( "n10_RAT1" ) ) {
return false;
}
}
final PhylogenyNode n11 = PhylogenyNode
.createInstanceFromNhxString( "n111111_ECOLI/jdj:0.4",
- ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
if ( !n11.getName().equals( "n111111_ECOLI/jdj" ) ) {
return false;
}
}
final PhylogenyNode n12 = PhylogenyNode
.createInstanceFromNhxString( "n111111-ECOLI---/jdj:0.4",
- ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
if ( !n12.getName().equals( "n111111-ECOLI---/jdj" ) ) {
return false;
}
return false;
}
final PhylogenyNode n13 = PhylogenyNode
- .createInstanceFromNhxString( "blah_12345/1-2", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ .createInstanceFromNhxString( "blah_12345/1-2",
+ PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
return false;
}
return false;
}
final PhylogenyNode n14 = PhylogenyNode
- .createInstanceFromNhxString( "blah_12X45/1-2", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ .createInstanceFromNhxString( "blah_12X45/1-2",
+ PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
if ( !n14.getName().equals( "blah_12X45/1-2" ) ) {
return false;
}
}
final PhylogenyNode n15 = PhylogenyNode
.createInstanceFromNhxString( "something_wicked[123]",
- ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
if ( !n15.getName().equals( "something_wicked" ) ) {
return false;
}
}
final PhylogenyNode n16 = PhylogenyNode
.createInstanceFromNhxString( "something_wicked2[9]",
- ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
if ( !n16.getName().equals( "something_wicked2" ) ) {
return false;
}
}
final PhylogenyNode n17 = PhylogenyNode
.createInstanceFromNhxString( "something_wicked3[a]",
- ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
if ( !n17.getName().equals( "something_wicked3" ) ) {
return false;
}
return false;
}
final PhylogenyNode n18 = PhylogenyNode
- .createInstanceFromNhxString( ":0.5[91]", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+ .createInstanceFromNhxString( ":0.5[91]", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
return false;
}
import org.forester.archaeopteryx.Archaeopteryx;
import org.forester.io.parsers.PhylogenyParser;
+import org.forester.io.parsers.util.ParserUtils;
import org.forester.phylogeny.Phylogeny;
-import org.forester.util.ForesterUtil;
+import org.forester.phylogeny.PhylogenyMethods;
public class Example1 {
final File treefile = new File( "/home/czmasek/tol_117_TEST.xml" );
PhylogenyParser parser = null;
try {
- parser = ForesterUtil.createParserDependingOnFileType( treefile, true );
+ parser = ParserUtils.createParserDependingOnFileType( treefile, true );
}
catch ( final IOException e ) {
e.printStackTrace();
}
Phylogeny[] phys = null;
try {
- phys = ForesterUtil.readPhylogenies( parser, treefile );
+ phys = PhylogenyMethods.readPhylogenies( parser, treefile );
}
catch ( final IOException e ) {
e.printStackTrace();
import java.io.IOException;
import org.forester.io.parsers.PhylogenyParser;
+import org.forester.io.parsers.util.ParserUtils;
import org.forester.io.writers.PhylogenyWriter;
import org.forester.phylogeny.Phylogeny;
+import org.forester.phylogeny.PhylogenyMethods;
import org.forester.util.ForesterUtil;
public class Example4 {
final File treefile = new File( "/home/czmasek/tol_117_TEST.xml" );
PhylogenyParser parser = null;
try {
- parser = ForesterUtil.createParserDependingOnFileType( treefile, true );
+ parser = ParserUtils.createParserDependingOnFileType( treefile, true );
}
catch ( final IOException e ) {
e.printStackTrace();
}
Phylogeny[] phys = null;
try {
- phys = ForesterUtil.readPhylogenies( parser, treefile );
+ phys = PhylogenyMethods.readPhylogenies( parser, treefile );
}
catch ( final IOException e ) {
e.printStackTrace();
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.forester.archaeopteryx.Util;
import org.forester.io.parsers.nhx.NHXFormatException;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.PhylogenyNode;
}
if ( new_values != null ) {
if ( new_values.containsKey( TP_TAXONOMY_CODE ) ) {
- ForesterUtil.ensurePresenceOfTaxonomy( node );
+ Util.ensurePresenceOfTaxonomy( node );
node.getNodeData().getTaxonomy().setTaxonomyCode( new_values.get( TP_TAXONOMY_CODE ) );
}
if ( new_values.containsKey( TP_TAXONOMY_ID )
&& new_values.containsKey( TP_TAXONOMY_ID_PROVIDER ) ) {
- ForesterUtil.ensurePresenceOfTaxonomy( node );
+ Util.ensurePresenceOfTaxonomy( node );
node.getNodeData()
.getTaxonomy()
.setIdentifier( new Identifier( new_values.get( TP_TAXONOMY_ID ),
new_values.get( TP_TAXONOMY_ID_PROVIDER ) ) );
}
else if ( new_values.containsKey( TP_TAXONOMY_ID ) ) {
- ForesterUtil.ensurePresenceOfTaxonomy( node );
+ Util.ensurePresenceOfTaxonomy( node );
node.getNodeData().getTaxonomy()
.setIdentifier( new Identifier( new_values.get( TP_TAXONOMY_ID ) ) );
}
if ( new_values.containsKey( TP_TAXONOMY_SN ) ) {
- ForesterUtil.ensurePresenceOfTaxonomy( node );
+ Util.ensurePresenceOfTaxonomy( node );
node.getNodeData().getTaxonomy().setScientificName( new_values.get( TP_TAXONOMY_SN ) );
}
if ( new_values.containsKey( TP_TAXONOMY_CN ) ) {
- ForesterUtil.ensurePresenceOfTaxonomy( node );
+ Util.ensurePresenceOfTaxonomy( node );
node.getNodeData().getTaxonomy().setCommonName( new_values.get( TP_TAXONOMY_CN ) );
}
if ( new_values.containsKey( TP_TAXONOMY_SYN ) ) {
- ForesterUtil.ensurePresenceOfTaxonomy( node );
+ Util.ensurePresenceOfTaxonomy( node );
node.getNodeData().getTaxonomy().getSynonyms().add( new_values.get( TP_TAXONOMY_SYN ) );
}
if ( new_values.containsKey( TP_SEQ_ACCESSION )
&& new_values.containsKey( TP_SEQ_ACCESSION_SOURCE ) ) {
- ForesterUtil.ensurePresenceOfSequence( node );
+ Util.ensurePresenceOfSequence( node );
node.getNodeData()
.getSequence()
.setAccession( new Accession( new_values.get( TP_SEQ_ACCESSION ),
new_values.get( TP_SEQ_ACCESSION_SOURCE ) ) );
}
if ( new_values.containsKey( TP_SEQ_ANNOTATION_DESC ) ) {
- ForesterUtil.ensurePresenceOfSequence( node );
+ Util.ensurePresenceOfSequence( node );
final Annotation ann = new Annotation( "?" );
ann.setDesc( new_values.get( TP_SEQ_ANNOTATION_DESC ) );
node.getNodeData().getSequence().addAnnotation( ann );
}
if ( new_values.containsKey( TP_SEQ_ANNOTATION_REF ) ) {
- ForesterUtil.ensurePresenceOfSequence( node );
+ Util.ensurePresenceOfSequence( node );
final Annotation ann = new Annotation( new_values.get( TP_SEQ_ANNOTATION_REF ) );
node.getNodeData().getSequence().addAnnotation( ann );
}
if ( new_values.containsKey( TP_SEQ_SYMBOL ) ) {
- ForesterUtil.ensurePresenceOfSequence( node );
+ Util.ensurePresenceOfSequence( node );
node.getNodeData().getSequence().setSymbol( new_values.get( TP_SEQ_SYMBOL ) );
}
if ( new_values.containsKey( TP_SEQ_NAME ) ) {
- ForesterUtil.ensurePresenceOfSequence( node );
+ Util.ensurePresenceOfSequence( node );
node.getNodeData().getSequence().setName( new_values.get( TP_SEQ_NAME ) );
}
if ( new_values.containsKey( TP_SEQ_MOL_SEQ ) ) {
- ForesterUtil.ensurePresenceOfSequence( node );
+ Util.ensurePresenceOfSequence( node );
node.getNodeData().getSequence().setMolecularSequence( new_values.get( TP_SEQ_MOL_SEQ ) );
}
if ( new_values.containsKey( TP_NODE_NAME ) ) {
if ( PhylogenyDecorator.VERBOSE ) {
System.out.println( name + ": " + new_value );
}
- ForesterUtil.ensurePresenceOfTaxonomy( node );
+ Util.ensurePresenceOfTaxonomy( node );
node.getNodeData().getTaxonomy().setTaxonomyCode( new_value );
break;
case TAXONOMY_SCIENTIFIC_NAME:
if ( PhylogenyDecorator.VERBOSE ) {
System.out.println( name + ": " + new_value );
}
- ForesterUtil.ensurePresenceOfTaxonomy( node );
+ Util.ensurePresenceOfTaxonomy( node );
node.getNodeData().getTaxonomy().setScientificName( new_value );
break;
case SEQUENCE_NAME:
private static void extractBracketedScientificNames( final PhylogenyNode node, final String new_value ) {
final int i = new_value.lastIndexOf( "[" );
final String scientific_name = new_value.substring( i + 1, new_value.length() - 1 );
- ForesterUtil.ensurePresenceOfTaxonomy( node );
+ Util.ensurePresenceOfTaxonomy( node );
node.getNodeData().getTaxonomy().setScientificName( scientific_name );
}
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
-import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
-import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.forester.io.parsers.PhylogenyParser;
-import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
-import org.forester.io.parsers.nhx.NHXParser;
-import org.forester.io.parsers.phyloxml.PhyloXmlParser;
-import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
-import org.forester.io.parsers.tol.TolParser;
-import org.forester.io.parsers.util.PhylogenyParserException;
-import org.forester.phylogeny.Phylogeny;
-import org.forester.phylogeny.PhylogenyMethods;
-import org.forester.phylogeny.PhylogenyNode;
-import org.forester.phylogeny.data.Confidence;
-import org.forester.phylogeny.data.Distribution;
-import org.forester.phylogeny.data.Identifier;
-import org.forester.phylogeny.data.Sequence;
-import org.forester.phylogeny.data.Taxonomy;
-import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
-import org.forester.phylogeny.factories.PhylogenyFactory;
-import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
-
public final class ForesterUtil {
public final static String FILE_SEPARATOR = System.getProperty( "file.separator" );
return file;
}
- final public static PhylogenyParser createParserDependingFileContents( final File file,
- final boolean phyloxml_validate_against_xsd )
- throws FileNotFoundException, IOException {
- PhylogenyParser parser = null;
- final String first_line = ForesterUtil.getFirstLine( file ).trim().toLowerCase();
- if ( first_line.startsWith( "<" ) ) {
- parser = new PhyloXmlParser();
- if ( phyloxml_validate_against_xsd ) {
- final ClassLoader cl = PhyloXmlParser.class.getClassLoader();
- final URL xsd_url = cl.getResource( ForesterConstants.LOCAL_PHYLOXML_XSD_RESOURCE );
- if ( xsd_url != null ) {
- ( ( PhyloXmlParser ) parser ).setValidateAgainstSchema( xsd_url.toString() );
- }
- else {
- if ( ForesterConstants.RELEASE ) {
- throw new RuntimeException( "failed to get URL for phyloXML XSD from jar file from ["
- + ForesterConstants.LOCAL_PHYLOXML_XSD_RESOURCE + "]" );
- }
- }
- }
- }
- else if ( ( first_line.startsWith( "nexus" ) ) || ( first_line.startsWith( "#nexus" ) )
- || ( first_line.startsWith( "# nexus" ) ) || ( first_line.startsWith( "begin" ) ) ) {
- parser = new NexusPhylogeniesParser();
- }
- else {
- parser = new NHXParser();
- }
- return parser;
- }
-
- final public static PhylogenyParser createParserDependingOnFileType( final File file,
- final boolean phyloxml_validate_against_xsd )
- throws FileNotFoundException, IOException {
- PhylogenyParser parser = null;
- parser = createParserDependingOnSuffix( file.getName(), phyloxml_validate_against_xsd );
- if ( parser == null ) {
- parser = createParserDependingFileContents( file, phyloxml_validate_against_xsd );
- }
- return parser;
- }
-
- /**
- * Return null if it can not guess the parser to use based on name suffix.
- *
- * @param filename
- * @return
- */
- final public static PhylogenyParser createParserDependingOnSuffix( final String filename,
- final boolean phyloxml_validate_against_xsd ) {
- PhylogenyParser parser = null;
- final String filename_lc = filename.toLowerCase();
- if ( filename_lc.endsWith( ".tol" ) || filename_lc.endsWith( ".tolxml" ) || filename_lc.endsWith( ".tol.zip" ) ) {
- parser = new TolParser();
- }
- else if ( filename_lc.endsWith( ".xml" ) || filename_lc.endsWith( ".px" ) || filename_lc.endsWith( "phyloxml" )
- || filename_lc.endsWith( ".zip" ) ) {
- parser = new PhyloXmlParser();
- if ( phyloxml_validate_against_xsd ) {
- final ClassLoader cl = PhyloXmlParser.class.getClassLoader();
- final URL xsd_url = cl.getResource( ForesterConstants.LOCAL_PHYLOXML_XSD_RESOURCE );
- if ( xsd_url != null ) {
- ( ( PhyloXmlParser ) parser ).setValidateAgainstSchema( xsd_url.toString() );
- }
- else {
- if ( ForesterConstants.RELEASE ) {
- throw new RuntimeException( "failed to get URL for phyloXML XSD from jar file from ["
- + ForesterConstants.LOCAL_PHYLOXML_XSD_RESOURCE + "]" );
- }
- }
- }
- }
- else if ( filename_lc.endsWith( ".nexus" ) || filename_lc.endsWith( ".nex" ) || filename_lc.endsWith( ".nx" ) ) {
- parser = new NexusPhylogeniesParser();
- }
- else if ( filename_lc.endsWith( ".nhx" ) || filename_lc.endsWith( ".nh" ) || filename_lc.endsWith( ".newick" ) ) {
- parser = new NHXParser();
- }
- return parser;
- }
-
- final public static PhylogenyParser createParserDependingOnUrlContents( final URL url,
- final boolean phyloxml_validate_against_xsd )
- throws FileNotFoundException, IOException {
- final String lc_filename = url.getFile().toString().toLowerCase();
- PhylogenyParser parser = createParserDependingOnSuffix( lc_filename, phyloxml_validate_against_xsd );
- if ( ( parser != null ) && lc_filename.endsWith( ".zip" ) ) {
- if ( parser instanceof PhyloXmlParser ) {
- ( ( PhyloXmlParser ) parser ).setZippedInputstream( true );
- }
- else if ( parser instanceof TolParser ) {
- ( ( TolParser ) parser ).setZippedInputstream( true );
- }
- }
- if ( parser == null ) {
- final String first_line = getFirstLine( url ).trim().toLowerCase();
- if ( first_line.startsWith( "<" ) ) {
- parser = new PhyloXmlParser();
- if ( phyloxml_validate_against_xsd ) {
- final ClassLoader cl = PhyloXmlParser.class.getClassLoader();
- final URL xsd_url = cl.getResource( ForesterConstants.LOCAL_PHYLOXML_XSD_RESOURCE );
- if ( xsd_url != null ) {
- ( ( PhyloXmlParser ) parser ).setValidateAgainstSchema( xsd_url.toString() );
- }
- else {
- throw new RuntimeException( "failed to get URL for phyloXML XSD from jar file from ["
- + ForesterConstants.LOCAL_PHYLOXML_XSD_RESOURCE + "]" );
- }
- }
- }
- else if ( ( first_line.startsWith( "nexus" ) ) || ( first_line.startsWith( "#nexus" ) )
- || ( first_line.startsWith( "# nexus" ) ) || ( first_line.startsWith( "begin" ) ) ) {
- parser = new NexusPhylogeniesParser();
- }
- else {
- parser = new NHXParser();
- }
- }
- return parser;
- }
-
- final public static void ensurePresenceOfDate( final PhylogenyNode node ) {
- if ( !node.getNodeData().isHasDate() ) {
- node.getNodeData().setDate( new org.forester.phylogeny.data.Date() );
- }
- }
-
- final public static void ensurePresenceOfDistribution( final PhylogenyNode node ) {
- if ( !node.getNodeData().isHasDistribution() ) {
- node.getNodeData().setDistribution( new Distribution( "" ) );
- }
- }
-
- public static void ensurePresenceOfSequence( final PhylogenyNode node ) {
- if ( !node.getNodeData().isHasSequence() ) {
- node.getNodeData().setSequence( new Sequence() );
- }
- }
-
- public static void ensurePresenceOfTaxonomy( final PhylogenyNode node ) {
- if ( !node.getNodeData().isHasTaxonomy() ) {
- node.getNodeData().setTaxonomy( new Taxonomy() );
- }
- }
-
- /**
- * Extracts a code if and only if:
- * one and only one _,
- * shorter than 25,
- * no |,
- * no .,
- * if / present it has to be after the _,
- * if PFAM_STYLE_ONLY: / must be present,
- * tax code can only contain uppercase letters and numbers,
- * and must contain at least one uppercase letter.
- * Return null if no code extractable.
- *
- * @param name
- * @param limit_to_five
- * @return
- */
- public static String extractTaxonomyCodeFromNodeName( final String name,
- final boolean limit_to_five,
- final ForesterUtil.TAXONOMY_EXTRACTION taxonomy_extraction ) {
- if ( ( name.indexOf( "_" ) > 0 )
- && ( name.length() < 25 )
- && ( name.lastIndexOf( "_" ) == name.indexOf( "_" ) )
- && ( name.indexOf( "|" ) < 0 )
- && ( name.indexOf( "." ) < 0 )
- && ( ( taxonomy_extraction != ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ) || ( name
- .indexOf( "/" ) >= 0 ) )
- && ( ( ( name.indexOf( "/" ) ) < 0 ) || ( name.indexOf( "/" ) > name.indexOf( "_" ) ) ) ) {
- final String[] s = name.split( "[_/]" );
- if ( s.length > 1 ) {
- String str = s[ 1 ];
- if ( limit_to_five ) {
- if ( str.length() > 5 ) {
- str = str.substring( 0, 5 );
- }
- else if ( ( str.length() < 5 ) && ( str.startsWith( "RAT" ) || str.startsWith( "PIG" ) ) ) {
- str = str.substring( 0, 3 );
- }
- }
- final Matcher letters_and_numbers = NHXParser.UC_LETTERS_NUMBERS_PATTERN.matcher( str );
- if ( !letters_and_numbers.matches() ) {
- return null;
- }
- final Matcher numbers_only = NHXParser.NUMBERS_ONLY_PATTERN.matcher( str );
- if ( numbers_only.matches() ) {
- return null;
- }
- return str;
- }
- }
- return null;
- }
-
public static void fatalError( final String prg_name, final String message ) {
System.err.println();
System.err.println( "[" + prg_name + "] > " + message );
return ForesterUtil.LINE_SEPARATOR;
}
- /**
- * Returns all custom data tag names of this Phylogeny as Hashtable. Tag
- * names are keys, values are Boolean set to false.
- */
- final public static Hashtable<String, Boolean> getPropertyRefs( final Phylogeny phylogeny ) {
- final Hashtable<String, Boolean> ht = new Hashtable<String, Boolean>();
- if ( phylogeny.isEmpty() ) {
- return ht;
- }
- for( final PhylogenyNodeIterator iter = phylogeny.iteratorPreorder(); iter.hasNext(); ) {
- final PhylogenyNode current_node = iter.next();
- if ( current_node.getNodeData().isHasProperties() ) {
- final String[] tags = current_node.getNodeData().getProperties().getPropertyRefs();
- for( int i = 0; i < tags.length; ++i ) {
- ht.put( tags[ i ], new Boolean( false ) );
- }
- }
- }
- return ht;
- }
-
final public static void increaseCountingMap( final Map<String, Integer> counting_map, final String item_name ) {
if ( !counting_map.containsKey( item_name ) ) {
counting_map.put( item_name, 1 );
}
}
- final static public boolean isAllNonEmptyInternalLabelsArePositiveNumbers( final Phylogeny phy ) {
- final PhylogenyNodeIterator it = phy.iteratorPostorder();
- while ( it.hasNext() ) {
- final PhylogenyNode n = it.next();
- if ( !n.isRoot() && !n.isExternal() ) {
- if ( !ForesterUtil.isEmpty( n.getName() ) ) {
- double d = -1.0;
- try {
- d = Double.parseDouble( n.getName() );
- }
- catch ( final Exception e ) {
- d = -1.0;
- }
- if ( d < 0.0 ) {
- return false;
- }
- }
- }
- }
- return true;
- }
-
final public static boolean isContainsParanthesesableNhCharacter( final String nh ) {
return PARANTHESESABLE_NH_CHARS_PATTERN.matcher( nh ).find();
}
return n % 2 == 0;
}
- final static public boolean isHasAtLeastNodeWithEvent( final Phylogeny phy ) {
- final PhylogenyNodeIterator it = phy.iteratorPostorder();
- while ( it.hasNext() ) {
- if ( it.next().getNodeData().isHasEvent() ) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Returns true if at least one branch has a length larger than zero.
- *
- *
- * @param phy
- */
- final static public boolean isHasAtLeastOneBranchLengthLargerThanZero( final Phylogeny phy ) {
- final PhylogenyNodeIterator it = phy.iteratorPostorder();
- while ( it.hasNext() ) {
- if ( it.next().getDistanceToParent() > 0.0 ) {
- return true;
- }
- }
- return false;
- }
-
- final static public boolean isHasAtLeastOneBranchWithSupportValues( final Phylogeny phy ) {
- final PhylogenyNodeIterator it = phy.iteratorPostorder();
- while ( it.hasNext() ) {
- if ( it.next().getBranchData().isHasConfidences() ) {
- return true;
- }
- }
- return false;
- }
-
/**
* This determines whether String[] a and String[] b have at least one
* String in common (intersect). Returns false if at least one String[] is
return Integer.parseInt( str );
}
- final public static void postOrderRelabelInternalNodes( final Phylogeny phylogeny, final int starting_number ) {
- int i = starting_number;
- for( final PhylogenyNodeIterator it = phylogeny.iteratorPostorder(); it.hasNext(); ) {
- final PhylogenyNode node = it.next();
- if ( !node.isExternal() ) {
- node.setName( String.valueOf( i++ ) );
- }
- }
- }
-
final public static void printArray( final Object[] a ) {
for( int i = 0; i < a.length; ++i ) {
System.out.println( "[" + i + "]=" + a[ i ] );
System.out.println( "[" + prg_name + "] > " + message );
}
- public final static Phylogeny[] readPhylogenies( final PhylogenyParser parser, final File file ) throws IOException {
- final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
- final Phylogeny[] trees = factory.create( file, parser );
- if ( ( trees == null ) || ( trees.length == 0 ) ) {
- throw new PhylogenyParserException( "Unable to parse phylogeny from file: " + file );
- }
- return trees;
- }
-
final public static String removeSuffix( final String file_name ) {
final int i = file_name.lastIndexOf( '.' );
if ( i > 1 ) {
return null;
}
- final static public void transferInternalNamesToBootstrapSupport( final Phylogeny phy ) {
- final PhylogenyNodeIterator it = phy.iteratorPostorder();
- while ( it.hasNext() ) {
- final PhylogenyNode n = it.next();
- if ( !n.isExternal() && !ForesterUtil.isEmpty( n.getName() ) ) {
- double value = -1;
- try {
- value = Double.parseDouble( n.getName() );
- }
- catch ( final NumberFormatException e ) {
- throw new IllegalArgumentException( "failed to parse number from [" + n.getName() + "]: "
- + e.getLocalizedMessage() );
- }
- if ( value >= 0.0 ) {
- n.getBranchData().addConfidence( new Confidence( value, "bootstrap" ) );
- n.setName( "" );
- }
- }
- }
- }
-
- final static public void transferInternalNodeNamesToConfidence( final Phylogeny phy ) {
- final PhylogenyNodeIterator it = phy.iteratorPostorder();
- while ( it.hasNext() ) {
- final PhylogenyNode n = it.next();
- if ( !n.isRoot() && !n.isExternal() && !n.getBranchData().isHasConfidences() ) {
- if ( !ForesterUtil.isEmpty( n.getName() ) ) {
- double d = -1.0;
- try {
- d = Double.parseDouble( n.getName() );
- }
- catch ( final Exception e ) {
- d = -1.0;
- }
- if ( d >= 0.0 ) {
- n.getBranchData().addConfidence( new Confidence( d, "" ) );
- n.setName( "" );
- }
- }
- }
- }
- }
-
- final static public void transferNodeNameToField( final Phylogeny phy, final PhylogenyNodeField field ) {
- final PhylogenyNodeIterator it = phy.iteratorPostorder();
- while ( it.hasNext() ) {
- final PhylogenyNode n = it.next();
- final String name = n.getName().trim();
- if ( !ForesterUtil.isEmpty( name ) ) {
- switch ( field ) {
- case TAXONOMY_CODE:
- //temp hack
- // if ( name.length() > 5 ) {
- // n.setName( "" );
- // if ( !n.getNodeData().isHasTaxonomy() ) {
- // n.getNodeData().setTaxonomy( new Taxonomy() );
- // }
- // n.getNodeData().getTaxonomy().setScientificName( name );
- // break;
- // }
- //
- n.setName( "" );
- PhylogenyMethods.setTaxonomyCode( n, name );
- break;
- case TAXONOMY_SCIENTIFIC_NAME:
- n.setName( "" );
- if ( !n.getNodeData().isHasTaxonomy() ) {
- n.getNodeData().setTaxonomy( new Taxonomy() );
- }
- n.getNodeData().getTaxonomy().setScientificName( name );
- break;
- case TAXONOMY_COMMON_NAME:
- n.setName( "" );
- if ( !n.getNodeData().isHasTaxonomy() ) {
- n.getNodeData().setTaxonomy( new Taxonomy() );
- }
- n.getNodeData().getTaxonomy().setCommonName( name );
- break;
- case SEQUENCE_SYMBOL:
- n.setName( "" );
- if ( !n.getNodeData().isHasSequence() ) {
- n.getNodeData().setSequence( new Sequence() );
- }
- n.getNodeData().getSequence().setSymbol( name );
- break;
- case SEQUENCE_NAME:
- n.setName( "" );
- if ( !n.getNodeData().isHasSequence() ) {
- n.getNodeData().setSequence( new Sequence() );
- }
- n.getNodeData().getSequence().setName( name );
- break;
- case TAXONOMY_ID_UNIPROT_1: {
- if ( !n.getNodeData().isHasTaxonomy() ) {
- n.getNodeData().setTaxonomy( new Taxonomy() );
- }
- String id = name;
- final int i = name.indexOf( '_' );
- if ( i > 0 ) {
- id = name.substring( 0, i );
- }
- else {
- n.setName( "" );
- }
- n.getNodeData().getTaxonomy()
- .setIdentifier( new Identifier( id, PhyloXmlUtil.UNIPROT_TAX_PROVIDER ) );
- break;
- }
- case TAXONOMY_ID_UNIPROT_2: {
- if ( !n.getNodeData().isHasTaxonomy() ) {
- n.getNodeData().setTaxonomy( new Taxonomy() );
- }
- String id = name;
- final int i = name.indexOf( '_' );
- if ( i > 0 ) {
- id = name.substring( i + 1, name.length() );
- }
- else {
- n.setName( "" );
- }
- n.getNodeData().getTaxonomy()
- .setIdentifier( new Identifier( id, PhyloXmlUtil.UNIPROT_TAX_PROVIDER ) );
- break;
- }
- }
- }
- }
- }
-
final public static void unexpectedFatalError( final String prg_name, final Exception e ) {
System.err.println();
System.err.println( "[" + prg_name
}
return sb.toString();
}
-
- public static enum PhylogenyNodeField {
- CLADE_NAME,
- TAXONOMY_CODE,
- TAXONOMY_SCIENTIFIC_NAME,
- TAXONOMY_COMMON_NAME,
- SEQUENCE_SYMBOL,
- SEQUENCE_NAME,
- TAXONOMY_ID_UNIPROT_1,
- TAXONOMY_ID_UNIPROT_2;
- }
-
- public static enum TAXONOMY_EXTRACTION {
- NO, YES, PFAM_STYLE_ONLY;
- }
}