a
    VA(f                     @   s\   d dl mZmZmZmZmZ d dlmZ G dd deZ	G dd de
ZG dd deZd	S )
    )CallableListTupleIterableUnion)_pysam_dispatchc                   @   s    e Zd ZdZdd Zdd ZdS )SamtoolsErrorzJexception raised in case of an error incurred in the samtools
    library.c                 C   s
   || _ d S N)value)selfr
    r   *lib/python3.9/site-packages/pysam/utils.py__init__   s    zSamtoolsError.__init__c                 C   s
   t | jS r	   )reprr
   r   r   r   r   __str__   s    zSamtoolsError.__str__N)__name__
__module____qualname____doc__r   r   r   r   r   r   r      s   r   c                   @   s   e Zd ZdZdZdZdZeeee	ee
eeee f geeee f f f  dddZeeeee f dddZd	d
 Zdd ZdS )PysamDispatchera  The dispatcher emulates the samtools/bctools command line.

    Captures stdout and stderr.

    Raises a :class:`pysam.SamtoolsError` exception in case samtools
    exits with an error code other than 0.

    Some command line options are associated with parsers.  For
    example, the samtools command "pileup -c" creates a tab-separated
    table on standard output. In order to associate parsers with
    options, an optional list of parsers can be supplied. The list
    will be processed in order checking for the presence of each
    option.

    If no parser is given or no appropriate parser is found, the
    stdout output of samtools/bcftools commands will be returned.

    N)
collectiondispatchparsersc                 C   s   || _ || _|| _g | _d S r	   )r   r   r   stderr)r   r   r   r   r   r   r   r   /   s    zPysamDispatcher.__init__)argsreturnc           	   	   O   s   t | j| j||dd|ddd\}}}|ddrL| }|rL| }|rftd| j|||f || _|d	s|r| jr| jD ]*\}}|D ]}||vr qq||  S q|S )
a  
        execute a samtools command.

        Keyword arguments:
        catch_stdout -- redirect stdout from the samtools command and
            return as variable (default True)
        save_stdout -- redirect stdout to a filename.
        raw -- ignore any parsers associated with this samtools command.
        split_lines -- return stdout (if catch_stdout is True and stderr
                       as a list of strings.
        catch_stdoutTsave_stdoutN)r   r   Zsplit_linesFz/%s returned with error %i: stdout=%s, stderr=%sraw)r   r   r   get
splitlinesr   r   r   )	r   r   kwargsretvalr   stdoutZoptionsparserZoptionr   r   r   __call__:   s:    

zPysamDispatcher.__call__c                 C   s   | j S r	   )r   r   r   r   r   get_messagesh   s    zPysamDispatcher.get_messagesc                 C   s*   t | j| jddd\}}}|r"|S |S dS )z6return the samtools usage information for this commandT)Zis_usager   N)r   r   r   )r   r#   r   r$   r   r   r   usagek   s    zPysamDispatcher.usage)r   r   r   r   r   r   r   strr   r   r   r   r   r   r&   r'   r(   r   r   r   r   r      s   0.r   c                   @   s   e Zd ZdZdS )unquoted_strzTag a value as an unquoted string. Meta-information in the VCF
    header takes the form of key=value pairs. By default, pysam will
    enclose the value in quotation marks. Tagging that value with
    unquoted_str will prevent this quoting.N)r   r   r   r   r   r   r   r   r*   y   s   r*   N)typingr   r   r   r   r   Zpysam.libcutilsr   	Exceptionr   objectr   r)   r*   r   r   r   r   <module>   s   b