Ejemplo n.º 1
0
def regenerate_mutfile(PredictionID):
    '''I needed to write this function as I forgot to add a *.mutfile mask to the ProtocolCleaner at first so mutfiles were not kept.'''
    raise Exception("We should never need to call this")

    KeepHETATMLines = False

    results = ddGdb.execute_select("SELECT ExperimentID, UserDataSetExperimentID FROM Prediction WHERE ID=%s", parameters = (PredictionID,))
    assert(len(results) == 1)
    ExperimentID = results[0]['ExperimentID']
    UserDataSetExperimentID = results[0]['UserDataSetExperimentID']

    results = ddGdb.execute_select("SELECT PDBFileID FROM UserDataSetExperiment WHERE ID=%s", parameters = (UserDataSetExperimentID,))
    assert(len(results) == 1)
    PDB_ID = results[0]['PDBFileID']

    results = ddGdb.execute_select("SELECT PDBFileID, Content FROM Experiment INNER JOIN PDBFile WHERE Experiment.PDBFileID=PDBFile.ID AND Experiment.ID=%s", parameters = (ExperimentID,))
    assert(len(results) == 1)
    experimentPDB_ID = results[0]["PDBFileID"]

    results = ddGdb.execute_select("SELECT ID, Content FROM PDBFile WHERE ID=%s", parameters=(PDB_ID))
    if len(results) != 1:
        raise colortext.Exception("The SQL query '%s' returned %d results where 1 result was expected." % (sql, len(results)))
    predictionPDB_ID = results[0]["ID"]

    # Get the related PDB ID and file
    assert(len(results) == 1)
    result = results[0]
    pdbID = result["ID"]
    contents = result["Content"]

    pdb = PDB(contents.split("\n"))

    # Check that the mutated positions exist and that the wild-type matches the PDB
    mutations = ddGdb.call_select_proc("GetMutations", parameters = (ExperimentID,))

    # todo: Hack. This should be removed when PDB homologs are dealt with properly.
    for mutation in mutations:
        if experimentPDB_ID == "1AJ3" and predictionPDB_ID == "1U5P":
            assert(int(mutation['ResidueID']) < 1000)
            mutation['ResidueID'] = str(int(mutation['ResidueID']) + 1762)

    pdb.validate_mutations(mutations)

    # Strip the PDB to the list of chains. This also renumbers residues in the PDB for Rosetta.
    chains = [result['Chain'] for result in ddGdb.call_select_proc("GetChains", parameters = (ExperimentID,))]
    pdb.stripForDDG(chains, KeepHETATMLines, numberOfModels = 1)

    # - Post stripping checks -
    # Get the 'Chain ResidueID' PDB-formatted identifier for each mutation mapped to Rosetta numbering
    # then check again that the mutated positions exist and that the wild-type matches the PDB
    remappedMutations = pdb.remapMutations(mutations, pdbID)
    remappedMutations = [[m[0], PDB.ResidueID2String(m[1]), m[2], m[3]] for m in remappedMutations]

    #resfile = self._createResfile(pdb, remappedMutations)
    return( _createMutfile(pdb, remappedMutations))