ó
,ÍÃIc           @   s£   d  Z  d d l Z d d l Z d d l Z d d „ Z d d d „  ƒ  YZ d d d „  ƒ  YZ i d	 d
 6d	 d 6d d 6d d 6d d 6d d 6Z d d d „  ƒ  YZ d S(   sÊ   Connect with a BioSQL database and load Biopython like objects from it.

This provides interfaces for loading biological objects from a relational
database, and is compatible with the BioSQL standards.
iÿÿÿÿNt   MySQLdbc         K   s¨  t  |  ƒ } t | d ƒ } | j ƒ  } |  d k r~ d | k rW | d | d <| d =n  d | k rÆ | d | d <| d =qÆ nH d | k r¢ | d | d <| d =n  d | k rÆ | d | d <| d =n  |  d k rï | j d ƒ rï d	 | d <n  y | |   } Wn™ | j k
 ršd | k r6| d | d
 <| d =n$ d | k rZ| d | d
 <| d =n  d j g  | j ƒ  D] } d j | ƒ ^ qmƒ } | | ƒ } n Xt | | ƒ S(   s·  Main interface for loading a existing BioSQL-style database.

    This function is the easiest way to retrieve a connection to a
    database, doing something like:
        
        >>> from BioSeq import BioSeqDatabase
        >>> server = BioSeqDatabase.open_database(user = "root", db="minidb")

    the various options are:
    driver -> The name of the database driver to use for connecting. The
    driver should implement the python DB API. By default, the MySQLdb
    driver is used.
    user -> the username to connect to the database with.
    password, passwd -> the password to connect with
    host -> the hostname of the database
    database or db -> the name of the database
    t   connectR    t   databaset   dbt   passwordt   passwdt   psycopgt   psycopg2t	   template1t   dbnamet    t   =(   R   R   (   t
   __import__t   getattrt   copyt   gett   InterfaceErrort   joint   itemst   DBServer(   t   drivert   kwargst   moduleR   t   kwt   connt   it   dsn(    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   open_database   s<    




1R   c           B   s}   e  Z d d  „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d d d „ Z
 d „  Z d	 „  Z d
 „  Z d „  Z RS(   c         C   sI   | |  _  | d  k r! | j } n  t | t j | ƒ ƒ |  _ | |  _ d  S(   N(   R   t   Nonet   __name__t   Adaptort   DBUtilst   get_dbutilst   adaptort   module_name(   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/BioSQL/BioSeqDatabase.pyt   __init__L   s
    	c         C   s   |  j  j d |  j j S(   Ns   (%r)(   t	   __class__R   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/BioSQL/BioSeqDatabase.pyt   __repr__S   s    c         C   s   t  |  j | ƒ S(   N(   t   BioSeqDatabaseR!   (   R#   t   name(    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   __getitem__U   s    c         C   s   |  j  j ƒ  S(   N(   R!   t   list_biodatabase_names(   R#   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   keysW   s    c         C   s!   g  |  j  ƒ  D] } |  | ^ q S(   N(   R+   (   R#   t   key(    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   valuesY   s    c         C   s'   g  |  j  ƒ  D] } | |  | f ^ q S(   N(   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/BioSQL/BioSeqDatabase.pyR   [   s    c         C   s5   |  j  j | ƒ } t j |  j  | ƒ } | j ƒ  d S(   s=   Try to remove all references to items in a database.
        N(   R!   t   fetch_dbid_by_dbnamet   Loadert   DatabaseRemovert   remove(   R#   t   db_namet   db_idt   remover(    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   remove_database^   s    c         C   s2   d } |  j  j | | | | f ƒ t |  j  | ƒ S(   s8   Add a new database to the server and return it.
        sJ   INSERT INTO biodatabase (name, authority, description) VALUES (%s, %s, %s)(   R!   t   executeR'   (   R#   R2   t	   authorityt   descriptiont   sql(    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   new_databasee   s    c         C   s
  t  | d ƒ } d } xm | j ƒ  D]_ } | j d ƒ d k r@ q" | j d ƒ d k rX q" | j ƒ  r" | | j ƒ  7} | d 7} q" q" W|  j d k rª |  j j j | ƒ n\ |  j d k ró | j d
 ƒ } x; | d  D] } |  j j j | ƒ qÓ Wn t	 d |  j ƒ ‚ d S(   sú   Load a database schema into the given database.

        This is used to create tables, etc when a database is first created.
        sql_file should specify the complete path to a file containing
        SQL entries for building the tables.
        t   rbt    s   --i    t   #R
   R   R   R    t   ;iÿÿÿÿs&   Module %s not supported by the loader.N(   R   R   (   R    (
   t   opent
   xreadlinest   findt   stripR"   R!   t   cursorR6   t   splitt
   ValueError(   R#   t   sql_filet
   sql_handleR9   t   linet	   sql_partst   sql_line(    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   load_database_sqln   s$    c         C   s   |  j  j ƒ  S(   s0   Commits the current transaction to the database.(   R!   t   commit(   R#   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyRL   •   s    c         C   s   |  j  j ƒ  S(   s$   Rolls backs the current transaction.(   R!   t   rollback(   R#   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyRM   ™   s    c         C   s   |  j  j ƒ  S(   s3   Close the connection. No further activity possible.(   R!   t   close(   R#   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyRN      s    N(   R   t
   __module__R   R$   R&   R)   R+   R-   R   R5   R:   RK   RL   RM   RN   (    (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyR   K   s   								'		R   c           B   sÔ   e  Z d  „  Z 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 d „ Z d d „ Z d „  Z d d „ Z d d „ Z RS(   c         C   s%   | |  _  | j ƒ  |  _ | |  _ d  S(   N(   R   RC   t   dbutils(   R#   R   RP   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyR$   ¢   s    	c         C   s   |  j  j |  j | ƒ S(   N(   RP   t   last_idRC   (   R#   t   table(    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyRQ   §   s    c         C   s   |  j  j |  j | ƒ S(   sA   Set the autocommit mode. True values enable; False value disable.(   RP   t
   autocommitR   (   R#   t   y(    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyRS   ª   s    c         C   s   |  j  j ƒ  S(   s    Commits the current transaction.(   R   RL   (   R#   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyRL   ®   s    c         C   s   |  j  j ƒ  S(   s$   Rolls backs the current transaction.(   R   RM   (   R#   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyRM   ²   s    c         C   s   |  j  j ƒ  S(   s3   Close the connection. No further activity possible.(   R   RN   (   R#   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyRN   ¶   s    c         C   sJ   |  j  j d | f ƒ |  j  j ƒ  } | s> t d | ƒ ‚ n  | d d S(   Ns6   select biodatabase_id from biodatabase where name = %ss$   Cannot find biodatabase with name %ri    (   RC   R6   t   fetchallt   KeyError(   R#   R	   t   rv(    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyR.   º   s    	
c         C   s›   d } | g } | r/ | d 7} | j  | ƒ n  |  j j | | ƒ |  j j ƒ  } | sj t d | ƒ ‚ n  t | ƒ d k r t d | ƒ ‚ n  | d d S(   Ns0   select bioentry_id from bioentry where name = %ss    and biodatabase_id = %ss   Cannot find display id %ri   s&   More than one entry with display id %ri    (   t   appendRC   R6   RU   t
   IndexErrort   len(   R#   t   dbidR(   R9   t   fieldsRW   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   fetch_seqid_by_display_idÅ   s    	
c         C   s›   d } | g } | r/ | d 7} | j  | ƒ n  |  j j | | ƒ |  j j ƒ  } | sj t d | ƒ ‚ n  t | ƒ d k r t d | ƒ ‚ n  | d d S(   Ns5   select bioentry_id from bioentry where accession = %ss    and biodatabase_id = %ss   Cannot find accession %ri   s%   More than one entry with accession %ri    (   RX   RC   R6   RU   RY   RZ   (   R#   R[   R(   R9   R\   RW   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   fetch_seqid_by_accessionÓ   s    	
c         C   s?   d } | g } | r/ | d 7} | j  | ƒ n  |  j | | ƒ S(   Ns5   select bioentry_id from bioentry where accession = %ss    and biodatabase_id = %s(   RX   t   execute_and_fetch_col0(   R#   R[   R(   R9   R\   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   fetch_seqids_by_accessioná   s    	
c   	      C   s  | j  d ƒ } t | ƒ d k r4 t d | ƒ ‚ n  | d } t | ƒ d k r] | d } n d } d } | | g } | r• | d 7} | j | ƒ n  |  j j | | ƒ |  j j ƒ  } | sÐ t d	 | ƒ ‚ n  t | ƒ d k rõ t d
 | ƒ ‚ n  | d d S(   Nt   .i   s   Bad version %ri    i   t   0sF   SELECT bioentry_id FROM bioentry WHERE accession = %s AND version = %ss    and biodatabase_id = %ss   Cannot find version %rs#   More than one entry with version %r(   RD   RZ   RY   RX   RC   R6   RU   (	   R#   R[   R(   t   acc_versiont   acct   versionR9   R\   RW   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   fetch_seqid_by_versioné   s&    

c         C   sv   d } | g } | r/ | d 7} | j  | ƒ n  |  j j | | ƒ |  j j ƒ  } | sj t d | ƒ ‚ n  | d d S(   Ns6   SELECT bioentry_id FROM bioentry WHERE identifier = %ss    and biodatabase_id = %ss   Cannot find display id %ri    (   RX   RC   R6   RU   RY   (   R#   R[   t
   identifierR9   R\   RW   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   fetch_seqid_by_identifier   s    	
c         C   s   |  j  d ƒ S(   Ns   SELECT name FROM biodatabase(   R_   (   R#   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyR*     s    c         C   s   |  j  d | f ƒ S(   Ns:   SELECT bioentry_id FROM bioentry WHERE biodatabase_id = %s(   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/BioSQL/BioSeqDatabase.pyt   list_bioentry_ids  s    c         C   s   |  j  d | f ƒ S(   Ns3   SELECT name FROM bioentry WHERE biodatabase_id = %s(   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/BioSQL/BioSeqDatabase.pyt   list_bioentry_display_ids  s    c         C   s   |  j  j | | ƒ S(   s  Return ids given a SQL statement to select for them.
        
        This assumes that the given SQL does a SELECT statement that
        returns a list of items. This parses them out of the 2D list
        they come as and just returns them in a list.
        (   RC   R_   (   R#   R9   t   args(    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   list_any_ids  s    c         C   sX   |  j  j | | p d ƒ |  j  j ƒ  } t | ƒ d k sP t d t | ƒ ƒ ‚ | d S(   Ni   s   Expected 1 response, got %di    (    (   RC   R6   RU   RZ   t   AssertionError(   R#   R9   Rk   RW   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   execute_one$  s    (c         C   s   |  j  j | | p d ƒ d S(   s%   Just execute an sql command.
        N(    (   RC   R6   (   R#   R9   Rk   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyR6   *  s    c         C   s+   | | } |  j  d | d | | f ƒ d S(   Nsa   select SUBSTRING(seq FROM %s FOR %s)
                     from biosequence where bioentry_id = %si   i    (   Rn   (   R#   t   seqidt   startt   endt   length(    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   get_subseq_as_string/  s    
c         C   s=   |  j  j | | p d ƒ g  |  j  j ƒ  D] } | d ^ q) S(   Ni    (    (   RC   R6   RU   (   R#   R9   Rk   t   field(    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyR_   6  s    c         C   s&   |  j  j | | p d ƒ |  j  j ƒ  S(   N(    (   RC   R6   RU   (   R#   R9   Rk   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   execute_and_fetchall:  s    N(   R   RO   R$   RQ   t   TrueRS   RL   RM   RN   R.   R]   R^   R`   Rf   Rh   R*   Ri   Rj   Rl   R   Rn   R6   Rs   R_   Ru   (    (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyR   ¡   s*   																	Rh   t
   primary_idt   giR]   t
   display_idR(   R^   t	   accessionRf   Re   R'   c           B   s’   e  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 RS(   c         C   s+   | |  _  | |  _ |  j  j | ƒ |  _ d  S(   N(   R!   R(   R.   R[   (   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/BioSQL/BioSeqDatabase.pyR$   I  s    		c         C   s   d |  j  |  j f S(   Ns   BioSeqDatabase(%r, %r)(   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/BioSQL/BioSeqDatabase.pyR&   M  s    c         C   s+   |  j  j |  j | ƒ } t j |  j  | ƒ S(   sk   Gets a Bio::Seq object by its name

        Example: seq = db.get_Seq_by_id('ROA1_HUMAN')
        
        (   R!   R]   R[   t   BioSeqt   DBSeqRecord(   R#   R(   Ro   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   get_Seq_by_idP  s    c         C   s+   |  j  j |  j | ƒ } t j |  j  | ƒ S(   sh   Gets a Bio::Seq object by accession number

        Example: seq = db.get_Seq_by_acc('X77802')

        (   R!   R^   R[   R{   R|   (   R#   R(   Ro   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   get_Seq_by_accY  s    c         C   s+   |  j  j |  j | ƒ } t j |  j  | ƒ S(   sh   Gets a Bio::Seq object by version number

        Example: seq = db.get_Seq_by_ver('X77802.1')

        (   R!   Rf   R[   R{   R|   (   R#   R(   Ro   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   get_Seq_by_verb  s    c         C   s>   |  j  j |  j | ƒ } g  | D] } t j |  j  | ƒ ^ q S(   st   Gets a *list* of Bio::Seq objects by accession number

        Example: seqs = db.get_Seq_by_acc('X77802')

        (   R!   R`   R[   R{   R|   (   R#   R(   t   seqidsRo   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   get_Seqs_by_acck  s    c         C   s   t  d ƒ ‚ d  S(   Ns   waiting for Python 2.2's iter(   t   NotImplementedError(   R#   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   get_PrimarySeq_streamt  s    c         C   s   |  j  j |  j ƒ S(   s  Array of all the primary_ids of the sequences in the database.

        These maybe ids (display style) or accession numbers or
        something else completely different - they *are not*
        meaningful outside of this database implementation.
        (   R!   Ri   R[   (   R#   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   get_all_primary_ids{  s    c         C   s   t  j |  j | ƒ S(   N(   R{   R|   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/BioSQL/BioSeqDatabase.pyR)   „  s    c         C   s
   |  j  ƒ  S(   N(   R„   (   R#   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyR+   †  s    c         C   s!   g  |  j  ƒ  D] } |  | ^ q S(   N(   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/BioSQL/BioSeqDatabase.pyR-   ˆ  s    c         C   s'   g  |  j  ƒ  D] } | |  | f ^ q S(   N(   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/BioSQL/BioSeqDatabase.pyR   Š  s    c         K   s¶   t  | ƒ d k r! t d ƒ ‚ n  | j ƒ  d \ } } | t k ru t d t t j ƒ  ƒ d d !t | ƒ f ƒ ‚ n  t | } t |  j | ƒ } | |  j | ƒ } t	 j
 |  j | ƒ S(   Ni   s#   single key/value parameter expectedi    s"   lookup() expects one of %s, not %riÿÿÿÿ(   RZ   t	   TypeErrorR   t   _allowed_lookupst   reprR+   R   R!   R[   R{   R|   (   R#   R   t   kt   vt   lookup_namet   lookup_funcRo   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   lookup  s    ,
c         C   s   |  | S(   sç   Gets a Bio::Seq object by the primary (internal) id.

        The primary id in these cases has to come from
        $db->get_all_primary_ids.  There is no other way to get (or
        guess) the primary_ids in a database.
        (    (   R#   Ro   (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   get_Seq_by_primary_id™  s    c         C   sM   t  j |  j |  j | ƒ } d } x% | D] } | d 7} | j | ƒ q( W| S(   s¡  Load a set of SeqRecords into the BioSQL database.

        record_iterator is either a list of SeqRecord objects, or an
        Iterator object that returns SeqRecord objects (such as the
        output from the Bio.SeqIO.parse() function), which will be
        used to populate the database.

        fetch_NCBI_taxonomy is boolean flag allowing or preventing
        connection to the taxonomic database on the NCBI server
        (via Bio.Entrez) to fetch a detailed taxonomy for each
        SeqRecord.

        Example:
        from Bio import SeqIO
        count = db.load(SeqIO.parse(open(filename), format))

        Returns the number of records loaded.
        i    i   (   R/   t   DatabaseLoaderR!   R[   t   load_seqrecord(   R#   t   record_iteratort   fetch_NCBI_taxonomyt	   db_loadert   num_recordst
   cur_record(    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyt   load¢  s    	
(   R   RO   R$   R&   R}   R~   R   R   Rƒ   R„   R)   R+   R-   R   RŒ   R   t   FalseR•   (    (    (    sˆ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/BioSQL/BioSeqDatabase.pyR'   H  s   																				(    (    (    (	   t   __doc__R{   R/   R   R   R   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/BioSQL/BioSeqDatabase.pyt   <module>   s   9V
