#!/usr/bin/env python """phipsi: compute the phi and psi angles in a protein. Supported input format is currently only PDB. Supported output format is residue-angle list or phi-psi-count histogram.""" import logging def main(): import sys, getopt, os.path import pdb # Set up default values try: logging.basicConfig(format=os.path.basename(sys.argv[0]) + ": %(levelname)s: %(message)s") except TypeError: logging.basicConfig() try: opts, args = getopt.getopt(sys.argv[1:], "dv") except getopt.GetoptError as e: logging.error(e) raise SystemExit(1) surfaceType = "SES" # Process command line flags for opt, val in opts: if opt == "-d": logging.getLogger().setLevel(logging.DEBUG) elif opt == "-v": logging.getLogger().setLevel(logging.INFO) # Identify input and output streams Stdin = "" Stdout = "" if len(args) == 2: inFilename = args[0] outFilename = args[1] elif len(args) == 1: inFilename = args[0] outFilename = "" elif len(args) == 0: inFilename = "" outFilename = "" else: logging.error("Usage: %s [-dv] [ input_PDB [ output ]]" % sys.argv[0]) raise SystemExit(1) # Read in data logging.info("Reading from %s" % inFilename) if inFilename is Stdin: inFile = sys.stdin else: try: inFile = open(inFilename, "r") except IOError as e: logging.error(e) raise SystemExit(1) import protein try: p = protein.read(inFile, inFilename) except IOError as msg: logging.error("%s: %s", inFilename, msg) raise SystemExit(1) inFile.close() # Convert atoms into protein and compute phi-psi values protein.computePhiPsi(p) for c in protein.chains(p): logging.debug("%d amino acids in chain", len(protein.aminoAcids(c))) # Write out data logging.info("Writing to %s" % outFilename) if outFilename is Stdout: outFile = sys.stdout else: try: outFile = open(outFilename, "w") except IOError as e: logging.error(e) raise SystemExit(1) import output try: output.write(outFile, outFilename, p) except IOError as msg: logging.error("%s: %s", outFilename, msg) raise SystemExit(1) outFile.close() raise SystemExit(0) if __name__ == "__main__": main()