<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def dataset(path, mode='r', fmt=None, verbose=False, **kwargs):
 """Open a dataset object MSMBuilder supports several dataset 'formats' for storing lists of sequences on disk. This function can also be used as a context manager. Parameters path : str The path to the dataset on the filesystem mode : {'r', 'w', 'a'} Open a dataset for reading, writing, or appending. Note that some formats only support a subset of these modes. fmt : {'dir-npy', 'hdf5', 'mdtraj'} The format of the data on disk ``dir-npy`` A directory of binary numpy files, one file per sequence ``hdf5`` A single hdf5 file with each sequence as an array node ``mdtraj`` A read-only set of trajectory files that can be loaded with mdtraj verbose : bool Whether to print information about the dataset """


    if mode == 'r' and fmt is None:
        fmt = _guess_format(path)
    elif mode in 'wa' and fmt is None:
        raise ValueError('mode="%s", but no fmt. fmt=%s' % (mode, fmt))

    if fmt == 'dir-npy':
        return NumpyDirDataset(path, mode=mode, verbose=verbose)
    elif fmt == 'mdtraj':
        return MDTrajDataset(path, mode=mode, verbose=verbose, **kwargs)
    elif fmt == 'hdf5':
        return HDF5Dataset(path, mode=mode, verbose=verbose)
    elif fmt.endswith("-union"):
        raise ValueError("union datasets have been removed. "
                         "Please use msmbuilder.featurizer.FeatureUnion")
    else:
        raise NotImplementedError("Unknown format fmt='%s'" % fmt)