Skip to content

Commit bd8713d

Browse files
committed
refactor reconstruct_multi_models
1 parent 2f68e8c commit bd8713d

6 files changed

Lines changed: 34 additions & 50 deletions

File tree

bin/amis.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,22 @@ def diff(seq_old, seq_new, start=0, end=None):
203203
different_muts.append((idx, ch_old, ch_new))
204204
return different_muts
205205

206-
def reconstruct_multi_models(wt_seq, models, alpha=None, return_names=False):
206+
def reconstruct_multi_models(
207+
wt_seq,
208+
model_names=[
209+
'esm1b',
210+
'esm1v1',
211+
'esm1v2',
212+
'esm1v3',
213+
'esm1v4',
214+
'esm1v5',
215+
],
216+
alpha=None,
217+
return_names=False,
218+
):
207219
mutations_models, mutations_model_names = {}, {}
208-
for model in models:
220+
for model_name in model_names:
221+
model = get_model_name(model_name)
209222
if alpha is None:
210223
wt_new = reconstruct(
211224
wt_seq, model, decode_kwargs={ 'exclude': 'unnatural' }
@@ -221,12 +234,13 @@ def reconstruct_multi_models(wt_seq, models, alpha=None, return_names=False):
221234
mutations_model_names[mutation] = []
222235
mutations_models[mutation] += 1
223236
mutations_model_names[mutation].append(model.name_)
237+
del model
224238

225239
if return_names:
226240
return mutations_models, mutations_model_names
227241

228242
return mutations_models
229-
243+
230244
def evolve(seq_uca, model, n_generations=1):
231245
print(f'Gen 0: {seq_uca}')
232246
seq_curr = seq_uca

bin/dms.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
import pandas as pd
33
import scipy.stats as ss
44

5-
from amis import (
6-
get_model_name,
7-
reconstruct_multi_models,
8-
)
5+
from amis import reconstruct_multi_models
96

107
def parse_args():
118
import argparse
@@ -26,7 +23,7 @@ def parse_args():
2623
args = parser.parse_args()
2724
return args
2825

29-
def dms_results(fname, models, alpha=None,):
26+
def dms_results(fname, model_names, alpha=None,):
3027
namespace = fname.split('/')[-1].split('.')[0]
3128
with open(fname):
3229
df = pd.read_csv(fname, delimiter=',')
@@ -39,7 +36,7 @@ def dms_results(fname, models, alpha=None,):
3936
else:
4037
wt_seq += aa_orig
4138

42-
mutations_models = reconstruct_multi_models(wt_seq, models, alpha=alpha)
39+
mutations_models = reconstruct_multi_models(wt_seq, model_names, alpha=alpha)
4340

4441
mutation_scores, studies = {}, []
4542
for column in df.columns:
@@ -70,10 +67,6 @@ def dms_results(fname, models, alpha=None,):
7067
if __name__ == '__main__':
7168
args = parse_args()
7269

73-
models = [
74-
get_model_name(model_name) for model_name in args.model_names
75-
]
76-
7770
fnames = [
7871
'data/dms/dms_adrb2.csv',
7972
'data/dms/dms_bla.csv',
@@ -87,4 +80,4 @@ def dms_results(fname, models, alpha=None,):
8780
]
8881

8982
for fname in fnames:
90-
dms_results(fname, models, alpha=args.alpha)
83+
dms_results(fname, args.model_names, alpha=args.alpha)

bin/dms_esm.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
import pandas as pd
33
import scipy.stats as ss
44

5-
from amis import (
6-
get_model_name,
7-
reconstruct_multi_models,
8-
)
5+
from amis import reconstruct_multi_models
96
from predict_esm import predict_esm
107

118
def parse_args():
@@ -50,17 +47,14 @@ def dms_esm(fname, model_locations):
5047
]))
5148
df_esm['ESM_summed'] = summed_log_probs
5249

53-
models = [
54-
get_model_name(model_name) for model_name in
55-
[ 'esm1b', 'esm1v1', 'esm1v2', 'esm1v3', 'esm1v4', 'esm1v5', ]
56-
]
50+
model_names = [ 'esm1b', 'esm1v1', 'esm1v2', 'esm1v3', 'esm1v4', 'esm1v5', ]
5751
if '_infa' in fname:
5852
alpha = 0.5
5953
else:
6054
alpha = None
6155
mutations_models, mutations_model_names = reconstruct_multi_models(
6256
wt_seq,
63-
models,
57+
models_names,
6458
alpha=alpha,
6559
return_names=True,
6660
)

bin/originality.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
from utils import *
2-
from amis import (
3-
get_model_name,
4-
reconstruct_multi_models,
5-
)
2+
from amis import reconstruct_multi_models
63

74
seqs_abs = {
85
'medi_vh': 'QVQLQQSGPGLVKPSQTLSLTCAISGDSVSSYNAVWNWIRQSPSRGLEWLGRTYYRSGWYNDYAESVKSRITINPDTSKNQFSLQLNSVTPEDTAVYYCARSGHITVFGVNVDAFDMWGQGTMVTVSS',
@@ -62,14 +59,10 @@ def load_ratios(name, database='abysis'):
6259
if __name__ == '__main__':
6360
model_names = [ 'esm1b', 'esm1v1', 'esm1v2', 'esm1v3', 'esm1v4', 'esm1v5', ]
6461

65-
models = [
66-
get_model_name(model_name) for model_name in model_names
67-
]
68-
6962
for name in seqs_abs:
7063
seq = seqs_abs[name]
7164
print(f'\n{name}')
72-
mutations_models = reconstruct_multi_models(seq, models, alpha=0.5)
65+
mutations_models = reconstruct_multi_models(seq, model_names, alpha=0.5)
7366

7467
abysis_likelihood_ratios = load_ratios(name, 'abysis')
7568
uniref_likelihood_ratios = load_ratios(name, 'uniref')

bin/recommend.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
from amis import (
2-
get_model_name,
3-
reconstruct_multi_models,
4-
)
1+
from amis import reconstruct_multi_models
52

63
def parse_args():
74
import argparse
@@ -29,11 +26,11 @@ def parse_args():
2926
if __name__ == '__main__':
3027
args = parse_args()
3128

32-
models = [
33-
get_model_name(model_name) for model_name in args.model_names
34-
]
35-
36-
mutations_models = reconstruct_multi_models(args.sequence, models, alpha=args.alpha)
29+
mutations_models = reconstruct_multi_models(
30+
args.sequence,
31+
args.model_names,
32+
alpha=args.alpha,
33+
)
3734
for k, v in sorted(mutations_models.items(), key=lambda item: -item[1]):
3835
mut_str = f'{k[1]}{k[0] + 1}{k[2]}'
3936
print(f'{mut_str}\t{v}')

bin/therapeutic_antibodies.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import pandas as pd
22
import time
33

4-
from amis import (
5-
get_model_name,
6-
reconstruct_multi_models,
7-
)
4+
from amis import reconstruct_multi_models
85
from utils import tprint
96

107

@@ -37,10 +34,6 @@ def parse_args():
3734
if __name__ == '__main__':
3835
args = parse_args()
3936

40-
models = [
41-
get_model_name(model_name) for model_name in args.model_names
42-
]
43-
4437
df = pd.read_csv(args.seq_fname, sep=',')
4538

4639
data = []
@@ -60,7 +53,7 @@ def parse_args():
6053
for wt_seq in [ vh, vl, vh_bi, vl_bi ]:
6154
if wt_seq == 'na':
6255
continue
63-
mutations_models = reconstruct_multi_models(wt_seq, models)
56+
mutations_models = reconstruct_multi_models(wt_seq, args.model_names)
6457
for mutation, n_models in sorted(
6558
mutations_models.items(), key=lambda item: item[1]
6659
):

0 commit comments

Comments
 (0)