Skip to content

Commit

Permalink
phased-r2 bugfix: clip single negative root up to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchang committed Jan 29, 2025
1 parent 956b8f0 commit ca0af51
Show file tree
Hide file tree
Showing 11 changed files with 294 additions and 33 deletions.
4 changes: 2 additions & 2 deletions 2.0/pgenlibr/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: pgenlibr
Type: Package
Title: PLINK 2 Binary (.pgen) Reader
Version: 0.4.0
Date: 2025-01-15
Version: 0.4.1
Date: 2025-0x-yy
Authors@R: c(person(given = "Christopher",
family = "Chang",
role = c("aut", "cre"),
Expand Down
2 changes: 2 additions & 0 deletions 2.0/pgenlibr/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export(GetVariantId)
export(GetVariantPos)
export(GetVariantsById)
export(HardcallPhasePresent)
export(HasSparseHardcalls)
export(IntAlleleCodeBuf)
export(IntBuf)
export(NewPgen)
Expand All @@ -24,6 +25,7 @@ export(ReadAlleles)
export(ReadHardcalls)
export(ReadIntList)
export(ReadList)
export(ReadSparseHardcalls)
export(VariantScores)
import(Rcpp)
importFrom(Rcpp,evalCpp)
Expand Down
40 changes: 38 additions & 2 deletions 2.0/pgenlibr/R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,49 @@ BoolBuf <- function(pgen) {
#' @param variant_num Variant index (1-based).
#' @param allele_num Allele index; 1 corresponds to REF, 2 to the first ALT
#' allele, 3 to the second ALT allele if it exists, etc. Optional, defaults
#' 2.
#' to 2.
#' @return No return value, called for buf-filling side-effect.
#' @export
ReadHardcalls <- function(pgen, buf, variant_num, allele_num = 2L) {
invisible(.Call(`_pgenlibr_ReadHardcalls`, pgen, buf, variant_num, allele_num))
}

#' Returns whether hardcalls for the variant_numth variant and given allele
#' are represented in a sparse manner that is supported by
#' ReadSparseHardcalls().
#'
#' @param pgen Object returned by NewPgen().
#' @param variant_num Variant index (1-based).
#' @param allele_num Allele index; 1 corresponds to REF, 2 to the first ALT
#' allele, 3 to the second ALT allele if it exists, etc. Optional, defaults
#' to 2.
#' @return True iff the (variant, allele) pair has a sparse representation
#' that can be returned by ReadSparseHardcalls().
#' @export
HasSparseHardcalls <- function(pgen, variant_num, allele_num = 2L) {
.Call(`_pgenlibr_HasSparseHardcalls`, pgen, variant_num, allele_num)
}

#' If HasSparseHardcalls() is true, returns a sparse representation for the
#' (variant, allele) pair. If HasSparseHardcalls() is false, the function
#' fails.
#'
#' @param pgen Object returned by NewPgen().
#' @param variant_num Variant index (1-based).
#' @param allele_num Allele index; 1 corresponds to REF, 2 to the first ALT
#' allele, 3 to the second ALT allele if it exists, etc. Optional, defaults
#' to 2.
#' @param return_ints Whether to make the "counts" component of the return
#' value an IntegerVector instead of a NumericVector; defaults to false.
#' @return Either an empty list, in which case buf is filled in the same
#' mannerObject where "sample_ids" is an increasing sequence of positive
#' integers listing which samples have the allele, and "counts" is a vector
#' listing the allele counts for those samples.
#' @export
ReadSparseHardcalls <- function(pgen, variant_num, allele_num = 2L, return_ints = FALSE) {
.Call(`_pgenlibr_ReadSparseHardcalls`, pgen, variant_num, allele_num, return_ints)
}

#' Loads the variant_numth variant, and then fills buf with numeric dosages
#' in [0, 2] indicating the dosages of the first ALT (or user-specified)
#' allele for each sample, with missing values represented by NA.
Expand All @@ -148,7 +184,7 @@ ReadHardcalls <- function(pgen, buf, variant_num, allele_num = 2L) {
#' @param variant_num Variant index (1-based).
#' @param allele_num Allele index; 1 corresponds to REF, 2 to the first ALT
#' allele, 3 to the second ALT allele if it exists, etc. Optional, defaults
#' 2.
#' to 2.
#' @return No return value, called for buf-filling side-effect.
#' @export
Read <- function(pgen, buf, variant_num, allele_num = 2L) {
Expand Down
28 changes: 28 additions & 0 deletions 2.0/pgenlibr/man/HasSparseHardcalls.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion 2.0/pgenlibr/man/Read.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion 2.0/pgenlibr/man/ReadHardcalls.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions 2.0/pgenlibr/man/ReadSparseHardcalls.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions 2.0/pgenlibr/src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,33 @@ BEGIN_RCPP
return R_NilValue;
END_RCPP
}
// HasSparseHardcalls
bool HasSparseHardcalls(List pgen, int variant_num, int allele_num);
RcppExport SEXP _pgenlibr_HasSparseHardcalls(SEXP pgenSEXP, SEXP variant_numSEXP, SEXP allele_numSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< List >::type pgen(pgenSEXP);
Rcpp::traits::input_parameter< int >::type variant_num(variant_numSEXP);
Rcpp::traits::input_parameter< int >::type allele_num(allele_numSEXP);
rcpp_result_gen = Rcpp::wrap(HasSparseHardcalls(pgen, variant_num, allele_num));
return rcpp_result_gen;
END_RCPP
}
// ReadSparseHardcalls
List ReadSparseHardcalls(List pgen, int variant_num, int allele_num, bool return_ints);
RcppExport SEXP _pgenlibr_ReadSparseHardcalls(SEXP pgenSEXP, SEXP variant_numSEXP, SEXP allele_numSEXP, SEXP return_intsSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< List >::type pgen(pgenSEXP);
Rcpp::traits::input_parameter< int >::type variant_num(variant_numSEXP);
Rcpp::traits::input_parameter< int >::type allele_num(allele_numSEXP);
Rcpp::traits::input_parameter< bool >::type return_ints(return_intsSEXP);
rcpp_result_gen = Rcpp::wrap(ReadSparseHardcalls(pgen, variant_num, allele_num, return_ints));
return rcpp_result_gen;
END_RCPP
}
// Read
void Read(List pgen, NumericVector buf, int variant_num, int allele_num);
RcppExport SEXP _pgenlibr_Read(SEXP pgenSEXP, SEXP bufSEXP, SEXP variant_numSEXP, SEXP allele_numSEXP) {
Expand Down Expand Up @@ -320,6 +347,8 @@ static const R_CallMethodDef CallEntries[] = {
{"_pgenlibr_IntAlleleCodeBuf", (DL_FUNC) &_pgenlibr_IntAlleleCodeBuf, 1},
{"_pgenlibr_BoolBuf", (DL_FUNC) &_pgenlibr_BoolBuf, 1},
{"_pgenlibr_ReadHardcalls", (DL_FUNC) &_pgenlibr_ReadHardcalls, 4},
{"_pgenlibr_HasSparseHardcalls", (DL_FUNC) &_pgenlibr_HasSparseHardcalls, 3},
{"_pgenlibr_ReadSparseHardcalls", (DL_FUNC) &_pgenlibr_ReadSparseHardcalls, 4},
{"_pgenlibr_Read", (DL_FUNC) &_pgenlibr_Read, 4},
{"_pgenlibr_ReadAlleles", (DL_FUNC) &_pgenlibr_ReadAlleles, 4},
{"_pgenlibr_ReadIntList", (DL_FUNC) &_pgenlibr_ReadIntList, 2},
Expand Down
Loading

0 comments on commit ca0af51

Please sign in to comment.