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 Classes
Modifier and Type
Class
Description
`static class`
`NexusImporter.MissingBlockException`
Thrown when a block is missing that is required for importing a particular type of data from the nexus input.
`static enum`
`NexusImporter.NexusBlock`
Represents 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(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 Type
Method
Description
`void`
`findEndBlock()`
Read ahead to the end of the current block.
`NexusImporter.NexusBlock`
`findNextBlock()`
Read ahead to the next block in the input.
`String`
`getNextBlockName()`
`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.
`List<Alignment>`
`importAlignments()`
Import all alignments in the input from the current position.
`List<DistanceMatrix>`
`importDistanceMatrices()`
Import all distance matrices from all DISTANCES blocks in the input form the current position.
`Tree`
`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.
`List<Sequence>`
`importSequences()`
Import all sequences in the input from the current position
`List<Tree>`
`importTrees()`
Import all trees in the file from the current position.
`Iterator<Tree>`
`iterator()`
`static String`
`makeIntoAllowableIdentifier(String identifier)`
`List<Sequence>`
`parseCharactersBlock(List<Taxon> taxonList)`
Parse the next 'CHARACTERS' block encountered in the input.
`List<Sequence>`
`parseDataBlock(List<Taxon> taxonList)`
Parse the next 'DATA' block encountered in the input.
`DistanceMatrix`
`parseDistancesBlock(List<Taxon> taxonList)`
Parse the next 'DISTANCES' block encountered in the input.
`List<Taxon>`
`parseTaxaBlock()`
Parse the next 'TAXA' block encountered in the input.
`List<Tree>`
`parseTreesBlock(List<Taxon> taxonList)`
Parse the next 'TREES' block encountered in the input.
`boolean`
`startReadingTrees()`
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

public NexusImporter(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(Reader reader)

### NexusImporter

public NexusImporter(Reader reader, boolean compactTrees, long expectedInputLength)

Parameters:
  `reader` -
  `compactTrees` - true to import trees as `CompactRootedTree`, false to use `SimpleRootedTree`.
  `expectedInputLength` - Expected length of the input in bytes, or 0 if unknown. Used for optimization and tracking progress.

### NexusImporter

@Deprecated public NexusImporter(Reader reader, boolean compactTrees)
Deprecated.
Use NexusImporter(Reader reader, boolean compactTrees, long expectedInputLength)

Parameters:
  `reader` -
  `compactTrees` -

## Method Details

### findNextBlock

public NexusImporter.NexusBlock findNextBlock() throws 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:
  `IOException`

### getNextBlockName

public String getNextBlockName()

Returns:
  the name of the next block which will be read. eg "TREES"

### iterator

public Iterator<Tree> iterator()

Specified by:
  `iterator` in interface `Iterable<Tree>`
Returns:
  an Iterator over the trees in the nexus input.

### parseTaxaBlock

public List<Taxon> parseTaxaBlock() throws ImportException, IOException
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

public List<Sequence> parseDataBlock(List<Taxon> taxonList) throws ImportException, IOException
Parse the next 'DATA' block encountered in the input.

Throws:
  `ImportException`
  `IOException`

### parseTreesBlock

public List<Tree> parseTreesBlock(List<Taxon> taxonList) throws ImportException, IOException
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

public List<Alignment> importAlignments() throws IOException, ImportException
Import all alignments in the input from the current position.

Specified by:
  `importAlignments` in interface `AlignmentImporter`
Throws:
  `IOException`
  `ImportException`

### importSequences

public List<Sequence> importSequences() throws IOException, ImportException
Import all sequences in the input from the current position

Specified by:
  `importSequences` in interface `SequenceImporter`
Throws:
  `IOException`
  `ImportException`

### hasTree

public boolean hasTree() throws 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 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 interface `TreeImporter`
Returns:
  true if another tree is available, false otherwise.
Throws:
  `IOException`
  `ImportException`

### importNextTree

public Tree importNextTree() throws 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:
  `importNextTree` in interface `TreeImporter`
Returns:
  the next available tree or null if no more trees are available
Throws:
  `IOException`
  `ImportException`

### importTrees

public List<Tree> importTrees() throws IOException, ImportException
Import all trees in the file from the current position. Will read ahead to the next TREES block if necessary

Specified by:
  `importTrees` in interface `TreeImporter`
Returns:
  list of trees
Throws:
  `IOException`
  `ImportException`

### startReadingTrees

public boolean startReadingTrees() throws IOException, ImportException
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

public List<DistanceMatrix> importDistanceMatrices() throws IOException, ImportException
Import all distance matrices from all DISTANCES blocks in the input form the current position.

Specified by:
  `importDistanceMatrices` in interface `DistanceMatrixImporter`
Throws:
  `IOException`
  `ImportException`

### findEndBlock

public void findEndBlock() throws IOException
Read ahead to the end of the current block.

Throws:
  `IOException`

### makeIntoAllowableIdentifier

public static String makeIntoAllowableIdentifier(String identifier)