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, unable to find an inherited method for function '.readSampleId' for signature #28

Closed
jychungbu opened this issue Jul 28, 2019 · 9 comments

Comments

@jychungbu
Copy link

Hello,

I'd like to ask your help for solving an error. I got this error during the pcair.

Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function '.readSampleId' for signature

Could you tell me how to resolve this error?

Thanks,
Jaeyoon

fn.gds<- "xxx.gds"
fn.out<- "xxx"
gds_obj <- snpgdsOpen(fn.gds) # from plink
#KING-----------------------------------------------------------------
king <- snpgdsIBDKING( gds_obj, verbose = FALSE)
kingMat <- king$kinship
dimnames(kingMat) <- list(king$sample.id, king$sample.id)
saveRDS(kingMat, paste(fn.out, ".rds", sep=""))
pcair_obj<- pcair( gdsobj=gds_obj, kinMat=kingMat, kin.thresh=2^(-9/2), divMat=kingMat, div.thresh=-2^(-9/2) )
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function '.readSampleId' for signature
'"SNPGDSFileClass"'
gds_obj
File: xxx.gds (453.4M)

  • [ ] *
    |--+ sample.id { Str8 5109 LZMA_ra(14.5%), 8.4K }
    |--+ snp.id { Str8 370810 LZMA_ra(18.5%), 780.1K }
    |--+ snp.position { Int32 370810 LZMA_ra(54.9%), 795.7K }
    |--+ snp.chromosome { UInt8 370810 LZMA_ra(0.08%), 293B } *
    |--+ snp.allele { Str8 370810 LZMA_ra(11.6%), 167.5K }
    |--+ genotype { Bit2 5109x370810, 451.7M } *
    --+ sample.annot [ data.frame ] *
    |--+ sex { Str8 5109 LZMA_ra(2.15%), 117B }
    --+ phenotype { Int32 5109 LZMA_ra(0.69%), 149B }
@smgogarten
Copy link
Collaborator

I could not reproduce this error. If it persists after restarting your R session, could you please share sessionInfo()?

@wcmoors
Copy link

wcmoors commented Jan 3, 2020

was there a solution to this?

@smgogarten
Copy link
Collaborator

Restart your R session. If that doesn't work and you are seeing this error, please share sessionInfo().

@jychungbu
Copy link
Author

jychungbu commented Jan 6, 2020 via email

@EEsdaile
Copy link

EEsdaile commented Jan 6, 2021

Hate to dredge this up again, but I'm getting the same error. Here's my sessionInfo()

Edit to add that I have restarted R and encounter the same issue.

R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] GENESIS_2.20.0 SNPRelate_1.24.0 gdsfmt_1.26.1

loaded via a namespace (and not attached):
[1] quantsmooth_1.56.0 Rcpp_1.0.5 lattice_0.20-41 tidyr_1.1.2 Biostrings_2.58.0
[6] formula.tools_1.7.1 zoo_1.8-8 digest_0.6.27 lmtest_0.9-38 foreach_1.5.1
[11] R6_2.5.0 GenomeInfoDb_1.26.2 backports_1.2.0 MatrixModels_0.4-1 stats4_4.0.3
[16] RSQLite_2.2.1 pillar_1.4.7 zlibbioc_1.36.0 rlang_0.4.9 rstudioapi_0.13
[21] data.table_1.13.4 SparseM_1.78 blob_1.2.1 S4Vectors_0.28.1 Matrix_1.2-18
[26] splines_4.0.3 GWASExactHW_1.01 RCurl_1.98-1.2 bit_4.0.4 tinytex_0.28
[31] broom_0.7.3 compiler_4.0.3 xfun_0.19 pkgconfig_2.0.3 BiocGenerics_0.36.0
[36] mgcv_1.8-33 tidyselect_1.1.0 tibble_3.0.4 GenomeInfoDbData_1.2.4 DNAcopy_1.64.0
[41] IRanges_2.24.1 codetools_0.2-18 matrixStats_0.57.0 crayon_1.3.4 dplyr_1.0.2
[46] conquer_1.0.2 bitops_1.0-6 grid_4.0.3 nlme_3.1-151 lifecycle_0.2.0
[51] DBI_1.1.0 magrittr_2.0.1 SeqVarTools_1.28.1 XVector_0.30.0 mice_3.12.0
[56] ellipsis_0.3.1 generics_0.1.0 vctrs_0.3.6 sandwich_3.0-0 iterators_1.0.13
[61] tools_4.0.3 bit64_4.0.5 Biobase_2.50.0 glue_1.4.2 purrr_0.3.4
[66] parallel_4.0.3 survival_3.2-7 SeqArray_1.30.0 GenomicRanges_1.42.0 GWASTools_1.36.0
[71] operator.tools_1.6.3 memoise_1.1.0 logistf_1.24 quantreg_5.75

@smgogarten
Copy link
Collaborator

I think this is an error that can be resolved by restarting R. Can you try starting a brand-new R session and running the following?

library(GENESIS)
library(SNPRelate)

gdsfile <- system.file("extdata", "HapMap_ASW_MXL_geno.gds", package="GENESIS")
gds <- snpgdsOpen(gdsfile)
class(gds) # should see "SNPGDSFileClass"

data("HapMap_ASW_MXL_KINGmat")
mypcair <- pcair(gds, kinobj = HapMap_ASW_MXL_KINGmat, divobj = HapMap_ASW_MXL_KINGmat)

snpgdsClose(gds)

@AlexHatoum
Copy link

Hello, I am having the same issue but this time with pcrelate. I am wondering if the R version or the version of the packages could be the issue?

I have run the above code in a new R session, but with pc relate at the end (like below) but pcrelate still generates the error, any thoughts?

Code that is sufficient to produce error, R v 4.1.3 :

library(GENESIS)
library(SNPRelate)

gdsfile <- system.file("extdata", "HapMap_ASW_MXL_geno.gds", package="GENESIS")
gds <- snpgdsOpen(gdsfile)
class(gds) # should see "SNPGDSFileClass"

data("HapMap_ASW_MXL_KINGmat")
mypcair <- pcair(gds, kinobj = HapMap_ASW_MXL_KINGmat, divobj = HapMap_ASW_MXL_KINGmat)

mypcrelate <- pcrelate(gds, pcs = mypcair$vectors[,1:2],
training.set = mypcair$unrels,
BPPARAM = BiocParallel::SerialParam())
snpgdsClose(gds)

@AlexHatoum
Copy link

I have figured out the issue. It is with the way the .gds files are read into R, perhaps in different versions. If your data produces this error, reading the .gds files back into R in different ways can help (which you should probably do after restarting R according to this thread, but in my experience it is not necessary as long as you can reload in the .gds files). It is always best to do so using the two part commands like this:

HapMap_geno <- GdsGenotypeReader(filename = "MyGDS.gds")
HapMap_genoData <- GenotypeData(HapMap_geno)

Instead of using other GDS commands like this:
genofile <- snpgdsOpen("MyGDS.gds")

Both sets of code produce the same class of object but the package throws an error for the latter and not the former. Apologies to the developers if this is something obvious, but I thought I would just post here in case others run into this issue.

Best,

Alexander

@smgogarten
Copy link
Collaborator

@AlexHatoum pcair has more options for input classes than pcrelate, which is why you saw the error for the latter but not the former. This has to do with the way the two functions are implemented internally: pcair calls the snpgdsPCA function in the SNPRelate package, so it can accept SNPRelate classes, but pcrelate requires an Iterator object defined in GWASTools or SeqVarTools. You can see this difference in the "Usage" section of the man pages for the two functions:

Usage:

     ## S4 method for signature 'gds.class'
     pcair(gdsobj, kinobj = NULL, divobj = NULL,
 <...>
     ## S4 method for signature 'SNPGDSFileClass'
     pcair(gdsobj, ...)
     ## S4 method for signature 'GdsGenotypeReader'
     pcair(gdsobj, ...)
     ## S4 method for signature 'MatrixGenotypeReader'
     pcair(gdsobj, ...)
     ## S4 method for signature 'GenotypeData'
     pcair(gdsobj, ...)
     ## S4 method for signature 'SeqVarGDSClass'
     pcair(gdsobj, ...)
     

vs

Usage:

     ## S4 method for signature 'GenotypeIterator'
     pcrelate(gdsobj,
<...>
     ## S4 method for signature 'SeqVarIterator'
     pcrelate(gdsobj,

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

5 participants