From 50744f046fdbb05ab9c57d4954325d6448c4c9b9 Mon Sep 17 00:00:00 2001 From: Tanushree Tunstall Date: Tue, 17 Nov 2020 13:56:23 +0000 Subject: [PATCH] added my_pdbtools containing pdbtools cloned from a git repo --- scripts/my_pdbtools/chain_splitter.py | 28 +++++++++ scripts/my_pdbtools/pdb_chain_splitter.py | 71 +++++++++++++++++++++++ scripts/my_pdbtools/pdbtools | 1 + scripts/my_pdbtools/pdbtools_commands | 6 ++ 4 files changed, 106 insertions(+) create mode 100755 scripts/my_pdbtools/chain_splitter.py create mode 100755 scripts/my_pdbtools/pdb_chain_splitter.py create mode 160000 scripts/my_pdbtools/pdbtools create mode 100644 scripts/my_pdbtools/pdbtools_commands diff --git a/scripts/my_pdbtools/chain_splitter.py b/scripts/my_pdbtools/chain_splitter.py new file mode 100755 index 0000000..b798dde --- /dev/null +++ b/scripts/my_pdbtools/chain_splitter.py @@ -0,0 +1,28 @@ +#!/usr/bin/python3 + +#======================================================================= +# TASK: extract chain from pdb and save each chain as a separate file + +# link for saving each chain as a separate file +#======================================================================= +__description__ = \ +""" +pdb_chain_splitter.py + +extracts chains and saves them as separate pdb files. +""" +__author__ = "Tanushree Tunstall" +__date__ = "" + +from Bio.PDB import Select, PDBIO +from Bio.PDB.PDBParser import PDBParser + +class ChainSelect(Select): + def __init__(self, chain): + self.chain = chain + + def accept_chain(self, chain): + if chain.get_id() == self.chain: + return 1 + else: + return 0 diff --git a/scripts/my_pdbtools/pdb_chain_splitter.py b/scripts/my_pdbtools/pdb_chain_splitter.py new file mode 100755 index 0000000..030971e --- /dev/null +++ b/scripts/my_pdbtools/pdb_chain_splitter.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 + +# Copyright 2020, Tanushree Tunstall +# This program is distributed under General Public License v. 3. See the file +# COPYING for a copy of the license. + +__description__ = \ +""" +chain_splitter.py + +extract chain/s from pdb and saves each chain as a separate file +""" +__author__ = "Tanushree Tunstall" +__date__ = "" +#======================================================================= +import os, shutil, sys +#from pdbtools.helper import cmdline +from chain_splitter import ChainSelect +from Bio.PDB import Select, PDBIO +from Bio.PDB.PDBParser import PDBParser +#io = PDBIO() +import argparse +#======================================================================= + +def main(): + """ + Function to call if run from command line. + + Example use: + 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.', 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() + + # Extract chains and write each chain as a separate file + pdb_file = args.pdb_file + print('input pdb file:', pdb_file) + + # type = list, makes it a list of lists. Hence extracting the list of chains. + chains = args.chain[0] + #chains = ['A','B','C'] + print ('user supplied chain:', chains) + + # output filename and path + outpath = args.out_path + outfile = args.out_file + + # get structure + p = PDBParser(PERMISSIVE=1) + structure = p.get_structure(pdb_file, pdb_file) + print('input pdb filename:', structure.get_id()) + + for chain in chains: + chain = chain.upper() + print ('Extracting chain:', chain) + + pdb_chain_file = outpath + '/' + outfile + '_{}.pdb'.format(chain) + + io = PDBIO() + io.set_structure(structure) + io.save('{}'.format(pdb_chain_file), ChainSelect(chain)) + +if __name__ == "__main__": + main() + diff --git a/scripts/my_pdbtools/pdbtools b/scripts/my_pdbtools/pdbtools new file mode 160000 index 0000000..881ff8f --- /dev/null +++ b/scripts/my_pdbtools/pdbtools @@ -0,0 +1 @@ +Subproject commit 881ff8f27aaf1db4266a84fb03baad3dab552c64 diff --git a/scripts/my_pdbtools/pdbtools_commands b/scripts/my_pdbtools/pdbtools_commands new file mode 100644 index 0000000..0a85be7 --- /dev/null +++ b/scripts/my_pdbtools/pdbtools_commands @@ -0,0 +1,6 @@ +#====================================================== +# pdb_seq.py: extract seq from structure +#====================================================== +~/git/LSHTM_analysis/scripts/my_pdbtools/pdbtools/scripts/pdb_seq -c B -a > + +