ó
²“Ic           @   s>  d  Z  d d l m Z d d l m Z d d l m Z d d l m Z e d d „ Z
 d e f d „  ƒ  YZ e d	 k r:d
 GHd d l Z d d l m Z m Z d Z d Z d „  Z d „  Z e j j e ƒ rGd GHd GHe
 e e d ƒ d e d e ƒZ d Z x" e D] Z e d Z e e ƒ qWe d k s6t ‚ e e j ƒ GHn  e j j e ƒ rÓd GHd GHe
 e e d ƒ d e d e ƒZ d Z x# e D] Z e d Z e e ƒ Pq‘We d k sÂt ‚ e e j ƒ GHn  d d l m Z d GHd GHe
 e d ƒ ƒ Z d Z x e D] Z e d Z qWe d k s2t ‚ d GHn  d S(   s‡   Bio.SeqIO support for the "fasta" (aka FastA or Pearson) file format.

You are expected to use this module via the Bio.SeqIO functions.iÿÿÿÿ(   t   single_letter_alphabet(   t   Seq(   t	   SeqRecord(   t   SequentialSequenceWriterc         c   sz  x: t  r< |  j ƒ  } | d k r% d S| d d k r Pq q Wx$t  rc| d d k re t d ƒ ‚ n  | r | | d j ƒ  ƒ \ } } } n& | d j ƒ  } | j ƒ  d } | } g  } |  j ƒ  } x_ t  r&| sØ Pn  | d d k rì Pn  | j | j ƒ  j d d ƒ j d d ƒ ƒ |  j ƒ  } qÈ Wt t d j	 | ƒ | ƒ d	 | d
 | d | ƒV| s@ d Sq@ Wt
 svt d ƒ ‚ d S(   sI  Generator function to iterate over Fasta records (as SeqRecord objects).

    handle - input file
    alphabet - optional alphabet
    title2ids - A function that, when given the title of the FASTA
    file (without the beginning >), will return the id, name and
    description (in that order) for the record as a tuple of strings.

    If this is not given, then the entire title line will be used
    as the description, and the first word as the id and name.

    Note that use of title2ids matches that of Bio.Fasta.SequenceParser
    but the defaults are slightly different.
    t    Ni    t   >s6   Records in Fasta files should start with '>' characteri   t    s   t   idt   namet   descriptions   Should not reach this line(   t   Truet   readlinet
   ValueErrort   rstript   splitt   appendt   replaceR   R   t   joint   Falset   AssertionError(   t   handlet   alphabett	   title2idst   lineR   R   t   descrt   lines(    (    s„   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/FastaIO.pyt   FastaIterator   s8    	 	"	  + t   FastaWriterc           B   s&   e  Z d  Z d d d „ Z d „  Z RS(   s"   Class to write Fasta format files.i<   c         C   sM   t  j |  | ƒ d |  _ | r7 | d k  r7 t ‚ q7 n  | |  _ | |  _ d S(   s¿  Create a Fasta writer.

        handle - Handle to an output file, e.g. as returned
                 by open(filename, "w")
        wrap -   Optional line length used to wrap sequence lines.
                 Defaults to wrapping the sequence at 60 characters
                 Use zero (or None) for no wrapping, giving a single
                 long line for the sequence.
        record2title - Optional function to return the text to be
                 used for the title line of each record.  By default the
                 a combination of the record.id and record.description
                 is used.  If the record.description starts with the
                 record.id, then just the record.description is used.

        You can either use:

        myWriter = FastaWriter(open(filename,"w"))
        writer.write_file(myRecords)

        Or, follow the sequential file writer system, for example:

        myWriter = FastaWriter(open(filename,"w"))
        writer.write_header() # does nothing for Fasta files
        ...
        Multiple calls to writer.write_record() and/or writer.write_records()
        ...
        writer.write_footer() # does nothing for Fasta files
        writer.close()
        i   N(   R   t   __init__t   Nonet   wrapR   t   record2title(   t   selfR   R   R   (    (    s„   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/FastaIO.pyR   H   s    		c         C   s‚  |  j  s t ‚ |  j s t ‚ t |  _ |  j rL |  j |  j | ƒ ƒ } n_ |  j | j ƒ } |  j | j ƒ } | r› | j	 d d ƒ d | k r› | } n d | | f } d | k s½ t ‚ d | k sÏ t ‚ |  j j d | ƒ |  j | ƒ } d | k st ‚ d | k st ‚ |  j rjx\ t d t | ƒ |  j ƒ D]( } |  j j | | | |  j !d ƒ q;Wn |  j j | d ƒ d S(   s(   Write a single Fasta record to the file.i   i    s   %s %ss   
s   s   >%s
N(   t   _header_writtenR   t   _footer_writtenR
   t   _record_writtenR   t   cleanR   R	   R   R   R   t   writet   _get_seq_stringR   t   ranget   len(   R    t   recordt   titleR   R	   t   datat   i(    (    s„   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/FastaIO.pyt   write_recordo   s(    		"		")N(   t   __name__t
   __module__t   __doc__R   R   R-   (    (    (    s„   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/FastaIO.pyR   F   s   't   __main__s   Running quick self testN(   t   generic_proteint   generic_nucleotides   NC_005213.fnas   NC_005213.faac         C   sN   |  j  d  d ƒ \ }  } |  j  d ƒ d } | j  d d ƒ d } | | | f S(   Ni   t   |i   t   .i    (   R   R   (   t   textR   R   R   (    (    s„   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/FastaIO.pyt   genbank_name_functionœ   s    c         C   sˆ   d |  j  GHd |  j GHd |  j GH|  j GHx' |  j D] } d | |  j | f GHq6 W|  j r„ d GHx |  j D] } d | GHqn Wn  d  S(   Ns   ID:s   Name:s   Descr:s   /%s=%ss   Database cross references:s    - %s(   R   R   R	   t   seqt   annotationst   dbxrefs(   R)   t   featuret   x(    (    s„   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/FastaIO.pyt   print_record¢   s    	 s   --------s   FastaIterator (single sequence)t   rR   R   i    i   s"   FastaIterator (multiple sequences)(   t   StringIOs    FastaIterator (empty input file)R   t   Done(   R0   t   Bio.AlphabetR    t   Bio.SeqR   t   Bio.SeqRecordR   t
   InterfacesR   R   R   R   R.   t   osR2   R3   t   fna_filenamet   faa_filenameR7   R=   t   patht   isfilet   opent   iteratort   countR)   R   t   strt	   __class__t	   cStringIOR?   (    (    (    s„   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/FastaIO.pyt   <module>   sX   2K		!
!

