<commit_before>#Author : <NAME> <EMAIL>
#Supervisor : Dr. A. Bender
#All rights reserved 2014
#Protein Target Prediction Tool trained on SARs from PubChem (Mined 08/04/14) and ChEMBL18
#Molecular Descriptors : 2048bit Morgan Binary Fingerprints (Rdkit) - ECFP4
#Dependencies : rdkit, sklearn, numpy

#libraries
from rdkit import Chem
from rdkit.Chem import AllChem
from sklearn.naive_bayes import BernoulliNB
import cPickle
import glob
import os
import sys
import pymysql
import numpy as np
from multiprocessing import Pool
import multiprocessing
import getpass
multiprocessing.freeze_support()	# Allows entire job to die
N_cores = 25

def login():
    user = raw_input(" Enter Username for PIDGIN DB [%s]: " % getpass.getuser())
    if not user:
        user = getpass.getuser()

    pprompt = lambda: (getpass.getpass(), getpass.getpass(' Retype password: '))

    p1, p2 = pprompt()
    while p1 != p2:
        print(' Passwords do not match. Try again')
        p1, p2 = pprompt()
    samples = raw_input(" Enter Number of Samples: ")

    return user, p1, int(samples)

def introMessage():
	print '=============================================================================================='
	print ' Author: <NAME>\n Email:  <EMAIL>\n Supervisor: Dr. A. Bender.  Number of cores: ' + str(N_cores)
	print ' Address: Centre For Molecular Informatics, Dept. Chemistry, Lensfield Road, Cambridge CB2 1EW'
	print '==============================================================================================\n'
	return

#import user query
def importQuery(name):
	query = open(name).read().splitlines()
	matrix = []
	for q in query:
		matrix.append(calcFingerprints(q))
	matrix = np.array(matrix, dtype=np.uint8)
	return matrix
	
#calculate 2048bit morgan fingerprints, radius 2
def calcFingerprints(smiles):
	m1 = Chem.MolFromSmiles(smiles)
	fp = AllChem.GetMorganFingerprintAsBitVect(m1,2, nBits=2048)
	binary = fp.ToBitString()
	return list(binary)

#get names of uniprots
def getUpName():
	global u_name
	t_file = open('classes_in_model.txt').read().splitlines()
	t_file.pop(0)
	for t in t_file:
		t = t.split('\t')
		u_name[t[1]] = t[0]
	return

#import thresholds as specified by user	
def importThresholds():
	global thresholds
	global metric
	if metric == 'p':
		m = 1	
	if metric == 'f':
		m = 2
	if metric == 'r':
		m = 3	
	if metric == 'a':
		m = 4
	if metric == '0.5':
		m = 5
	t_file = open('thresholds.txt').read().splitlines()
	for t in t_file:
		t = t.split('\t')
		thresholds[t[0]] = float(t[m])
	return
	
def getRandomFP(needed):
	global usr, pw
    conn = pymysql.connect(db='pidgin', user=usr, passwd=pw, host='localhost', port=3306)
    cur = conn.cursor()
	#cur.execute("SELECT stdsmiles FROM compounds limit "+str(needed)+";")
	cur.execute("SELECT stdsmiles FROM compounds WHERE RAND(12)<(SELECT (("+str(needed)+"/COUNT(*))*10) FROM compounds) ORDER BY RAND(12) LIMIT "+str(needed)+";")
        #cur.execute("SELECT stdsmiles FROM compounds ORDER BY RAND(123) LIMIT "+str(needed)+";")
	smiles = cur.fetchall()
	print ' Number of BG mols : ' + str(len(smiles))
	return chunks(smiles, len(querymatrix))

#predict worker
def predict(x):
	global models
	mod, input = x
	results = dict()	
	hits = 0<commit_msg>remove error<commit_after>#Author : <NAME> <EMAIL>
#Supervisor : Dr. A. Bender
#All rights reserved 2014
#Protein Target Prediction Tool trained on SARs from PubChem (Mined 08/04/14) and ChEMBL18
#Molecular Descriptors : 2048bit Morgan Binary Fingerprints (Rdkit) - ECFP4
#Dependencies : rdkit, sklearn, numpy

#libraries
from rdkit import Chem
from rdkit.Chem import AllChem
from sklearn.naive_bayes import BernoulliNB
import cPickle
import glob
import os
import sys
import pymysql
import numpy as np
from multiprocessing import Pool
import multiprocessing
import getpass
multiprocessing.freeze_support()	# Allows entire job to die
N_cores = 25

def login():
    user = raw_input(" Enter Username for PIDGIN DB [%s]: " % getpass.getuser())
    if not user:
        user = getpass.getuser()

    pprompt = lambda: (getpass.getpass(), getpass.getpass(' Retype password: '))

    p1, p2 = pprompt()
    while p1 != p2:
        print(' Passwords do not match. Try again')
        p1, p2 = pprompt()
    samples = raw_input(" Enter Number of Samples: ")

    return user, p1, int(samples)

def introMessage():
	print '=============================================================================================='
	print ' Author: <NAME>\n Email:  <EMAIL>\n Supervisor: Dr. A. Bender.  Number of cores: ' + str(N_cores)
	print ' Address: Centre For Molecular Informatics, Dept. Chemistry, Lensfield Road, Cambridge CB2 1EW'
	print '==============================================================================================\n'
	return

#import user query
def importQuery(name):
	query = open(name).read().splitlines()
	matrix = []
	for q in query:
		matrix.append(calcFingerprints(q))
	matrix = np.array(matrix, dtype=np.uint8)
	return matrix
	
#calculate 2048bit morgan fingerprints, radius 2
def calcFingerprints(smiles):
	m1 = Chem.MolFromSmiles(smiles)
	fp = AllChem.GetMorganFingerprintAsBitVect(m1,2, nBits=2048)
	binary = fp.ToBitString()
	return list(binary)

#get names of uniprots
def getUpName():
	global u_name
	t_file = open('classes_in_model.txt').read().splitlines()
	t_file.pop(0)
	for t in t_file:
		t = t.split('\t')
		u_name[t[1]] = t[0]
	return

#import thresholds as specified by user	
def importThresholds():
	global thresholds
	global metric
	if metric == 'p':
		m = 1	
	if metric == 'f':
		m = 2
	if metric == 'r':
		m = 3	
	if metric == 'a':
		m = 4
	if metric == '0.5':
		m = 5
	t_file = open('thresholds.txt').read().splitlines()
	for t in t_file:
		t = t.split('\t')
		thresholds[t[0]] = float(t[m])
	return
	
def getRandomFP(needed):
	global usr, pw
	conn = pymysql.connect(db='pidgin', user=usr, passwd=pw, host='localhost', port=3306)
	cur = conn.cursor()
	#cur.execute("SELECT stdsmiles FROM compounds limit "+str(needed)+";")
	cur.execute("SELECT stdsmiles FROM compounds WHERE RAND(12)<(SELECT (("+str(needed)+"/COUNT(*))*10) FROM compounds) ORDER BY RAND(12) LIMIT "+str(needed)+";")
        #cur.execute("SELECT stdsmiles FROM compounds ORDER BY RAND(123) LIMIT "+str(needed)+";")
	smiles = cur.fetchall()
	print ' Number of BG mols : ' + str(len(smiles))
	return chunks(smiles, len(querymatrix))

#predict worker
def predict(x):
	global models
	mod, input = x
	results = dict()	
	hits = 0
{'fraction_non_alphanumeric': 0.18001549186676993, 'fraction_numerical': 0.020449264136328426, 'mean_word_length': 4.613913043478261, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6409145', 'n_tokens_mistral': 2374, 'n_tokens_neox': 2165, 'n_words': 656}