Package jebl.evolution.io
Class NexusImporter
java.lang.Object
jebl.evolution.io.NexusImporter
- All Implemented Interfaces:
Iterable<Tree>,AlignmentImporter,DistanceMatrixImporter,SequenceImporter,TreeImporter
public class NexusImporter
extends 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 ClassesModifier and TypeClassDescriptionstatic classThrown when a block is missing that is required for importing a particular type of data from the nexus input.static enumRepresents the block types used in the nexus formatNested classes/interfaces inherited from interface jebl.evolution.io.DistanceMatrixImporter
DistanceMatrixImporter.Triangle -
Constructor Summary
ConstructorsConstructorDescriptionNexusImporter(Reader reader) NexusImporter(Reader reader, boolean compactTrees) Deprecated.Use NexusImporter(Reader reader, boolean compactTrees, long expectedInputLength)NexusImporter(Reader reader, boolean compactTrees, long expectedInputLength) NexusImporter(Reader reader, long expectedLength) -
Method Summary
Modifier and TypeMethodDescriptionvoidRead ahead to the end of the current block.Read ahead to the next block in the input.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.Import all alignments in the input from the current position.Import all distance matrices from all DISTANCES blocks in the input form the current position.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.Import all sequences in the input from the current positionImport all trees in the file from the current position.iterator()static StringmakeIntoAllowableIdentifier(String identifier) parseCharactersBlock(List<Taxon> taxonList) Parse the next 'CHARACTERS' block encountered in the input.parseDataBlock(List<Taxon> taxonList) Parse the next 'DATA' block encountered in the input.parseDistancesBlock(List<Taxon> taxonList) Parse the next 'DISTANCES' block encountered in the input.Parse the next 'TAXA' block encountered in the input.parseTreesBlock(List<Taxon> taxonList) Parse the next 'TREES' block encountered in the input.booleanRead nexus blocks until the next TREES block (or the end of the input) is encountered.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
NexusImporter
- Parameters:
reader-expectedLength- Expected length of the input in bytes, or 0 if unknown. Used for optimization and tracking progress.
-
NexusImporter
-
NexusImporter
- 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.Use NexusImporter(Reader reader, boolean compactTrees, long expectedInputLength)- Parameters:
reader-compactTrees-
-
-
Method Details
-
findNextBlock
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:
IOException
-
getNextBlockName
- Returns:
- the name of the next block which will be read. eg "TREES"
-
iterator
-
parseTaxaBlock
Parse the next 'TAXA' block encountered in the input.- Throws:
ImportExceptionIOException
-
parseCharactersBlock
public List<Sequence> parseCharactersBlock(List<Taxon> taxonList) throws ImportException, IOException Parse the next 'CHARACTERS' block encountered in the input.- Throws:
ImportExceptionIOException
-
parseDataBlock
Parse the next 'DATA' block encountered in the input.- Throws:
ImportExceptionIOException
-
parseTreesBlock
Parse the next 'TREES' block encountered in the input.- Throws:
ImportExceptionIOException
-
parseDistancesBlock
public DistanceMatrix parseDistancesBlock(List<Taxon> taxonList) throws ImportException, IOException Parse the next 'DISTANCES' block encountered in the input.- Throws:
ImportExceptionIOException
-
importAlignments
Import all alignments in the input from the current position.- Specified by:
importAlignmentsin interfaceAlignmentImporter- Throws:
IOExceptionImportException
-
importSequences
Import all sequences in the input from the current position- Specified by:
importSequencesin interfaceSequenceImporter- Throws:
IOExceptionImportException
-
hasTree
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 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:
IOExceptionImportException
-
importNextTree
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:
IOExceptionImportException
-
importTrees
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:
IOExceptionImportException
-
startReadingTrees
Read 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:
IOExceptionImportException
-
importDistanceMatrices
Import all distance matrices from all DISTANCES blocks in the input form the current position.- Specified by:
importDistanceMatricesin interfaceDistanceMatrixImporter- Throws:
IOExceptionImportException
-
findEndBlock
Read ahead to the end of the current block.- Throws:
IOException
-
makeIntoAllowableIdentifier
-