o
    Rŀgv
                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ eeeedZ	zdd	lm
Z
 e
e	d
< W n	 eyB   Y nw dd Zdd Zdd ZdddZdS )zI/O function wrappers for phylogenetic tree formats.

This API follows the same semantics as Biopython's ``SeqIO`` and
``AlignIO``.
    )File)BaseTree)NewickIO)NeXMLIO)NexusIO)
PhyloXMLIO)newicknexusphyloxmlnexml)CDAOIOcdaoc                 k   sR    t | }tt| d|fi |E dH  W d   dS 1 s"w   Y  dS )al  Parse a file iteratively, and yield each of the trees it contains.

    If a file only contains one tree, this still returns an iterable object that
    contains one element.

    Examples
    --------
    >>> import Bio.Phylo
    >>> trees = Bio.Phylo.parse('PhyloXML/apaf.xml', 'phyloxml')
    >>> for tree in trees:
    ...     print(tree.rooted)
    True

    parseN)r   	as_handlegetattrsupported_formats)fileformatkwargsfp r   A/var/www/html/myenv/lib/python3.10/site-packages/Bio/Phylo/_io.pyr   $   s   ""r   c                 K   sb   zt | |fi |}t|}W n ty   tddw z	t| W td ty0   | Y S w )zParse a file in the given format and return a single tree.

    Raises a ``ValueError`` if there are zero or multiple trees -- if this
    occurs, use ``parse`` instead to get the complete sequence of trees.
    z There are no trees in this file.Nz;There are multiple trees in this file; use parse() instead.)r   nextStopIteration
ValueError)r   r   r   tree_gentreer   r   r   read7   s   

r   c                 K   sf   t | tjtjfr| g} t|d}tt| d| |fi |}W d   |S 1 s,w   Y  |S )z6Write a sequence of trees to file in the given format.zw+writeN)
isinstancer   TreeClader   r   r   r   )treesr   r   r   r   nr   r   r   r   J   s   
r   Nc                 K   s2   |du ri }t | |fi |}t|||fi |S )z&Convert between two tree file formats.N)r   r   )in_file	in_formatout_file
out_format
parse_argsr   r"   r   r   r   convertT   s   r)   )N)__doc__Bior   	Bio.Phylor   r   r   r   r   r   r   ImportErrorr   r   r   r)   r   r   r   r   <module>   s,   
