-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRamaArgumentParser.py
132 lines (106 loc) · 4.06 KB
/
RamaArgumentParser.py
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
"""
====================================================================================
If running script from the command line, functions here are called to parsed user's
arguments into the main() function in RamachandranPlotter.py.
Version 2.0.1:
- Relies on the easily accessible Biopython package, rather than Phenix as in
versions <2.0
- User arguments can be now easily parsed in from the command line (as facilitated
by functions here)
- If required, the script could be implemented into existing protein analysis
pipelines by importing this function ( main() ).
Author information:
- Joseph I. J. Ellaway
- https://github.com/Joseph-Ellaway
====================================================================================
"""
import argparse
def CollctUserArgs():
"""
====================================================================================
When called, function collects input arguments from the command line. Outputs
variables to be used by main()
====================================================================================
"""
# Defining arguments
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbose", help="Increase output verbosity",
action="store_true")
parser.add_argument("-p", "--pdb",
help="PDB file name: <filename.pdb>. Include path if necessary.",
type=str)
parser.add_argument("-m", "--models",
help="Desired model number (default: all models). Model number corresponds to order in PDB file.",
type=int)
parser.add_argument("-c", "--chains",
help="Desired chain number (default: all chains). Chain number corresponds to order in PDB file.",
type=int)
parser.add_argument("-d", "--out_dir",
help="Out directory. Must be available before-hand.",
type=str)
parser.add_argument("-t", "--plot_type",
help="Type of angles plotted on Ramachandran diagram. Refer to README.md for options and details.",
type=int)
parser.add_argument("-f", "--file_type",
help="File type for output plot. Options: PNG (default, 96 dpi), PDF, SVG, EPS and PS.",
type=str)
parser.add_argument("-s", "--save_csv",
help="Save calculated dihedral angles in separate CSV.",
action="store_true")
args = parser.parse_args()
# Analysing arguments
if not args.models: # Iterate models?
model_num = 0
itmod = True
elif isinstance(args.models, int):
model_num = args.models
itmod = False
else:
print("Invalid model number. ")
if not args.chains: # Iterate chains?
chain_num = 0
itchain = True
elif isinstance(args.chains, int):
chain_num = args.chains
itchain = False
else:
print("Invalid chain number.")
if not args.out_dir: # Handling the out directory
out_dir = "./"
elif isinstance(args.out_dir, str):
out_dir = args.out_dir
else:
print("Enter valid directory to write Ramachandran plot.")
if args.plot_type is None:
plot_type = 0
elif args.plot_type in [0, 1, 2, 3, 4, 5]:
plot_type = args.plot_type
else:
print("Invalid plot type given. Give integer value between 0-5 to compute dihedral angles.")
print(" E.g. --plot_type <int>")
print("Options:")
print(" 0 : All \n \
1 : General (All residues bar Gly, Pro, Ile, Val and pre-Pro) \n \
2 : Glycine \n \
3 : Proline (cis and trans) \n \
4 : Pre-proline (residues preceeding a proline) \n \
5 : Ile or Val")
exit()
if not args.file_type:
file_type = "png"
else:
# convert file type to lower case
file_type = args.file_type.lower()
return args.pdb, itmod, model_num, itchain, chain_num, plot_type, out_dir, args.verbose, args.save_csv, file_type
def VerboseStatement(verb_boolean, statement):
"""
=============================================================================
If first argument is true, function prints a given statement to command line.
=============================================================================
"""
if verb_boolean: # Parsed from argparser
print(statement)
# print("\n")
else:
pass