seqAddValue: Add values to a GDS File

Description Usage Arguments Value Author(s) See Also Examples

View source: R/AddValue.R

Description

Add or modify the values in a GDS file with hash code

Usage

1
2
seqAddValue(gdsfile, varnm, val, desp=character(), replace=FALSE,
    compress="LZMA_RA", packed=TRUE, verbose=TRUE, verbose.attr=TRUE)

Arguments

gdsfile

character for file name, or a SeqVarGDSClass object

varnm

the variable name, e.g., "sample.id", "variant.id", "chromosome", "annotation/info/NEW_VARIABLE"

val

the R value can be integers, real numbers, characters, factor, logical, raw variable, data.frame or a list; a list of vectors is used for variable-length annotation data

desp

variable description

replace

if TRUE, replace the existing variable silently if possible

compress

the compression method can be "" (no compression), see add.gdsn

packed

TRUE, pack data if there is any missing value

verbose

if TRUE, show information

verbose.attr

if TRUE, show attribute information in a GDS node

Value

Return none.

Author(s)

Xiuwen Zheng

See Also

seqVCF2GDS

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# the file of GDS
gds.fn <- seqExampleFileName("gds")
file.copy(gds.fn, "tmp.gds", overwrite=TRUE)

# display
(f <- seqOpen("tmp.gds", FALSE))

show(index.gdsn(f, "sample.id"))
seqAddValue(f, "sample.id", 1:90, replace=TRUE)
show(index.gdsn(f, "sample.id"))

show(index.gdsn(f, "chromosome"))
v <- seqGetData(f, "chromosome")
seqAddValue(f, "chromosome", paste0("chr", v), replace=TRUE)
show(index.gdsn(f, "chromosome"))
table(seqGetData(f, "chromosome"))

# annotation info
seqAddValue(f, "annotation/info/folder", NULL)  # add a new folder
seqAddValue(f, "annotation/info/folder/val", 1:1348, "random number")
seqAddValue(f, "annotation/info/folder/packed", c(rep(2L, 1000), rep(NA, 348)))
seqAddValue(f, "annotation/info/newff",
    data.frame(x=1:1348, y=rep("s", 1348), stringsAsFactors=FALSE),
    desp=c("integer numbers", "character"))

# variable-length annotation info data
v <- lapply(1:1348, function(x) as.character(x))
v[[1]] <- 1:10
seqAddValue(f, "annotation/info/folder/val1", v)
head(seqGetData(f, "annotation/info/folder/val1", .tolist=TRUE))


# sample annotation
seqAddValue(f, "sample.annotation", data.frame(ii=1:90, y=rep("A", 90)),
    replace=TRUE)
seqAddValue(f, "sample.annotation/float", (1:90)/90)

# close the GDS file
seqClose(f)


# remove the temporary file
unlink("tmp.gds", force=TRUE)

Example output

Loading required package: gdsfmt
[1] TRUE
Object of class "SeqVarGDSClass"
File: /work/tmp/tmp.gds (287.6K)
+    [  ] *
|--+ description   [  ] *
|--+ sample.id   { Str8 90 LZMA_ra(34.7%), 257B } *
|--+ variant.id   { Int32 1348 LZMA_ra(16.7%), 905B } *
|--+ position   { Int32 1348 LZMA_ra(64.4%), 3.4K } *
|--+ chromosome   { Str8 1348 LZMA_ra(4.39%), 157B } *
|--+ allele   { Str8 1348 LZMA_ra(16.6%), 901B } *
|--+ genotype   [  ] *
|  |--+ data   { Bit2 2x90x1348 LZMA_ra(26.3%), 15.6K } *
|  |--+ ~data   { Bit2 2x1348x90 LZMA_ra(29.2%), 17.3K } *
|  |--+ extra.index   { Int32 3x0 LZMA_ra, 18B } *
|  \--+ extra   { Int16 0 LZMA_ra, 18B }
|--+ phase   [  ]
|  |--+ data   { Bit1 90x1348 LZMA_ra(0.86%), 137B } *
|  |--+ ~data   { Bit1 1348x90 LZMA_ra(0.86%), 137B } *
|  |--+ extra.index   { Int32 3x0 LZMA_ra, 18B } *
|  \--+ extra   { Bit1 0 LZMA_ra, 18B }
|--+ annotation   [  ]
|  |--+ id   { Str8 1348 LZMA_ra(38.3%), 5.5K } *
|  |--+ qual   { Float32 1348 LZMA_ra(2.11%), 121B } *
|  |--+ filter   { Int32,factor 1348 LZMA_ra(2.11%), 121B } *
|  |--+ info   [  ]
|  |  |--+ AA   { Str8 1328 LZMA_ra(22.1%), 593B } *
|  |  |--+ AC   { Int32 1348 LZMA_ra(24.1%), 1.3K } *
|  |  |--+ AN   { Int32 1348 LZMA_ra(19.6%), 1.0K } *
|  |  |--+ DP   { Int32 1348 LZMA_ra(47.7%), 2.5K } *
|  |  |--+ HM2   { Bit1 1348 LZMA_ra(145.6%), 253B } *
|  |  |--+ HM3   { Bit1 1348 LZMA_ra(145.6%), 253B } *
|  |  |--+ OR   { Str8 1348 LZMA_ra(19.6%), 341B } *
|  |  |--+ GP   { Str8 1348 LZMA_ra(24.3%), 3.8K } *
|  |  \--+ BN   { Int32 1348 LZMA_ra(20.7%), 1.1K } *
|  \--+ format   [  ]
|     \--+ DP   [  ] *
|        |--+ data   { VL_Int 90x1348 LZMA_ra(70.8%), 115.2K } *
|        \--+ ~data   { VL_Int 1348x90 LZMA_ra(65.1%), 105.9K } *
\--+ sample.annotation   [  ]
   \--+ family   { Str8 90 LZMA_ra(55.0%), 221B } *
+ sample.id   { Str8 90 LZMA_ra(34.7%), 257B } *
Preview:
NA06984
NA06985
NA06986
NA06989
NA06994
NA07000
...
NA12874
NA12878
NA12889
NA12890
NA12891
NA12892
+ sample.id   { Int32 90 LZMA_RA.def:256K(51.7%), 193B } *< md5: 3133effc005bdba70558ac496c5e7194
+ sample.id   { Int32 90 LZMA_ra(51.7%), 193B } *
Preview:
 1
 2
 3
 4
 5
 6
...
85
86
87
88
89
90
+ chromosome   { Str8 1348 LZMA_ra(4.39%), 157B } *
Preview:
1 
1 
1 
1 
1 
1 
...
22
22
22
22
22
22
+ chromosome   { Str8 1348 LZMA_RA.def:256K(2.33%), 181B } *< md5: 7a93135d605fcc3fd38b68c1a6da563d
+ chromosome   { Str8 1348 LZMA_ra(2.33%), 181B } *
Preview:
chr1 
chr1 
chr1 
chr1 
chr1 
chr1 
...
chr22
chr22
chr22
chr22
chr22
chr22

 chr1 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19  chr2 chr20 
  142    70    16    62    11    61    46    84   100    54   111    59    59 
chr21 chr22  chr3  chr4  chr5  chr6  chr7  chr8  chr9 
   23    23    81    48    61    99    58    51    29 
+ annotation/info/folder   [  ]
+ annotation/info/folder/val   { Int32 1348 LZMA_RA.def:256K(16.7%), 905B } *< Number: 1; Type: Integer; Description: random number; md5: c9602a5420b6a5a148f5a0120a8750e1
+ annotation/info/folder/packed   { Int32 1000 LZMA_RA.def:256K(2.75%), 117B } *< Number: .; Type: Integer; Description: ; md5: ab9b771a1678c158d542d1127b47de9d
+ annotation/info/newff   [  ]
+ annotation/info/newff/x   { Int32 1348 LZMA_RA.def:256K(16.7%), 905B } *< Number: 1; Type: Integer; Description: integer numbers; md5: c9602a5420b6a5a148f5a0120a8750e1
+ annotation/info/newff/y   { Str8 1348 LZMA_RA.def:256K(3.78%), 109B } *< Number: 1; Type: String; Description: character; md5: 32ada2164d0e10f8ba171cbfa6273c9c
+ annotation/info/folder/val1   { Str8 1357 LZMA_RA.def:256K(13.2%), 753B } *< Number: .; Type: String; Description: ; md5: 4a142a45d44058f6f71bd2fc405c8683
[[1]]
 [1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10"

[[2]]
[1] "2"

[[3]]
[1] "3"

[[4]]
[1] "4"

[[5]]
[1] "5"

[[6]]
[1] "6"

+ sample.annotation/float   { Float64 90 LZMA_RA.def:256K(57.5%), 421B } *< md5: 8865a69a103565ca994d833a8a9dd6e2

SeqArray documentation built on Nov. 8, 2020, 5:08 p.m.