ó
a#nSc           @   sÜ  d  Z  d d l m Z d d l m Z d d l Z d d l Z d d l Z d d l Z d d l Z y d d l	 m
 Z
 m Z Wn e k
 r• d Z n Xd Z d d l m Z m Z d d	 l m Z d d
 l m Z d d l m Z e j ƒ  a d Z d d „ Z d „  Z d d „ Z d d d d „ Z d d d d d d d d d „ Z d d d d d d d d d „ Z d d d d d d d d „ Z  d „  Z! d d „ Z" d d d d d d d d d „ Z# d d „ Z$ d d d d d „ Z% d d d „ Z& d „  Z' d d „ Z( d „  Z) d d „ Z* d  „  Z+ e, d! k rØe( ƒ  Z- e+ e- ƒ Z. e* d" d ƒ g  Z/ e- j0 re- j1 re. d Z2 e d# ƒ e e- j1 e2 ƒ Z3 e3 j4 d$ d% d& d' e- j0 ƒ Z5 x˜ e5 D]Z Z6 e6 d Z6 y  e/ j7 e j8 e9 e6 ƒ ƒ ƒ Wq²d d l: Z: e: j; ƒ  e d( ƒ q²Xq²Wn3 e d) ƒ e< e. d d* ƒ Z= e/ j7 e j> e= ƒ ƒ e? e/ ƒ sle d+ ƒ e j@ d ƒ n e d, e? e/ ƒ ƒ e. d Z. xKe. D]@ZA e- j1 d- k rÐeA e- _B e- jC d. e- jD d/ e jE ƒ ZF n e jG eA ƒ ZF eF jH ƒ  ZI e? e/ ƒ ZJ d g eJ ZK d g eJ ZL e d0 ƒ eM eF jN ƒ  ƒ ZO eO ZP xueM eJ ƒ D]gZQ eF ZR e/ eQ ZS e d d1 d ƒy eS jT ZU Wn eV k
 r†n Xe jW eU ƒ e- jX s¦e- jY rÔe- jX ZZ d Z[ e j\ eR d2 e- jX d3 e- ƒn e] Z[ e] ZZ e^ eS d4 ƒ r eS j_ r eZ r e d5 ƒ e d6 ƒ e d5 ƒ n  e^ eS d7 ƒ r`eS j` r`e[ r`e d5 ƒ e d8 ƒ e d5 ƒ n  e" eS e- eR d9 d ƒ\ ZP ZO e eO eR eS d: e- ja ƒeK eQ <eO eL eQ <q@Wx#e- jb D]Zc e? e- jb ƒ d k rëe d; ƒ e d< ec ƒ n  e jd eJ e je ƒ Zf e jd eJ e je ƒ Zg e jd eJ e je ƒ Zh e jd eJ e je ƒ Zi e jd eJ e je ƒ Zj e jd eJ e je ƒ Zk e- jl d k r�e jd eJ e je ƒ Zm n  i  Zn i  Zo i  Zp d Zq xÇeM eJ ƒ D]¹ZQ e/ eQ ZS eS jr eI ƒ eL eQ ZO eK eQ Zs e- jt s1e  eS eO eR e- ju ec d9 e- jv d= es ƒ\ Zw Zx Zy Zz Z{ Z| Z} nùeS j~ ƒ  rVe? eS j~ ƒ  ƒ d Z n eS j€ ƒ  d d Z g  Z� g  Z‚ e^ e- d> ƒ rŽe- jƒ s¦e^ e- d? ƒ r¯e- j„ r¯g  Z… n d Z… e eO eR eS e ec d9 e- jv d= es d@ e� dA e‚ dB e… d: e- ja ƒ\ Zw Zx Zy Zz Z{ Z| Z} eq d k r3e jd e} j† e je ƒ Zq n  e- j‡ r[	x‹ e� D]ƒ \ Zˆ Z‰ ZŠ Z‹ eO e‹ ZŒ e^ e- dC ƒ r¬e- jl d k r¬eˆ e- jl k rÆeo j� eŒ d ƒ d eo eŒ <qÆqCeo j� eŒ d ƒ d eo eŒ <qCWxŽ e‚ D]ƒ \ Zˆ Z‰ ZŠ Z‹ eO e‹ ZŒ e^ e- dC ƒ r:	e- jl d k r:	eˆ e- jl k rT	ep j� eŒ d ƒ d ep eŒ <qT	qÑep j� eŒ d ƒ d ep eŒ <qÑWn  e^ e- d> ƒ rõ	e- jƒ rõ	x e… D]t \ Zˆ Z‰ ZŠ Z‹ eO e‹ ZŒ e- jl d k rÔ	eˆ e- jl k rî	en j� eŒ d ƒ d en eŒ <qî	qz	en j� eŒ d ƒ d en eŒ <qz	Wn  e- jl d k r 
e e} dD e- jl ƒem eQ <n  eq e} 7Zq e- jt rm
e^ e- d? ƒ rm
e- j„ rm
e& e- eO eR e… e� e d9 d ƒn  e^ e- d> ƒ r2e- jƒ r2dE GHdF GHx† e… D]~ \ ZŽ Z� Z� Z‹ eR eO e‹ Z‘ eS j~ ƒ  sø
e‘ d eŽ k sø
t’ dG e9 e‘ d ƒ e9 eŽ ƒ f ƒ ‚ dH e9 e‘ d ƒ e� e� f GHq–
Wx† e� D]~ \ ZŽ Z� Z� Z‹ eR eO e‹ Z‘ eS j~ ƒ  s�e‘ d eŽ k s�t’ dG e9 e‘ d ƒ e9 eŽ ƒ f ƒ ‚ dI e9 e‘ d ƒ e� e� f GHqWx† e‚ D]~ \ ZŽ Z� Z� Z‹ eR eO e‹ Z‘ eS j~ ƒ  s
e‘ d eŽ k s
t’ dG e9 e‘ d ƒ e9 eŽ ƒ f ƒ ‚ dJ e9 e‘ d ƒ e� e� f GHq¨WdK GHn  ew ef eQ <ex eg eQ <ey eh eQ <ez ei eQ <e{ ej eQ <e| ek eQ <qµWHeJ d k rñdL GHdM GHe“ eg ƒ eJ Z” e j• e“ eg e” dN ƒ eJ d ƒ Z– e j— eg ƒ d Z˜ e“ ef ƒ eJ Z™ e j• e“ ef e™ dN ƒ eJ d ƒ Zš e“ eh ƒ eJ Z› e j• e“ eh e› dN ƒ eJ d ƒ Zœ e“ ej ƒ eJ Z� e j• e“ ej e� dN ƒ eJ d ƒ Zž e“ ei ƒ eJ ZŸ e j• e“ ei eŸ dN ƒ eJ d ƒ Z  e“ ek ƒ eJ Z¡ e j• e“ ek e¡ dN ƒ eJ d ƒ Z¢ e™ e” Z£ e£ e› Z¤ dO dP e” e¤ dP e– e¤ e” e– e¤ f GHe› d k rsdQ dP e” e£ dP e– e£ e” e– e£ f GHHdR dP e› e¤ dP eœ e¤ e› eœ f GHn  HdS GHdT dP eŸ dP e  f GHdU dP e� dP ež f GHe› d k rÍdV dP e¡ dP e¢ f GHn  e- jt r÷e dW ƒ e j¥ eq ƒ eJ Zq e? eq ƒ Z¦ e j“ eq d ƒ Z§ e j“ eq d ƒ Z¨ Hx¤ eM e¦ ƒ D]– Z© e¨ e© d k rTd e¨ e© <n  eq e© Zª e dX d1 d ƒx2 eM e¦ ƒ D]$ Z« eª e« Z¬ e dY e¬ d1 d ƒq{We dZ d[ eq e© e© f e¨ e© ƒ q1We dX d1 d ƒx$ eM e¦ ƒ D] Z© e d\ d1 d ƒqèWe d- ƒ e dX d1 d ƒx[ eM e¦ ƒ D]M Z© e§ e© d k rLd e§ e© <n  e dY d[ eq e© e© f e§ e© d1 d ƒq)We d- ƒ e- jl d k rîe“ em ƒ eJ Z­ em e­ 8Zm e j• e“ em em ƒ ƒ eJ d Z® e d] e- jl e­ e® f ƒ qîq÷n d Z˜ d^ GHd_ Ge˜ d GHeg e˜ Z¯ ef e˜ Z° eh e˜ Z± e° e¯ Z£ e£ e± Z¤ d` dP e¯ e¤ e¯ e¤ f GHe± d k r–da dP e¯ e£ e¯ e£ f GHHdb dP e± e¤ e± f GHn  HdS GHdc dP ei e˜ GHdd dP ej e˜ GHe± d k rÞde dP ek e˜ GHn  eJ d k r³e- jt r³e d- ƒ e dW ƒ e j¥ e} ƒ Zq e? e} ƒ Z¦ e j“ eq d ƒ Z§ e j“ eq d ƒ Z¨ e d- ƒ x¤ eM e¦ ƒ D]– Z© e¨ e© d k r€d e¨ e© <n  eq e© Zª e dX d1 d ƒx2 eM e¦ ƒ D]$ Z« eª e« Z¬ e dY e¬ d1 d ƒq§We dZ d[ eq e© e© f e¨ e© ƒ q]We dX d1 d ƒx$ eM e¦ ƒ D] Z© e d\ d1 d ƒqWe d- ƒ e dX d1 d ƒx[ eM e¦ ƒ D]M Z© e§ e© d k rxd e§ e© <n  e dY d[ eq e© e© f e§ e© d1 d ƒqUWe d- ƒ n  e- j‡ rPe df ƒ eo j² ƒ  Z³ e? e³ ƒ rëe dg ƒ n  ep j² ƒ  Z³ e? e³ ƒ rPe dh ƒ x= e³ D]2 Z´ eF e´ Z‘ e di e9 e‘ d ƒ ep e´ f ƒ qWqPn  e^ e- d> ƒ rµe- jƒ rµen j² ƒ  Z³ e? e³ ƒ rÍe dj ƒ x= e³ D]2 Z´ eF e´ Z‘ e di e9 e‘ d ƒ en e´ f ƒ q‘WqÍqµqµWq‘Wn  d S(k   s3   command line utility for screening composite models

**Usage**

  _ScreenComposite [optional args] modelfile(s) datafile_

Unless indicated otherwise (via command line arguments), _modelfile_ is
a file containing a pickled composite model and _filename_ is a QDAT file.

**Command Line Arguments**

  - -t *threshold value(s)*: use high-confidence predictions for the final
     analysis of the hold-out data.  The threshold value can be either a single
     float or a list/tuple of floats.  All thresholds should be between
     0.0 and 1.0

  - -D: do a detailed screen.

  - -d *database name*: instead of reading the data from a QDAT file,
     pull it from a database.  In this case, the _datafile_ argument
     provides the name of the database table containing the data set.

  - -N *note*: use all models from the database which have this note.
               The modelfile argument should contain the name of the table
               with the models. 

  - -H: screen only the hold out set (works only if a version of 
        BuildComposite more recent than 1.2.2 was used).

  - -T: screen only the training set (works only if a version of 
        BuildComposite more recent than 1.2.2 was used).

  - -E: do a detailed Error analysis.  This shows each misclassified
     point and the number of times it was missed across all screened
     composites.  If the --enrich argument is also provided, only compounds
     that have true activity value equal to the enrichment value will be
     used.

  - --enrich *enrichVal*: target "active" value to be used in calculating
     enrichments.

  - -A: show All predictions.

  - -S: shuffle activity values before screening

  - -R: randomize activity values before screening

  - -F *filter frac*: filters the data before training to change the
     distribution of activity values in the training set.  *filter frac*
     is the fraction of the training set that should have the target value.
     **See note in BuildComposite help about data filtering**

  - -v *filter value*: filters the data before training to change the
     distribution of activity values in the training set. *filter value*
     is the target value to use in filtering.
     **See note in BuildComposite help about data filtering**

  - -V: be verbose when screening multiple models

  - -h: show this message and exit

  - --OOB: Do out an "out-of-bag" generalization error estimate.  This only
      makes sense when applied to the original data set.

  - --pickleCol *colId*: index of the column containing a pickled value
      (used primarily for cases where fingerprints are used as descriptors)

  *** Options for making Prediction (Hanneke) Plots ***

  - --predPlot=<fileName>: triggers the generation of a Hanneke plot and
      sets the name of the .txt file which will hold the output data.
      A Gnuplot control file, <fileName>.gnu, will also be generated.
    
  - --predActTable=<name> (optional):  name of the database table
      containing activity values.  If this is not provided, activities
      will be read from the same table containing the screening data

  - --predActCol=<name> (optional):  name of the activity column. If not
      provided, the name of the last column in the activity table will
      be used.

  - --predLogScale (optional):  If provided, the x axis of the
      prediction plot (the activity axis) will be plotted using a log
      scale  

  - --predShow: launch a gnuplot instance and display the prediction
      plot (the plot will still be written to disk).
  
  *** The following options are likely obsolete ***

  - -P: read pickled data.  The datafile argument should contain
     a pickled data set. *relevant only to qdat files*

  - -q: data are not quantized (the composite should take care of
     quantization itself if it requires quantized data). *relevant only to
     qdat files*



iÿÿÿÿ(   t   RDConfig(   t   DataStructsN(   t   Imaget	   ImageDrawi    i   (   t	   DataUtilst	   SplitData(   t   CompositeRun(   t	   DbConnect(   t   DbModules   3.3.0c         C   s5   | r t  j j d |  ƒ n t  j j d |  ƒ d S(   s¥    emits messages to _sys.stdout_
    override this in modules which import this one to redirect output

    **Arguments**

      - msg: the string to be displayed

  s   %s s   %s
N(   t   syst   stdoutt   write(   t   msgt   noRet(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/ScreenComposite.pyt   messageƒ   s    	c         C   s   t  j j d |  ƒ d S(   s¥    emits messages to _sys.stderr_
    override this in modules which import this one to redirect output

    **Arguments**

      - msg: the string to be displayed

  s
   ERROR: %s
N(   R	   t   stderrR   (   R   (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/ScreenComposite.pyt   error�   s    	c         C   s²   | d k  s | |  j  d k r# d St t t |  ƒ ƒ ƒ } t t |  d  d  … | f ƒ ƒ } | r¦ |  | | f | } t t |  | d  d  … f ƒ ƒ } | | } n d S| | S(   Ni    g        (   t   shapet   floatt   sum(   t   matt   tgtt   nPtst   nTgtPredt
   pctCorrectt   nTgtRealt
   pctOverall(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/ScreenComposite.pyt   CalcEnrichment›   s     ""c         C   s¶  x’ t  t | ƒ ƒ D]~ } | j | ƒ } t | d ƒ r t | j ƒ t j k r i  } t | d ƒ r… x | j D] }	 d | |	 <qn Wn  | | _ q q Wt |  ƒ }
 d g |
 } xt  |
 ƒ D]ó } |  | } | | } | r5g  } xW t  t | ƒ ƒ D]: } | j | ƒ } | j j	 | d ƒ sô | j
 | ƒ qô qô Wn d } | j | d | d | ƒ\ } } | j ƒ  r~| j | ƒ d } n
 | d } | | | f | | <| r» | | ƒ q» q» W| S(   sh   screens a set of examples through a composite and returns the
  results
#DOC

  **Arguments**

    - examples: the examples to be screened (a sequence of sequences)
       it's assumed that the last element in each example is it's "value"
    
    - composite:  the composite model to be used

    - callback: (optional)  if provided, this should be a function
      taking a single argument that is called after each example is
      screened with the number of examples screened so far as the
      argument.

    - appendExamples: (optional)  this value is passed on to the
      composite's _ClassifyExample()_ method.

    - errorEstimate: (optional) calculate the "out of bag" error
      estimate for the composite using Breiman's definition.  This
      only makes sense when screening the original data set!
      [L. Breiman "Out-of-bag Estimation", UC Berkeley Dept of
      Statistics Technical Report (1996)]

  **Returns**

    a list of 3-tuples _nExamples_ long:

      1)  answer: the value from the example

      2)  pred: the composite model's prediction

      3)  conf: the confidence of the composite

  t   _trainIndicesi   i    t   appendExamplet
   onlyModelsiÿÿÿÿN(   t   ranget   lent   GetModelt   hasattrt   typeR   t   typest   DictTypet   Nonet   gett   appendt   ClassifyExamplet   GetActivityQuantBoundst   QuantizeActivity(   t   indicest   dataSett	   compositet   callbackt   appendExamplest   errorEstimatet   jt   tmpt   tist   vR   t   rest   it   idxt   examplet   uset   mdlt   predt   conft   answer(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/ScreenComposite.pyt   CollectResults¨   s:    )' 


 c      
   C   s  | d k r3 t |  | | d | d |	 d |
 ƒ} n  | d k rH g  } n  | d k r] g  } n  | d k rr g  } n  x– t t | ƒ ƒ D]‚ } | | \ } } } | | k rî | | k rÒ | j | | | | f ƒ q| j | | | | f ƒ q… | j | | | | f ƒ q… Wd S(   s´   screens a set of examples cross a composite and breaks the
      predictions into *correct*,*incorrect* and *unclassified* sets.
#DOC
  **Arguments**

    - examples: the examples to be screened (a sequence of sequences)
       it's assumed that the last element in each example is its "value"
    
    - composite:  the composite model to be used

    - threshold: (optional) the threshold to be used to decide whether
      or not a given prediction should be kept

    - screenResults: (optional) the results of screening the results
      (a sequence of 3-tuples in the format returned by
      _CollectResults()_).  If this is provided, the examples will not
      be screened again.

    - goodVotes,badVotes,noVotes: (optional)  if provided these should
      be lists (or anything supporting an _append()_ method) which
      will be used to pass the screening results back.

    - callback: (optional)  if provided, this should be a function
      taking a single argument that is called after each example is
      screened with the number of examples screened so far as the
      argument.

    - appendExamples: (optional)  this value is passed on to the
      composite's _ClassifyExample()_ method.

    - errorEstimate: (optional) calculate the "out of bag" error
      estimate for the composite using Breiman's definition.  This
      only makes sense when screening the original data set!
      [L. Breiman "Out-of-bag Estimation", UC Berkeley Dept of
      Statistics Technical Report (1996)]

  **Notes**

    - since this function doesn't return anything, if one or more of
      the arguments _goodVotes_, _badVotes_, and _noVotes_ is not
      provided, there's not much reason to call it

  R/   R0   R1   N(   R&   R?   R   R    R(   (   R,   t   dataR.   t	   thresholdt   screenResultst	   goodVotest   badVotest   noVotesR/   R0   R1   R7   R>   R<   R=   (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/ScreenComposite.pyt   DetailedScreenò   s"    . 	 	 	c   &      C   s“  t  |  ƒ } |	 d k r! g  }	 n  |
 d k r6 g  }
 n  | d k rK g  } n  t |  | | | d | d |	 d |
 d | d | d | d | ƒt  |
 ƒ } t  |	 ƒ } | | } | rï d GHd	 | | d
 t | ƒ | | | d
 t | ƒ | f GHn  t  | ƒ } | d k ro| r0d | | d
 t | ƒ | f GHn  t j g  | D] } | d ^ q=ƒ } t | ƒ t | ƒ } n d } | d k rÀt j g  |
 D] } | d ^ qŽƒ } t | ƒ t | ƒ } n d } | d k r.g  |	 D] } | d ^ qÙ} t j g  |	 D] } | d ^ qüƒ } t | ƒ t | ƒ } n g  } g  } d } | r\Hd | GHd | GHn  t j | | f t j ƒ } x$ | D] } | | | f c d 7<q~Wx0 |
 D]( \ } } } } | | | f c d 7<q¥W| rzHd GH| j	 ƒ  } t j | d ƒ }  t j | d ƒ }! t
 d ƒ x¤ t | ƒ D]– }" |! |" d k rGd |! |" <n  | |" }# t
 d d d ƒx2 t | ƒ D]$ }$ |# |$ }% t
 d |% d d ƒqnWt
 d d
 | |" |" f |! |" ƒ q$Wt
 d d d ƒx$ t | ƒ D] }" t
 d d d ƒqÛWt
 d ƒ t
 d d d ƒx[ t | ƒ D]M }" |  |" d k r?d |  |" <n  t
 d d
 | |" |" f |  |" d d ƒqWt
 d ƒ n  | | | | | | | f S(   s×   screens the results and shows a detailed workup

  The work of doing the screening and processing the results is
  handled by _DetailedScreen()_
#DOC

  **Arguments**

    - examples: the examples to be screened (a sequence of sequences)
       it's assumed that the last element in each example is its "value"
    
    - composite:  the composite model to be used

    - nResultCodes: the number of possible results the composite can
      return

    - threshold: the threshold to be used to decide whether or not a
      given prediction should be kept

    - screenResults: (optional) the results of screening the results
      (a sequence of 3-tuples in the format returned by
      _CollectResults()_).  If this is provided, the examples will not
      be screened again.

    - callback: (optional)  if provided, this should be a function
      taking a single argument that is called after each example is
      screened with the number of examples screened so far as the
      argument.

    - appendExamples: (optional)  this value is passed on to the
      composite's _ClassifyExample()_ method.

    - goodVotes,badVotes,noVotes: (optional)  if provided these should
      be lists (or anything supporting an _append()_ method) which
      will be used to pass the screening results back.

    - errorEstimate: (optional) calculate the "out of bag" error
      estimate for the composite using Breiman's definition.  This
      only makes sense when screening the original data set!
      [L. Breiman "Out-of-bag Estimation", UC Berkeley Dept of
      Statistics Technical Report (1996)]

  **Returns**

    a 7-tuple:

      1) the number of good (correct) predictions

      2) the number of bad (incorrect) predictions

      3) the number of predictions skipped due to the _threshold_

      4) the average confidence in the good predictions

      5) the average confidence in the bad predictions

      6) the average confidence in the skipped predictions

      7) the results table

  RB   RC   RD   RE   R/   R0   R1   s   
	*** Vote Results ***s.   misclassified: %d/%d (%%%4.2f)	%d/%d (%%%4.2f)g      Y@i    s   skipped: %d/%d (%%% 4.2f)i   g        i   s$   average correct confidence:   % 6.4fs$   average incorrect confidence: % 6.4fs   	Results Table:t    s       R   s    % 6ds        | % 4.2fs   -------s    % 6.2fN(   R    R&   RF   R   t   numpyt   arrayR   t   zerost   intt	   transposeR   R   (&   R,   R@   R.   t   nResultCodesRA   t   verboseRB   R/   R0   RC   RD   RE   R1   t	   nExamplest   nBadt   nGoodt   nClassifiedt   nSkipt   xt   noConft   avgSkipt   badConft   avgBadt   goodRest   goodConft   avgGoodt   voteTabR6   t   ansR=   R8   t   vTabt	   colCountst	   rowCountsR7   t   rowR2   t   entry(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/ScreenComposite.pyt   ShowVoteResults1  s’    A			
	#&&&	
 

(
 .g        c
         C   s«  | d k r g  } n  | d k r* g  } n  |	 d k r? g  }	 n  | sN d } n  t | | |  | d | d | d | d |	 ƒt | ƒ }
 d } x$ | D] \ } } } } | | 7} q’ Wt | ƒ } d } x$ | D] \ } } } } | | 7} qË Wt |	 ƒ } d } d } d } xG |	 D]? \ } } } } | | 7} | | k rE| d 7} q| d 7} qW|
 | | } | rsd G| GHn  | r| | } | rGd	 | d
 t | ƒ | f GHd | d
 t | ƒ | f GHd | d
 t | ƒ | f GHd | d
 t | ƒ | f GHqGnD | rGd	 | d
 t | ƒ | f GHd | | | GHd | | GHn  d } d } d } |
 rl| |
 } n  | r| | } n  | r’| | } n  |
 | | | | | d f S(   sÞ   screens a set of data using a composite model and prints out
             statistics about the screen. 
#DOC
    The work of doing the screening and processing the results is
    handled by _DetailedScreen()_

  **Arguments**

    - composite:  the composite model to be used

    - data: the examples to be screened (a sequence of sequences)
       it's assumed that the last element in each example is its "value"

    - partialVote: (optional) toggles use of the threshold value in
      the screnning.

    - voteTol: (optional) the threshold to be used to decide whether or not a
      given prediction should be kept

    - verbose: (optional) sets degree of verbosity of the screening

    - screenResults: (optional) the results of screening the results
      (a sequence of 3-tuples in the format returned by
      _CollectResults()_).  If this is provided, the examples will not
      be screened again.

    - goodVotes,badVotes,noVotes: (optional)  if provided these should
      be lists (or anything supporting an _append()_ method) which
      will be used to pass the screening results back.


  **Returns**

    a 7-tuple:

      1) the number of good (correct) predictions

      2) the number of bad (incorrect) predictions

      3) the number of predictions skipped due to the _threshold_

      4) the average confidence in the good predictions

      5) the average confidence in the bad predictions

      6) the average confidence in the skipped predictions

      7) None

  g        RB   RC   RD   RE   i    i   s   Total N Points:s    Misclassifications: %d (%%%4.2f)g      Y@s   N Skipped: %d (%%%4.2f)s!   	Good Votes Skipped: %d (%%%4.2f)s    	Bad Votes Skipped: %d (%%%4.2f)s)   Average Correct Vote Confidence:   % 6.4fs)   Average InCorrect Vote Confidence: % 6.4fN(   R&   RF   R    R   (   R.   R,   R@   t   partialVotet   voteTolRN   RB   RC   RD   RE   RQ   t	   goodAccumR6   R<   R=   R8   t   misCountt   badAccumt   nSkippedt   goodSkippedt
   badSkippedt	   skipAccumR]   t   nDatat   nCountedR[   RX   RV   (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/ScreenComposite.pyt   ScreenItÅ  sf    4				

#c         C   sQ   xJ t  t |  ƒ ƒ D]6 } |  | \ } } } } | | | | | f |  | <q Wd S(   st   *Internal Use Only*

  converts a list of 4 tuples: (answer,prediction,confidence,idx) into
  an alternate list: (answer,prediction,confidence,data point)

   **Arguments**

     - votes: a list of 4 tuples: (answer, prediction, confidence,
       index)

     - data: a _DataUtils.MLData.MLDataSet_

   
   **Note**: alterations are done in place in the _votes_ list

  N(   R   R    (   t   votesR@   R7   R]   R<   R=   R8   (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/ScreenComposite.pyt   _processVoteList6  s    c   	   	   C   s\  t  | d ƒ r | j s0 t  | d ƒ r\| j r\y |  j } Wn t k
 rP n� X| rj t d d d ƒn  t  | d ƒ r» | j r» t  | d ƒ r» | j r» t d ƒ t d ƒ t d ƒ n  t j | j	 ƒ  | d	 d ƒ\ } } t  | d
 ƒ r*| j
 d k r*| rt d d d ƒn  t j | | j | j
 d d | d d ƒ\ } } | | 7} | } q*nÎ t  | d ƒ r| j rt  | d
 ƒ r÷| j
 d k r÷| r«t d d d ƒn  t j | | j | j
 d d t | j	 ƒ  ƒ d d ƒ\ } } | j | ƒ n t | j	 ƒ  ƒ } g  } n t | j	 ƒ  ƒ } g  } t  | d ƒ rR| j rR| | } } n  | | f S(   Nt	   doHoldoutt
   doTrainingt   sR   i   R1   s'   *!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*sL   ******  WARNING: OOB screening should not be combined with doHoldout option.t   silentt
   filterFracg        t   fiÿÿÿÿt   indicesToUset   indicesOnly(   R"   Rr   Rs   t
   _splitFract   AttributeErrorR   R1   R   t   SplitIndicest   GetNPtsRv   R   t
   FilterDatat	   filterValR   t   extend(	   t   modelt   detailsR@   RN   t   splitFt   trainIdxt   testIdxt	   trainFiltt   temp(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/ScreenComposite.pyt   PrepareDataFromDetailsK  sN    

$
	c
   8      C   s˜  | d k rK t | d ƒ r< | j d | j d t j ƒ } qK | j ƒ  } n  | j d k rc d }
 n d }
 t |  ƒ t j	 t j
 g k r“ |  f }  n  t |  ƒ } | d k	 rÂ | | | j ƒ  ƒ n  t j | t j ƒ } t j | t j ƒ } t j | t j ƒ } t j | t j ƒ } t j | t j ƒ } t j | t j ƒ } d } | d k r[g  } n  | d k rpg  } n  | d k r…g  } n  |	 d k r¡d g | }	 n  i  } i  } x't | ƒ D]} | d k rág  } g  } g  } n  |  | } y | j } Wn t k
 rn Xt j | ƒ t | d ƒ r1| j sIt | d ƒ r’| j r’t | d ƒ rj| j rjt } n t } t } t j | d | d	 | ƒn t } t } t | d
 ƒ rÞ| j rÞ| rÞt d ƒ t d ƒ t d ƒ n  t | d ƒ r| j r| rt d ƒ t d ƒ t d ƒ n  t | | | ƒ \ } } | j ƒ  d } | rh| | | j ƒ  d „ } n d } t | d ƒ sˆ| j r‘d } n d } t  | | | | d | j d d d | d | d | d | d | d | ƒ\ } }  }! }" }# }$ }% | d k rt j |% j! t j ƒ } n  t | d ƒ rS| j" rSx‹ | D]ƒ \ }& }' }( }) | |) }* t | d ƒ r¤| j# d k r¤|& | j# k r¾| j$ |* d ƒ d | |* <q¾q;| j$ |* d ƒ d | |* <q;WxŽ | D]ƒ \ }& }' }( }) | |) }* t | d ƒ r2| j# d k r2|& | j# k rL| j$ |* d ƒ d | |* <qLqÉ| j$ |* d ƒ d | |* <qÉWn  | |% 7} | | | <|  | | <|! | | <|" | | <|# | | <|$ | | <t | d ƒ rº| j# d k rºt% |% d | j# ƒ|	 | <qºqºW| d k rü| |  |! |" |# |$ |% f S| | :} t& | ƒ | }+ t j' t& | |+ d ƒ | d ƒ }, t j( | ƒ d }- t& | ƒ | }. t j' t& | |. d ƒ | d ƒ }/ t& | ƒ | }0 t j' t& | |0 d ƒ | d ƒ }1 t& | ƒ | }2 t j' t& | |2 d ƒ | d ƒ }3 t& | ƒ | }4 t j' t& | |4 d ƒ | d ƒ }5 t& | ƒ | }6 t j' t& | |6 d ƒ | d ƒ }7 |. |/ f |+ |, f |0 |1 f |4 |5 f |2 |3 f |6 |7 f | f Sd S(   sZ    Screens a set of data using a a _CompositeRun.CompositeRun_
       instance to provide parameters

# DOC

    The actual data to be used are extracted from the database and
    table specified in _details_

    Aside from dataset construction,  _ShowVoteResults()_ does most of
    the heavy lifting here.

  **Arguments**

      - model: a composite model
      
      - details:  a _CompositeRun.CompositeRun_ object containing details
        (options, parameters, etc.) about the run

      - callback: (optional)  if provided, this should be a function
        taking a single argument that is called after each example is
        screened with the number of examples screened so far as the
        argument.

      - setup: (optional) a function taking a single argument which is
        called at the start of screening with the number of points to
        be screened as the argument.
         
      - appendExamples: (optional)  this value is passed on to the
        composite's _ClassifyExample()_ method.

      - goodVotes,badVotes,noVotes: (optional)  if provided these should
        be lists (or anything supporting an _append()_ method) which
        will be used to pass the screening results back.


  **Returns**

    a 7-tuple:

      1) the number of good (correct) predictions

      2) the number of bad (incorrect) predictions

      3) the number of predictions skipped due to the _threshold_

      4) the average confidence in the good predictions

      5) the average confidence in the bad predictions

      6) the average confidence in the skipped predictions

      7) the results table

  t	   pickleColt   pickleClassg        i   i    t   shuffleActivitiest   randomActivitiest   shufflet
   runDetailst   _shuffleActivitiess'   *!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*sD   ******  WARNING: Shuffled model being screened with unshuffled data.t   _randomizeActivitiessB   ******  WARNING: Random model being screened with non-random data.c         S   s   | |  | ƒ S(   N(    (   RT   t   yt   z(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/ScreenComposite.pyt   <lambda>  s    R1   iÿÿÿÿRN   R/   R0   RC   RD   RE   t   errorAnalysist	   enrichTgtR   i   N()   R&   R"   t
   GetDataSetR‰   R   t   ExplicitBitVectRA   R#   R$   t   ListTypet	   TupleTypeR    R}   RH   RJ   R   R   t   _randomSeedR{   R   t   InitRandomNumbersR‹   RŒ   t   Truet   Falset   RandomizeActivitiesR�   R   R�   Rˆ   t   GetQuantBoundsR1   Rc   R   R”   R•   R'   R   R   t   sqrtt   argsort(8   t   modelsR‚   R/   t   setupR0   RC   RD   RE   R@   t   enrichmentsRd   t   nModelsRQ   RP   RS   t   confGoodt   confBadt   confSkipR\   t   badVoteDictt
   noVoteDictR7   R�   t   seedR�   t	   randomizeR„   R…   t	   nPossiblet   cbR1   t   gt   bRt   t   aGt   aBt   aSt   vTt   at   pt   cR8   t   labelt   avgNBadt   devNBadt   bestIdxt   avgNGoodt   devNGoodt   avgNSkipt   devNSkipt
   avgConfBadt
   devConfBadt   avgConfGoodt   devConfGoodt   avgConfSkipt   devConfSkip(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/ScreenComposite.pyt   ScreenFromDetails{  sð    9					
	
	

	

	
 
 !






 
%%%%%%c         C   sÄ  t  s
 d  Sy$ t |  ƒ t | ƒ t | ƒ } WnO t k
 r |  d }  | d } | d } t |  ƒ t | ƒ t | ƒ } n X| sŠ d  Sd	 } d
 } d } t |  ƒ | } t | ƒ | }	 t | ƒ | }
 | d  k rá d } n  t j d | d ƒ } t j | ƒ } d d | d d | d d f } d } t | | d ƒ } | j	 | | | d | ƒ| } t | |	 d ƒ } | j	 | | | d | ƒ| } t | |
 d ƒ } | j	 | | | d | ƒ| S(   Ni    id   iÿ   t   RGBi   i¦ÿÿÿih  t   fill(   id   id   iÿ   (   iÿ   id   id   (   iÿ   iÿ   id   (   id   id   (   iÿ   iÿ   iÿ   (
   t   hasPilR&   R   t	   TypeErrorR   t   newR   t   DrawRK   t   pieslice(   RQ   RP   t   nRejt   sizet   nTott	   goodColort   badColort   rejColort   pctGoodt   pctBadt   pctRejt   imgt   drawt   boxt   startPt   endP(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/ScreenComposite.pyt   GetScreenImageL  s@    $


$	"t   .c         C   s¯  t  |  ƒ t j k r d } n d } | rC d g } | j d ƒ n g  } | j d ƒ |	 s¼ t |  | | ƒ } | r¼ | r’ d j | d f ƒ } n d } | j | ƒ | j d | ƒ q¼ n  t | ƒ } t j	 | d ƒ } t j	 | d ƒ } t j
 | t j ƒ } t j
 | t j ƒ } xr t | ƒ D]d } | | rXt | | | f ƒ | | | | <n  | | r#t | | | f ƒ | | | | <q#q#W| j d	 ƒ | j d
 ƒ x% t | ƒ D] } | j d | ƒ q²W| j d ƒ | j d ƒ xt | ƒ D]} | j d | ƒ x¡ t | ƒ D]“ } | | k rl| sN| j d | | | f ƒ q«| j d | | | f ƒ q| s�| j d | | | f ƒ q| j d | | | f ƒ qW| j d d | | ƒ | d k rè| j d | ƒ qô| j d ƒ qôW| j d ƒ x- t | ƒ D] } | j d d | | ƒ qW| j d ƒ | j d | ƒ | j d ƒ | s–| |  | } | |  } | rœd t | ƒ | } n d } | j d | |  | | f ƒ | d k r3d t | ƒ |  | | } | j d | | | f ƒ d t | ƒ | } | j d | | | f ƒ n  |  d k rS| j d | ƒ n  | d k rs| j d | ƒ n  | d k rc| j d  | ƒ qcnÍ| d |  d | d } | d |  d } | d |  d } | rd t | d ƒ | } d t | d ƒ | } n d } d } | j d! | d | d | | | | f ƒ | d k rd t | d ƒ | } d t | d ƒ | } | j d" | d | d | | | f ƒ d t | d ƒ | } d t | d ƒ | } | j d# | d | d | | | f ƒ n  |  d k r#| j d$ | ƒ n  | d k rC| j d% | ƒ n  | d k rc| j d& | ƒ n  | j d' ƒ |
 rŒd( } | j | ƒ n  | r¢| j d) ƒ n  d* j | ƒ S(+   s   returns the text of a web page showing the screening details
#DOC
    **Arguments**

     - nGood: number of correct predictions

     - nBad:  number of incorrect predictions

     - nRej:  number of rejected predictions

     - avgGood: average correct confidence

     - avgBad:  average incorrect confidence

     - avgSkip: average rejected confidence

     - voteTable: vote table

     - imgDir: (optional) the directory to be used to hold the vote
       image (if constructed)

   **Returns**

     a string containing HTML

  i   i    s   <html><body>s&   <center><h2>VOTE DETAILS</h2></center>s   <font>t   /s	   votes.pngs   <center><img src="%s"></center>s   <center><table border=1>s   <tr><td></td>s   <th>%d</th>s   <th>% Accurate</th>s   </tr>s   <tr><th>%d</th>s   <td bgcolor="#A0A0FF">%d</td>s   <td bgcolor="#A0A0FF">%.2f</td>s   <td>%d</td>s   <td>%.2f</td>s   <td>%4.2f</td</tr>g      Y@s"   <th rowspan=%d>Predicted</th></tr>s   <tr><th>% Pure</th>s   <td>%4.2f</td>s)   <tr><td></td><th colspan=%d>Original</th>s   </table></center>g        s1   <p>%d of %d examples were misclassified (%%%4.2f)s.   <p>                %d of %d overall: (%%%4.2f)s,   <p>%d of %d examples were rejected (%%%4.2f)sG   <p>The correctly classified examples had an average confidence of %6.4fsI   <p>The incorrectly classified examples had an average confidence of %6.4fs;   <p>The rejected examples had an average confidence of %6.4fsH   <p>%.2f(%.2f) of %.2f(%.2f) examples were misclassified (%%%4.2f(%4.2f))s=   <p>                %.2f(%.2f) of %d overall: (%%%4.2f(%4.2f))s;   <p>%.2f(%.2f) of %d examples were rejected (%%%4.2f(%4.2f))sM   <p>The correctly classified examples had an average confidence of %6.4f(%.4f)sO   <p>The incorrectly classified examples had an average confidence of %6.4f(%.4f)sA   <p>The rejected examples had an average confidence of %6.4f(%.4f)s   </font>s	  
    <p><b>Definitions:</b>
    <ul>
    <li> <i>% Pure:</i>  The percentage of, for example, known positives predicted to be positive.
    <li> <i>% Accurate:</i>  The percentage of, for example, predicted positives that actually
      are positive.
    </ul>
    s   </body></html>s   
(   R#   R$   R™   R(   RÜ   t   joint   saveR    RH   R   RJ   R   R   t   xrange(   RQ   RP   RÎ   R[   RX   RV   t	   voteTablet   imgDirt   fullPaget   skipImgt   includeDefst
   multModelst   outTxtR×   t   imgFileNamet   nPosst
   pureCountst	   accCountst   pureVectt   accVectR7   R2   t   nTotalt   nClasst   pctErrRÖ   t   devClasst	   devPctErrt	   devPctRejt   txt(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/ScreenComposite.pyt   ScreenToHtmlt  sÌ    		
%
)
	"		"c   &      C   sâ  t  |  d ƒ s |  j r d S| r1 t d ƒ n  t |  j d ƒ } t d |  j d ƒ }	 g  | D] }
 | |
 | ^ q` } t |  j |  j d |  j d |  j ƒ} | j	 ƒ  } | | } t  |  d ƒ sã |  j
 sã |  j
 |  j k rì | } n' t |  j |  j
 d |  j d |  j ƒ} | r&t d	 ƒ n  g  } t | d
 ƒ t d ƒ t d ƒ g k rvg  | D] }
 t |
 ƒ ^ q[} n  t j g t | ƒ } t  |  d ƒ r°|  j r°|  j } n | j	 ƒ  d } d | d j | ƒ f } | j d d | | f d | d | ƒ } | rt d ƒ n  d g t | ƒ } x3 | D]+ } | \ } } | j | ƒ } | | | <q.W| j d | ƒ xf | D]^ \ } } } } | | } | d k r¬t | ƒ } n d
 } | j d | | | | | f ƒ quWxf | D]^ \ } } } } | | } | d k rt | ƒ } n d
 } | j d | | | | | f ƒ qÞW| j ƒ  t  |  d ƒ sd|  j rm| } n
 d | } | j d d ƒ } d t | f } |	 j | ƒ g  } xe t | ƒ D]W }  t  |  d ƒ sÙ|  j rö| j d |  j |  f ƒ q¹| j d |  j |  f ƒ q¹W|	 j d  d j | ƒ ƒ d! }! |	 j |! ƒ |	 j ƒ  t  |  d" ƒ rÞ|  j rÞyX d d l }" d d# l m }# |# ƒ  }$ |$ d$ |" j  ƒ  ƒ |$ d% |  j ƒ t! d& ƒ WqÞd d l" }% |% j# ƒ  qÞXn  d S('   s¥  

  **Arguments**

    - details:  a CompositeRun.RunDetails object

    - indices: a sequence of integer indices into _data_

    - data: the data set in question.  We assume that the ids for
      the data points are in the _idCol_ column

    - goodVotes/badVotes: predictions where the model was correct/incorrect.
      These are sequences of 4-tuples:
        (answer,prediction,confidence,index into _indices_)

  t   predPlotNs*   
-> Constructing Prediction (Hanneke) Plots   w+s   %s.gnut   usert   passwordt   predActTables   	-> Pulling Activity Datai    RG   u    t
   predActColiÿÿÿÿs
   %s in (%s)t   ,t   fieldss   %s,%st   wheret   extrass   	-> Creating Plots   #ID Pred Conf %s
R&   s   %s %d %.4f %f
t   predLogScales   log(%s)t   _t    sð   # Generated by ScreenComposite.py version: %s
  set size square 0.7
  set yrange [:1]
  set data styl points
  set ylab 'confidence'
  set xlab '%s'
  set grid
  set nokey
  set term postscript enh color solid "Helvetica" 16
  set term X
  s   '%s' us 4:($2==%d?$3:0/0)s#   '%s' us (log10($4)):($2==%d?$3:0/0)s   plot %s
s   
  # EOF
  t   predShow(   t   Gnuplots   cd "%s"s   load "%s.gnu"s   press return to continue...
($   R"   R÷   R   t   openR   t   dbNamet	   tableNamet   dbUsert
   dbPasswordt   GetColumnNamesRú   R#   t   strR   t   placeHolderR    Rû   Rß   t   GetDataR&   t   indexR   R   t   closeR   t   replacet   __VERSION_STRINGR   R(   R  t   osR  t   getcwdt	   raw_inputt	   tracebackt	   print_exc(&   R‚   R,   R@   RC   RD   t   nRest   idColRN   t   outFt   gnuFRT   t   ptIdst   origConnt   colNamest   idNamet   actConnt   ptst   whereLt
   actColNamet   whereTxtt   rawDt   actsRb   t   idt   actR8   R]   R<   R=   t   actLabelt   gnuHdrt   plotsR7   t   gnuTailR  R  R¶   R  (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/ScreenComposite.pyt   MakePredPlot  s˜     !

	 (" 
%
%
	

	c         C   s   d  S(   N(    (   R‚   (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/ScreenComposite.pyt   Go‘  s    c         C   sh   |  d  k r t }  n  t j |  ƒ d g |  _ d |  _ d |  _ d |  _ d |  _ d |  _	 d |  _
 |  S(   Ng        i    (   R&   t   _detailsR   t   SetDefaultst   screenVoteTolt   detailedScreenRr   Rs   R”   RN   Rd   (   R‚   (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/ScreenComposite.pyR/  ”  s    							c           C   s   t  GHt j d ƒ d S(   s\    prints a list of arguments for when this is used from the
  command line and then exits

  iÿÿÿÿN(   t   __doc__R	   t   exit(    (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/ScreenComposite.pyt   Usage¢  s    c         C   s8   d t  GH|  r4 d d l } d GHd j | j ƒ GHn  d S(   s-    prints the version number of the program

  s%   This is ScreenComposite.py version %siÿÿÿÿNs   command line was:R  (   R  R	   Rß   t   argv(   t   includeArgsR	   (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/ScreenComposite.pyt   ShowVersionª  s
    	c         C   sñ  d d  l  } y> | j  t j d d d d d d d d	 d
 d g ƒ \ } } Wn$ d d  l } | j ƒ  t ƒ  n Xd } d |  _ d |  _ d |  _ d |  _	 d |  _
 d |  _ d |  _ d |  _ x| D]\ } } | d k rê | |  _ qÆ | d k rd |  _ qÆ | d k r¢d |  _ t | ƒ } t | ƒ t g  ƒ t d& ƒ g k rS| g } n  x@ | D]8 }	 |	 d k sx|	 d k  rZt d ƒ t j d ƒ qZqZW| |  _ qÆ | d k rº| |  _ qÆ | d k rÛd |  _ d |  _ qÆ | d k rüd |  _ d |  _ qÆ | d k rd |  _ d |  _ qÆ | d k r>d |  _ d |  _ qÆ | d k rVd |  _ qÆ | d k rnd |  _ qÆ | d k r„t ƒ  qÆ | d k r¢t | ƒ |  _ qÆ | d k rÀt | ƒ |  _ qÆ | d k rÕd }
 qÆ | d k röd |  _ | |  _ qÆ | d k r| |  _ qÆ | d  k r&| |  _ qÆ | d! k r>d |  _	 qÆ | d" k rVd |  _
 qÆ | d" k rnd |  _
 qÆ | d# k r†d |  _ qÆ | d$ k r¨t  | ƒ d |  _ qÆ | d% k rÆt  | ƒ |  _ qÆ t ƒ  qÆ Wt! | ƒ d k  rít ƒ  n  | S('   Niÿÿÿÿi   s   EDd:t:VN:HThSRF:v:AXs	   predPlot=s   predActCol=s   predActTable=R   R  t   OOBs
   pickleCol=s   enrich=RG   i    s   -ds   -Ds   -ts(   Voting threshold must be between 0 and 1iþÿÿÿs   -Ns   -Hs   -Ts   -Es   -As   -Ss   -Rs   -hs   -Fs   -vs   -Vs
   --predPlots   --predActCols   --predActTables   --predLogScales
   --predShows   --OOBs   --pickleCols   --enrich(   i   i   ("   t   getoptR	   R5  R  R  R4  R÷   Rû   Rú   R   R  R1   R‰   R•   R  R1  Rd   t   evalR#   R   R3  R0  t   noteRs   Rr   R”   t   showAllR‹   RŒ   R   Rv   R   RK   R    (   R‚   R9  t   argsRÿ   R  t   fNamet   argt   valRe   t   tolRN   (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/ScreenComposite.pyt	   ParseArgs´  s¦    	
									$
				
		
t   __main__R6  s"   -> Retrieving models from databaseRý   R�   Rþ   s   where note='%s's   Model load faileds   -> Loading modelt   rbs   No composite models founds   -> Working with %d models.RG   R‰   RŠ   s'   -> Constructing and screening data setsR   R�   RŽ   R�   s'   *!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*sD   ******  WARNING: Shuffled model being screened with unshuffled data.R�   sB   ******  WARNING: Random model being screened with non-random data.RN   R1   sC   
-----*****-----*****-----*****-----*****-----*****-----*****-----
s   Tolerance: %fRB   R<  R÷   RD   RE   RC   R•   R   s1   -v-v-v-v-v-v-v-    All Votes      -v-v-v-v-v-v-v-s>   id, prediction, confidence, flag(-1=skipped,0=wrong,1=correct)s   bad point?: %s != %ss   %s, %d, %.4f, 1s   %s, %d, %.4f, 0s   %s, %d, %.4f, -1s    -^-^-^-^-^-^-^-  -^-^-^-^-^-^-^-s0   -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*s	   AVERAGES:i   s9   Misclassifications: 	%%%5.2f(%%%5.2f)   %4.1f(%4.1f) / %did   s1   	threshold: 	%%%5.2f(%%%5.2f)   %4.1f(%4.1f) / %ds0   Number Skipped: %%%4.2f(%%%4.2f)    %4.2f(%4.2f)s   Confidences:s   	Correct: 	%4.2f(%4.2f)s   	Incorrect: 	%4.2f(%4.2f)s   	Skipped: 	%4.2f(%4.2f)s   Results Table:s       s    % 6.2fs        | % 4.2fg      Y@s   -------s&      Enrichment of value %d: %.4f (%.4f)s0   ------------------------------------------------s   Best Model: s&   Misclassifications: 	%%%5.2f   %d / %ds   	threshold: 	%%%5.2f   %d / %ds   Number Skipped: %%%4.2f    %ds   	Correct: 	%4.2fs   	Incorrect: 	%4.2fs   	Skipped: 	%4.2fs2   
*-*-*-*-*-*-*-*- ERROR ANALYSIS -*-*-*-*-*-*-*-*
s    ---> Bad Vote Countss    ---> Skipped Compound Countss   %s,%ds    ---> Good Vote Counts(µ   R2  t   rdkitR    R   R	   t   cPickleR$   t   copyRH   t   PILR   R   t   ImportErrorRÉ   t   rdkit.ML.DataR   R   t   rdkit.MLR   t   rdkit.Dbase.DbConnectionR   t   rdkit.DbaseR   R.  R  R   R   R   R&   R?   RF   Rc   Ro   Rq   Rˆ   RÆ   RÜ   Rö   R,  R-  R/  R4  R7  RB  t   __name__R‚   Rÿ   R¢   R;  R  t   tblNamet   connR  t   blobst   blobR(   t   loadsR  R  R  R  t	   modelFilet   loadR    R3  R>  R  R–   R‰   R—   R@   t   BuildDataSett   GetVarNamest	   descNamesR¥   RB   t   dataSetsR   R}   R…   R„   t   modelIdxt   tmpDR�   Rš   R«   R{   R›   R‹   RŒ   R�   R¬   Rž   R�   R"   R�   R�   R1   R0  RA  RJ   R   RQ   RP   RS   R¦   R§   R¨   R•   R¤   t   goodVoteDictR©   Rª   R\   t   SetInputOrdert	   screenResR1  Rd   RN   R¯   R°   Rt   R±   R²   R³   R´   R*   R  RŸ   RD   RE   R<  R÷   RC   R   R”   Rµ   R¶   R·   R8   R¸   R'   R]   R<   R=   t   ptt   AssertionErrorR   R¹   R    Rº   R¡   R»   R¼   R½   R¾   R¿   RÀ   RÁ   RÂ   RÃ   RÄ   RÅ   RR   RO   RL   RM   R_   R`   R7   Ra   R2   Rb   t   meant   devt   bestBadt   bestGoodt   bestSkipt   keyst   kst   k(    (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/ML/ScreenComposite.pyt   <module>n   sª  0
	I=		‘p	0	Ï(¥w		
	Z	


 



	

	
	

	





	*		!	
 
 !
 !
!"# # # 




%%%%%%

			
 

(
 .

!#







 

(
 .	


,

