Toolbox Datatypes

The following is a short guide to some of the datatypes used in this toolbox.

General datatypes

Matlab has support for matrixes, cell arrays, structs, maps, tables and objects. If you are not familiar with the basic Matlab datatypes please refer to the Matlab documentation.

csm_spectra is the main container for spectral data. It contains X, a m*n matrix of intensities, x_scale, a 1*n vector of chemical shift, and user specific sample metadata.

csm_nmr_spectra and csm_ms_spectra extend csm_spectra and should be used for these platforms.

Creating a csm_nmr_spectra object:

X = [ 0 : 5 ];
ppm = [ 0 : 5 ];
spectra = csm_nmr_spectra( X , ppm );

spectra.X

ans =

  Columns 1 through 5

    1     2     3     4     5

You can specify the sample_ids using varargin. sample_ids is a cell array of the sample IDs.

X = [ 0 : 5 ];
ppm = [ 0 : 5 ];
sample_ids = {'Sample 1','Sample 2','Sample 3','Sample 4','Sample 5'};
spectra = csm_nmr_spectra( X , ppm , 'sample_ids', sample_ids );

spectra.sample_ids

ans =

    'Sample 1'    'Sample 2'    'Sample 3'    'Sample 4'    'Sample 5'

Other sample metadata can be stored in the csm_spectra object. You can import the metadata for a spectra using the following method:

X = [ 0 : 5 ];
ppm = [ 0 : 5 ];
sample_ids = {'Sample 1','Sample 2','Sample 3','Sample 4','Sample 5'};
spectra = csm_nmr_spectra( X , ppm , 'sample_ids', sample_ids );

metadata_import_worker = csm_import_sample_metadata( 'filename', metadata_path );

spectra = csm_nmr_spectra( X , ppm , 'sample_ids', sample_ids, 'sample_metadata', metadata_import_worker.sample_metadata );

The method csm_nmr_spectra.sample_metadata.getTable() will return a Matlab Table of the sample metadata, used for plotting functions.

spectra.sample_metadata.getTable();

See csm_spectra, csm_nmr_spectra, csm_ms_spectra and csm_jres_spectra for more information.

csm_wrapper is the API base class for accessing the legacy methods in the toolbox.

This means that the legacy wrappers extend this class, and thereby inherit it's properties and methods.

The input arguments are stored as a struct in csm_wrapper.input, and the output is stored as a struct in csm_wrapper.output.

There outputs can be accessed as follows:

X = [ 0 : 5 ];
ppm = [ 0 : 5 ];
spectra = csm_nmr_spectra( X , ppm );

pca_model = csm_pca( csm_spectra, 3 );

loadings = pca_model.output.P

ans =

    0.5860    0.3678    0.1253   -0.1172   -0.3597   -0.6021
    0.5443    0.2722    0.1361   -0.1361   -0.5443   -0.5443
    0.5443    0.2722    0.1361   -0.1361   -0.5443   -0.5443

Please refer to the function documentation for the list of output variables.

csm_figure extends csm_wrapper by adding graphic handles to the objects.

Handles for output figures are stored in a cell array in output.handles, and can be accessed as follows:

X = [ 0 : 5 ];
ppm = [ 0 : 5 ];
spectra = csm_nmr_spectra( X , ppm );

pca_model = csm_pca( csm_spectra, 3 );

pca_plot = csm_plot_pca(pca_model);

pca_plot = csm_plot_pca(pca_model);

pca_plot.handles

ans =

    [1x1 Figure]    [1x1 Figure]    [1x1 Figure]    [1x1 Figure]

pca_plot.handles{1}

ans =

  Figure (1: PCA scores coloured by class1 PC1vs2) with properties:

      Number: 1
        Name: 'PCA scores coloured by class1 PC1vs2'
       Color: [1 1 1]
    Position: [560 528 560 420]
       Units: 'pixels'

  Show all properties

Now we've covered the basic types, it's time to read about data import and export.

Copyright Imperial College London 2019