integration example: integrate_2dΒΆ

This example shows how to use nmrglue to integrate a 2D NMRPipe spectra. The script reads in point limits from limits.in and takes a simple summation integral of all points in each box described. The integrated volumes are writting to volumes.out. For a method to graphically examine these limits see plotting example: plot_2d_boxes. Similarly to check the peak assignments see plotting example: plot_2d_assignments.

The data used in this example is available for download.

[source code]

#! /usr/bin/env python
# Example script to show integration of a 2D spectrum

import nmrglue as ng
import numpy as np

# read in the data from a NMRPipe file
dic, data = ng.pipe.read("nmrpipe_2d/test.ft2")

# read in the integration limits
peak_list = np.recfromtxt("limits.in")

# prepare the output file
f = open("volumes.out",'w')
f.write("# Name\tVolume\n")

# loop over the integration limits
for name, x0, y0, x1, y1 in peak_list:

    if x0 > x1:
        x0, x1 = x1, x0
    if y0 > y1:
        y0, y1 = y1, y0

    vol = data[y0:y1 + 1, x0:x1 + 1].sum()
    f.write("%s\t%.3f\n"%(name, vol))

# close the output file
f.close()

[input file]

#Peak   X0      Y0      X1      Y1
# Peak defines 15N resonance in 2D NCO spectra.
# Limits are in term of points from 0 to length-1.
# These can determined from nmrDraw by subtracting 1 from the X and Y
# values reported.
#Peak   X0      Y0      X1      Y1
T49     1992    1334    2003    1316
T11     1996    1302    2008    1284
# comments can appear anywhere in this file just start the line with #
G14     2032    1314    2044    1293
E15     2077    1025    2087    1004
W43     2008    952     2019    933

Results:

[output file]

# Name	Volume
T49	10194682.000
T11	8478199.000
G14	9677602.000
E15	9187130.000
W43	8778141.000