
    Ri                         d 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	      Z
ed
k(  rddlmZ  e        yy)a   Bio.SeqIO support for the "ace" file format.

You are expected to use this module via the Bio.SeqIO functions.
See also the Bio.Sequencing.Ace module which offers more than just accessing
the contig consensus sequences in an ACE file as SeqRecord objects.
    )Seq)	SeqRecord)Ace   )_TextIOSource)SequenceIteratorc                   6     e Zd ZdZdZdeddf fdZd Z xZS )AceIteratorz*Return SeqRecord objects from an ACE file.tsourcereturnNc                 p    t         |   |d       t        j                  | j                        | _        y)a  Iterate over SeqRecord objects read from an ACE file.

        Arguments:
         - source - input stream opened in text mode, or a path to a file

        This uses the Bio.Sequencing.Ace module to do the hard work.  Note that
        by iterating over the file in a single pass, we are forced to ignore any
        WA, CT, RT or WR footer tags.

        Ace files include the base quality for each position, which are taken to
        be PHRED style scores. Just as if you had read in a FASTQ or QUAL file
        using PHRED scores using Bio.SeqIO, these are stored in the SeqRecord's
        letter_annotations dictionary under the "phred_quality" key.

        >>> from Bio import SeqIO
        >>> with open("Ace/consed_sample.ace") as handle:
        ...     for record in SeqIO.parse(handle, "ace"):
        ...         print("%s %s... %i" % (record.id, record.seq[:10], len(record)))
        ...         print(max(record.letter_annotations["phred_quality"]))
        Contig1 agccccgggc... 1475
        90

        However, ACE files do not include a base quality for any gaps in the
        consensus sequence, and these are represented in Biopython with quality
        of zero. Using zero is perhaps misleading as there may be very strong
        evidence to support the gap in the consensus. Previous versions of
        Biopython therefore used None instead, but this complicated usage,
        and prevented output of the gapped sequence as FASTQ format.

        >>> from Bio import SeqIO
        >>> with open("Ace/contig1.ace") as handle:
        ...     for record in SeqIO.parse(handle, "ace"):
        ...         print("%s ...%s..." % (record.id, record.seq[85:95]))
        ...         print(record.letter_annotations["phred_quality"][85:95])
        ...         print(max(record.letter_annotations["phred_quality"]))
        Contig1 ...AGAGG-ATGC...
        [57, 57, 54, 57, 57, 0, 57, 72, 72, 72]
        90
        Contig2 ...GAATTACTAT...
        [68, 68, 68, 68, 68, 68, 68, 68, 68, 68]
        90

        ACE)fmtN)super__init__r   parsestreamace_contigs)selfr   	__class__s     G/home/agent/.friday_env/lib/python3.12/site-packages/Bio/SeqIO/AceIO.pyr   zAceIterator.__init__   s-    ^ 	U+99T[[1    c                    	 t        | j                        }|j                  }d|v r"d|vsJ t	        |j                  dd            }nt	        |      }t        ||j                  |j                        }g }d}|D ]<  }|dk(  r|j                  d       |j                  |j                  |          |dz  }> |t        |j                        k(  sJ ||j                  d<   |S # t        $ r t        d w xY w)N*-)idnamer   r   phred_quality)nextr   StopIterationsequencer   replacer   r   appendqualitylenletter_annotations)r   
ace_contigconsensus_seq_strconsensus_seq
seq_recordqualsibases           r   __next__zAceIterator.__next__M   s   	*d../J '//## //// 1 9 9#s CDM 12M }zW
 ! 	Ds{QZ//23Q	 C
**++++9>
%%o6I  	*T)	*s   C& &C7)	__name__
__module____qualname____doc__modesr   r   r/   __classcell__)r   s   @r   r
   r
      s(    4E0202 
02d'r   r
   __main__)run_doctestN)r3   Bio.Seqr   Bio.SeqRecordr   Bio.Sequencingr   
Interfacesr   r   r
   r0   
Bio._utilsr7    r   r   <module>r>      sB     #  % (^" ^B z&M r   