package jalview.ext.forester.io;
-import jalview.datamodel.SequenceI;
+import jalview.ext.archaeopteryx.AptxInit;
import jalview.ext.archaeopteryx.Tree;
import jalview.ext.treeviewer.TreeI;
import jalview.ext.treeviewer.TreeParserI;
+import java.io.File;
import java.io.IOException;
import org.forester.io.parsers.PhylogenyParser;
+import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
+import org.forester.io.parsers.phyloxml.PhyloXmlParser;
+import org.forester.io.parsers.util.PhylogenyParserException;
import org.forester.phylogeny.Phylogeny;
-public class ForesterParser implements TreeParserI
+public class ForesterParser
+ implements TreeParserI
{
private final PhylogenyParser parser;
- private SequenceI[] seqs;
+ private TreeI[] parsedTrees;
- public ForesterParser(PhylogenyParser foresterParser)
+ protected ForesterParser(PhylogenyParser foresterParser, File file)
+ throws PhylogenyParserException, IOException
{
parser = foresterParser;
+ parser.setSource(file);
}
+ public static ForesterParser createNexusParser(File file)
+ throws PhylogenyParserException, IOException
+ {
+ NexusPhylogeniesParser nxParser = new NexusPhylogeniesParser();
+ nxParser.setReplaceUnderscores(
+ AptxInit.APTX_CONFIG.isReplaceUnderscoresInNhParsing());
+ nxParser.setIgnoreQuotes(false);
+ return new ForesterParser(new NexusPhylogeniesParser(), file);
+ }
+
+ public static ForesterParser createPhyloXmlParser(File file)
+ throws PhylogenyParserException, IOException
+ {
+ // support non-xsd validating?
+ return new ForesterParser(
+ PhyloXmlParser.createPhyloXmlParserXsdValidating(), file);
+ }
+
+ // ParserBasedPhylogenyFactory.getInstance().create(foresterParser, source)
@Override
public TreeI[] parse() throws IOException
{
Phylogeny[] foresterTrees = parser.parse();
- TreeI[] jalviewTrees = new TreeI[foresterTrees.length];
+ parsedTrees = new TreeI[foresterTrees.length];
for (int i = 0; i < foresterTrees.length; i++)
{
- jalviewTrees[i] = new Tree(foresterTrees[i]);
+ parsedTrees[i] = new Tree(foresterTrees[i]);
}
- return jalviewTrees;
+ return parsedTrees;
}
{
return parser.getName();
}
+
+
+ @Override
+ public TreeI[] getParsedTrees()
+ {
+ return parsedTrees;
+ }
}
\ No newline at end of file