Réimplémentation du programme DSSP en Python

dssp.py 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import pdb
  2. import sys
  3. from structure import *
  4. from chem import *
  5. import argparse
  6. from datetime import date
  7. def print_dssp(pdb_file, verbose=False, raw_ladd=False):
  8. # gets export date
  9. export_date = date.today().strftime("%d/%m/%Y")
  10. ################### OUTPUT ####################
  11. # print DSSP-style formatted header of PDB file
  12. print("################### DSSP OUTPUT ####################\n####",
  13. "Exported on",export_date,
  14. "\n####################################################")
  15. for elem in pdb_file.get_header() :
  16. print(pdb_file.get_header()[elem], end="")
  17. # Get preliminary data for print loop
  18. residues = pdb_file.residues
  19. bridges = get_bridges(residues)
  20. ladders = get_ladders(bridges, residues)
  21. sheets = get_sheets(ladders)
  22. helix = build_helix_patterns(residues)
  23. # iterating over residues
  24. # print header of table
  25. print(' # RESIDUE AA STRUCTURE BP1 TCO KAPPA ALPHA ' \
  26. 'PHI PSI X-CA Y-CA Z-CA')
  27. for i,res in enumerate(residues):
  28. #res.get_turns(residues, turns)
  29. kappa = res.get_bends(residues)[0]
  30. bend_symbol = res.get_bends(residues)[1]
  31. t_co = res.get_tco(residues)
  32. alpha = res.get_chirality(residues)[0]
  33. chirality = res.get_chirality(residues)[1]
  34. phi = res.get_phi_psi(residues)[0]
  35. psi = res.get_phi_psi(residues)[1]
  36. x_ca = res.atoms["CA"].coord_x
  37. y_ca = res.atoms["CA"].coord_y
  38. z_ca = res.atoms["CA"].coord_z
  39. turns = build_turns_patterns(residues)
  40. turn_3 = print_turn_pattern(residues, res, turns[0])
  41. turn_4 = print_turn_pattern(residues, res, turns[1])
  42. turn_5 = print_turn_pattern(residues, res, turns[2])
  43. helix_3 = print_helix_pattern(residues, res, helix[0])
  44. helix_4 = print_helix_pattern(residues, res, helix[1])
  45. helix_5 = print_helix_pattern(residues, res, helix[2])
  46. if i in bridges.keys():
  47. bp1 = bridges[i].j
  48. else:
  49. bp1 = 0
  50. print('{0: >5}{1: >5}{2: >2}{3: >2}{4: >2}{5: >2}{6: >2}{7: >2}'\
  51. '{8: >2}{9: >2}{10: >2}{11: >1}{12: >5}{13: >7}{14: >7}' \
  52. '{15: >7}{16: >7}{17: >7}{18: >7}{19: >7}'\
  53. '{20: >7}'.format(i+1, res.resid,
  54. res.chain_id,
  55. res.res_letter,
  56. helix_3, helix_4,
  57. helix_5, turn_3,
  58. turn_4, turn_5, bend_symbol,
  59. chirality, bp1,round(t_co, 3),
  60. round(kappa,1), round(alpha, 1),
  61. round(phi, 1), round(psi,1),
  62. round(x_ca,1), round(y_ca,1),
  63. round(z_ca,1)))
  64. if(raw_ladd):
  65. raw_ladders_print(ladders)
  66. parser = argparse.ArgumentParser()
  67. if(len(sys.argv)<2):
  68. print("Not enough arguments! Run with --help to learn more about proper"
  69. "call structure and parameters.")
  70. else:
  71. parser.add_argument("file", type=str, help="input file in PDB format")
  72. parser.add_argument("-v","--verbose", help="add ladders verbose output",
  73. action="store_true")
  74. args = parser.parse_args()
  75. pdb_file = pdb.PDBFile(sys.argv[1])
  76. if(args.verbose):
  77. print_dssp(pdb_file, raw_ladd=True)
  78. else:
  79. print_dssp(pdb_file)