Files
digital-trial/digital-trial/main_biotransformer.nf
Olamide Isreal 9e75f44f1a Digital Trials pipeline configured for WES
Source-only snapshot of the cluster branch for WES execution. Large
reference files (HPA/MANE/ensemble FASTA, model weights, ~597 MB) are
omitted: they are baked into the container images at build time and
mounted from the dreamdock-data PVC at runtime, and exceed the Gitea
request size limit.

Pipeline entry point is main.nf, which orchestrates the biotransformer,
conplex and tissue modules as a single workflow. Ligand inputs are read
from the eureka workspace; protein_zarr and chembl_db come from the
dreamdock-data PVC.
2026-07-27 21:59:52 +01:00

221 lines
8.0 KiB
Plaintext

nextflow.enable.dsl=2
process SUPER_TRANSFORMER {
container "${params.container_biotransformer}"
containerOptions "${params.containerOptions}"
publishDir "${params.outdir}/${params.project_name}/receptors", mode: 'copy'
debug true
input:
path smiles_csv
output:
path "${smiles_csv.simpleName}_out.csv"
script:
"""
#!/bin/bash
workdir=`pwd`
cd /home/omic/biotransformer
## Predicting Biotransformation Using the Human Super Transformer:
# This command predicts the biotransformation of molecules from an SDF input (example.csv) using the human super transformer (superbio) and annotates the metabolites with names and database IDs (from PubChem).
java -jar /home/omic/biotransformer/biotransformer -k pred -b superbio -isdf \$workdir/${smiles_csv.simpleName}.csv -ocsv \${workdir}/${smiles_csv.simpleName}_out.csv -osdf \${workdir}/${smiles_csv.simpleName}.sdf -a
"""
}
process HUMAN_TRANSFORMER {
container "${params.container_biotransformer}"
containerOptions "${params.containerOptions}"
publishDir "${params.outdir}/${params.project_name}/sdf", mode: 'copy'
debug true
input:
path smiles_csv
output:
path "${smiles_csv.simpleName}_out.csv"
script:
"""
#!/bin/bash
set -e
workdir=\$(pwd)
cd /home/omic/biotransformer
# Function to get available memory percentage
get_available_mem_percent() {
free | awk '/Mem:/ {print int(\$7/\$2 * 100)}'
}
# Function to log memory usage
log_memory() {
local pid=\$1
echo "MEMLOG: Timestamp,BioTransformer Memory (MB),Available System Memory (%)" >&2
while kill -0 \$pid 2>/dev/null; do
local biotrans_mem=\$(ps -o rss= -p \$pid | awk '{print \$1/1024}')
local avail_mem=\$(get_available_mem_percent)
echo "MEMLOG: \$(date '+%Y-%m-%d %H:%M:%S'),\$biotrans_mem,\$avail_mem" >&2
if [ \$avail_mem -lt 5 ]; then
echo "MEMLOG: Available memory below 5%. Terminating process." >&2
kill -15 \$pid
wait \$pid
echo 'PROCESS TERMINATED DUE TO LOW MEMORY' > "\${workdir}/${smiles_csv.simpleName}_out.csv"
exit 1
fi
sleep 1800 # Sleep for 30 minutes
done
}
# Calculate max Java heap size (90% of available memory)
max_heap=\$(free -g | awk '/Mem:/ {print int(\$7 * 0.9)}')
# Start the biotransformer process
java -Xmx"\${max_heap}g" -jar /home/omic/biotransformer/biotransformer -a -k pred -b superbio -isdf "\$workdir/${smiles_csv.simpleName}.csv" -ocsv "\${workdir}/${smiles_csv.simpleName}_out.csv" -osdf "\${workdir}/${smiles_csv.simpleName}.sdf" -s 100 &
biotrans_pid=\$!
# Start memory logging in the background
log_memory \$biotrans_pid &
log_pid=\$!
# Wait for the biotransformer process to finish
wait \$biotrans_pid
status=\$?
# Stop the logging process
kill \$log_pid 2>/dev/null || true
if [ ! -s "\${workdir}/${smiles_csv.simpleName}_out.csv" ]; then
if [ \$status -ne 0 ] && [ ! -f "\${workdir}/${smiles_csv.simpleName}_out.csv" ]; then
echo 'PROCESS FAILED' > "\${workdir}/${smiles_csv.simpleName}_out.csv"
else
echo 'NO METABOLITES' > "\${workdir}/${smiles_csv.simpleName}_out.csv"
fi
fi
"""
}
process METABOLITES_BY_MASS {
container "${params.container_biotransformer}"
containerOptions "${params.containerOptions}"
publishDir "${params.outdir}/${params.project_name}/graphs", mode: 'copy'
debug true
input:
path smiles_csv
output:
path "${smiles_csv.simpleName}_out.csv"
script:
"""
#!/bin/bash
workdir=`pwd`
cd /home/omic/biotransformer
## Identifying Metabolites with Specific Masses:
# This command identifies all human metabolites of compounds in example.csv with masses 292.0946 Da and 304.0946 Da (max depth = 2), with a mass tolerance of 0.01 Da. It provides annotations when available.
java -jar /home/omic/biotransformer/biotransformer -k cid -b allHuman -isdf \$workdir/${smiles_csv.simpleName}.csv -ocsv \${workdir}/${smiles_csv.simpleName}_out.csv -osdf \${workdir}/${smiles_csv.simpleName}.sdf -s 2 -m "292.0946;304.0946" -t 0.01 -a
"""
}
process ORDERED_SEQUENCE {
container "${params.container_biotransformer}"
containerOptions "${params.containerOptions}"
publishDir "${params.outdir}/${params.project_name}/screening", mode: 'copy'
debug true
input:
path smiles_csv
output:
path "${smiles_csv.simpleName}_out.csv"
script:
"""
#!/bin/bash
workdir=`pwd`
cd /home/omic/biotransformer
## Simulating an Ordered Sequence of Metabolism:
# This command simulates an ordered sequence of metabolism for compounds in example.csv, starting with two steps of CYP450 oxidation, followed by one step of conjugation. The output is saved in an SDF file (output.sdf).
java -jar /home/omic/biotransformer/biotransformer -isdf \$workdir/${smiles_csv.simpleName}.csv -ocsv \${workdir}/${smiles_csv.simpleName}_out.csv -osdf \${workdir}/${smiles_csv.simpleName}.sdf -k pred -q "cyp450:2; phaseII:1"
"""
}
process GET_FINAL_METABOLITES {
container "${params.container_biotransformer}"
containerOptions "${params.containerOptions}"
publishDir "${params.outdir}/${params.project_name}/screening", mode: 'copy'
debug true
input:
path smiles_csv
output:
path "${smiles_csv.simpleName}.txt"
script:
"""
#!/opt/conda/envs/biotransformer/bin/python
from rdkit import Chem
import numpy as np
import pandas as pd
import requests
#load biotransformet ouput
biotransformer = pd.read_csv('$smiles_csv')
#check if metabolites exist
if biotransformer.shape[0] == 0:
with open('${smiles_csv.simpleName}.txt', 'w') as f:
f.write(f"NO_METABOLITES\\n")
else:
metabolite_id = biotransformer['Metabolite ID']
#get only metabolites that are not precursors for next metabolisam step
last_step_metabolites = biotransformer[[i not in list(biotransformer['Precursor ID']) for i in metabolite_id]]
last_step_metabolites = last_step_metabolites.drop_duplicates()
#get only "active" ones
InChIKey = last_step_metabolites['InChIKey']
InChIKey = pd.unique(InChIKey)
#look if metabolite is in chembl
chembl = []
for i in InChIKey:
curl_commend = f"https://www.ebi.ac.uk/chembl/api/data/molecule/{i}"
c = requests.get(curl_commend)
if c.status_code == 200:
#compund exists in chembl
chembl.append(True)
else:
#compund does not exists in chembl
chembl.append(False)
ChEMBL_bool = pd.DataFrame([InChIKey, chembl]).T.rename({0:'InChIKey',1:'in_ChEMBL'}, axis = 1)
last_step_metabolites = last_step_metabolites.merge(ChEMBL_bool, how='inner', on='InChIKey')
#if in PUBCHEM
last_step_metabolites['in_PUBCHEM'] = ~last_step_metabolites['PUBCHEM_CID'].isna()
##logic
#if metabolite is not in PUBCHEM pass it to next step. We don't know if it's "active"
#has to be in ChEMBL and PUBCHEM to have "activity"
mask = (last_step_metabolites['in_PUBCHEM'] == False) | (np.sum(last_step_metabolites[['in_ChEMBL','in_PUBCHEM']], 1) == 2)
#filtered metabolites
last_step_metabolites = last_step_metabolites[mask]
#convert biotransformer smi to canonical smi and eliminate nonsense structures
metabolite_smi = list(np.unique(last_step_metabolites['SMILES']))
metabolite_smi = [Chem.CanonSmiles(i) for i in metabolite_smi if Chem.MolFromSmiles(i) != None]
#final metabolites
metabolite_smi_filteres = np.array(metabolite_smi)
#save smi
with open('${smiles_csv.simpleName}.txt', 'w') as f:
for n, line in enumerate(metabolite_smi_filteres):
f.write(f"{line}\\tmetabol_{n}\\n")
"""
}