Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@ export(variant.genotypes.float.attribute)
export(variant.genotypes.allele.idx0)
export(variant.genotypes.allele.counts)
export(variant.genotypes.allele.strings)

export(variant.genotypes.set.int.attribute)
export(variant.genotypes.set.float.attribute)
export(variant.genotypes.set.allele.strings)
81 changes: 81 additions & 0 deletions R/rbcf.R
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,87 @@ variant.genotypes.float.attribute <- function(vc, att) {
.Call("VariantGenotypesFloatAttribute", vc, att)
}

#' Set a specific FORMAT integer value on all genotypes
#'
#' The vector must contain the values by sample and attribute number (if the attribute comprises multiple integer values).
#'
#' For example, for a 3 sample VCF setting the allelic read depth (AD) on a singleton variant, the would look like:
#' ```
#' GT1-REF, GT1-ALT, GT2-REF, GT2-ALT, GT3-REF, GT3-ALT
#' c( 10, 100, 25, 94, 45, 7)
#' ```
#'
#' @param vc the variant
#' @param att a character vector containing the variant attribute
#' @param values a numeric vector to set the value (will be converted to integer)
#'
#' @return the variant `vc`
#'
#' @seealso
#' \link{variant.genotypes.int.attribute}
#'
variant.genotypes.set.int.attribute <- function(vc, att, values) {
stopifnot(looks_like_variant_context(vc))
stopifnot(is.character(att))
stopifnot(length(att) == 1)
stopifnot(is.numeric(values))
.Call("VariantGenotypesSetInt32Attribute", vc, att, as.integer(values))
}

#' Set a specific FORMAT float value on all genotypes
#'
#' The vector must contain the values by sample and attribute number (if the attribute comprises multiple integer values).
#'
#' For example, for a 3 sample VCF setting the allelic read fraction (AF) on a singleton variant, the would look like:
#' ```
#' GT1-AF, GT2-AF, GT3-AF
#' c( 1.0, 0.8, 0.25)
#' ```
#'
#' @param vc the variant
#' @param att a character vector containing the variant attribute
#' @param values a numeric vector to set the value (will be converted to float)
#'
#' @return the variant `vc`
#'
#' @seealso
#' \link{variant.genotypes.int.attribute}
#'
variant.genotypes.set.float.attribute <- function(vc, att, values) {
stopifnot(looks_like_variant_context(vc))
stopifnot(is.character(att))
stopifnot(length(att) == 1)
stopifnot(is.numeric(values))
.Call("VariantGenotypesSetFloatAttribute", vc, att, values)
}

#' Set the genotypes `FORMAT/GT` for all genotype call of a variant
#'
#' The vector must contain the values in the order of `bcf.samples`:
#' ```
#' Sample1, Sample2, Sample3
#' c( "0/1", "0/0", NA)
#' ```
#'
#' The `NA` will be replaces by ".".
#'
#' @param vc the variant
#' @param values a characters vector containing the genotype calls (see details)
#'
#' @return the variant `vc`
#'
#' @seealso
#' \link{variant.genotypes.allele.strings}
#'
variant.genotypes.set.allele.strings <- function(vc, values) {
stopifnot(looks_like_variant_context(vc))
stopifnot(is.character(values))
values[ is.na(values) ] <- "."
.Call("VariantGenotypesSetAllGtStrings", vc, as.character(values))
}



#' @param gt the genotype
#' @param att the key
#' @return the values for this key+genotype
Expand Down
115 changes: 111 additions & 4 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Makevars
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ $(HTSDIR)/Makefile:
wget -O "htslib-$(HSTLIB_VERSION).tar.bz2" "https://github.com/samtools/htslib/releases/download/$(HSTLIB_VERSION)/htslib-$(HSTLIB_VERSION).tar.bz2"
tar xfj htslib-$(HSTLIB_VERSION).tar.bz2
mv "htslib-$(HSTLIB_VERSION)" "$(HTSDIR)"
(cd $(HTSDIR) && ./configure && sed -i '/^CFLAGS/s/$$/ -fPIC/' config.mk) || rm $@
(cd $(HTSDIR) && ./configure --without-libdeflate && sed -i '/^CFLAGS/s/$$/ -fPIC/' config.mk) || rm $@

clean:
rm -f librbcf.so
Expand Down
Loading