Tuesday, April 3, 2012

converting massspecs to an array using postgres stored functions

currently I'm in the progress of writing a couple of stored procedures to query our BinBase database directly by spectral similarity and so the first step was to transform a standard leco spectra string to a standard double array, which represents a spectra.

-- converts a spectra string to a float array for further use --
create or replace function convertSpectra(spectra text) returns float8[] AS $$

result float8[1000];
spectraSplit text[];
ionSplit text[];
array_len int;

ion int;
value float8;


spectraSplit = regexp_split_to_array(spectra,' ');
array_len = array_upper(spectraSplit,1);

for i in 1 .. array_len
ionSplit = regexp_split_to_array(spectraSplit[i],':');

ion := ionSplit[1];
value := ionSplit[2];

result[ion] = value;


RETURN result;

$$ LANGUAGE plpgsql;

No comments:

Post a Comment