Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: vector::_M_range_check: __n (which is 2538) >= this->size() (which is 2538) #133

Open
i-marques opened this issue Jan 21, 2024 · 3 comments

Comments

@i-marques
Copy link

Hi. I've been trying to use SAIGE to run GWAS. I am using R version 4.3.1 and SAIGE 1.2.0.
I tested the code for chr 21 and 22 and these are running fine. When I started chr 1 to 22 I get this error message halfway each chr analysis:

 user   system  elapsed

1051.383 4.797 1059.989
isVcfEnd FALSE
(2024-01-17 18:51:28.035157) ---- Analyzing Chunk 40 : chrom InitialChunk ----
Error: vector::_M_range_check: __n (which is 2538) >= this->size() (which is 2538)
Execution halted

I don't think it a memory issue, I was saving 50GB for this to run and I can see it is using only around 21GB. Any idea how to solve it? Thanks

@laurent-ntnu
Copy link

Hi,

I get exactly the same error with SAIGE v1.3.1:
vector::_M_range_check: __n (which is 2538) >= this->size() (which is 2538)

I found out that the program crashes in src/Binary_ComputeExact.cpp line 47 in the function ComputeExact::CalTestStat:
m_teststat.at(m_idx) = stat ;

where the 0-based index m_idx should be smaller than the size of vector m_teststat:

(gdb) p m_teststat
std::vector of length 2538
(gdb) p m_idx
2538

In my case, increasing the minmac option prevented from having this error so far.

@laurent-ntnu
Copy link

Hi @weizhouUMICH ,
I found the bug causing this error in the file ER_binary_func.cpp.
It is an overflow when computing n_choose_r and factorial with n>=13.

It results in the wrong values of n_choose_r(13,0:13) in the total_k variable: {1, 4, 24, 88, 221, 399, 532, 532, 399, 221, 88, 24, 4, 1}
instead of {1, 13, 78, 286, 715, 1287, 1716, 1716, 1287, 715, 286, 78, 13, 1}.

It results in the wrong value of the sum(total_k) in the m_total variable: 2538, instead of 8192.
m_total is used to allocate the size of the m_teststat vector, which results in the error about too small vector.

Enclosed is a patch which computes n_choose_r while minimizing the risks of overflow.
patch_nchooser.txt

@i-marques
Copy link
Author

i-marques commented Jan 30, 2024

Indeed, I was using the default values and increasing min_MAC solved the issue. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants