From 4459872e11e2d9058fd708d3887962fb7581bba0 Mon Sep 17 00:00:00 2001 From: "cmzmasek@gmail.com" Date: Wed, 27 Jun 2012 16:57:10 +0000 Subject: [PATCH] removed old classes/tools --- .../java/src/org/forester/application/sdix.java | 196 -------------------- forester/java/src/org/forester/sdi/SDIx.java | 134 ------------- 2 files changed, 330 deletions(-) delete mode 100644 forester/java/src/org/forester/application/sdix.java delete mode 100644 forester/java/src/org/forester/sdi/SDIx.java diff --git a/forester/java/src/org/forester/application/sdix.java b/forester/java/src/org/forester/application/sdix.java deleted file mode 100644 index 9375b2d..0000000 --- a/forester/java/src/org/forester/application/sdix.java +++ /dev/null @@ -1,196 +0,0 @@ -// $Id: -// FORESTER -- software libraries and applications -// for evolutionary biology research and applications. -// -// Copyright (C) 2008-2009 Christian M. Zmasek -// Copyright (C) 2008-2009 Burnham Institute for Medical Research -// All rights reserved -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -// -// Contact: phylosoft @ gmail . com -// WWW: www.phylosoft.org/forester - -package org.forester.application; - -import java.io.File; -import java.io.FilenameFilter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.forester.io.parsers.phyloxml.PhyloXmlParser; -import org.forester.phylogeny.Phylogeny; -import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory; -import org.forester.phylogeny.factories.PhylogenyFactory; -import org.forester.sdi.SDIException; -import org.forester.sdi.SDIx; -import org.forester.util.CommandLineArguments; -import org.forester.util.ForesterUtil; - -public class sdix { - - final static private String HELP_OPTION_1 = "help"; - final static private String HELP_OPTION_2 = "h"; - final static private String PRG_NAME = "sdix"; - final static private String PRG_VERSION = "0.001 alpha"; - final static private String PRG_DATE = "2009.10.14"; - - public static void main( final String args[] ) throws SDIException { - ForesterUtil.printProgramInformation( PRG_NAME, PRG_VERSION, PRG_DATE ); - System.out.println(); - CommandLineArguments cla = null; - try { - cla = new CommandLineArguments( args ); - } - catch ( final Exception e ) { - ForesterUtil.fatalError( PRG_NAME, e.getMessage() ); - } - if ( cla.isOptionSet( HELP_OPTION_1 ) || cla.isOptionSet( HELP_OPTION_2 ) ) { - System.out.println(); - print_help(); - System.exit( 0 ); - } - else if ( ( args.length != 3 ) ) { - System.out.println(); - System.out.println( "wrong number of arguments" ); - System.out.println(); - print_help(); - System.exit( -1 ); - } - final List allowed_options = new ArrayList(); - final String dissallowed_options = cla.validateAllowedOptionsAsString( allowed_options ); - if ( dissallowed_options.length() > 0 ) { - ForesterUtil.fatalError( PRG_NAME, "unknown option(s): " + dissallowed_options ); - } - File gene_trees_dir = null; - File species_trees_file = null; - //File out_file = null; - File out_dir = null; - Phylogeny[] species_trees = null; - try { - gene_trees_dir = cla.getFile( 0 ); - species_trees_file = cla.getFile( 1 ); - out_dir = cla.getFile( 2 ); - } - catch ( final IllegalArgumentException e ) { - ForesterUtil.fatalError( PRG_NAME, "error in command line: " + e.getMessage() ); - } - if ( ForesterUtil.isReadableFile( species_trees_file ) != null ) { - ForesterUtil.fatalError( PRG_NAME, ForesterUtil.isReadableFile( species_trees_file ) ); - } - if ( !gene_trees_dir.isDirectory() || !gene_trees_dir.canRead() ) { - ForesterUtil.fatalError( PRG_NAME, "cannot read gene trees from [" + gene_trees_dir + "]" ); - } - // if ( ForesterUtil.isWritableFile( out_file ) != null ) { - // ForesterUtil.fatalError( PRG_NAME, ForesterUtil.isWritableFile( out_file ) ); - // } - if ( !out_dir.exists() ) { - boolean success = false; - try { - success = out_dir.mkdir(); - } - catch ( final Exception e ) { - ForesterUtil.fatalError( PRG_NAME, "failed to create [" + out_dir + "] [" + e.getMessage() + "]" ); - } - if ( !success ) { - ForesterUtil.fatalError( PRG_NAME, "failed to create [" + out_dir + "]" ); - } - } - try { - final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); - species_trees = factory.create( species_trees_file, new PhyloXmlParser() ); - } - catch ( final IOException e ) { - ForesterUtil.fatalError( PRG_NAME, - "failed to read species trees from [" + species_trees_file + "] [" - + e.getMessage() + "]" ); - } - if ( ( species_trees == null ) || ( species_trees.length < 1 ) ) { - ForesterUtil.fatalError( PRG_NAME, "failed to read species trees from [" + species_trees_file + "]" ); - } - ForesterUtil.programMessage( PRG_NAME, "read in " + species_trees.length + " species trees from [" - + species_trees_file + "]" ); - final FilenameFilter filter = new FilenameFilter() { - - @Override - public boolean accept( final File dir, final String name ) { - return ( !name.startsWith( "." ) && !name.startsWith( "00_" ) && name.endsWith( ".xml" ) ); - } - }; - final String[] gene_tree_names = gene_trees_dir.list( filter ); - Arrays.sort( gene_tree_names ); - final List gene_tree_files = new ArrayList(); - for( final String gene_tree_name : gene_tree_names ) { - final File gene_tree_file = new File( gene_trees_dir + ForesterUtil.FILE_SEPARATOR + gene_tree_name ); - if ( !gene_tree_file.isDirectory() ) { - gene_tree_files.add( gene_tree_file ); - } - } - ForesterUtil.programMessage( PRG_NAME, "going to analyze " + gene_tree_files.size() + " gene trees from [" - + gene_trees_dir + "]" ); - final SDIx shin = new SDIx(); - try { - shin.method1( gene_tree_files, species_trees, out_dir ); - } - catch ( final IOException e ) { - ForesterUtil.fatalError( PRG_NAME, e.getMessage() ); - e.printStackTrace(); - } - ForesterUtil.programMessage( PRG_NAME, "OK" ); - // System.out.println(); - // System.out.println( "Strip species tree: " + strip ); - // SDI sdi = null; - // final long start_time = new Date().getTime(); - // try { - // if ( use_sdise ) { - // System.out.println(); - // System.out.println( "Using SDIse algorithm." ); - // sdi = new SDIse( gene_tree, species_tree ); - // } - // else { - // System.out.println(); - // System.out.println( "Using GSDI algorithm." ); - // System.out.println(); - // System.out.println( "Use most parsimonous duplication model: " + most_parsimonous_duplication_model ); - // sdi = new GSDI( gene_tree, species_tree, most_parsimonous_duplication_model ); - // } - // } - // catch ( final Exception e ) { - // ForesterUtil.unexpectedFatalError( PRG_NAME, e ); - // } - // System.out.println(); - // System.out.println( "Running time (excluding I/O): " + ( new Date().getTime() - start_time ) + "ms" ); - // try { - // final PhylogenyWriter writer = new PhylogenyWriter(); - // writer.toPhyloXML( out_file, gene_tree, 1 ); - // } - // catch ( final IOException e ) { - // ForesterUtil.fatalError( PRG_NAME, "Failed to write to \"" + out_file + "\" [" + e.getMessage() + "]" ); - // } - // System.out.println(); - // System.out.println( "Successfully wrote resulting gene tree to: " + out_file ); - // System.out.println(); - // System.out.println(); - } - - private static void print_help() { - System.out.println( "Usage: " + PRG_NAME + " [-options] " ); - System.out.println(); - System.out.println( "Options:" ); - System.out.println(); - } -} diff --git a/forester/java/src/org/forester/sdi/SDIx.java b/forester/java/src/org/forester/sdi/SDIx.java deleted file mode 100644 index 4667f72..0000000 --- a/forester/java/src/org/forester/sdi/SDIx.java +++ /dev/null @@ -1,134 +0,0 @@ -// $Id: -// FORESTER -- software libraries and applications -// for evolutionary biology research and applications. -// -// Copyright (C) 2008-2009 Christian M. Zmasek -// Copyright (C) 2008-2009 Burnham Institute for Medical Research -// All rights reserved -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -// -// Contact: phylosoft @ gmail . com -// WWW: www.phylosoft.org/forester - -package org.forester.sdi; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.forester.io.parsers.phyloxml.PhyloXmlParser; -import org.forester.io.writers.PhylogenyWriter; -import org.forester.phylogeny.Phylogeny; -import org.forester.phylogeny.PhylogenyMethods; -import org.forester.phylogeny.PhylogenyNode; -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.ForesterUtil; - -public class SDIx { - - public SDIx() { - } - - private void analyze( final Phylogeny gene_tree, - final String gene_tree_file_name, - final Phylogeny[] species_trees, - final File out_dir ) throws IOException, SDIException { - final boolean minimize_cost = true; - final boolean minimize_sum_of_dup = true; - final boolean minimize_height = true; - final int trees_to_return = 1; - System.out.println( gene_tree_file_name + ": " + gene_tree.getName() ); - final Set species_tree_species = getAllExternalSpecies( species_trees[ 0 ] ); - final PhylogenyWriter w = new PhylogenyWriter(); - for( final Phylogeny species_tree : species_trees ) { - PhylogenyMethods.deleteExternalNodesPositiveSelection( species_tree_species, gene_tree ); - if ( gene_tree.isEmpty() ) { - System.out.println( " >> empty: " + gene_tree_file_name + ": " + gene_tree.getName() ); - continue; - } - final File outfile = new File( out_dir + ForesterUtil.FILE_SEPARATOR + gene_tree_file_name ); - if ( outfile.exists() ) { - System.out - .println( " >> already exists, skipping: " + gene_tree_file_name + ": " + gene_tree.getName() ); - } - final SDIR sdir = new SDIR(); - final Phylogeny[] analyzed_gene_trees = sdir.infer( gene_tree, - species_tree, - minimize_cost, - minimize_sum_of_dup, - minimize_height, - true, - trees_to_return ); - final int duplications = sdir.getMinimalDuplications(); - final int mapping_cost = sdir.getMinimalMappingCost(); - final List phys = new ArrayList(); - for( final Phylogeny phy : analyzed_gene_trees ) { - phys.add( phy ); - } - w.toPhyloXML( outfile, phys, 0, ForesterUtil.LINE_SEPARATOR ); - } - } - - private void checkSpeciesTreesForEqualNumberOfExtNodes( final Phylogeny[] species_trees ) { - int ext_nodes = -1; - for( final Phylogeny phylogeny : species_trees ) { - if ( ext_nodes < 0 ) { - ext_nodes = phylogeny.getNumberOfExternalNodes(); - } - else if ( ext_nodes != phylogeny.getNumberOfExternalNodes() ) { - throw new IllegalArgumentException( "species trees must have all the same number of external nodes" ); - } - } - } - - public void method1( final List gene_tree_files, final Phylogeny[] species_trees, final File out_dir ) - throws IOException, SDIException { - checkSpeciesTreesForEqualNumberOfExtNodes( species_trees ); - final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); - for( final File gene_tree_file : gene_tree_files ) { - if ( ForesterUtil.isReadableFile( gene_tree_file ) != null ) { - throw new IOException( "[" + gene_tree_file + "] is not readable" ); - } - Phylogeny[] gene_trees = null; - gene_trees = factory.create( gene_tree_file, new PhyloXmlParser() ); - if ( gene_trees.length != 1 ) { - throw new IOException( "[" + gene_tree_file + "] contains " + gene_trees.length - + " gene trees, expecting precisely one" ); - } - analyze( gene_trees[ 0 ], gene_tree_file.getName(), species_trees, out_dir ); - } - } - - private static Set getAllExternalSpecies( final Phylogeny phy ) { - final Set specs = new HashSet(); - for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) { - final PhylogenyNode n = it.next(); - if ( n.getNodeData().isHasTaxonomy() ) { - specs.add( n.getNodeData().getTaxonomy() ); - } - else { - throw new IllegalArgumentException( "node " + n.getId() + " has no taxonomic data" ); - } - } - return specs; - } -} -- 1.7.10.2