
    Ri	%                     v    d Z ddl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	ej                        Zy)
a  Bio.Align support for GCG MSF format.

The file format was produced by the GCG PileUp and LocalPileUp tools, and later
tools such as T-COFFEE and MUSCLE support it as an optional output format.

You are expected to use this module via the Bio.Align functions.
    N)BiopythonParserWarning)	Alignment)
interfaces)Seq)	SeqRecordc                       e Zd ZdZdZd Zy)AlignmentIteratorzGCG MSF alignment iterator.MSFc                 r
   |j                         }|s |j                         dk(  rt        d      d y g d}|j                         j	                         d   |vr>t        |j                         j	                         d   ddj                  |            |D ]+  }|j                  d      }d|v s|j                  d      s+ n t        d	      |j	                         }|j                  d
      }||dz      dk7  s|d   dvrt        d|z        	 t        ||dz            }||dz      }|dvrt        d|z        g }g }	g }
g }|D ]	  }|j                         }|dk(  r n|j                  d      s-|j	                         }	 |j                  d      }|j                  d      }|j                  d      }|j                  d      }||dz      }t        ||dz            }t        ||dz            }||dz      }||v rt        d|      |j                  |       |	j                  |       |
j                  |       |j                  |        t        d      |j                         }|st        d      d |j                         rt        d      d gt        |      z  }|D ]  }|j	                         }|s|d   }	 |j                  |      }d j                  |dd        }|	|   t        |      |j                  d#      z
  z
  }|dk  rt        d$|z        ||xx   |z  cc<   ||	|<   t!        d% |	D              s n t        d&      |D ]  }|j                         d k(  rJ  t#        d' |D              }||k7  r#t%        j&                  d(||fz  t(        d)       |}t+        |      D ]]  \  }}d j                  |      j-                  d*d#      j-                  d+d#      }t        |      |k  r|d#|t        |      z
  z  z  }|||<   _ |D cg c]  }|j/                          }}t1        j2                  |      \  }}t5        |||      D cg c]!  \  }}}t7        t9        |      |||d,|i-      # }}}}t1        ||      }|j:                  }||k7  rt        d(||fz        |S # t        $ r t        d||dz      z        d w xY w# t        $ r t        d|      d w xY w# t        $ r- |D ]  }|j                         r n Y mt        d!| d"      d w xY wc c}w c c}}}w ).Nr   zEmpty file.)z!!NA_MULTIPLE_ALIGNMENTz!!AA_MULTIPLE_ALIGNMENTPileUpz  is not a known GCG MSF header: z, 
zMSF: z..z6Reached end of file without MSF/Type/Check header linezMSF:   zType:)Check:z
CompCheck:zsGCG MSF header line should be '<optional text> MSF: <int> Type: <letter> <optional date> Check: <int> ..',  not: %r   zCGCG MSF header line should have MSF: <int> for column count, not %r   )PNz]GCG MSF header line should have 'Type: P' (protein) or 'Type: N' (nucleotide), not 'Type: %s'z//zName: zName:zLen:zWeight:r   zMalformed GCG MSF name line: zDuplicated ID of z4End of file while looking for end of header // line.z.End of file after // line, expected sequences.z4After // line, expected blank line before sequences. zUnexpected line 'z
' in input-z-Received longer sequence than expected for %sc              3   &   K   | ]	  }|d k(    yw)r   N ).0lengths     E/home/agent/.friday_env/lib/python3.12/site-packages/Bio/Align/msf.py	<genexpr>z9AlignmentIterator._read_next_alignment.<locals>.<genexpr>   s     766Q;7s   z*End of file where expecting sequence data.c              3   2   K   | ]  }t        |        y w)N)len)r   seqs     r   r   z9AlignmentIterator._read_next_alignment.<locals>.<genexpr>   s     .#SX.s   z6GCG MSF headers said alignment length %i, but found %i)
stacklevel~.weight)idnamedescriptionannotations)readlinetell
ValueErrorstripsplitjoinrstripendswithindexint
startswithfloatappendr   isdigitcountallmaxwarningswarnr   	enumeratereplaceencoder   parse_printed_alignmentzipr   r   r   )selfstreamlineknown_headerspartsoffset
aln_lengthseq_typenames	remainingchecksweightswords
index_name	index_lenindex_weightindex_checkr%   r   r#   checkseqsr0   wordr   coordinatesrecords	alignmentcolumnss                                r   _read_next_alignmentz&AlignmentIterator._read_next_alignment   s    {{}! /T9X ::<"-7::<%%'*DIIm,DF 
  	WD;;t$D$4==#6	W
 UVVN 

V$!'59<T+T!" 
	U6A:./J !$:%<>FG & 	 	UD::<Dt|x(

Y!&W!5J %F 3I#(;;y#9L"'++h"7K Z!^,U9q=12u\A%567kAo.5=$'8%ABBT"  (e$v&-	U0 STT MNTXX::<STT tc%j  	KDJJLE8D
QD) ''%)$Cu%SCIIcN)BCFz !PSW!WXXK3K%Ie7Y77/	K2 IJJ  	&D::<2%%%	& ...ZMMHv&'&	  J $D/ 	JE3''#,&&sC088cBC3x*$sj3s8344DK		 )--

--%==dCk (+5$'@	
 	
 $sF C %v.	
 	
 g{3	""j Hw'(  K  	U
#$ 	R " Y$'DTH%MNTXXY<  Q! D<<>
  #4TF*!EFDPQR .	
s=   R6 ASS4T-&T26SS14T*T*T*N)__name__
__module____qualname____doc__fmtrX   r       r   r	   r	      s    %
CVr^   r	   )r\   r9   Bior   	Bio.Alignr   r   Bio.Seqr   Bio.SeqRecordr   r	   r   r^   r   <module>rc      s2     &     #[
44 [r^   