
    XfO                     0    d Z d Zd Z G d d          ZdS )a  Large file parsing of Genepop files.

The standard parser loads the whole file into memory. This parser
provides an iterator over data.

Classes:
- LargeRecord - Holds GenePop data.

Functions:
- read - Parses a GenePop record (file) into a Record object.

c                 <   |                      d          \  }}|                    dd                               d          }d |D             }t          |d                   dv rdnd	 fd	|D             }n# t          $ r fd
|D             }Y nw xY w||fS )z Get individual's data from line.,	 c                     g | ]
}|d k    |S )  ).0markers     Blib/python3.11/site-packages/Bio/PopGen/GenePop/LargeFileParser.py
<listcomp>zget_indiv.<locals>.<listcomp>   s    <<<&v||v|||        )      r      c                 l    g | ]0}t          |d                    t          |d                   f1S )r   Nintr	   r
   
marker_lens     r   r   zget_indiv.<locals>.<listcomp>    sM     
 
 
FLS*%&&F:;;,?(@(@A
 
 
r   c                 @    g | ]}t          |d                    fS )r   r   r   s     r   r   zget_indiv.<locals>.<listcomp>$   s-    JJJF1Z<0113JJJr   )splitreplacelen
ValueError)line
indiv_namemarker_linemarkersallele_listr   s        @r   	get_indivr!      s    "jjooJ!!$,,22377G<<G<<<G
71:&  


K
 
 
 
PW
 
 
  K K KJJJJ'JJJK{J..s   ,A; ;BBc                    t          |           }t          |                                           |_        t          |                                                               dd          }|                    d          }|j                            |           |                                 }|dk    r{|                                }|	                                dk    r|j
                            d           n4|j                            |           |                                 }|dk    {|                                                                 }t          |          \  }}|_        |j
                            |           |S )zParse a handle containing a GenePop file.

    Arguments:
    - handle is a file-like object that contains a GenePop record.

    r   r   r   POP)Recordnextrstripcomment_liner   r   	loci_listextendreadlineupperstackappendr!   r   )handlerecordsample_loci_lineall_locir   	next_liner   r    s           r   readr3   (   sN    F^^Fv,,--//F F||**,,44S"==%%c**H
H%%%??D
"**{{}}::<<5  L&&&%%%   "** !!((**I1:91E1E.JV.
L	"""Mr   c                       e Zd ZdZd Zd ZdS )r$   a  Hold information from a GenePop record.

    Members:
    marker_len         The marker length (2 or 3 digit code per allele).

    comment_line       Comment line.

    loci_list          List of loci names.

    data_generator     Iterates over population data.

    The generator will only work once. If you want to read a handle
    twice you have to re-open it!

    data_generator can either be () - an empty tuple - marking a new
    population or an individual. An individual is something like
    ('Ind1', [(1,1), (3,None), (200,201)],
    In the case above the individual is called Ind1,
    has three diploid loci. For the second loci, one of the alleles
    is unknown.

    c                 Z    || _         d| _        d| _        g | _        g | _        g | _        dS )zInitialize the class.r   r   N)r.   r   r'   r(   populationsr,   )selfr.   s     r   __init__zRecord.__init__]   s2    


r   c              #     K   | j         | j        fD ]}|D ]}|                                }|                                dk    rdV  3t	          |          \  }}}g }|D ]\}g }|D ]3}	|	dk    r|                    d           |                    |	           4|                    t          |                     ]||fV  dS )zExtract population data.r#   r   r   N)r,   r.   r&   r+   r!   r-   tuple)
r7   r.   r   r   r    r   
clean_listlocusmk_realals
             r   data_generatorzRecord.data_generatorf   s     z4;/ 	1 	1F 1 1{{}}::<<5((HHHH:CD//7JZ!#J!, : :"$"' 3 3B!Qww 't 4 4 4 4 'r 2 2 2 2"))%..9999$j000001	1 	1r   N)__name__
__module____qualname____doc__r8   r?   r   r   r   r$   r$   E   s<         .  1 1 1 1 1r   r$   N)rC   r!   r3   r$   r   r   r   <module>rD      s_    / / /$  :31 31 31 31 31 31 31 31 31 31r   