Beispiel #1
0
def readData(filepath, format=FileFormats.NEXUS, out=None):
    """Returns a data matrix (or None if there is no data) from `filepath`

    Currently only supports NEXUS and only returns the last data matrix, but
    this will be generalized to read other formats and return the
    supermatrix of all data matrices in the file."""
    _readFileSanityCheck(filepath, format, out)
    from phycas.readnexus import NexusReader
    reader = NexusReader()
    reader.readFile(filepath)
    return reader.getLastDiscreteMatrix(True)
Beispiel #2
0
def readTrees(filepath, format=FileFormats.NEXUS, out=None):
    """Returns a (taxon_list, list of TreeDescription objects) (or an empty list if there are no trees) from `filepath`

    Currently only supports NEXUS and only returns the last data matrix, but
    this will be generalized to read other formats and return the
    supermatrix of all data matrices in the file."""

    _readFileSanityCheck(filepath, format, out)
    from phycas.readnexus import NexusReader
    reader = NexusReader()
    reader.readFile(filepath)
    return reader.taxa, reader.getTrees()
Beispiel #3
0
def readFileNoSideEffects(filepath, format=FileFormats.NEXUS, out=None):
    """Returns a (list of taxon labels, DataSource, TreeCollection) from the file `filepath`"""
    _readFileSanityCheck(filepath, format, out)
    from phycas.readnexus import NexusReader
    reader = NexusReader()
    reader.readFile(filepath)
    x = PhyloPackage()
    x.taxon_labels = reader.taxa
    matrix = reader.getLastDiscreteMatrix(True)
    x.characters = DataSource(matrix=matrix, taxon_labels=x.taxon_labels)
    x.trees = TreeCollection(trees=reader.getTrees(), taxon_labels=x.taxon_labels)
    return x