
nQc           @   s   d  Z  d d l Z d d l Z d d l Z d d l m Z e j d  Z d e f d     YZ d e	 f d     YZ
 d	 e	 f d
     YZ d e f d     YZ d   Z d S(   sP    Represent a read alignment in SAM format

Created on Sep 25, 2010
@author: ian
iN(   t   AlignedReads   (M|N|D|I|S|H|P)t	   SAMHeaderc           B   st   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z e	 d    Z
 e	 d    Z e	 d	    Z RS(
   c         C   sw   t  j |   t  j |  d i d d 6 t  j |  d g   t  j |  d g   t  j |  d g   t  j |  d g   d  S(   Nt   HDs   1.3t   VNt   SQt   RGt   PGt   CO(   t   dictt   __init__t   __setitem__(   t   self(    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyR	      s    c         C   s6   | d k r" t  j |  | |  n t d |   d  S(   NR   R   R   R   R   s&   SAMHeader.__setitem__, Illegal key: %s(   s   HDs   SQs   RGs   PGs   CO(   R   R
   t   KeyError(   R   t   keyt   value(    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyR
      s    c         C   s.   |  j  d  j i | d 6t |  d 6 d  S(   NR   t   SNt   LN(   t   gett   appendt   int(   R   t   ref_namet
   ref_length(    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt
   add_refseq   s    c         C   s4   x- t  | |  D] \ } } |  j | |  q Wd  S(   N(   t   zipR   (   R   t	   name_listt   length_listR   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   populate_refseqs"   s    c         C   sJ   d } x= t  |  j d   D]& \ } } | d | k r | } Pq q W| S(   NiR   R   (   t	   enumerateR   (   R   R   t   tidt   it   ref(    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   find_tid&   s    "c         C   s   |  j  d  | j  d  S(   NR   R   (   R   (   R   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   get_ref_name.   s    c         C   s@  g  } d |  j  k rj | j d d j g  |  j d  j   D]" \ } } d | t |  f ^ q:   n  x d D] } | |  j  k rq xi |  j |  D]U } | j d | d j g  | j   D]" \ } } d | t |  f ^ q  f  q Wqq qq Wd	 |  j  k r3x+ |  j d	  D] } | j d
 |  qWn  d j |  S(   NR   s   @HD	%ss   	s   %s:%sR   R   R   s   @%s	%sR   s   @CO	%ss   
(   s   SQs   RGs   PG(   R   R   t   joinR   t   itemst   str(   R   t   linesR   R   t   superkeyt   subdictt   item(    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   __str__1   s    UZc         C   sT   t    } xD |  D]< } | j   j   } | d } | d } | j | |  q W| S(   Ni    i   (   R   t   stript   splitR   (   R$   t   resultt   linet   fieldsR   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt
   from_lines?   s    	

c         C   s)   t  |   } t j |  } | j   | S(   N(   t   openR   R.   t   close(   t   fai_filenamet   handleR+   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   from_faiI   s    
c         C   s   t    } | j |   | S(   N(   R   t   update(   t   headerR+   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   from_samfile_headerP   s    	(   t   __name__t
   __module__R	   R
   R   R   R   R    R(   t   staticmethodR.   R3   R6   (    (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyR      s   							
t   SAMReadc           B   s  e  Z d8 d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z e d    Z e d    Z d   Z d   Z d   Z d   Z d   Z  d   Z! d   Z" d   Z# d    Z$ d!   Z% d"   Z& d#   Z' d$   Z( d%   Z) e* d&  Z+ e* d'  Z, d(   Z- d)   Z. d*   Z/ d+   Z0 d,   Z1 d-   Z2 d.   Z3 d/   Z4 d0   Z5 e* d1  Z6 d2   Z7 e* d3  Z8 e* d4  Z9 d5   Z: d6   Z; d7   Z< e= e7 e9  Z> e= e1 e4  Z? e= e2 e5  Z@ e= e3 e6  ZA e= e" e)  ZB e= e# e+  ZC e= e$ e,  ZD e= e% e-  ZE e= e& e.  ZF e= e' e/  ZG e= e( e0  ZH e= e  e!  ZI e= e:  ZJ e= e; e<  ZK RS(9   c         C   st   t  j |   | |  _ | r( | |  _ nH t   |  _ d |  j _ d |  j _ d |  j _ d |  j _ d |  j _	 d  S(   Ni   i(
   t   objectR	   t   _bam_headert   _readR    t   flagt   rnamet   mrnmt   post   mpos(   R   R5   t   aligned_read(    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyR	   W   s    	c         C   s   | j  |  j  d S(   s?   The header in samfile should match the _bam_header of this readN(   t   writeR=   (   R   t   samfile(    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   write_to_samfiled   s    c         C   s   |  j  t |  j  |  j t |  j d  t |  j  |  j |  j t |  j d  t |  j	  |  j
 |  j g } |  j } | r | j |  j  n  d j |  S(   Ni   s   	(   t   qnameR#   R>   R?   RA   t   mapqt   cigarR@   RB   t   isizet   seqt   qualt   tagst   extendR!   (   R   t   str_listRM   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyR(   h   s
    n	c         C   sw   t  |  j  |  j t  |  j  t  |  j  t  |  j  t  |  j  |  j |  j t  |  j	  t  |  j
  t j @S(   N(   t   hashRG   R>   R?   RA   RI   R@   RB   RJ   RK   RL   t   syst   maxint(   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   __hash__o   s    c         C   s   y |  j  | j  k o |  j | j k o |  j | j k o |  j | j k o |  j | j k o |  j | j k o |  j | j k o |  j | j k o |  j | j k o |  j	 | j	 k SWn t
 SXd  S(   N(   RG   R>   R?   RA   RI   R@   RB   RJ   RK   RL   t   False(   R   t   other(    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   __eq__r   s    c         C   s
   |  j  j S(   N(   R=   t	   is_paired(   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyRW   x   s    c         C   s   t  |  j _ d  S(   N(   t   TrueR=   RW   (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   set_paired_flag{   s    c         C   s
   |  j  j S(   N(   R=   t   is_proper_pair(   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   is_properly_paired~   s    c         C   s   t  |  j _ d  S(   N(   RX   R=   RZ   (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   set_proper_pair_flag   s    c         C   s   |  j  j t k S(   N(   R=   t   is_unmappedRT   (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt	   is_mapped   s    c         C   s   t  |  j _ d  S(   N(   RX   R=   R]   (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   set_unmapped_flag   s    c         C   s   t  |  j _ d  S(   N(   RT   R=   R]   (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   set_mapped_flag   s    c         C   s   t  |  j _ d  S(   N(   RX   R=   t
   is_reverse(   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   set_reverse_strand_flag   s    c         C   s
   |  j  j S(   N(   R=   Ra   (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   is_reversed   s    c         C   s   t  |  j _ d  S(   N(   RT   R=   Ra   (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   set_forward_strand_flag   s    c         C   s
   |  j  j S(   N(   R=   t   mate_is_reverse(   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   is_mate_reversed   s    c         C   s   t  |  j _ d  S(   N(   RX   R=   Re   (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   set_mate_reverse_strand_flag   s    c         C   s   t  |  j _ d  S(   N(   RT   R=   Re   (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   set_mate_forward_strand_flag   s    c         C   s
   |  j  j S(   N(   R=   t   is_read1(   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   is_first_of_pair   s    c         C   s(   t  |  j _ t |  j _ t  |  j _ d  S(   N(   RX   R=   Ri   RT   t   is_read2RW   (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   set_first_of_pair_flag   s    c         C   s
   |  j  j S(   N(   R=   Rk   (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   is_second_of_pair   s    c         C   s(   t  |  j _ t |  j _ t |  j _ d  S(   N(   RT   R=   Ri   RX   Rk   RW   (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   set_second_of_pair_flag   s    c         C   s%   |  j    j d  } t j | |  S(   Ns   	(   R)   R*   R:   t
   fromFields(   R,   R5   R-   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt
   fromString   s    c         C   s   t  |  } |  d | _ t |  d  | _ |  d | _ t |  d  d | _ t |  d  | _ |  d | _ |  d | _ t |  d  d | _	 t |  d	  | _
 |  d
 | _ |  d | _ |  d | _ | S(   Ni    i   i   i   i   i   i   i   i   i	   i
   i   (   R:   RG   R   R>   R?   RA   RH   RI   R@   RB   RJ   RK   RL   RM   (   R-   R5   R+   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyRo      s    c         C   sd   t  j |  j |  j |  j |  j d |  j |  j |  j |  j	 d |  j
 |  j |  j g |  j |  j  S(   Ni   (   R:   Ro   RG   R>   R?   RA   RH   RI   R@   RB   RJ   RK   RL   RM   R<   (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   clone   s    c         C   s
   |  j  j S(   N(   R=   t   aend(   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   get_end_position   s    c         C   s"   |  j  |  } |  j d | d S(   NR   R   (   R   R<   (   R   t   refnameR   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   get_ref_len   s    c         C   s.   |  j  |  } t |  |  j d | d <d  S(   NR   R   (   R   R   R<   (   R   Rt   t   lengthR   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   set_ref_len   s    c         C   s
   |  j  j S(   N(   R=   RG   (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt	   get_qname   s    c         C   s   | |  j  _ d  S(   N(   R=   RG   (   R   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt	   set_qname   s    c         C   s
   |  j  j S(   N(   R=   R>   (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   get_flag   s    c         C   s
   |  j  j S(   N(   R=   RA   (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   get_pos   s    c         C   s
   |  j  j S(   N(   R=   RB   (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   get_mpos   s    c         C   s
   |  j  j S(   N(   R=   RJ   (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt	   get_isize   s    c         C   s   |  j  j r |  j  j Sd S(   Nt   *(   R=   RK   (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   get_seq   s    
c         C   s   |  j  j r |  j  j Sd S(   NR~   (   R=   RL   (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   get_qual   s    
c         C   s
   |  j  j S(   N(   R=   RH   (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   get_mapq   s    c         C   s   | |  j  _ d  S(   N(   R=   R>   (   R   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   set_flag   s    c         C   sT   t  |  } | rD | |  j |  j  k rD |  j |  j | d  n  | |  j _ d  S(   Ni   (   R   Ru   R?   Rw   R=   RA   (   R   R   t
   extend_reft   val(    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   set_pos   s    c         C   sT   t  |  } | rD | |  j |  j  k rD |  j |  j | d  n  | |  j _ d  S(   Ni   (   R   Ru   R@   Rw   R=   RB   (   R   R   R   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   set_mpos   s    c         C   s   | |  j  _ d  S(   N(   R=   RJ   (   R   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt	   set_isize  s    c         C   s   | |  j  _ d  S(   N(   R=   RK   (   R   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   set_seq  s    c         C   s   | |  j  _ d  S(   N(   R=   RL   (   R   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   set_qual	  s    c         C   s   | |  j  _ d  S(   N(   R=   RH   (   R   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   set_mapq  s    c      	   C   s  g  } |  j  j } | rx | D] \ } } t | t  rT | j d | | f  q t | t  r} | j d | | f  q | j   r t |  d k r | d k r | j d | t t |   f  q t |  d k r | j d | | f  q | j d | | f  q Wn  | S(   Ns   %s:i:%ds   %s:f:%fi   t   MDs   %s:A:%si   s   %s:Z:%s(	   R=   RM   t
   isinstanceR   R   t   floatt   isdigitt   chrt   len(   R   t   tagstrst	   read_tagst   tagnamet   tagvalue(    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   get_tags  s    *&c         C   sp   d } g  } |  j  j } | rY x8 |  j  j D]' \ } } | j d | | | f  q+ Wn  | rl d j |  Sd S(   Nt   MIDNSHPs   %d%st    R~   (   R=   RI   R   R!   (   R   t   cigar_opcodesR+   RI   t   codet   count(    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt	   get_cigar   s    "c         C   s,   |  j  j d k r d S|  j j |  j  j  S(   NiR~   (   R=   R@   R<   R    (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   get_mrnm+  s    c         C   s   g  } x | D] } | j  d d  \ } } } | d k rV | j | t |  f  q | d k r~ | j | t |  f  q | d k r | j | | f  q | j | | f  q W| |  j _ d  S(   Nt   :i   R   t   ft   A(   R*   R   R   R   R=   RM   (   R   t   tag_listt   tuplest   tagR   t   tagtypeR   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   set_tags0  s    c         C   s~   d } g  } | } xY | rm t  j |  r t  j | d  \ } } } | j | j |  t |  g  q q W| |  j _ d  S(   NR   i   (   t   cigar_opcode_patt   searchR*   R   t   indexR   R=   RI   (   R   R   R   R+   t	   remaindert   width_st   opcode(    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt	   set_cigar>  s    	)c         C   s   |  j  | |  |  j _ d  S(   N(   R   R=   R@   (   R   R   t   extend_refs(    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   set_mrnmH  s    c         C   s,   |  j  j d k r d S|  j j |  j  j  S(   s   Name of the reference sequence iR~   (   R=   R?   R<   R    (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt	   get_rnameK  s    c         C   s    | d k r d S|  j  j |  S(   NR~   i(   R<   R   (   R   R   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyR   Q  s    c         C   s   |  j  | |  |  j _ d  S(   N(   R   R=   R?   (   R   R   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt	   set_rnameV  s    c         C   s
   |  j  j S(   s   Aligned length of the read(   R=   t   alen(   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   get_alenY  s    c         C   s   |  j  S(   sO   The SAMHeader instance that defines the mapping from rname to tid for this read(   R<   (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt
   get_header]  s    c         C   s   | |  _  d  S(   N(   R<   (   R   R5   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt
   set_headera  s    N(L   R7   R8   t   NoneR	   RF   R(   RS   RV   RW   RY   R[   R\   R^   R_   R`   Rb   Rc   Rd   Rf   Rg   Rh   Rj   Rl   Rm   Rn   R9   Rp   Ro   Rq   Rs   Ru   Rw   Rx   Ry   Rz   R{   R|   R}   R   R   R   R   RT   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t   propertyR?   RM   RI   R@   R>   RA   RB   RJ   RK   RL   RH   RG   R   R5   (    (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyR:   V   s   																																												
				t   SAMReadIteratorc           B   s   e  Z d    Z d   Z RS(   c         C   s   t  j |   d  S(   N(   R;   R	   (   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyR	   u  s    c         C   s
   t   d S(   s   Dummy implementationN(   t   StopIteration(   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   iteratorx  s    (   R7   R8   R	   R   (    (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyR   t  s   	t   SAMReadFileIteratorc           B   s&   e  Z d d   Z d   Z d   Z RS(   c         C   s   t  j |   | d  k r\ | j d  r1 d } q\ | j d  rI d } q\ t d |   n  t j | d | |  _ t j	 |  j j
  |  _
 d  S(   Ns   .samt   rs   .bamt   rbsH   [Reads.samRead.SAMReadFileIterator] Format of SAM/BAM file %s is unknownt   mode(   R   R	   R   t   endswitht
   ValueErrort   pysamt   SamfileRE   R   R6   R5   (   R   t   filenameR   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyR	   }  s    		c         c   s/   x( |  j  D] } t |  j |  } | Vq
 Wd  S(   N(   RE   R:   R5   (   R   t   readt   sam_read(    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyR     s    c         c   s/   x( |  j  D] } t |  j |  } | Vq
 Wd  S(   N(   RE   R:   R5   (   R   R   R   (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   __iter__  s    N(   R7   R8   R   R	   R   R   (    (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyR   |  s   	c         C   s}   g  } t  |   } xQ | D]I } | j   j   } | d } | d } d | | f } | j |  q W| j   d j |  S(   Ni    i   s   @SQ	SN:%s	LN:%ss   
(   R/   R)   R*   R   R0   R!   (   R1   t   header_linest   faiR,   R-   R   R   t   hdr_line(    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   generate_SAM_header_from_fai  s    


(   t   __doc__RQ   t   reR   R    t   compileR   R   R   R;   R:   R   R   R   (    (    (    sQ   /woldlab/castor/data00/home/georgi/programs/RNA-Seq-Simulator.v1.0/lib/samRead.pyt   <module>	   s   F 