<commit_before>#!/usr/bin/python2.4
# encoding: utf-8
"""
dbapi.py
High-level functions for interacting with the ddG database.

Created by <NAME> 2012.
Copyright (c) 2012 __UCSF__. All rights reserved.
"""

import os
import string
import re
import shutil
import glob
import traceback
import pickle
import md5
import random
import datetime
import zipfile

try:
    import matplotlib
    # A non-interactive backend to generate PNGs. matplotlib.use('PS') is used for PS files. If used, this command must be run before importing matplotlib.pyplot.
    matplotlib.use("AGG")
    import matplotlib.pyplot as plt
    import textwrap
except ImportError:
    plt=None


import score
import ddgdbapi
from tools.bio.pdb import PDB
from tools.bio.basics import residue_type_3to1_map as aa1
from tools.bio.basics import Mutation
from tools.bio.alignment import ScaffoldModelChainMapper
#from Bio.PDB import *
from tools.fs.io import write_file, read_file
from tools.process import Popen
from tools.constants import rosetta_weights
from tools import colortext
#import analysis
#from ddgfilters import PredictionResultSet, ExperimentResultSet, StructureResultSet

#todo: dbfields = ddgdbapi.FieldNames()

class MutationSet(object):
    def __init__(self):
        self.mutations = []

    def addMutation(self, chainID, residueID, wildtypeAA, mutantAA):
        self.mutations.append((chainID, residueID, wildtypeAA, mutantAA))

    def getChains(self):
        return sorted(list(set([m[0] for m in self.mutations])))


class ddG(object):
    '''This class is responsible for inserting prediction jobs to the database.'''

    def __init__(self, passwd = None, username = 'kortemmelab'):
        self.ddGDB = ddgdbapi.ddGDatabase(passwd = <PASSWORD>, username = username)
        self.ddGDataDB = ddgdbapi.ddGPredictionDataDatabase(passwd = <PASSWORD>, username = username)
        self.prediction_data_path = self.ddGDB.execute('SELECT Value FROM _DBCONSTANTS WHERE VariableName="PredictionDataPath"')[0]['Value']

    def __del__(self):
        pass
        #self.ddGDB.close()
        #self.ddGDataDB.close()

    def _createResfile(self, pdb, mutations):
        '''The mutations here are in the original PDB numbering. pdb is assumed to use Rosetta numbering.
            We use the pdb mapping from PDB numbering to Rosetta numbering to generate the resfile.
        '''
        resfile = []
        for mutation in mutations:
            chain = mutation[0]
            resid = mutation[1]<commit_msg>Removing prediction database.<commit_after>#!/usr/bin/python2.4
# encoding: utf-8
"""
dbapi.py
High-level functions for interacting with the ddG database.

Created by <NAME> 2012.
Copyright (c) 2012 __UCSF__. All rights reserved.
"""

import os
import string
import re
import shutil
import glob
import traceback
import pickle
import md5
import random
import datetime
import zipfile

try:
    import matplotlib
    # A non-interactive backend to generate PNGs. matplotlib.use('PS') is used for PS files. If used, this command must be run before importing matplotlib.pyplot.
    matplotlib.use("AGG")
    import matplotlib.pyplot as plt
    import textwrap
except ImportError:
    plt=None


import score
import ddgdbapi
from tools.bio.pdb import PDB
from tools.bio.basics import residue_type_3to1_map as aa1
from tools.bio.basics import Mutation
from tools.bio.alignment import ScaffoldModelChainMapper
#from Bio.PDB import *
from tools.fs.io import write_file, read_file
from tools.process import Popen
from tools.constants import rosetta_weights
from tools import colortext
#import analysis
#from ddgfilters import PredictionResultSet, ExperimentResultSet, StructureResultSet

#todo: dbfields = ddgdbapi.FieldNames()

class MutationSet(object):
    def __init__(self):
        self.mutations = []

    def addMutation(self, chainID, residueID, wildtypeAA, mutantAA):
        self.mutations.append((chainID, residueID, wildtypeAA, mutantAA))

    def getChains(self):
        return sorted(list(set([m[0] for m in self.mutations])))


class ddG(object):
    '''This class is responsible for inserting prediction jobs to the database.'''

    def __init__(self, passwd = None, username = 'kortemmelab'):
        self.ddGDB = ddgdbapi.ddGDatabase(passwd = passwd, username = username)
        self.prediction_data_path = self.ddGDB.execute('SELECT Value FROM _DBCONSTANTS WHERE VariableName="PredictionDataPath"')[0]['Value']

    def __del__(self):
        pass
        #self.ddGDB.close()
        #self.ddGDataDB.close()

    def _createResfile(self, pdb, mutations):
        '''The mutations here are in the original PDB numbering. pdb is assumed to use Rosetta numbering.
            We use the pdb mapping from PDB numbering to Rosetta numbering to generate the resfile.
        '''
        resfile = []
        for mutation in mutations:
            chain = mutation[0]
            resid = mutation[1]
{'fraction_non_alphanumeric': 0.0826530612244898, 'fraction_numerical': 0.007755102040816327, 'mean_word_length': 3.776803118908382, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5114176', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1455, 'n_words': 478}