xihaoli / STAARpipeline-Tutorial

The tutorial for performing single-/multi-trait association analysis of whole-genome/whole-exome sequencing (WGS/WES) studies using FAVORannotator, STAARpipeline and STAARpipelineSummary
GNU General Public License v3.0
24 stars 17 forks source link

Error in Fit STAAR null model step: asMethod(object) : matrix is not symmetric [1,2] #42

Closed liu-xu-bing closed 10 months ago

liu-xu-bing commented 10 months ago

Hello,

When I ran the command in script STAARpipeline_Null_Model.r, I got this error: obj_nullmodel <- fit_nullmodel(phenotype~age+sex+PC1+PC2+PC3+PC4+PC5+PC6+PC7+PC8+PC9+PC10, data=phenotype,kins=sgrm,use_sparse=TRUE,kins_cutoff=0.022,id="sample.id", family=gaussian(link="identity"),verbose=TRUE) [1] "kins is a sparse matrix." Fixed-effect coefficients: (Intercept) age sex PC1 PC2 PC3 -0.09710790 0.01004128 0.01336379 0.59188157 0.82643259 -0.88178803 PC4 PC5 PC6 PC7 PC8 PC9 -0.38470585 0.74543827 0.04345983 0.81811801 -1.34958786 -0.52993129 PC10 0.13472704 Error in asMethod(object) : matrix is not symmetric [1,2]

Then I generated the sgrm data by FastSparseGRM with no error again and the result for command "isSymmetric(as.matrix(sgrm))" was "TRUE". I also check the colnames and rownames by running command "unique(colnames(sgrm) == rownames(sgrm))" and result was "TRUE". I don't know what lead to this error. Could you help me to resolve this problem?

Best Xubing

xihaoli commented 10 months ago

Hi Xubing,

Thanks for letting me know. Could you please check (1) whether your sparse GRM is symmetric, and (2) whether the rowname/colname of your sparse GRM has all sample ids for your phenotype/covariate file.

Best, Xihao

liu-xu-bing commented 10 months ago

I have tested both info and got the "True":

unique(phenotype$sample.id %in% colnames(sgrm)) [1] TRUE unique(colnames(sgrm) %in% phenotype$sample.id) [1] TRUE isSymmetric(sgrm) Error in UseMethod("isSymmetric") : no applicable method for 'isSymmetric' applied to an object of class "c('dsCMatrix', 'CsparseMatrix', 'dsparseMatrix', 'symmetricMatrix', 'dCsparseMatrix', 'dMatrix', 'sparseMatrix', 'compMatrix', 'Matrix', 'xMatrix', 'mMatrix', 'replValueSp')" isSymmetric(as.matrix(sgrm)) [1] TRUE

xihaoli commented 10 months ago

Hi Xubing,

Could you please then check (1) whether fit_nullmodel() works if you set kins <- NULL (assuming samples are unrelated); and (2) whether your sample.id in phenotype data and rowname/colname of your sparse GRM have duplicates (if there are no duplicates, then the dimension of phenotype and sgrm should be exactly the same).

Best, Xihao

liu-xu-bing commented 10 months ago

The result of first command was:

obj_nullmodel <- fit_nullmodel(phenotype~age+sex+PC1+PC2+PC3+PC4+PC5+PC6+PC7+PC8+PC9+PC10, data=phenotype,kins=NULL,use_sparse=TRUE,kins_cutoff=0.022,id="sample.id", family=gaussian(link="identity"),verbose=TRUE) [1] "kins is NULL, fit generalized linear model." It looks like code can run well without sgrm.

And the sgrm name was same to phenotype$sample.id, only different order between them:

length(colnames(sgrm)) [1] 641 length(phenotype$sample.id) [1] 641

liu-xu-bing commented 10 months ago

Hi Xihao,

I have tested another grm data which was generated by gcta tools and found that the script "STAARpipeline_Null_Model.r" runned successfully. I think maybe something error in old sgrm data which generated by FastSparseGRM.

In the end, thanks for your help.

Best Xubing

xihaoli commented 10 months ago

Hi Xubing,

Thank you very much for the updates. I can confirm that STAARpipeline supports any valid (sparse) kinship/GRM as input, so you can safely proceed to the next steps.

I shall close this case for now. Please let me know if you have any other questions.

Best, Xihao