Subsetting a VCF by a logical vector
1
1
Entering edit mode
2.2 years ago
Timotheus ▴ 40

Hello,

I'd like to subset variants in my VCF using a logical vector with indices corresponding to variant indices. I started familiarising myself with the vcfR package: I load my VCF into R, perform some custom operations to obtain the logical vector (note: the point is NOT simple filtering by QUAL, DP etc.), and then I'm stuck. Any suggestions?

(I'm not providing a reproducible example since this should be a general feature of the package I'm probably missing?)

Thanks in advance!

vcf vcfR R • 789 views
ADD COMMENT
0
Entering edit mode
2.1 years ago
zx8754 12k

We can subset the same way as we do with data.frames, for example:

# load example vcf
library(vcfR)
pkg <- "pinfsc50"
vcf_file <- system.file("extdata", "pinf_sc50.vcf.gz", package = pkg)
vcf <- read.vcfR( vcf_file, verbose = FALSE )

# check - we have 22031 variants
vcf
# ***** Object of Class vcfR *****
# 18 samples
# 1 CHROMs
# 22,031 variants
# Object size: 22.4 Mb
# 7.929 percent missing data
# *****        *****         *****

# rows to subset
rowNumber <- c(1, 3, 5)

# subset, keep only 3 rows
vcf@fix <- vcf@fix[ rowNumber, ]
vcf@gt <- vcf@gt[ rowNumber, ]

# check - now we have 3 variants
vcf
# ***** Object of Class vcfR *****
# 18 samples
# 1 CHROMs
# 3 variants
# Object size: 0 Mb
# 7.407 percent missing data
# *****        *****         *****
ADD COMMENT

Login before adding your answer.

Traffic: 2113 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6