Tuesday, April 3, 2012

converting an absolute massspec to a relative massspec using postgres stored functions

the next step to a working similarity calculation is to convert our absolute massspec to a relative spectra. Which is rather simple using stored procedures



-- calculates a relative spectra
create or replace function createRelavieSpectra(spectra float8[]) returns float8[] AS $$

DECLARE
result float8[1000];
array_len int;
maxValue float8 := 0;

BEGIN

array_len = array_upper(spectra,1);

for i in 1 .. array_len
LOOP
IF spectra[i] is not null and spectra[i] > maxValue
THEN
maxValue := spectra[i];
END IF;
END LOOP;

for i in 1 .. array_len
LOOP
if spectra[i] is not null
then
result[i] := spectra[i]/maxValue * 100;
end if;
END LOOP;

RETURN result;

END;
$$ LANGUAGE plpgsql;

No comments:

Post a Comment