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 class
Thrown when a block is missing that is required for importing a particular type of data from the nexus input.static enum
Represents 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 TypeMethodDescriptionvoid
Read ahead to the end of the current block.Read ahead to the next block in the input.boolean
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.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 String
makeIntoAllowableIdentifier
(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.boolean
Read 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, wait
Methods 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:
ImportException
IOException
-
parseCharactersBlock
public List<Sequence> parseCharactersBlock(List<Taxon> taxonList) throws ImportException, IOException Parse the next 'CHARACTERS' block encountered in the input.- Throws:
ImportException
IOException
-
parseDataBlock
Parse the next 'DATA' block encountered in the input.- Throws:
ImportException
IOException
-
parseTreesBlock
Parse the next 'TREES' block encountered in the input.- Throws:
ImportException
IOException
-
parseDistancesBlock
public DistanceMatrix parseDistancesBlock(List<Taxon> taxonList) throws ImportException, IOException Parse the next 'DISTANCES' block encountered in the input.- Throws:
ImportException
IOException
-
importAlignments
Import all alignments in the input from the current position.- Specified by:
importAlignments
in interfaceAlignmentImporter
- Throws:
IOException
ImportException
-
importSequences
Import all sequences in the input from the current position- Specified by:
importSequences
in interfaceSequenceImporter
- Throws:
IOException
ImportException
-
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:
hasTree
in interfaceTreeImporter
- Returns:
- true if another tree is available, false otherwise.
- Throws:
IOException
ImportException
-
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:
importNextTree
in interfaceTreeImporter
- Returns:
- the next available tree or null if no more trees are available
- Throws:
IOException
ImportException
-
importTrees
Import all trees in the file from the current position. Will read ahead to the next TREES block if necessary- Specified by:
importTrees
in interfaceTreeImporter
- Returns:
- list of trees
- Throws:
IOException
ImportException
-
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:
IOException
ImportException
-
importDistanceMatrices
Import all distance matrices from all DISTANCES blocks in the input form the current position.- Specified by:
importDistanceMatrices
in interfaceDistanceMatrixImporter
- Throws:
IOException
ImportException
-
findEndBlock
Read ahead to the end of the current block.- Throws:
IOException
-
makeIntoAllowableIdentifier
-