lgatto/synapter — pull request #50 by sgibb (2014-03-05 12:03:06+00:00)
Title: Optimize gridSearch2 (and fix a bug in the calculation of non unique matches)

Dear Laurent,

as mentioned in https://github.com/lgatto/synapter/pull/49 there was still some potential to optimize the running time of `gridSearch2`. This PR moves `doHDMSePredictions` and `findRtIndices` (new subroutine) to the outer `for` loop of `gridSearch2`. Addtionally it removes some redundant code/calculation in the calculation of `grd1`, `grd2` and `details` and avoids some copy of large data objects (e.g. it avoids the creation of the `pep3d2` matrix in a `gridSearch2` completely).

Altogether it results in a 2-3x faster running time (in comparison to `synapter 1.5.3`; the data object is different from the data object used in https://github.com/lgatto/synapter/pull/49 , in fact it should be the same as you used in `run_test_report.R`).

## synapter 1.5.1
system.time(searchGrid(obj1))
# user system elapsed
# 1740.895 9.924 1756.952

## synapter 1.5.3
system.time(searchGrid(obj3))
# user system elapsed
# 65.460 0.820 66.737

## synapter 1.5.4
system.time(searchGrid(obj4))
# user system elapsed
# 18.637 0.340 19.174

The most important side effect of this PR is the fix of a wrong calculation of non unique matches.
This nasty bug cost me two days (and a night) of my life. I was wondering why `run_test_report.R` reports a mismatch for `$GridDetails`, e.g.:

# synapter 1.5.3
# $`3.9`
#-2 -1 0 1 2
# 4 107 92 3470 9

# synapter 1.5.4
# $`3.9`
#-2 -1 0 1 2
# 1 107 92 3470 12

The reason for this difference is the representation of `precursor.leID.quant` as `character` vector (and the missing conversion to `numeric`) in `getAssignmentDetails` (`synapter <= 1.5.3`: https://github.com/lgatto/synapter/blob/624cd2594f273cf29331b78c8864b639cae98240/R/utils.R#L392-L393) and the fact that `" 252" %in% c(225, 252) == FALSE`! (I do not know why there is a space prefixed.) Please find a MWE at https://gist.github.com/sgibb/9365785.
It generates the following output:

# precursor.leID.quant (character):
# precursor.leID.quant
# " 5622"
# matched.quant.spectrumIDs:
# [1] 5469 5622
# reported result: -2 (should be 2 )
#
# precursor.leID.quant (character):
# precursor.leID.quant
# " 252"
# matched.quant.spectrumIDs:
# [1] 225 252
# reported result: -2 (should be 2 )
#
# precursor.leID.quant (character):
# precursor.leID.quant
# " 9466"
# matched.quant.spectrumIDs:
# [1] 9466 9650
# reported result: -2 (should be 2 )

I hope this was the last time I have to touch `gridSearch2`.

Best wishes,

Sebastian