def store_chars(char_block, format, dest=None): "Writes the CharacterBlock `char_block` to `dest` using writer." deprecation("'dataio.store_chars()' is deprecated: use 'write()' method of a Dataset object instead", logger_obj=_LOG) dataset = Dataset() dataset.add_char_block(char_block=char_block) return store_dataset(dataset=dataset, format=format, dest=dest)
def dataset_from_string(string, format): """ Returns a Dataset object parsed from the source, where: `string` - a string containing the data to be parsed. `format` - file format specification """ deprecation("'dataio.dataset_from_string()' is deprecated; use 'from_string()' method of a Dataset object instead", logger_obj=_LOG) reader = get_reader(format) return reader.read_dataset(source_file_handle(string=string))
def trees_from_string(string, format, encode_splits=False, rooted=RootingInterpretation.UNKNOWN_DEF_UNROOTED): """ Returns a *list* of TreesBlock objects parsed from the source, where: `string` - a string containing the data to be parsed. `format` - file format specification """ deprecation("'dataio.trees_from_string()' is deprecated: use 'trees_from_string()' method of a Dataset object instead", logger_obj=_LOG) reader = get_reader(format) return reader.read_trees(source_file_handle(string=string), encode_splits=encode_splits, rooted=rooted)
def trees_from_file(file_obj, format, encode_splits=False, rooted=RootingInterpretation.UNKNOWN_DEF_UNROOTED): """ Returns a *list* of TreesBlock objects parsed from the source, where: `file_obj` - can either be a file descriptor object/handle opened for reading or a string indicating a filepath that can be opened for reading using open(). `format` - file format specification """ deprecation("'dataio.trees_from_file()' is deprecated: use 'read_trees()' method of a Dataset object instead", logger_obj=_LOG) reader = get_reader(format) return reader.read_trees(source_file_handle(file_obj=file_obj), encode_splits=encode_splits, rooted=rooted)
def dataset_from_file(file_obj, format): """ Returns a Dataset object parsed from the source, where: `file_obj` - can either be a file descriptor object/handle opened for reading or a string indicating a filepath that can be opened for reading using open(). `format` - file format specification """ deprecation("'dataio.dataset_from_file()' is deprecated; use 'read()' method of a Dataset object instead", logger_obj=_LOG) reader = get_reader(format) return reader.read_dataset(source_file_handle(file_obj=file_obj))
def from_nexus(file_obj=None, string=None): """ Returns a Dataset object parsed from a NEXUS or NEWICK source. `file_obj` - can either be a file descriptor object/handle opened for reading or a string indicating a filepath that can be opened for reading using open(). `string` - a string containing the data to be parsed. Either `file_obj` or `string` must be given. If both are given, `file_obj` is used. """ deprecation("'dataio.from_nexus() is deprecated: use 'read()' method of a Dataset object instead", logger_obj=_LOG) return nexus.read_dataset(source_file_handle(file_obj=file_obj, string=string))
def store_trees(trees_collection, format, dest=None): "Writes the list of trees `trees` to `dest` using writer." deprecation("'dataio.store_trees()' is deprecated: use 'write()' method of a Dataset object instead", logger_obj=_LOG) if isinstance(trees_collection, TreesBlock): trees_block = trees_collection else: trees_block = TreesBlock() for tree in trees_collection: trees_block.append(tree) trees_block.normalize_taxa() dataset = Dataset() dataset.add_trees_block(trees_block=trees_block) return store_dataset(dataset=dataset, format=format, dest=dest)
def store_dataset(dataset, format, dest=None): """ Writes the Dataset object `dataset` using `writer` (a DatasetWriter or derived object) to `dest`. If `dest` is a string, then it is assumed to be a path name, and open() is used to construct an output stream handle from it. If `dest` is not given, then the dataset is written to a string and a string is returned. """ deprecation("'dataio.store_dataset()' is deprecated: use 'write()' method of a Dataset object instead", logger_obj=_LOG) writer = get_writer(format) if dest is None: dest = StringIO() if isinstance(dest, str): dest = open(dest, "w") writer.write_dataset(dataset, dest) if hasattr(dest, "getvalue"): return dest.getvalue()