privefl / bigsnpr

R package for the analysis of massive SNP arrays.
https://privefl.github.io/bigsnpr/
192 stars 44 forks source link

Error in (function (cl, name, valueClass) : assignment of an object of class “NULL” is not valid for @‘i’ in an object of class “dsCMatrix”; is(value, "integer") is not TRUE #431

Closed Mahantesh-Biradar closed 1 year ago

Mahantesh-Biradar commented 1 year ago

I'm getting the following error, when I tried to run the calculate LD step.

My code:

# calculate LD
for (chr in 1:22) {
  # Extract SNPs that are included in the chromosome
  ind.chr <- which(info_snp$chr == chr)
  ind.chr2 <- info_snp$`_NUM_ID_`[ind.chr]
  # Calculate the LD
  corr0 <- snp_cor(
    genotype2,
    ind.col = ind.chr2,
    ncores = NCORES,
    infos.pos = POS2[ind.chr2],
    size = 3 / 1000
  )
  if (chr == 1) {
    ld <- Matrix::colSums(corr0^2)
    corr <- as_SFBM(corr0, tmp)
  } else {
    ld <- c(ld, Matrix::colSums(corr0^2))
    corr$add_columns(corr0, nrow(corr))
  }
}

Error:

Error in (function (cl, name, valueClass)  : 
  assignment of an object of class “NULL” is not valid for @‘i’ in an object of class “dsCMatrix”; is(value, "integer") is not TRUE

Can you please suggest how I can address this error? TIA

privefl commented 1 year ago

It's almost as if there is no data in corr0. What is the size of these sparse matrices?

Mahantesh-Biradar commented 1 year ago

dim(corr0) NULL

I'm not sure why this is happening?

privefl commented 1 year ago

Check ind.chr and ind.chr2 I guess

Mahantesh-Biradar commented 1 year ago

dim(ind.chr) NULL dim(ind.chr2) NULL

privefl commented 1 year ago

It's normal since these are vectors. Look at the length.

Mahantesh-Biradar commented 1 year ago

length(ind.chr) [1] 0 length(ind.chr2) [1] 0

privefl commented 1 year ago

Yes, that's definitely the issue. You should check your code.

Mahantesh-Biradar commented 1 year ago

Can you please suggest, which step in the code be causing this issue?

privefl commented 1 year ago

You need to check why you get no index when running ind.chr <- which(info_snp$chr == chr).

Mahantesh-Biradar commented 1 year ago

I tend to have issues like this when the software version is updated. Can you please tell me how I can switch back to 1.12.1 from 1.12.2?

Let me also try your suggestion.

Mahantesh-Biradar commented 1 year ago

Hi Florian,

The info and info_snp looks as follows:

info: chr pos a0 a1 rsid af_UKBB ld block_id pos_hg18 pos_hg38

1 1 68082 T C rs367789441 0.0708 1.81 1 57945 68082 2 1 77866 C T rs563593912 0.0769 1.30 1 67729 77866 3 1 87409 C T rs139490478 0.0768 1.57 1 77272 87409 info_snp: info_snp chr pos a0 a1 rsid.ss CHR:BP_A1_A2 Z n_eff MAF beta beta_se mtag_z p 1 1 1229680 T G rs2477781 1:1229680_G_T 1.36363636 139555 0.9543 7.483735e-03 0.008507473 0.879665945 3.790403e-01 2 1 1231656 G A rs1749951 1:1231656_G_A 0.11232877 139555 0.0378 -6.861773e-03 0.009315852 0.736569550 4.613842e-01 3 1 1239847 C T rs77641120 1:1239847_C_T 2.03218391 139555 0.0149 -2.646836e-02 0.014664521 1.804925040 7.108641e-02 4 1 1241529 G A rs1536168 1:1241529_A_G -0.11918605 139555 0.9553 -6.278337e-03 0.008597605 -0.730242521 4.652420e-01
privefl commented 1 year ago

You should check your code by yourself, I can't help you more with this. This is not an issue on my part. E.g. do you know for which chromosome the problem occurs? Why? Do you have an issue with how chromosomes are labelled? How many variants are matched?

Mahantesh-Biradar commented 1 year ago

Thanks. In my summary stats I had about 12K variants and around 11K are matched. I'm not sure which chromosome is causing the issue.

privefl commented 1 year ago

table(info_snp$chr)

privefl commented 1 year ago

Sumstats with only 12K variants is odd.

Mahantesh-Biradar commented 1 year ago

Thanks for your help again. I agree, I have filtered my summary stats file to include only a selected SNPs.

table(info_snp$chr)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 1122 987 1492 343 639 364 358 628 238 356 574 406 125 700 190 576 781 59 562 179 430

privefl commented 1 year ago

You don't have anything from chr 21..

Mahantesh-Biradar commented 1 year ago

Thanks Florian. I think that address the issue. Going to close this now!