
    Ri                     b    d Z ddlZd Zd Z e       Zd Zd Zd Zedk(  rdd	l	m
Z
  e
        yy)
z3Functions to calculate assorted sequence checksums.    Nc                     	 t        |       }t        j                  |      S # t        $ r | j                         }Y 0w xY w)zReturn the crc32 checksum for a sequence (string or Seq object).

    Note that the case is important:

    >>> crc32("ACGTACGTACGT")
    20049947
    >>> crc32("acgtACGTacgt")
    1688586483

    )bytes	TypeErrorencodebinasciicrc32)seqss     M/home/agent/.friday_env/lib/python3.12/site-packages/Bio/SeqUtils/CheckSum.pyr   r      s=    #J >>!  JJLs   " >>c                      g } t        d      D ]H  }|}d}t        d      D ]#  }|dz  }|dz  }|dz  r|dz  }|dz  }|s|dz  }% | j                  |       J | S )N   r         l        l      0 )rangeappend)_table_hipart_lpart_hjrflags         r   _init_table_hr   $   s    H3Z  q 	%AQJEqLFz'!qLF*$	% 	  O    c                     d}d}| D ]6  }|dz  dz  }|dz	  }|dz	  |z  }|t        |      z  dz  }|t        |   z  }|}8 d|d|dS )zReturn the crc64 checksum for a sequence (string or Seq object).

    Note that the case is important:

    >>> crc64("ACGTACGTACGT")
    'CRC-C4FBB762C4A87EBD'
    >>> crc64("acgtACGTacgt")
    'CRC-DA4509DC64A87EBD'

    r         r   zCRC-08X)ordr   )r
   crclcrchcshrtemp1htemp1lidxs           r   crc64r&   9   s~     DD d{r!!)s"c!f}$% $sD:&&r   c                 z    dx}}| D ].  }|dz  }||t        |j                               z  z  }|dk(  s-d}0 |dz  S )a  Return the GCG checksum (int) for a sequence (string or Seq object).

    Given a nucleotide or amino-acid sequence (or any string),
    returns the GCG checksum (int). Checksum used by GCG program.
    seq type = str.

    Based on BioPerl GCG_checksum. Adapted by Sebastian Bassi
    with the help of John Lenton, Pablo Ziliani, and Gabriel Genellina.

    All sequences are converted to uppercase.

    >>> gcg("ACGTACGTACGT")
    5688
    >>> gcg("acgtACGTacgt")
    5688

    r   r   9   i'  )r   upper)r	   indexchecksumchars       r   gcgr-   Q   sY    $ EH 
EC

---B;E	
 er   c                 b   ddl }ddl}|j                         }	 t        |       } |j                  | j                                |j                  |j                               }|j                         j                  dd      j                  d      S # t        $ r | j                         } Y w xY w)a  Return the SEGUID (string) for a sequence (string or Seq object).

    Given a nucleotide or amino-acid sequence (or any string),
    returns the SEGUID string (A SEquence Globally Unique IDentifier).
    seq type = str.

    Note that the case is not important:

    >>> seguid("ACGTACGTACGT")
    'If6HIvcnRSQDVNiAoefAzySc6i4'
    >>> seguid("acgtACGTacgt")
    'If6HIvcnRSQDVNiAoefAzySc6i4'

    For more information about SEGUID, see:
    http://bioinformatics.anl.gov/seguid/
    https://doi.org/10.1002/pmic.200600032
    r   N
 =)base64hashlibsha1r   r   r   updater)   encodebytesdigestdecodereplacerstrip)r	   r2   r3   mtmps        r   seguidr=   l   s    $ ACj HHSYY[


QXXZ
(C::<b)0055  jjls   B B.-B.__main__)run_doctest)__doc__r   r   r   r   r&   r-   r=   __name__
Bio._utilsr?    r   r   <module>rD      sI    :
 ($ ?'066B z&M r   