3
7]                 @   s>   d dl m Z  G dd dZG dd deZG dd deZdS )	    )xopenc               @   s2   e Zd ZedfddZdd Zdd Zdd	 ZdS )

FileWriterNc             C   s2   || _ t|tr$||d| _ d| _n
t|| _d S )NwbT)_file
isinstancestr_close_on_exitbool)selffileopener_close_file r   ]/home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python3.6/site-packages/dnaio/writers.py__init__   s
    
zFileWriter.__init__c             C   s   | j r| jj  d S )N)r   r   close)r
   r   r   r   r      s    zFileWriter.closec             C   s   | j jrtd| S )NzI/O operation on closed file)r   closed
ValueError)r
   r   r   r   	__enter__   s    zFileWriter.__enter__c             G   s   | j   d S )N)r   )r
   argsr   r   r   __exit__   s    zFileWriter.__exit__)__name__
__module____qualname__r   r   r   r   r   r   r   r   r   r      s   r   c                   s2   e Zd ZdZdedf fdd	ZdddZ  ZS )FastaWriterz4
    Write FASTA-formatted sequences to a file.
    Nc                s(   t  j|||d |dkr|nd| _dS )zm
        If line_length is not None, the lines will
        be wrapped after line_length characters.
        )r   r   r   N)superr   line_length)r
   r   r   r   r   )	__class__r   r   r      s    zFastaWriter.__init__c             C   s   |dkr|j }|j}n|}| jdk	r| jjd| d jd g }x6tdt|| jD ] }|j|||| j  d  qVW | jjdj	|jd n&d| d | d }| jj|jd dS )a  Write an entry to the the FASTA file.

        If only one parameter (name_or_record) is given, it must have
        attributes .name and .sequence, which are then used.
        Otherwise, the first parameter must be the name and the second
        the sequence.

        The effect is that you can write this:
        writer.write("name", "ACCAT")
        or
        writer.write(Sequence("name", "ACCAT"))
        N>
asciir    )
namesequencer   r   writeencoderangelenappendjoin)r
   Zname_or_recordr#   r"   sir   r   r   r$   '   s    
 zFastaWriter.write)N)r   r   r   __doc__r   r   r$   __classcell__r   r   )r   r   r      s   r   c                   s<   e Zd ZdZdZdedf fdd	Zdd Zd	d
 Z  Z	S )FastqWriterz
    Write sequences with qualities in FASTQ format.

    FASTQ files are formatted like this:
    @read name
    SEQUENCE
    +
    QUALITIS
    r   FNc                s   t  j|||d || _d S )N)r   r   )r   r   _two_headers)r
   r   Ztwo_headersr   r   )r   r   r   r   Q   s    zFastqWriter.__init__c             C   sP   | j r|jnd}d|j d |j d | d |j d }| jj|jd dS )z
        Write a Sequence record to the FASTQ file.

        The record object must have attributes .name, .sequence and .qualities.
        r!   @r   z
+r    N)r/   r"   r#   	qualitiesr   r$   r%   )r
   recordZname2r*   r   r   r   r$   U   s    *zFastqWriter.writec             C   s    | j jdj|||jd d S )Nz@{0:s}
{1:s}
+
{2:s}
r    )r   r$   formatr%   )r
   r"   r#   r1   r   r   r   writeseq`   s    
zFastqWriter.writeseq)
r   r   r   r,   Z	file_moder   r   r$   r4   r-   r   r   )r   r   r.   E   s
   	r.   N)r   r   r   r.   r   r   r   r   <module>   s   +