001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021package org.biojava.nbio.phylo;
022
023import org.forester.evoinference.distance.NeighborJoining;
024import org.forester.evoinference.matrix.distance.BasicSymmetricalDistanceMatrix;
025import org.forester.phylogeny.Phylogeny;
026import org.slf4j.Logger;
027import org.slf4j.LoggerFactory;
028
029/**
030 * The TreeConstructor uses the forester library to build different types of
031 * phylogenetic trees.
032 *
033 * @author Scooter Willis
034 * @author Aleix Lafita
035 *
036 */
037public class TreeConstructor {
038
039        private static final Logger logger = LoggerFactory
040                        .getLogger(TreeConstructor.class);
041
042        /** Prevent instantiation */
043        private TreeConstructor() {}
044
045        public static Phylogeny distanceTree(BasicSymmetricalDistanceMatrix distM,
046                        TreeConstructorType constructor) {
047
048                Phylogeny p = null;
049                switch (constructor) {
050                case NJ:
051                        NeighborJoining nj = NeighborJoining.createInstance();
052                        p = nj.execute(distM);
053                        p.setType(TreeType.DISTANCE.name);
054                        break;
055                default:
056                        logger.warn("Only NJ Tree Constructor Supported!");
057                        break;
058                }
059                logger.info("Tree Completed");
060                return p;
061        }
062}