Nmrglue



1D 1H NMR is a common technique applied to metabolomic studies, being well suitedto untargeted analysis of complex biofluids. It has been successfully applied tothe classification and diagnosis of a number of diseases including [ref].

Tutorial

There are a number of important steps that must be applied prior 1D 1H NMR datato statistical analysis, all gearded towards ensuring that the variation observedin the data is representative of real biological variation and not a artifact ofsample handling, metabolite extraction or NMR acquisition. These steps aredescribed briefly below and approached in turn in the following method. It isimportant to familiarise yourself with both the purpose of these steps, andany associated caveats or limits, so that you can correctly apply them to yourown data.

Developement Guide¶. This guide provides instructions for setting up an environment for developing nmrglue and an overview of the project layout and contribution process. Nmrglue provides you with a Python based module that you can use to process, analyze and view NMR data. Nmrglue supports multiple NMR file formats, such as NMRPipe, Agilent/Varian, Rowland NMR.

Setting up

To process raw NMR data we will be making use of of the nmrglue library. Inaddition we will make use of features from the numpy, scipy and matplotliblibraries, which you should already have installed.To make sure you can run the following command on the terminal:

The demo data for this example is available for download.

Download and unzip the file into your data folder.

Loading Bruker FID spectra

Create a new Jupyter notebook using the Python 3 kernel, and in the first cellenter and run the following. This will import all the neccessary libraries, aswell as using the %matplotlib magic to display output figures in the notebook.

Bruker-format data is processed using a digital filter before saving as FID, thisfilter must be removed for subsequent analysis to work. To open a given spectra,pass the parent folder of the fid file.

We can plot the spectra using matplotlib.

  1. We don't have the x-axis ppm scale yet, so we generate a linear scale of the same size as the data. Here .shape[0] is the length of the fid along the first (and only) axis of the 1D spectra.

Fourier transform (FT)

A fourier transform is a signal transformation that decomposes a signalinto it's constituent frequencies. In the case of NMR data, this decompositionis to a series of peaks, that represent the resonance of chemical subgroups. Thesepeaks contain both our identification (frequency) and quantification (amplitude)information.

The nmrglue package provides a fast fourier transform (FFT) for this purpose

You'll notice that the spectra is out of phase, i.e. the peaks are notsymmetrical and well defined. We will fix this shortly, but first lets loada complete set of spectra so we can view them all at once.

Batch loading + FFT for multiple spectra

  1. We build as a list, then transform to an array for speed.
  2. Zero-filling to a power of 2 speeds up FFT.
  3. Reverse the data to match common representation (for convenience only).
Nmrglue

The data is output in a 2D array, with samples along the first axis.

Nmrglue

We want to be able to plot multiple spectra on the same plot, so we'll writea simple function to do this.

  1. This block allows us to select regions of the spectra to view by filtering on the supplied ppms.

We can use this function to look at all spectra following fourier transform:

We can take a close up view of the TMSP peak, which is currently on the lefthand side of the spectra in the region 28000-30000.

Clearly the spectra are all out of phase and poorly aligned. We will fix thephasing problem first, but lets start off by getting the correct ppm values forthe spectra.

Calculating ppm values

The method for calculating ppm values is rather complicted for Bruker formatfiles. However, the following will give the correct output:

Nmrglue

We can now plot the spectra with the correct ppms.

Phase correction

The next step is to phase correct all the spectra. The package nmrglue providesa few automated algorithms that do a reasonable job with most normal, good qualityspectra. Thankfully, that's what we have here.

This guide provides instructions for setting up an environment for developingnmrglue and an overview of the project layout and contribution process.

Requirements¶

Github

Nmrglue Conda

To create an environment for developing nmrglue the following must be installedand available.

Nmrglue Tutorial

In addition the following Python packages are highly recommended.

Nmrglue Unit Conversion

A easy way of obtaining and installing these packages is to use a Pythondistribution which provides these packages, such asEPD. Detailed information oninstalling a Scipy stack isavailable.

Nmrglue Python

Finally, other NMR software packages must be installed to process and convertthe test and example data. These are not required for using nmrglue, but areneeded to verify its functionality and to run some of the examples.