ó
a#nSc           @   s¢   d  Z  d d l Z d d l Z d d l Z d d d „  ƒ  YZ d d e j d „ Z e d k rž d d l Z e j	 d	 Z
 e e
 ƒ \ Z Z d
 Ge GHd Ge GHn  d S(   s"    Generic file manipulation stuff

iÿÿÿÿNt   ReFilec           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d d d d „ Z RS(   sÛ   convenience class for dealing with files with comments

  blank (all whitespace) lines, and lines beginning with comment
    characters are skipped.

  anything following a comment character on a line is stripped off
  c         C   s[   d } xN | d k rV |  j  j ƒ  } | d k r4 d St j |  j j | ƒ d ƒ } q	 W| S(   s>    read the next line and return it.

    return '' on EOF

    t    i    (   t   inFilet   readlinet   stringt   stript   regExpt   split(   t   selft   resultt   inLine(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/files.pyR      s    #c         C   se   g  } |  j  j ƒ  } xI | D]A } t j |  j j | ƒ d ƒ } | d k r | j | ƒ q q W| S(   sW    return a list of all the lines left in the file

    return [] if there are none

    i    R   (   R   t	   readlinesR   R   R   R   t   append(   R   t   rest   inLinest   lineR	   (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/files.pyR       s    c         C   s   |  j  j d ƒ d S(   s0    rewinds the file (seeks to the beginning)

    i    N(   R   t   seek(   R   (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/files.pyt   rewind/   s    t   rt   #s   \nc         C   sQ   | d  k	 r) | d k r) | d | } n  t j | ƒ |  _ t | | ƒ |  _ d  S(   NR   t   |(   t   Nonet   ret   compileR   t   openR   (   R   t   fileNamet   modet   commentt   trailer(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/files.pyt   __init__5   s    (   t   __name__t
   __module__t   __doc__R   R   R   R   (    (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/files.pyR    
   s
   			R   i    c         C   s  t  |  ƒ } | j ƒ  } t | ƒ } | t j t j t j g k rK t } n t } t t j	 | d ƒ ƒ d } t j
 | | f | ƒ }	 t j
 | | ƒ }
 xa t | ƒ D]S } t j	 | | ƒ } | | | ƒ |
 | <| | =t | | ƒ |	 | d d … f <q¥ W|	 |
 f S(   s³   read in the data file and return a tuple of two Numeric arrays:
  (independant variables, dependant variables).

  **ARGUMENTS:**

  - fileName: the fileName

  - comment: the comment character for the file

  - depVarcol: the column number containing the dependant variable

  - dataType: the Numeric short-hand for the data type

  RETURNS:

   a tuple of two Numeric arrays:

    (independant variables, dependant variables).
  
  i    i   N(   R    R   t   lent   numpyt   floatt   float32t   float64t   intR   R   t   zerost   xranget   map(   R   R   t	   depVarColt   dataTypeR   t	   dataLinest   nPtst	   _convfunct   nIndVarst	   indVarMatt
   depVarVectt   it	   splitLine(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/files.pyt   ReadDataFile<   s    	#t   __main__i   s   iV:s   dV:(    (   R    R"   R   R   R    R#   R4   R   t   syst   argvt   fileNt   iVt   dV(    (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/files.pyt   <module>   s   2*	