From 01a7cbf26eb5b252fce2a7c2aa237e67e5aea8d2 Mon Sep 17 00:00:00 2001 From: Tanushree Tunstall Date: Fri, 15 May 2020 10:59:19 +0100 Subject: [PATCH] renamed extract chain file --- scripts/chain_extract.py | 30 ++++++++++++++++++++++++++++++ scripts/pdb_chain_splitter.py | 4 ++-- 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 scripts/chain_extract.py diff --git a/scripts/chain_extract.py b/scripts/chain_extract.py new file mode 100644 index 0000000..657f460 --- /dev/null +++ b/scripts/chain_extract.py @@ -0,0 +1,30 @@ +#!/usr/bin/python3 + +#======================================================================= +# TASK: select specified chains from the pdb & save a cropped PDB with +# the selected chains. Useful for dimer, etc modelling. + +# link for saving each chain as a separate file +# https://stackoverflow.com/questions/11685716/how-to-extract-chains-from-a-pdb-file +#======================================================================= + +from Bio.PDB import PDBParser, PDBIO, Select + +io = PDBIO() +pdb = PDBParser().get_structure("3byw", "3byw.pdb") + + +# Select() Method to return True for every chain in 'chains' +class ChainSelect(Select): + def accept_chain(self, chain): + #print dir(chain) + if chain.id in chains: + return 1 + else: + return 0 + +if __name__ == '__main__': + chains = ['G', 'H'] # specify selected chains + io.set_structure(pdb) + io.save(pdb.get_id() + "_crop.pdb", ChainSelect()) + diff --git a/scripts/pdb_chain_splitter.py b/scripts/pdb_chain_splitter.py index a0d7e70..9a163b2 100755 --- a/scripts/pdb_chain_splitter.py +++ b/scripts/pdb_chain_splitter.py @@ -27,13 +27,13 @@ def main(): Function to call if run from command line. Example use: - pdb_chain_splitter.py -f -c aB + pdb_chain_splitter.py -f -c Extracts chain 'A' by default. FIXME: extract all chains from the given pdb and write them out individually """ arg_parser = argparse.ArgumentParser() arg_parser.add_argument('-i', '--pdb_file', help='provide pdb file', default = 'None') - arg_parser.add_argument('-c', '--chain', help='chain/s to extract without spaces. Case insensitive.', nargs = '+', default = 'A', type = list) + arg_parser.add_argument('-c', '--chain', help='chain/s to extract without spaces.', nargs = '+', default = 'A', type = list) arg_parser.add_argument('-p', '--out_path', help='specify output path', default = '.', type = str) arg_parser.add_argument('-o', '--out_file', help='specify output filename. Will be used as a prefix to append chain id and pdb file extension', default = 'pdb_file_chain', type = str) args = arg_parser.parse_args()