ó
ÔYZc           @   sç   d  d l  Z  d  d l Z d  d l Z d  d l Z d d d d d d d d	 g Z d
 d g Z d „  Z d d d „  ƒ  YZ d d d „  ƒ  YZ d „  Z	 d „  Z
 d „  Z d „  Z	 d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d S(   iÿÿÿÿNs   .fas   .fass   .fastas   .seqs   .fsas   .fnas   .ffns   .frns   .fqt   fastqc         C   sH   |  j  d ƒ r. t j d ƒ t j |  | ƒ ƒ St j |  | d d ƒSd  S(   Ns   .gzs   UTF-8t   encodings   utf-8(   t   endswitht   codecst	   getreadert   gzipt   open(   t   ft   mode(    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyt   Open   s    t   Readerc           B   sP   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   c         C   s   | |  _  d  |  _ d  S(   N(   t   handlert   Nonet   cash(   t   selfR   (    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyt   __init__   s    	c         C   s(   |  j  d  k r$ |  j j ƒ  |  _  n  d  S(   N(   R   R   R   t   readline(   R   (    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyt   FillCash   s    c         C   s   d  |  _ d  S(   N(   R   R   (   R   (    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyt	   TrashCash   s    c         C   s   |  j  ƒ  |  j S(   N(   R   R   (   R   (    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyt   Top!   s    
c         C   s$   |  j  ƒ  |  j ƒ  } |  j ƒ  | S(   N(   R   R   R   (   R   t   result(    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyR   %   s    

c         C   sn   g  } xX t  r` |  j ƒ  } | d k s3 | | ƒ r@ d j | ƒ S|  j ƒ  | j | j ƒ  ƒ q	 Wd j | ƒ S(   Nt    (   t   TrueR   t   joinR   t   appendt   strip(   R   R   R   t   next(    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyt
   ReadUntill+   s    	
c         C   s²   d } g  } x„ |  j  ƒ  r’ |  j ƒ  d k r’ | t |  j ƒ  j ƒ  ƒ | k r’ | j |  j ƒ  j ƒ  ƒ | t |  j ƒ  j ƒ  ƒ 7} |  j ƒ  q W| | k s¥ t ‚ d j | ƒ S(   Ni    R   (   t   EOFR   t   lenR   R   R   t   AssertionErrorR   (   R   t   buf_sizet   cntR   (    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyt   ReadUntillFill5   s    Dc         C   s   |  j  ƒ  d k S(   NR   (   R   (   R   (    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyR   A   s    (
   t   __name__t
   __module__R   R   R   R   R   R   R!   R   (    (    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyR
      s   						
	t	   SeqRecordc           B   s8   e  Z d d  „ Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   sˆ   | d  k r? t | ƒ t | ƒ k r? t j j d | d ƒ n  | d  k si t | ƒ t | ƒ k si t ‚ | |  _ | |  _ | |  _ d  S(   Nt   oppa(	   R   R   t   syst   stdoutt   writeR   t   idt   seqt   qual(   R   R*   R)   R+   (    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyR   F   s    $*		c         C   s   t  |  j ƒ S(   N(   R   R*   (   R   (    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyt   __len__N   s    c         C   s   |  j  | S(   N(   R*   (   R   t   key(    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyt   __getitem__Q   s    c         C   s!   |  j  d  k r |  j  | | !Sd  S(   N(   R+   R   (   R   t   lt   r(    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyt
   QualSubseqT   s    c         C   sv   | d k s! | t  |  j ƒ k rn t |  j | | !|  j d t | d ƒ d t | ƒ d |  j | | ƒ ƒ S|  Sd  S(   Ni    t   (i   t   -t   )(   R   R*   R$   R)   t   strR1   (   R   R/   R0   (    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyt   subseqY   s    !MN(   R"   R#   R   R   R,   R.   R1   R6   (    (    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyR$   E   s
   			c         C   sB   | d k s t  ‚ | d k r( t |  ƒ S| d k r> t |  ƒ Sd  S(   Nt   fastaR    (   R7   R    (   R   t   parse_fastat   parse_fastq(   R   t	   file_type(    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyt   parse_   s
    
c         c   so   t  |  ƒ } x\ | j ƒ  sj | j ƒ  j ƒ  } | d d k sC t ‚ | j d „  ƒ } t | | d ƒ Vq Wd  S(   Ni    t   >c         S   s   |  j  d ƒ S(   NR<   (   t
   startswith(   t   s(    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyt   <lambda>k   s    i   (   R
   R   R   R   R   R   R$   (   R   t   readert   rec_idt   rec_seq(    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyR8   f   s    c         c   s©   t  |  ƒ } x– | j ƒ  s¤ | j ƒ  j ƒ  } | d d k sC t ‚ | j d „  ƒ } | j ƒ  } | d d k sw t ‚ | j t | ƒ ƒ } t | | d | ƒ Vq Wd  S(   Ni    t   @c         S   s   |  j  d ƒ S(   Nt   +(   R=   (   R>   (    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyR?   s   s    RD   i   (	   R
   R   R   R   R   R   R!   R   R$   (   R   R@   RA   RB   t   tmpt   rec_qual(    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyR9   n   s    c         C   s0   | d k r t  |  ƒ S| d k r, t |  ƒ Sd  S(   NR7   R    (   R8   R9   (   R   R:   (    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyR;   y   s    
c         C   s›   | d k r; | j  d |  j d ƒ | j  |  j d ƒ n\ | d k r— | j  d |  j d ƒ | j  |  j d ƒ | j  d ƒ | j  |  j d ƒ n  d  S(   NR7   R<   s   
R    RC   RD   s   +
(   R(   R)   R*   R+   (   t   recR   R:   (    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyR(      s    c         C   s=   x6 t  |  | ƒ D]% } | | ƒ r t | | | ƒ q q Wd  S(   N(   R;   R(   (   t   input_handlert   output_handlerR   R:   t   contig(    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyt   FilterContigsŠ   s    c         C   sÃ   x¼ t  |  d ƒ D]« } d } x0 | t | ƒ k  rN | | d k rN | d 7} q Wt | ƒ } x. | | k r‹ | | d d k r‹ | d 8} q^ W| | k r t t | j | | !| j ƒ ƒ q q Wd  S(   NR7   i    t   Ni   (   R;   R   R(   R$   R*   R)   (   RH   RI   RJ   R/   R0   (    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyt   RemoveNs   s    %#c         C   s%   x t  D] } | |  k r t Sq Wt S(   N(   t	   fasta_extR   t   False(   t	   file_namet   ext(    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyt   is_fasta›   s    c         C   s%   x t  D] } | |  k r t Sq Wt S(   N(   t	   fastq_extR   RO   (   RP   RQ   (    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyt   is_fastq£   s    c         C   s(   t  |  ƒ r d St |  ƒ r  d Sd  Sd  S(   NR    R7   (   RT   RR   R   (   RP   (    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyt   get_read_file_type«   s
    (    (    (   t	   itertoolsR&   R   R   RN   RS   R	   R
   R$   R;   R8   R9   R(   RK   RM   RR   RT   RU   (    (    (    sb   /home/psgendb/BIRCHDEV/pkg/SPAdes-3.13.0/linux-x86_64/share/spades/spades_pipeline/common/SeqIO.pyt   <module>   s$   	0									