@@ -0,0 +1,2495 @@
+package org.biojava.nbio.phylo;%0A%0Aimport java.io.ByteArrayOutputStream;%0Aimport java.io.OutputStream;%0A%0Aimport org.biojava.nbio.core.sequence.MultipleSequenceAlignment;%0Aimport org.biojava.nbio.core.sequence.io.FastaWriter;%0Aimport org.biojava.nbio.core.sequence.io.template.FastaHeaderFormatInterface;%0Aimport org.biojava.nbio.core.sequence.template.Compound;%0Aimport org.biojava.nbio.core.sequence.template.Sequence;%0Aimport org.forester.io.parsers.FastaParser;%0Aimport org.forester.io.writers.PhylogenyWriter;%0Aimport org.forester.msa.Msa;%0Aimport org.forester.phylogeny.Phylogeny;%0A%0A/**%0A * This class contains wrapper methods for communication between BioJava and%0A * forester (e.g, Data Structure conversion).%0A * %0A * @author Aleix Lafita%0A * @since 4.1.1%0A *%0A */%0Apublic class ForesterWrapper %7B%0A%0A%09/** Prevent instantiation */%0A%09private ForesterWrapper() %7B%7D%0A%0A%09/**%0A%09 * Convert a BioJava %7B@link MultipleSequenceAlignment%7D to a forester%0A%09 * %7B@link Msa%7D. The easiest way to convert them is writting the msa as a%0A%09 * FASTA file and then parsing it with the forester %7B@link FastaParser%7D.%0A%09 * %0A%09 * @param msa%0A%09 *            BioJava MultipleSequenceAlignment%0A%09 * @return forester Msa object%0A%09 * @throws Exception%0A%09 *             if the conversion was not possible%0A%09 */%0A%09public static %3CC extends Sequence%3CD%3E, D extends Compound%3E Msa convert(%0A%09%09%09MultipleSequenceAlignment%3CC, D%3E msa) throws Exception %7B%0A%0A%09%09// Convert the biojava MSA to a FASTA String%0A%09%09OutputStream os = new ByteArrayOutputStream();%0A%09%09FastaWriter%3CC, D%3E fastaW = new FastaWriter%3CC, D%3E(os,%0A%09%09%09%09msa.getAlignedSequences(),%0A%09%09%09%09new FastaHeaderFormatInterface%3CC, D%3E() %7B%0A%09%09%09%09%09@Override%0A%09%09%09%09%09public String getHeader(C sequence) %7B%0A%09%09%09%09%09%09return sequence.getAccession().toString();%0A%09%09%09%09%09%7D;%0A%09%09%09%09%7D);%0A%09%09fastaW.process();%0A%09%09String fastaMSA = os.toString();%0A%0A%09%09// Parse the FASTA file in forester%0A%09%09return FastaParser.parseMsa(fastaMSA);%0A%09%7D%0A%0A%09/**%0A%09 * Convert a Phylogenetic tree to its Newick representation, so that it can%0A%09 * be exported to an external application.%0A%09 * %0A%09 * @param phylo%0A%09 *            Phylogeny phylogenetic tree%0A%09 * @param simpleNewick%0A%09 * @param writeDistances%0A%09 *            write the branch lengths if true%0A%09 * @return%0A%09 * @throws Exception%0A%09 */%0A%09public static String getNewickString(Phylogeny phylo, boolean simpleNewick,%0A%09%09%09boolean writeDistances) throws Exception %7B%0A%0A%09%09PhylogenyWriter w = new PhylogenyWriter();%0A%09%09StringBuffer newickString = w.toNewHampshire(phylo, simpleNewick,%0A%09%09%09%09writeDistances);%0A%09%09return newickString.toString();%0A%09%7D%0A%0A%7D%0A

Create a Wrapper class for conversion biojava-forester