Skip to content

Commit

Permalink
changes for the release
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertCS committed May 31, 2024
1 parent ae29e21 commit d07c1d8
Show file tree
Hide file tree
Showing 30 changed files with 650 additions and 244 deletions.
16 changes: 12 additions & 4 deletions EAPM/EAPM.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,21 @@ def createPlugin():

eapmPlugin.addBlock(epPredBlock)

from Blocks.testBlock import testBlock # type: ignore
# from Blocks.testBlock import testBlock # type: ignore

eapmPlugin.addBlock(testBlock)
# eapmPlugin.addBlock(testBlock)

from Blocks.AnalyseGlideGPX import AnalyseGPXBlock # type: ignore
from Blocks.AnalyseGlide import AnalyseGBlock # type: ignore

eapmPlugin.addBlock(AnalyseGPXBlock)
eapmPlugin.addBlock(AnalyseGBlock)

# from Blocks.Rbcavity import rbCavityBlock # type: ignore

# eapmPlugin.addBlock(rbCavityBlock)

# from Blocks.Rbdock import rbDockBlock # type: ignore

# eapmPlugin.addBlock(rbDockBlock)

# Add the configs
from Configs.mafftConfig import mafftExecutableConfig # type: ignore
Expand Down
8 changes: 4 additions & 4 deletions EAPM/Include/Blocks/Ahatool.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import datetime
import os
import subprocess

from HorusAPI import PluginBlock, PluginVariable, VariableList, VariableTypes

# TODO Add to the documentation
Expand Down Expand Up @@ -85,6 +81,10 @@

def initialAction(block: PluginBlock):

import datetime
import os
import subprocess

container_name = block.inputs.get("container_name", "bsceapm/ahatool:2.2")
input_fasta = block.inputs.get("input_fasta", None)
fasta = os.path.basename(input_fasta)
Expand Down
18 changes: 11 additions & 7 deletions EAPM/Include/Blocks/AlignPdbEAPM.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,26 +124,30 @@ def initialAlign(block: PluginBlock):
alignmentMode = block.variables.get("alignment_mode", "aligned")
referenceResidues = block.variables.get("reference_residues", [])

import prepare_proteins

print("Loading PDB files...")

models = prepare_proteins.proteinModels(inputFolder)

# Parse the chain indexes
if chainIndexes is not None:
chainIndexes = [x["chain_index"] for x in chainIndexes]
else:
chainIndexes = [0]

trajectory_chain_indexes = None
# Parse the trajectory chain indexes
if trajectoryChainIndexes is not None:
trajectoryChainIndexes = [x["trajectory_chain_index"] for x in trajectoryChainIndexes]
trajectory_chain_indexes = {}
for i, model in enumerate(models.models_names):
trajectory_chain_indexes[model] = trajectoryChainIndexes[i]

# Parse the reference residues
if referenceResidues is not None:
referenceResidues = [x["reference_residues"] for x in referenceResidues]

import prepare_proteins

print("Loading PDB files...")

models = prepare_proteins.proteinModels(inputFolder)

print("Aligning models...")

import subprocess
Expand All @@ -163,7 +167,7 @@ def hookSubprocessMafft(command, **kwargs):
pdbReference,
outputFolder,
chain_indexes=chainIndexes,
trajectory_chain_indexes=trajectoryChainIndexes,
trajectory_chain_indexes=trajectory_chain_indexes,
aligment_mode=alignmentMode,
reference_residues=referenceResidues,
verbose=True,
Expand Down
6 changes: 4 additions & 2 deletions EAPM/Include/Blocks/AlphaFoldEAPM.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
Module containing the AlphaFold block for the EAPM plugin
"""

import os

from HorusAPI import PluginVariable, SlurmBlock, VariableTypes

# ==========================#
Expand Down Expand Up @@ -72,6 +70,8 @@ def initialAlphafold(block: SlurmBlock):
print("Alphafold requires an accelerated partition. Changing to acc_bscls.")
block.variables["partition"] = "acc_bscls"

import os

# If folder already exists, raise exception
if removeExisting and os.path.exists(folderName):
os.system("rm -rf " + folderName)
Expand Down Expand Up @@ -107,6 +107,8 @@ def finalAlhafoldAction(block: SlurmBlock):

resultsFolder = block.extraData["folder_name"]

import os

output_models_folder = os.path.join(downloaded_path, resultsFolder, "output_models")

block.setOutput(outputModelsVariable.id, output_models_folder)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
import json
import os
import shutil

import bsc_calculations
import pandas as pd
import prepare_proteins

from HorusAPI import PluginBlock, PluginVariable, VariableGroup, VariableTypes

# TODO Configure the inputs correctly
Expand All @@ -28,10 +20,16 @@
defaultValue=None,
)
residueProtein = PluginVariable(
name="Atom Protein", id="resi_id1", description="atom1", type=VariableTypes.ATOM
name="Atom Protein",
id="resi_id1",
description="Atom of the protein to calculate the distance to",
type=VariableTypes.ATOM,
)
residueLigand = PluginVariable(
name="Atom Ligand", id="resi_id2", description="atom2", type=VariableTypes.ATOM
name="Atom Ligand",
id="resi_id2",
description="Atom of the ligand to calculate the distance to",
type=VariableTypes.ATOM,
)
resNameProt = PluginVariable(
name="Protein residue name",
Expand All @@ -40,10 +38,10 @@
type=VariableTypes.STRING,
defaultValue="CYS",
)
resNameLig = PluginVariable(
name="Ligand residue name",
id="res_name_lig",
description="The ligand residue name",
atomNameProt = PluginVariable(
name="Protein atomname",
id="atom_name_prot",
description="The protein atom name",
type=VariableTypes.STRING,
defaultValue="SG",
)
Expand All @@ -54,12 +52,26 @@
type=VariableTypes.STRING,
defaultValue="GSH",
)
atomNameLig = PluginVariable(
name="Ligand atom name",
id="atom_name_ligand",
description="The atom name of the ligand",
type=VariableTypes.STRING,
defaultValue="S1",
)

stringGroup = VariableGroup(
id="string_input",
name="Input String",
description="The input are in string",
variables=[conservedResidues, glideOutputVariable, resNameProt, resNameLig, ligandName],
variables=[
conservedResidues,
glideOutputVariable,
resNameProt,
atomNameProt,
ligandName,
atomNameLig,
],
)
atomGroup = VariableGroup(
id="atom_input",
Expand All @@ -70,12 +82,18 @@

# Output variables
outputModelsVariable = PluginVariable(
id="models",
name="Alphafold models",
description="The output models",
id="best_poses",
name="Best poses",
description="The best poses from the analysis",
type=VariableTypes.FOLDER,
)

analyseGlideOutputVariable = PluginVariable(
id="glide_results_output",
name="Glide results output",
description="Output results of the Glide analysis",
type=VariableTypes.CUSTOM,
allowedValues=["glide_output"],
)

# ==========================#
# Variable
Expand All @@ -87,54 +105,85 @@
type=VariableTypes.STRING,
defaultValue="SG_S",
)
removePreviousVar = PluginVariable(
name="Remove previous models",
id="remove_previous",
description="Remove previous",
type=VariableTypes.BOOLEAN,
defaultValue=False,
)
separatorVar = PluginVariable(
name="Separator",
id="separator",
description="The separator",
type=VariableTypes.STRING,
defaultValue="@",
)


def finalAction(block: PluginBlock):

import prepare_proteins

bsc_result = block.inputs.get(glideOutputVariable.id, None)
folder_to_analyse = bsc_result["dock_folder"]
model_folder = bsc_result["model_folder"]

conserved_indexes = block.inputs.get(conservedResidues.id, None)

metrics = block.variables.get("metrics", "SG_S")
remove_previous = block.variables.get("remove_previous", False)
separator = block.variables.get("separator", "@")

if block.selectedInputGroup == stringGroup.id:
res_name_prot = block.inputs.get(resNameProt.id, "CYS")
res_name_lig = block.inputs.get(resNameLig.id, "SG")
atom_name_prot = block.inputs.get(atomNameProt.id, "SG")
ligand_name = block.inputs.get(ligandName.id, "GSH")
atom_name_lig = block.inputs.get(atomNameLig.id, "S1")
else:
residue_protein = block.inputs.get(residueProtein.id, None)
res_name_prot = residue_protein["auth_comp_id"]
atom_name_prot = residue_protein["auth_atom_id"]
residue_ligand = block.inputs.get(residueLigand.id, None)
ligand_name = residue_ligand["auth_comp_id"]
atom_name_lig = residue_ligand["auth_atom_id"]
metrics = f"{atom_name_prot}_{atom_name_lig}"

models = prepare_proteins.proteinModels(model_folder)

if conserved_indexes is None:
raise ValueError("Conserved residues must be provided")
if not isinstance(conserved_indexes, dict):
try:
conserved_indexes = int(conserved_indexes)
except ValueError:
raise ValueError("Conserved indexes must be an integer or a dictionary of integers")
conserved_indexes_f = {}
for model in models:
conserved_indexes_f[model] = [conserved_indexes]
conserved_indexes = conserved_indexes_f

center_atom = {} # Create dictionary to store the atom 3-element tuple for each model
for model in models: # Iterate the models inside the library
# Iterate the residues for each Bio.PDB.Structure object
for r in models.structures[model].get_residues():
# Check that the residue matches the defined index
aa = conserved_indexes[model]
# for cons_ind in conserved_indexes[model]:
if r.id[1] in conserved_indexes[model]:
# Assert that the residue has the correct residue identity
if r.resname == res_name_prot:
# Store the corresponsing tuple.
center_atom[model] = (r.get_parent().id, r.id[1], res_name_lig)
center_atom[model] = (r.get_parent().id, r.id[1], atom_name_prot)
break

print(f"center_atom: {center_atom}")

atom_pairs = {} # Define the dictionary containing the atom pairs for each model
for model in models:
atom_pairs[model] = {}
for ligand in [ligand_name]:
atom_pairs[model][ligand] = []
atom_pairs[model][ligand].append((center_atom[model], "S1"))
atom_pairs[model][ligand].append((center_atom[model], atom_name_lig))

print(f"Atom pairs: {atom_pairs}")

models.analyseDocking(folder_to_analyse, atom_pairs=atom_pairs)
models.analyseDocking(folder_to_analyse, atom_pairs=atom_pairs, separator=separator)

metric_distances = {} # Define the global dictionary
metric_distances[metrics] = {} # Define the metric nested dictionary
Expand All @@ -144,24 +193,38 @@ def finalAction(block: PluginBlock):
# Define the ligand nested dictionary with all the docking distances list
metric_distances[metrics][model][ligand] = models.getDockingDistances(model, ligand)

print(f"metric_distances: {metric_distances}")

models.combineDockingDistancesIntoMetrics(metric_distances)

print(f"models.docking_data: {models.docking_data}")

best_poses = models.getBestDockingPosesIteratively(metric_distances)

models.extractDockingPoses(best_poses, folder_to_analyse, "best_docking_poses", separator="@")
models.extractDockingPoses(
best_poses,
folder_to_analyse,
"best_docking_poses",
separator=separator,
remove_previous=remove_previous,
)

block.setOutput(outputModelsVariable.id, "best_docking_poses")

glideOutput = {
"poses_folder": "best_docking_poses",
"models_folder": model_folder, # "prepared_proteins",
"atom_pairs": atom_pairs,
}
import pickle

with open("glide_output.pkl", "wb") as f:
pickle.dump(glideOutput, f)

block.setOutput(analyseGlideOutputVariable.id, glideOutput)


AnalyseGPXBlock = PluginBlock(
name="Analyse Glide GPX",
description="To analyse Glide GPX results",
AnalyseGBlock = PluginBlock(
name="Analyse Glide",
description="To analyse Glide results",
action=finalAction,
variables=[metricsVar],
inputGroups=[stringGroup, atomGroup],
outputs=[outputModelsVariable],
variables=[metricsVar, removePreviousVar, separatorVar],
inputGroups=[atomGroup, stringGroup],
outputs=[outputModelsVariable, analyseGlideOutputVariable],
)
9 changes: 6 additions & 3 deletions EAPM/Include/Blocks/AnalyseGlideDocking.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import datetime
import os

from HorusAPI import (
Extensions,
PluginBlock,
Expand Down Expand Up @@ -133,6 +130,10 @@


def analyseDockingAction(block: PluginBlock):

import datetime
import os

if block.selectedInputGroup == "folder_variable_group":
folder_to_analyse = block.inputs.get("docking_folder", "docking")
model_folder = block.inputs.get("model_folder", "models")
Expand Down Expand Up @@ -391,6 +392,7 @@ def analyseDocking(
"""

import json
import os

import pandas as pd
import prepare_proteins
Expand Down Expand Up @@ -529,6 +531,7 @@ def extractDockingPoses(
Remove all content in the output folder
"""

import os
import shutil

# Check the separator is not in model or ligand names
Expand Down
Loading

0 comments on commit d07c1d8

Please sign in to comment.