File: pathology_plots.py

package info (click to toggle)
coot 1.1.18%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 219,964 kB
  • sloc: cpp: 495,934; python: 35,043; ansic: 26,143; lisp: 22,768; sh: 13,186; makefile: 2,746; awk: 441; xml: 245; csh: 14
file content (104 lines) | stat: -rw-r--r-- 3,049 bytes parent folder | download | duplicates (2)
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

import os
import coot
import math

import matplotlib
matplotlib.use('agg')
matplotlib.rc('font', family='Arial')
import matplotlib.pyplot as plt


def cairoplot_pathology_plots(mtz, fp, sigfp):
    import cairo
    import cairoplot
    try: 
        print("getting data for", mtz)
        data = coot.pathology_data(mtz, fp, sigfp)
        # print len(data), data
        prefix,tail = os.path.splitext(mtz)
        for i in range(4):
            png_file_name = prefix + "-" + str(i) + ".png"
            print("making plot", png_file_name)
            yt = 'I'
            xt = 'Resolution'
            if i == 1:
                yt = 'I/SIGI'
            if i == 2:
                yt = 'SIGI'
            if i == 3:
                yt = 'I/SIGI'
                xt = "I"
            cairoplot.scatter_plot(png_file_name,
                                   data = data[i+1],
                                   # series_colors = ['black'],
                                   series_colors = [[0.2, 0.2, 0.2]],
                                   width = 600, height = 600, border = 20,
                                   discrete = True,
                                   x_title = xt,
                                   y_title = yt,
                                   dots = True,
                                   axis = True)

    except TypeError as e:
                print("caught TypeError:", e)

# these can be I, SIGI also
#
def plots(mtz, fp, sigfp):

    # meta data
    intensity_data = False
    if fp[0] == 'I':
        intensity_data = True
        
    data = coot.pathology_data(mtz, fp, sigfp)
    print('len data is', len(data))
    print('data[0] is', data[0])

    prefix,tail = os.path.splitext(mtz)
    fp_lab = "FP"
    sigfp_lab = "SIGFP"
    if (intensity_data):
            fp_lab = "I"
            sigfp_lab = "SIGI"

    labels = [("Resolution", fp_lab),
              ('Resolution', fp_lab + '/' + sigfp_lab),
              (fp_lab, sigfp_lab),
              (fp_lab, fp_lab + '/' + sigfp_lab)]

    for icount in range(len(labels)):

        label_pair = labels[icount];
        
        ii = 0 # label indexing hack
        l_0 = label_pair[0].replace('/', '_')
        l_1 = label_pair[1].replace('/', '_')
        png_file_name = prefix + "-" + l_0 + "-vs-" + l_1 + ".png"

        fig1 = plt.figure()
        ax = plt.gca()
        plt.title(label_pair[1] + " vs. " + label_pair[0])
        ax.set_xlabel(label_pair[0])
        ax.set_ylabel(label_pair[1])
        xdata = [x[0] for x in data[icount+1]]
        ydata = [y[1] for y in data[icount+1]]

        ymin = 0
        if (intensity_data):
            ymin = min(ydata)

        xmax = max(xdata)
        ymax = max(ydata)
        plt.xlim(0, xmax)
        plt.ylim(ymin, ymax)

        s = 8
        # If this is F data the the y axis min should be 0.
        # The x-axis min should be 0.
        print("making plot", png_file_name)
        l = plt.scatter(xdata, ydata, s, alpha=0.2)
        plt.savefig(png_file_name)
        plt.close()