IMP logo
IMP Reference Guide  2.15.0
The Integrative Modeling Platform
plot_score.py
1 from __future__ import print_function
2 from IMP import ArgumentParser
3 
4 
5 __doc__ = "Plot score distributions of good-scoring models."
6 
7 
8 def parse_args():
9  parser = ArgumentParser(
10  description="Plot score distributions of good-scoring models")
11  parser.add_argument("-show", action="store_true",
12  help="Interactively show the plot")
13  parser.add_argument("score_file",
14  help="Score file generated by select_good")
15  parser.add_argument("column",
16  help="PMI stat file column to plot (or 'all' to "
17  "plot all columns)")
18  return parser.parse_args()
19 
20 
21 def plot_column(plt, scores, column, show):
22  print(column, "|| Mean:", scores[column].mean(),
23  "| SD:", scores[column].std())
24  plt.hist(scores[column], bins=100)
25  plt.xlabel(column)
26  plt.ylabel('P')
27  plt.title(column)
28  if show:
29  plt.show()
30  else:
31  plt.savefig(column+".png", dpi=300)
32  return plt
33 
34 
35 def main():
36  args = parse_args()
37 
38  import matplotlib
39  matplotlib.use('Agg')
40  import matplotlib.pyplot as plt
41  import pandas
42 
43  scores = pandas.read_csv(args.score_file, sep=' ')
44 
45  if args.column == "all":
46  print("Plotting all columns")
47  exclude = frozenset(('Model_index', 'Replica_id', 'Frame_id',
48  'Run_id'))
49  for k in scores.columns:
50  if k not in exclude:
51  p = plot_column(plt, scores, k, show=False)
52  p.clf()
53  elif args.column in scores.columns.values:
54  plot_column(plt, scores, args.column, show=args.show)
55  else:
56  raise KeyError(args.column
57  + " is not a valid score parameter. Use 'all' or one of: "
58  + ", ".join(scores.columns.values))
59 
60 
61 if __name__ == '__main__':
62  main()
std
STL namespace.