SNPRelate icon indicating copy to clipboard operation
SNPRelate copied to clipboard

Adding a new GDS node to my existing GDS file

Open GabryS3 opened this issue 1 year ago • 0 comments

Dear Dr Zheng, I am trying to add a node to my GDA file, but I am struggling a lot with it, so I would love some advice and help with this.

I obtained my GDS file by converting a "genlight" object (R package adegenet/dartR) into a GDS file for SNPRelate with the dartR::gl2gds() function. However, the GDS file has no sample annotation, and I would like to add this as I would like to run KING robust incluging the family.id field (geographic population or hybrids/pure individuals categories).

I have read your SNPRelate tutorial, but I am encountering troubles adding a gds node to my GDS object. Here is the code I used:

" mydataset_GDS = gl2gds( mydataset_genlight, outfile = "mydataset_GDS.gds", outpath = getwd(), snp_pos = "0", snp_chr = "0", chr_format = "character", verbose = 5)

sample.annotation = mydataset_genlight@other$ind.metrics # contains all individual metrics in a dataframe format

class(sample.annotation) # data.frame

    mydataset_GDS_File= snpgdsOpen("C:/gabry/analysis/mydataset_GDS.gds", readonly=FALSE, allow.duplicate=FALSE, 
                                                              allow.fork=TRUE)
    
    class(mydataset_GDS_File) # "SNPGDSFileClass" "gds.class"     
    
    get.attr.gdsn(index.gdsn(mydataset_GDS_File, "snp.chromosome")) # NULL
    get.attr.gdsn(index.gdsn(mydataset_GDS_File, "sample.annotation")) #   No such GDS node "sample.annotation"!

    
    add.gdsn(mydataset_GDS_File, "sample.annotation", sample.annotation)
        **# Error in add.gdsn(Blacktip_Rep0.98_test_5genotypes_GDS_File, "sample.annotation",  : 
        # Invalid GDS node object (it was unloaded or deleted).**
    "

I don't know how else to include the sample/individuals metadata in the GDS file. I would really appreciate some help! Thanks a lot! Best, Gabriella

GabryS3 avatar Nov 08 '23 03:11 GabryS3