zhengxwen / SNPRelate

R package: parallel computing toolset for relatedness and principal component analysis of SNP data (Development version only)
http://www.bioconductor.org/packages/SNPRelate
101 stars 25 forks source link

Samples names for IBS results #60

Closed NandiniBN closed 5 years ago

NandiniBN commented 5 years ago

Hi, I'm using SNPrelate to calculate IBS values for all pairs of individuals from my vcf sample. However, I am unable to include sample ids or even export the results in text format. Is there a way to do this ? My code is below

library(gdsfmt)
library(SNPRelate)

input_genotype <- "input_genotype.vcf"
snpgdsVCF2GDS(input_genotype, "test.gds", method="biallelic.only")

snpgdsSummary("test.gds")

genofile <- snpgdsOpen("test.gds")
ibs <- snpgdsIBS(genofile)
write.table(ibs, file="ibs.txt", sep="\t", col.names=TRUE, row.names=TRUE)

Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : 
  cannot coerce class ""snpgdsIBSClass"" to a data.frame
zhengxwen commented 5 years ago

See:

names(ibs)
[1] "sample.id" "snp.id"    "ibs"

ibs$sample.id  # get sample IDs
ibs$snp.id  # get SNP IDs

is(ibs$ibs)
[1] "matrix"    "array"     "structure" "vector"

ibs$ibs is a matrix.