File size: 1,812 Bytes
fae1173 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | import argparse
from dms_utils import deep_mutational_scan
from pathlib import Path
import numpy as np
import esm
from util import load_structure, extract_coords_from_structure
import biotite.structure
from collections import defaultdict
def get_native_seq(pdbfile, chain):
structure = load_structure(pdbfile, chain)
_ , native_seq = extract_coords_from_structure(structure)
return native_seq
def write_dms_lib(args):
'''Writes a deep mutational scanning library, including the native/wildtype (wt) of the
indicated target chain in the structure to an output Fasta file'''
sequence = get_native_seq(args.pdbfile, args.chain)
Path(args.outpath).parent.mkdir(parents=True, exist_ok=True)
with open(args.dmspath, 'w') as f:
f.write('>wt\n')
f.write(sequence+'\n')
for pos, wt, mt in deep_mutational_scan(sequence):
assert(sequence[pos] == wt)
mut_seq = sequence[:pos] + mt + sequence[(pos + 1):]
f.write('>' + str(wt) + str(pos+1) + str(mt) + '\n')
f.write(mut_seq + '\n')
def main():
parser = argparse.ArgumentParser(
description='Create a DMS library based on target chain in the structure.'
)
parser.add_argument(
'pdbfile', type=str,
help='input filepath, either .pdb or .cif',
)
parser.add_argument(
'--dmspath', type=str,
help='output filepath for dms library',
)
parser.add_argument(
'--chain', type=str,
help='chain id for the chain of interest', default='A',
)
args = parser.parse_args()
if args.dmspath is None:
args.dmspath = f'predictions/{args.pdbfile[:-4]}-{args.chain}_dms.fasta'
write_dms_lib(args)
if __name__ == '__main__':
main()
|