o
    RŀgE                     @   s\   d 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jZG dd	 d	ej	Z	d
S )zBio.Align support for aligned FASTA files.

Aligned FASTA files are FASTA files in which alignment gaps in a sequence are
represented by dashes. Each sequence line in an aligned FASTA should have the
same length.
    )	Alignment)
interfaces)Seq)	SeqRecordc                   @      e Zd ZdZdZdd ZdS )AlignmentWriterz8Alignment file writer for the aligned FASTA file format.FASTAc              	   C   s   t |ts	tdg }t|j|D ]7\}}z|j}W n ty(   |d Y nw |jr:|d|j d|j  n	|d|j  || qd	|d S )z;Return a string with the alignment in aligned FASTA format.zExpected an Alignment object> 
)

isinstancer   	TypeErrorzip	sequencesidAttributeErrorappenddescriptionjoin)self	alignmentlinessequencelinename r   C/var/www/html/myenv/lib/python3.10/site-packages/Bio/Align/fasta.pyformat_alignment   s   

z AlignmentWriter.format_alignmentN)__name__
__module____qualname____doc__fmtr   r   r   r   r   r      s    r   c                   @   r   )AlignmentIteratora  Alignment iterator for aligned FASTA files.

    An aligned FASTA file contains one multiple alignment. Alignment gaps are
    represented by dashes in the sequence lines. Header lines start with '>'
    followed by the name of the sequence, and optionally a description.
    r   c                 C   s$  g }g }g }|D ]G}| drE|dd   d d}t|dkr&|\}}nd}t|dkr3|d }nd}|| || |d q|d  | 7  < q|s_| j dkr]tdd S dd	 |D }t	
|\}	}
g }t|||	D ]\}}}t|}t|||d
}|| qut	||
}|S )Nr	          r   zEmpty file.c                 S   s   g | ]}|  qS r   )encode).0r   r   r   r   
<listcomp>N   s    z:AlignmentIterator._read_next_alignment.<locals>.<listcomp>)r   r   )
startswithrstripsplitlenr   strip_streamtell
ValueErrorr   parse_printed_alignmentr   r   r   )r   streamnamesdescriptionsr   r   partsr   r   seqscoordinatesrecordsseqr   recordr   r   r   r   _read_next_alignment6   s:   





z&AlignmentIterator._read_next_alignmentN)r   r   r    r!   r"   r=   r   r   r   r   r#   ,   s    r#   N)
r!   	Bio.Alignr   r   Bio.Seqr   Bio.SeqRecordr   r   r#   r   r   r   r   <module>   s   