o
    Rŀg                     @   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	 G d	d
 d
eZ
G dd de	Zdd ZedkrKddlmZ edd dS dS )a!  Bio.SeqIO support for the "tab" (simple tab separated) file format.

You are expected to use this module via the Bio.SeqIO functions.

The "tab" format is an ad-hoc plain text file format where each sequence is
on one (long) line.  Each line contains the identifier/description, followed
by a tab, followed by the sequence.  For example, consider the following
short FASTA format file::

    >ID123456 possible binding site?
    CATCNAGATGACACTACGACTACGACTCAGACTAC
    >ID123457 random sequence
    ACACTACGACTACGACTCAGACTACAAN

Apart from the descriptions, this can be represented in the simple two column
tab separated format as follows::

    ID123456(tab)CATCNAGATGACACTACGACTACGACTCAGACTAC
    ID123457(tab)ACACTACGACTACGACTCAGACTACAAN

When reading this file, "ID123456" or "ID123457" will be taken as the record's
.id and .name property.  There is no other information to record.

Similarly, when writing to this format, Biopython will ONLY record the record's
.id and .seq (and not the description or any other information) as in the
example above.
    )Seq)	SeqRecord   )_clean)_get_seq_string)SequenceIterator)SequenceWriterc                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )TabIteratorzParser for tab-delimited files.c                    s   t  j|ddd dS )a  Iterate over tab separated lines as SeqRecord objects.

        Each line of the file should contain one tab only, dividing the line
        into an identifier and the full sequence.

        Arguments:
         - source - file-like object opened in text mode, or a path to a file

        The first field is taken as the record's .id and .name (regardless of
        any spaces within the text) and the second field is the sequence.

        Any blank lines are ignored.

        Examples
        --------
        >>> with open("GenBank/NC_005816.tsv") as handle:
        ...     for record in TabIterator(handle):
        ...         print("%s length %i" % (record.id, len(record)))
        gi|45478712|ref|NP_995567.1| length 340
        gi|45478713|ref|NP_995568.1| length 260
        gi|45478714|ref|NP_995569.1| length 64
        gi|45478715|ref|NP_995570.1| length 123
        gi|45478716|ref|NP_995571.1| length 145
        gi|45478717|ref|NP_995572.1| length 357
        gi|45478718|ref|NP_995573.1| length 138
        gi|45478719|ref|NP_995574.1| length 312
        gi|45478720|ref|NP_995575.1| length 99
        gi|45478721|ref|NP_995576.1| length 90

        tzTab-separated plain-text)modefmtN)super__init__)selfsource	__class__ C/var/www/html/myenv/lib/python3.10/site-packages/Bio/SeqIO/TabIO.pyr   /   s   zTabIterator.__init__c                 C   s   |  |}|S )z9Start parsing the file, and return a SeqRecord generator.)iterate)r   handlerecordsr   r   r   parseP   s   
zTabIterator.parsec              
   c   s    |D ]<}z	| d\}}W n ty+   | dkrY qtdd|d|f  dw | }| }tt|||ddV  qdS )z.Parse the file and generate SeqRecord objects.	 z,Each line should have one tab separating thez. title and sequence, this line has %i tabs: %rN)idnamedescription)split
ValueErrorstripcountr   r   )r   r   linetitleseqr   r   r   r   U   s*   	zTabIterator.iterate)__name__
__module____qualname____doc__r   r   r   __classcell__r   r   r   r   r	   ,   s
    !r	   c                   @   s   e Zd ZdZdd ZdS )	TabWriteraZ  Class to write simple tab separated format files.

    Each line consists of "id(tab)sequence" only.

    Any description, name or other annotation is not recorded.

    This class is not intended to be used directly. Instead, please use
    the function ``as_tab``, or the top level ``Bio.SeqIO.write()`` function
    with ``format="tab"``.
    c                 C   s.   | j sJ | jr
J d| _| jt| dS )z$Write a single tab line to the file.TN)_header_written_footer_written_record_writtenr   writeas_tab)r   recordr   r   r   write_recordt   s   

zTabWriter.write_recordN)r%   r&   r'   r(   r1   r   r   r   r   r*   h   s    r*   c                 C   sj   t | j}t| }d|vsJ d|vsJ d|vsJ d|vs!J d|vs'J d|vs-J | d| dS )z3Return record as tab separated (id(tab)seq) string.r   
)r   r   r   )r0   r#   r$   r   r   r   r/   |   s   
r/   __main__)run_doctest)verboseN)r(   Bio.Seqr   Bio.SeqRecordr   
Interfacesr   r   r   r   r	   r*   r/   r%   
Bio._utilsr5   r   r   r   r   <module>   s   <