Skip to content

Commit 711b032

Browse files
committed
mtation screen added
1 parent 128f152 commit 711b032

File tree

2 files changed

+248
-19
lines changed

2 files changed

+248
-19
lines changed

run_PMGen.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import pandas as pd
33
from run_utils import (run_PMGen_wrapper, run_PMGen_modeling, protein_mpnn_wrapper, bioemu_assertions,
44
MultipleAnchors, get_best_structres, retrieve_anchors_and_fixed_positions, assert_iterative_mode,
5-
collect_generated_binders, create_new_input_and_fixed_positions, create_fixed_positions_if_given)
5+
collect_generated_binders, create_new_input_and_fixed_positions, create_fixed_positions_if_given,
6+
mutation_screen)
67
import shutil
78
from Bio import SeqIO
89
import warnings
@@ -99,6 +100,12 @@ def main():
99100
parser.add_argument('--bioemu_run_on_iter', type=int, default=None, help='Optional, only works when iterative_peptide_gen > 0. Runs bioemu on the structure taken'
100101
'from the iteration number given by user. If not set, runs on the 0 iteration by default.')
101102

103+
# Mutation screen Arguments
104+
parser.add_argument('--mutation_screen', action='store_true', help='samples <n_mutations> point mutations over each structure.'
105+
'e.g, if n_mutations==1, and peptide length is 9, samples 9 mutations '
106+
'one over each position using structure aware peptide selection pipeline.')
107+
parser.add_argument('--n_mutations', type=int, default=1, help='number of mutations in a single run on a single peptide in mutation_screen.')
108+
102109

103110
# Setting to Run only a part:
104111
parser.add_argument('--no_alphafold', action='store_false', help='does not run alphafold.')
@@ -110,6 +117,7 @@ def main():
110117
parser.add_argument('--only_collect_generated_binders', action='store_true', help='Use it only if you have a previous run with generated binders and you do not want'
111118
'to run proteinmpnn again, and instead you want to predict and collect binders using BA predictions.'
112119
'Overwrites all proteinmpnn flags.')
120+
parser.add_argument('--only_mutation_screen', action='store_true')
113121

114122
# Setting to run iterative peptide generation
115123
parser.add_argument('--iterative_peptide_gen', type=int, default=0, help='If used, the iterative peptide generation is performed, defines the number of iterations.')
@@ -119,7 +127,8 @@ def main():
119127
for iteration in range(args.iterative_peptide_gen + 1):
120128
if iteration == 0:
121129
fixed_positions_path = create_fixed_positions_if_given(args)
122-
args.fix_anchors = True
130+
if args.fixed_positions_given:
131+
args.fix_anchors = True
123132
else: fixed_positions_path = None
124133
# if we have entered the iterative generation mode
125134
if args.iterative_peptide_gen > 0:
@@ -163,8 +172,10 @@ def main():
163172
AMINO_ACIDS = set('ARNDCEQGHILKMFPSTWYV/')
164173
try:
165174
df = pd.read_csv(args.df, sep='\t')
175+
_ = df['mhc_seq']
166176
except:
167177
df = pd.read_csv(args.df)
178+
_ = df['mhc_seq']
168179
df['mhc_seq'] = [''.join([aa.upper() for aa in seq if aa.upper() in AMINO_ACIDS]) for seq in df['mhc_seq'].tolist()] # remove gaps from df:
169180
if args.multiple_anchors:
170181
L1 = len(df)
@@ -187,9 +198,9 @@ def main():
187198
benchmark=args.benchmark, best_n_templates=args.best_n_templates,
188199
n_homology_models=args.n_homology_models, pandora_force_run=args.no_pandora,
189200
no_modelling=args.initial_guess, return_all_outputs=args.return_all_outputs)
190-
if args.run == 'parallel' and not args.only_protein_mpnn:
201+
if args.run == 'parallel' and not args.only_protein_mpnn and not args.only_mutation_screen:
191202
runner.run_wrapper_parallel(max_ram=args.max_ram, max_cores=args.max_cores, run_alphafold=args.no_alphafold)
192-
elif args.run == 'single' and not args.only_protein_mpnn:
203+
elif args.run == 'single' and not args.only_protein_mpnn and not args.only_mutation_screen:
193204
runner.run_wrapper(run_alphafold=args.no_alphafold)
194205
else:
195206
print('--Warning!-- Only ProteinMPNN mode, Alphafold and PANDORA are skipped.')
@@ -222,17 +233,17 @@ def main():
222233
n_homology_models=args.n_homology_models,
223234
pandora_force_run=args.no_pandora,
224235
return_all_outputs=args.return_all_outputs)
225-
if not args.only_protein_mpnn:
236+
if not args.only_protein_mpnn and not args.only_mutation_screen:
226237
runner.run_PMGen(run_alphafold=args.no_alphafold)
227238
else:
228-
print('--Warning!-- Only ProteinMPNN mode, Alphafold and PANDORA are skipped.')
239+
print('Only ProteinMPNN mode, Alphafold and PANDORA are skipped.')
229240
output_pdbs_dict = {}
230241
out_alphafold = os.path.join(args.output_dir, 'alphafold', args.id)
231242
output_pdbs_dict[args.id] = [os.path.join(out_alphafold, i) for i in os.listdir(out_alphafold) if
232243
i.endswith('.pdb') and 'model_' in i and not i.endswith('.npy')]
233244
# {'id':[output1, output2, ...]}
234245

235-
if not args.only_protein_mpnn:
246+
if not args.only_protein_mpnn and not args.only_mutation_screen:
236247
print("Alphafold Runs completed.")
237248
else:
238249
print('Alphafold Runs Skipped!')
@@ -260,10 +271,17 @@ def main():
260271
print("### Start ProteinMPNN runs ###")
261272
print('files:\n', output_pdbs_dict)
262273
protein_mpnn_wrapper(output_pdbs_dict, args, args.max_cores, anchor_and_peptide=anchor_and_peptide, mode=args.run)
263-
if (args.peptide_design and args.mode and args.binder_pred == "wrapper") or args.only_collect_generated_binders:
274+
if (args.peptide_design and args.binder_pred and args.mode == "wrapper") or args.only_collect_generated_binders:
264275
print("Collecting the best binders")
265276
collected_generated_binders_path = collect_generated_binders(args, df, iteration)
266277

278+
if args.mutation_screen:
279+
print('**Mutation Screen Initiating**')
280+
assert os.path.join(args.output_dir, 'alphafold'), f'alphafold directory does not exist!'
281+
mt = mutation_screen(args, df)
282+
mt.run_mutation_screen()
283+
284+
267285
if args.run_bioemu:
268286
print('**BioEmu runs initiating**')
269287

0 commit comments

Comments
 (0)