Package jebl.evolution.io
Class NexusImporter
- java.lang.Object
-
- jebl.evolution.io.NexusImporter
-
- All Implemented Interfaces:
java.lang.Iterable<Tree>,AlignmentImporter,DistanceMatrixImporter,SequenceImporter,TreeImporter
public class NexusImporter extends java.lang.Object implements AlignmentImporter, SequenceImporter, TreeImporter, DistanceMatrixImporter
Class for importing NEXUS file format. This is a good starting point for documentation about the nexus file format: https://www.nescent.org/wg_phyloinformatics/NEXUS_Specification For a quick check if something is probably valid or not, consider this attempt at a nexus grammar (the above page says "Don't treat this as gospel, its just an attempt to get the syntax rules"): http://www.cs.nmsu.edu/~epontell/nexus/nexus_grammar- Version:
- $Id: NexusImporter.java 1052 2010-05-10 00:45:35Z richardmoir $
- Author:
- Andrew Rambaut, Alexei Drummond
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classNexusImporter.MissingBlockExceptionThrown when a block is missing that is required for importing a particular type of data from the nexus input.static classNexusImporter.NexusBlockRepresents the block types used in the nexus format-
Nested classes/interfaces inherited from interface jebl.evolution.io.DistanceMatrixImporter
DistanceMatrixImporter.Triangle
-
-
Constructor Summary
Constructors Constructor Description NexusImporter(java.io.Reader reader)NexusImporter(java.io.Reader reader, boolean compactTrees)Deprecated.Use NexusImporter(Reader reader, boolean compactTrees, long expectedInputLength)NexusImporter(java.io.Reader reader, boolean compactTrees, long expectedInputLength)NexusImporter(java.io.Reader reader, long expectedLength)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidfindEndBlock()Read ahead to the end of the current block.NexusImporter.NexusBlockfindNextBlock()Read ahead to the next block in the input.java.lang.StringgetNextBlockName()booleanhasTree()If not currently reading a TREES block then read ahead to the next TREES block, parsing TRANSLATE and TAXA blocks in the process if necessary.java.util.List<Alignment>importAlignments()Import all alignments in the input from the current position.java.util.List<DistanceMatrix>importDistanceMatrices()Import all distance matrices from all DISTANCES blocks in the input form the current position.TreeimportNextTree()If not currently reading a TREES block then read ahead to the next TREES block, parsing TRANSLATE and TAXA blocks in the process if necessary.java.util.List<Sequence>importSequences()Import all sequences in the input from the current positionjava.util.List<Tree>importTrees()Import all trees in the file from the current position.java.util.Iterator<Tree>iterator()static java.lang.StringmakeIntoAllowableIdentifier(java.lang.String identifier)java.util.List<Sequence>parseCharactersBlock(java.util.List<Taxon> taxonList)Parse the next 'CHARACTERS' block encountered in the input.java.util.List<Sequence>parseDataBlock(java.util.List<Taxon> taxonList)Parse the next 'DATA' block encountered in the input.DistanceMatrixparseDistancesBlock(java.util.List<Taxon> taxonList)Parse the next 'DISTANCES' block encountered in the input.java.util.List<Taxon>parseTaxaBlock()Parse the next 'TAXA' block encountered in the input.java.util.List<Tree>parseTreesBlock(java.util.List<Taxon> taxonList)Parse the next 'TREES' block encountered in the input.booleanstartReadingTrees()Read nexus blocks until the next TREES block (or the end of the input) is encountered.
-
-
-
Constructor Detail
-
NexusImporter
public NexusImporter(java.io.Reader reader, long expectedLength)- Parameters:
reader-expectedLength- Expected length of the input in bytes, or 0 if unknown. Used for optimization and tracking progress.
-
NexusImporter
public NexusImporter(java.io.Reader reader)
-
NexusImporter
public NexusImporter(java.io.Reader reader, boolean compactTrees, long expectedInputLength)- Parameters:
reader-compactTrees- true to import trees asCompactRootedTree, false to useSimpleRootedTree.expectedInputLength- Expected length of the input in bytes, or 0 if unknown. Used for optimization and tracking progress.
-
NexusImporter
@Deprecated public NexusImporter(java.io.Reader reader, boolean compactTrees)Deprecated.Use NexusImporter(Reader reader, boolean compactTrees, long expectedInputLength)- Parameters:
reader-compactTrees-
-
-
Method Detail
-
findNextBlock
public NexusImporter.NexusBlock findNextBlock() throws java.io.IOException
Read ahead to the next block in the input. This should be overridden to provide support for other blocks. Once the block is read in, nextBlock is automatically set to UNKNOWN by findEndBlock.- Returns:
- the type of the next block
- Throws:
java.io.IOException
-
getNextBlockName
public java.lang.String getNextBlockName()
- Returns:
- the name of the next block which will be read. eg "TREES"
-
iterator
public java.util.Iterator<Tree> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<Tree>- Returns:
- an Iterator over the trees in the nexus input.
-
parseTaxaBlock
public java.util.List<Taxon> parseTaxaBlock() throws ImportException, java.io.IOException
Parse the next 'TAXA' block encountered in the input.- Throws:
ImportExceptionjava.io.IOException
-
parseCharactersBlock
public java.util.List<Sequence> parseCharactersBlock(java.util.List<Taxon> taxonList) throws ImportException, java.io.IOException
Parse the next 'CHARACTERS' block encountered in the input.- Throws:
ImportExceptionjava.io.IOException
-
parseDataBlock
public java.util.List<Sequence> parseDataBlock(java.util.List<Taxon> taxonList) throws ImportException, java.io.IOException
Parse the next 'DATA' block encountered in the input.- Throws:
ImportExceptionjava.io.IOException
-
parseTreesBlock
public java.util.List<Tree> parseTreesBlock(java.util.List<Taxon> taxonList) throws ImportException, java.io.IOException
Parse the next 'TREES' block encountered in the input.- Throws:
ImportExceptionjava.io.IOException
-
parseDistancesBlock
public DistanceMatrix parseDistancesBlock(java.util.List<Taxon> taxonList) throws ImportException, java.io.IOException
Parse the next 'DISTANCES' block encountered in the input.- Throws:
ImportExceptionjava.io.IOException
-
importAlignments
public java.util.List<Alignment> importAlignments() throws java.io.IOException, ImportException
Import all alignments in the input from the current position.- Specified by:
importAlignmentsin interfaceAlignmentImporter- Throws:
java.io.IOExceptionImportException
-
importSequences
public java.util.List<Sequence> importSequences() throws java.io.IOException, ImportException
Import all sequences in the input from the current position- Specified by:
importSequencesin interfaceSequenceImporter- Throws:
java.io.IOExceptionImportException
-
hasTree
public boolean hasTree() throws java.io.IOException, ImportExceptionIf not currently reading a TREES block then read ahead to the next TREES block, parsing TRANSLATE and TAXA blocks in the process if necessary. Then determine if the current (or next) TREES block contains any more trees. If true then importNextTree will return a non-null value.- Specified by:
hasTreein interfaceTreeImporter- Returns:
- true if another tree is available, false otherwise.
- Throws:
java.io.IOExceptionImportException
-
importNextTree
public Tree importNextTree() throws java.io.IOException, ImportException
If not currently reading a TREES block then read ahead to the next TREES block, parsing TRANSLATE and TAXA blocks in the process if necessary. Then parse the next available tree.- Specified by:
importNextTreein interfaceTreeImporter- Returns:
- the next available tree or null if no more trees are available
- Throws:
java.io.IOExceptionImportException
-
importTrees
public java.util.List<Tree> importTrees() throws java.io.IOException, ImportException
Import all trees in the file from the current position. Will read ahead to the next TREES block if necessary- Specified by:
importTreesin interfaceTreeImporter- Returns:
- list of trees
- Throws:
java.io.IOExceptionImportException
-
startReadingTrees
public boolean startReadingTrees() throws java.io.IOException, ImportExceptionRead nexus blocks until the next TREES block (or the end of the input) is encountered.- Returns:
- true if a TREES block was found, false otherwise
- Throws:
java.io.IOExceptionImportException
-
importDistanceMatrices
public java.util.List<DistanceMatrix> importDistanceMatrices() throws java.io.IOException, ImportException
Import all distance matrices from all DISTANCES blocks in the input form the current position.- Specified by:
importDistanceMatricesin interfaceDistanceMatrixImporter- Throws:
java.io.IOExceptionImportException
-
findEndBlock
public void findEndBlock() throws java.io.IOExceptionRead ahead to the end of the current block.- Throws:
java.io.IOException
-
makeIntoAllowableIdentifier
public static java.lang.String makeIntoAllowableIdentifier(java.lang.String identifier)
-
-