-- this script performs some tasks that are not possible with the graphic interface: -- solvent removal after the normal processing -- removal of empty rows from a pseudo-2D amtrix (obtained by the Process Folder command) -- rob-by-row normalization -- set the values of these constants according to your needs -- if a constant is not required, set it to nil -- the unit for all values is ppm SolventLeft = 1.4 SolventRight = 1.2 Solvent2Left = nil Solvent2Right = nil Solvent3Left = nil Solvent3Right = nil bin_size = 0.02 -- size of each bucket, set to nil to skip bucketing bin_from = 6 bin_to = 0.5 NormalizedArea = 1000 -- area of each row, after the optional normalization -- the program starts here -- it operates upon a pseudo 2-D matrix, performing bucketing and other operations useful for a metabolomic study local X = getf "x" local Y = getf "y" local FilledRows = 0 local ppm_slice = Y.width / Y.size -- how the ppm scale increments between rows local base = Y.start + Y.width -- bottom of the scale -- removing the solvents if SolventLeft then region( SolventLeft, SolventRight, base, Y.start ) paste {} end if Solvent2Left then region( Solvent2Left, Solvent2Right, base, Y.start ) paste {} end if Solvent3Left then region( Solvent3Left, Solvent3Right, base, Y.start ) paste {} end -- moving the filled rows towards the bottom local growing = base for i = 1, Y.size do region( 1000, -1000, base - (i-1) * ppm_slice, base - i * ppm_slice ) local mono = copy() local signal = false for j = 1, X.size do if mono[j] ~= 0 then signal = true end end if signal == true then region( 1000, -1000, growing, growing - ppm_slice ) paste( mono ) growing = growing - ppm_slice FilledRows = FilledRows + 1 end end Y.size = FilledRows resize( X, Y ) -- bucketing if bin_size then bin( bin_from, bin_to, bin_size ) end -- normalization if NormalizedArea then region( 1000, -1000, 90000, -90000 ) -- select the whole matrix local T = copy() local rowsize = T.x local rows = T.y local zero = 0 local max = 1 for i = 1, rows do local sum = 0 for j = 1,rowsize do sum = sum + T[zero+j] end if sum ~= 0 then sum = sum / NormalizedArea if sum > max then max = sum end local norm = 1 / sum for j = 1,rowsize do T[zero+j] = norm * T[zero+j] end end zero = zero + rowsize end paste( T ) amp( max ) -- amplifies the visual appearance end full() -- to reorder the plot and to update the scales