
    RiE                         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ej                        Z G d d	ej                        Z	y
)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 Zy)AlignmentWriterz8Alignment file writer for the aligned FASTA file format.FASTAc                    t        |t              st        d      g }t        |j                  |      D ]z  \  }}	 |j
                  }|j                  r,|j                  d|j
                   d|j                          n|j                  d|j
                          	 |j                  |       | dj                  |      dz   S # t        $ r |j                  d       Y Cw xY w)z;Return a string with the alignment in aligned FASTA format.zExpected an Alignment object> 
)

isinstancer   	TypeErrorzip	sequencesiddescriptionappendAttributeErrorjoin)self	alignmentlinessequencelinenames         G/home/agent/.friday_env/lib/python3.12/site-packages/Bio/Align/fasta.pyformat_alignmentz AlignmentWriter.format_alignment   s    )Y/:;;!)"5"5yA 
	NHd4{{ ''LL1X[[M83G3G2H!IJLL1X[[M!23LL
	 yy$&& " "S!"s   CC"!C"N)__name__
__module____qualname____doc__fmtr        r   r   r      s    B
C'r%   r   c                       e Zd ZdZdZd Zy)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                    g }g }g }|D ]  }|j                  d      r|dd  j                         j                  d d      }t        |      dk(  r|\  }}nd}t        |      dk(  r|d   }nd}|j	                  |       |j	                  |       |j	                  d       |dxx   |j                         z  cc<    |s)| j                  j                         dk(  rt        d      y |D cg c]  }|j                          }}t        j                  |      \  }	}
g }t        |||	      D ]0  \  }}}t        |      }t        |||      }|j	                  |       2 t        ||
      }|S c c}w )	Nr          r   zEmpty file.)r   r   )
startswithrstripsplitlenr   strip_streamtell
ValueErrorencoder   parse_printed_alignmentr   r   r   )r   streamnamesdescriptionsr   r   partsr   r   seqscoordinatesrecordsseqr   recordr   s                   r   _read_next_alignmentz&AlignmentIterator._read_next_alignment6   sn    	*Ds#QR)//a8u:?(-%D+"$K5zQ$Qx!T"##K0R b	TZZ\)		*  ||  "a' //+01411%==eDk&)%t&D 	#"D+s3xHxDkJFNN6"	# g{3	 2s   ,E-N)r   r    r!   r"   r#   r@   r$   r%   r   r'   r'   ,   s     C r%   r'   N)
r"   	Bio.Alignr   r   Bio.Seqr   Bio.SeqRecordr   r   r'   r$   r%   r   <module>rD      s<         #'j00 '0*
44 *r%   