Skip to content

Commit

Permalink
USE_NO_REMAP
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengxwen committed Sep 26, 2024
1 parent 9ec7eaa commit 1240dd0
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 76 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Package: SNPRelate
Type: Package
Title: Parallel Computing Toolset for Relatedness and Principal Component
Analysis of SNP Data
Version: 1.37.5
Date: 2024-04-11
Version: 1.38.1
Date: 2024-09-26
Depends: R (>= 2.15), gdsfmt (>= 1.8.3)
LinkingTo: gdsfmt
Imports: methods
Expand Down
11 changes: 10 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
CHANGES IN VERSION 1.37.4
CHANGES IN VERSION 1.38.1
-------------------------

UTILITIES

o update the C codes according to '_R_USE_STRICT_R_HEADERS_=true' &
'_R_CXX_USE_NO_REMAP_=true'


CHANGES IN VERSION 1.38.0
-------------------------

UTILITIES
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The GDS format offers the efficient operations specifically designed for integer

## Bioconductor

Release Version: v1.36.1
Release Version: v1.38.0

[http://www.bioconductor.org/packages/SNPRelate](http://www.bioconductor.org/packages/SNPRelate)

Expand Down
15 changes: 8 additions & 7 deletions man/snpgdsGRM.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,24 @@ snpgdsGRM(gdsobj, sample.id=NULL, snp.id=NULL,
}
\details{
"GCTA": the genetic relationship matrix in GCTA is defined as
$G_{ij} = avg_l [(g_{il} - 2*p_l)*(g_{jl} - 2*p_l) / 2*p_l*(1 - p_l)]$ for
$G_ij = avg_l [(g_il - 2*p_l*(g_jl - 2*p_l) / 2*p_l*(1 - p_l)]$ for
individuals i,j and locus l;

"Eigenstrat": the genetic covariance matrix in EIGENSTRAT
$G_{ij} = avg_l [(g_{il} - 2*p_l)*(g_{jl} - 2*p_l) / 2*p_l*(1 - p_l)]$ for
$G_ij = avg_l [(g_il - 2*p_l)*(g_jl - 2*p_l) / 2*p_l*(1 - p_l)]$ for
individuals i,j and locus l; the missing genotype is imputed by the dosage
mean of that locus.

"EIGMIX" / "Weighted": it is the same as `2 * snpgdsEIGMIX(, ibdmat=TRUE,
diagadj=FALSE)$ibd`:
$G_{ij} = [sum_l (g_{il} - 2*p_l)*(g_{jl} - 2*p_l)] / [sum_l 2*p_l*(1 - p_l)]$
$G_ij = [sum_l (g_il - 2*p_l)*(g_jl - 2*p_l)] / [sum_l 2*p_l*(1 - p_l)]$
for individuals i,j and locus l;

"IndivBeta": `beta = snpgdsIndivBeta(, inbreeding=TRUE)` (Weir&Goudet, 2017), and
beta-based GRM is $grm_{ij} = 2 * (beta_{ij} - beta_{min}) / (1 - beta_{min})$ for $i!=j$,
$grm_{ij} = 1 + (beta_{i} - beta_{min}) / (1 - beta_{min})$ for $i=j$. It is relative to
the minimum value of beta estimates.
"IndivBeta": `beta = snpgdsIndivBeta(, inbreeding=TRUE)`
(Weir&Goudet, 2017), and beta-based GRM is
$grm_ij = 2 * (beta_ij - beta_min) / (1 - beta_min)$ for $i!=j$,
$grm_ij = 1 + (beta_i - beta_min) / (1 - beta_min)$ for $i=j$.
It is relative to the minimum value of beta estimates.
}
\value{
Return a list if \code{with.id = TRUE}:
Expand Down
38 changes: 19 additions & 19 deletions src/ConvToGDS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class COREARRAY_DLL_LOCAL CReadLine
}

// call ReadLine R function
SEXP val = eval(_ReadFun, _Rho);
SEXP val = Rf_eval(_ReadFun, _Rho);
PROTECT(val);
nProt ++;

Expand Down Expand Up @@ -544,17 +544,17 @@ COREARRAY_DLL_EXPORT SEXP gnrConvBEDFlag(SEXP File, SEXP ReadBinFun, SEXP Rho)
// 'readBin(File, raw(), 3)'
SEXP R_Read_Call = PROTECT(
LCONS(ReadBinFun, LCONS(File,
LCONS(NEW_RAW(0), LCONS(ScalarInteger(3), R_NilValue)))));
LCONS(NEW_RAW(0), LCONS(Rf_ScalarInteger(3), R_NilValue)))));

// call ...
SEXP val = PROTECT(eval(R_Read_Call, Rho));
SEXP val = PROTECT(Rf_eval(R_Read_Call, Rho));
unsigned char *prefix = RAW(val);

if ((prefix[0] != 0x6C) || (prefix[1] != 0x1B))
error("Invalid prefix in the bed file.");
Rf_error("Invalid prefix in the bed file.");

UNPROTECT(2);
return ScalarInteger((C_UInt8)prefix[2]);
return Rf_ScalarInteger((C_UInt8)prefix[2]);
}


Expand All @@ -578,7 +578,7 @@ COREARRAY_DLL_EXPORT SEXP gnrConvBED2GDS(SEXP GenoNode, SEXP Num, SEXP File,
// 'readBin(File, raw(), 3)'
SEXP R_Read_Call = PROTECT(
LCONS(ReadBinFun, LCONS(File,
LCONS(NEW_RAW(0), LCONS(ScalarInteger(nPack), R_NilValue)))));
LCONS(NEW_RAW(0), LCONS(Rf_ScalarInteger(nPack), R_NilValue)))));

CProgress Progress(verbose ? n : -1);
vector<C_UInt8> dstgeno(DLen[1]);
Expand All @@ -587,7 +587,7 @@ COREARRAY_DLL_EXPORT SEXP gnrConvBED2GDS(SEXP GenoNode, SEXP Num, SEXP File,
for (int i=0; i < n; i++)
{
// read genotypes
SEXP val = eval(R_Read_Call, Rho);
SEXP val = Rf_eval(R_Read_Call, Rho);
unsigned char *srcgeno = RAW(val);

// unpacked
Expand Down Expand Up @@ -670,9 +670,9 @@ COREARRAY_DLL_EXPORT SEXP gnrParseVCF4(SEXP vcf_fn, SEXP gds_root,
{
const char *fn = CHAR(STRING_ELT(vcf_fn, 0));
int met_idx = INTEGER(method)[0];
int verbose = asLogical(Verbose);
int verbose = Rf_asLogical(Verbose);
if (verbose == NA_LOGICAL)
error("'verbose' must be TRUE or FALSE.");
Rf_error("'verbose' must be TRUE or FALSE.");

// define a variable for reading lines
CReadLine RL;
Expand Down Expand Up @@ -991,7 +991,7 @@ COREARRAY_DLL_EXPORT SEXP gnrParseVCF4(SEXP vcf_fn, SEXP gds_root,
}

UNPROTECT(1);
rv_ans = ScalarInteger(GDS_Variant_Index - old_variant_index);
rv_ans = Rf_ScalarInteger(GDS_Variant_Index - old_variant_index);

COREARRAY_TRY_END
}
Expand All @@ -1017,9 +1017,9 @@ COREARRAY_DLL_EXPORT SEXP gnrParseGEN(SEXP gen_fn, SEXP gds_root,
SEXP ReadLine_N, SEXP rho, SEXP Verbose)
{
const char *fn = CHAR(STRING_ELT(gen_fn, 0));
int verbose = asLogical(Verbose);
int verbose = Rf_asLogical(Verbose);
if (verbose == NA_LOGICAL)
error("'verbose' must be TRUE or FALSE.");
Rf_error("'verbose' must be TRUE or FALSE.");
const double CallProb = REAL(CallThreshold)[0];

// define a variable for reading lines
Expand Down Expand Up @@ -1151,7 +1151,7 @@ COREARRAY_DLL_EXPORT SEXP gnrParseGEN(SEXP gen_fn, SEXP gds_root,
}

UNPROTECT(1);
rv_ans = ScalarInteger(LN);
rv_ans = Rf_ScalarInteger(LN);

COREARRAY_TRY_END
}
Expand Down Expand Up @@ -1179,7 +1179,7 @@ COREARRAY_DLL_EXPORT SEXP gnrParsePED(SEXP ped_fn, SEXP gds_root,
const char *fn = CHAR(STRING_ELT(ped_fn, 0));
int verbose = Rf_asLogical(Verbose);
if (verbose == NA_LOGICAL)
error("'verbose' must be TRUE or FALSE.");
Rf_error("'verbose' must be TRUE or FALSE.");

// the number of SNPs
const int nSNP = Rf_length(SNPIdx);
Expand Down Expand Up @@ -1215,7 +1215,7 @@ COREARRAY_DLL_EXPORT SEXP gnrParsePED(SEXP ped_fn, SEXP gds_root,
// 'readLine(con, n)'
SEXP R_Read_Call = PROTECT(
LCONS(ReadLineFun, LCONS(ReadLine_File1,
LCONS(ScalarInteger(1), R_NilValue))));
LCONS(Rf_ScalarInteger(1), R_NilValue))));
RL.Init(R_Read_Call, rho);
RL.SplitBySpaceTab();

Expand Down Expand Up @@ -1282,7 +1282,7 @@ COREARRAY_DLL_EXPORT SEXP gnrParsePED(SEXP ped_fn, SEXP gds_root,
// 'readLine(con, n)'
R_Read_Call = PROTECT(
LCONS(ReadLineFun, LCONS(ReadLine_File2,
LCONS(ScalarInteger(1), R_NilValue))));
LCONS(Rf_ScalarInteger(1), R_NilValue))));
RL.Init(R_Read_Call, rho);
RL.SplitBySpaceTab();

Expand Down Expand Up @@ -1383,7 +1383,7 @@ COREARRAY_DLL_EXPORT SEXP gnrParseGProbs(SEXP ped_fn, SEXP gds_root,
const char *fn = CHAR(STRING_ELT(ped_fn, 0));
int verbose = Rf_asLogical(Verbose);
if (verbose == NA_LOGICAL)
error("'verbose' must be TRUE or FALSE.");
Rf_error("'verbose' must be TRUE or FALSE.");

// the number of SNPs
const int nSNP = Rf_length(SNPIdx);
Expand Down Expand Up @@ -1419,7 +1419,7 @@ COREARRAY_DLL_EXPORT SEXP gnrParseGProbs(SEXP ped_fn, SEXP gds_root,
// 'readLine(con, n)'
SEXP R_Read_Call = PROTECT(
LCONS(ReadLineFun, LCONS(ReadLine_File1,
LCONS(ScalarInteger(1), R_NilValue))));
LCONS(Rf_ScalarInteger(1), R_NilValue))));
RL.Init(R_Read_Call, rho);
RL.SplitBySpaceTab();

Expand Down Expand Up @@ -1486,7 +1486,7 @@ COREARRAY_DLL_EXPORT SEXP gnrParseGProbs(SEXP ped_fn, SEXP gds_root,
// 'readLine(con, n)'
R_Read_Call = PROTECT(
LCONS(ReadLineFun, LCONS(ReadLine_File2,
LCONS(ScalarInteger(1), R_NilValue))));
LCONS(Rf_ScalarInteger(1), R_NilValue))));
RL.Init(R_Read_Call, rho);
RL.SplitBySpaceTab();

Expand Down
42 changes: 21 additions & 21 deletions src/SNPRelate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ COREARRAY_DLL_EXPORT SEXP gnrSSEFlag()
#else
int I = 0;
#endif
return ScalarInteger(I);
return Rf_ScalarInteger(I);
}


Expand Down Expand Up @@ -168,7 +168,7 @@ COREARRAY_DLL_EXPORT SEXP gnrGetGenoDim()
COREARRAY_DLL_EXPORT SEXP gnrGetGenoDimInfo()
{
COREARRAY_TRY
rv_ans = ScalarLogical(
rv_ans = Rf_ScalarLogical(
MCWorkingGeno.Space().GenoDimType() == RDim_Sample_X_SNP ?
FALSE : TRUE);
COREARRAY_CATCH
Expand All @@ -195,7 +195,7 @@ COREARRAY_DLL_EXPORT SEXP gnrSelSNP_Base(SEXP remove_mono, SEXP maf,
RM_MONO==TRUE, MAF, MRATE, &sel[0]);

rv_ans = PROTECT(NEW_LIST(2));
SET_ELEMENT(rv_ans, 0, ScalarInteger(OutNum));
SET_ELEMENT(rv_ans, 0, Rf_ScalarInteger(OutNum));
SEXP Flag = PROTECT(NEW_LOGICAL(n));
SET_ELEMENT(rv_ans, 1, Flag);

Expand Down Expand Up @@ -227,7 +227,7 @@ COREARRAY_DLL_EXPORT SEXP gnrSelSNP_Base_Ex(SEXP afreq, SEXP remove_mono,
pFreq, RM_MONO == TRUE, MAF, MRATE, &sel[0]);

rv_ans = PROTECT(NEW_LIST(2));
SET_ELEMENT(rv_ans, 0, ScalarInteger(OutNum));
SET_ELEMENT(rv_ans, 0, Rf_ScalarInteger(OutNum));
SEXP Flag = PROTECT(NEW_LOGICAL(n));
SET_ELEMENT(rv_ans, 1, Flag);

Expand Down Expand Up @@ -286,9 +286,9 @@ COREARRAY_DLL_EXPORT SEXP gnrSampFreq()
/// copy genotypes
COREARRAY_DLL_EXPORT SEXP gnrCopyGeno(SEXP Node, SEXP snpfirstorder)
{
int snpdim = asLogical(snpfirstorder);
int snpdim = Rf_asLogical(snpfirstorder);
if (snpdim == NA_LOGICAL)
error("'snpfirstdim' must be TRUE or FALSE.");
Rf_error("'snpfirstdim' must be TRUE or FALSE.");

COREARRAY_TRY

Expand Down Expand Up @@ -407,7 +407,7 @@ static void _ParseAlleleString(const char *str, string &A1, string &A2)
COREARRAY_DLL_EXPORT SEXP gnrStrandSwitch(SEXP Node, SEXP AlleleNode,
SEXP NewAlleleNode, SEXP SNP_First_Dim, SEXP A_Allele)
{
int snpfirstdim = asLogical(SNP_First_Dim);
int snpfirstdim = Rf_asLogical(SNP_First_Dim);

COREARRAY_TRY

Expand Down Expand Up @@ -665,10 +665,10 @@ COREARRAY_DLL_EXPORT SEXP gnrConvGDS2PED(SEXP pedfn, SEXP SampID, SEXP Allele,
SEXP fmt_code, SEXP verbose)
{
const char *fn = CHAR(STRING_ELT(pedfn, 0));
int fmt = asInteger(fmt_code);
int if_verbose = asLogical(verbose);
int fmt = Rf_asInteger(fmt_code);
int if_verbose = Rf_asLogical(verbose);
if (if_verbose == NA_LOGICAL)
error("'verbose' must be TRUE or FALSE.");
Rf_error("'verbose' must be TRUE or FALSE.");

COREARRAY_TRY

Expand Down Expand Up @@ -750,10 +750,10 @@ COREARRAY_DLL_EXPORT SEXP gnrConvGDS2PED(SEXP pedfn, SEXP SampID, SEXP Allele,
COREARRAY_DLL_EXPORT SEXP gnrConvGDS2BED(SEXP bedfn, SEXP SNPOrder, SEXP Verbose)
{
const char *fn = CHAR(STRING_ELT(bedfn, 0));
int if_snp = (asLogical(SNPOrder) == TRUE);
int if_verbose = asLogical(Verbose);
int if_snp = (Rf_asLogical(SNPOrder) == TRUE);
int if_verbose = Rf_asLogical(Verbose);
if (if_verbose == NA_LOGICAL)
error("'verbose' must be TRUE or FALSE.");
Rf_error("'verbose' must be TRUE or FALSE.");

COREARRAY_TRY

Expand Down Expand Up @@ -807,9 +807,9 @@ COREARRAY_DLL_EXPORT SEXP gnrConvGDS2BED(SEXP bedfn, SEXP SNPOrder, SEXP Verbose
COREARRAY_DLL_EXPORT SEXP gnrConvGDS2EIGEN(SEXP pedfn, SEXP verbose)
{
const char *fn = CHAR(STRING_ELT(pedfn, 0));
int if_verbose = asLogical(verbose);
int if_verbose = Rf_asLogical(verbose);
if (if_verbose == NA_LOGICAL)
error("'verbose' must be TRUE or FALSE.");
Rf_error("'verbose' must be TRUE or FALSE.");

COREARRAY_TRY

Expand Down Expand Up @@ -879,9 +879,9 @@ static inline void split_allele(const char *txt, string &a1, string &a2)
COREARRAY_DLL_EXPORT SEXP gnrAlleleStrand(SEXP allele1, SEXP allele2,
SEXP afreq1, SEXP afreq2, SEXP same_strand)
{
int same_on_strand = asLogical(same_strand);
int same_on_strand = Rf_asLogical(same_strand);
if (same_on_strand == NA_LOGICAL)
error("'same.strand' must be TRUE or FALSE.");
Rf_error("'same.strand' must be TRUE or FALSE.");

COREARRAY_TRY

Expand Down Expand Up @@ -993,15 +993,15 @@ COREARRAY_DLL_EXPORT SEXP gnrChromParse(SEXP gdsobj)
if (chr_max == -INT_MAX) chr_max = NA_INTEGER;

PROTECT(rv_ans = NEW_LIST(3));
SET_ELEMENT(rv_ans, 0, ScalarInteger(chr_min));
SET_ELEMENT(rv_ans, 1, ScalarInteger(chr_max));
SET_ELEMENT(rv_ans, 0, Rf_ScalarInteger(chr_min));
SET_ELEMENT(rv_ans, 1, Rf_ScalarInteger(chr_max));

SEXP tmp = PROTECT(NEW_CHARACTER(set_val.size()));
SET_ELEMENT(rv_ans, 2, tmp);
int id = 0;
for (set<string>::iterator i=set_val.begin(); i != set_val.end(); i++)
{
SET_STRING_ELT(tmp, id, mkChar(i->c_str()));
SET_STRING_ELT(tmp, id, Rf_mkChar(i->c_str()));
id ++;
}

Expand Down Expand Up @@ -1077,7 +1077,7 @@ COREARRAY_DLL_EXPORT SEXP gnrChromParseNumeric(SEXP gdsobj)
/// get an error message
COREARRAY_DLL_EXPORT SEXP gnrErrMsg()
{
SEXP ans_rv = mkString(GDS_GetError());
SEXP ans_rv = Rf_mkString(GDS_GetError());
GDS_SetError(NULL);
return ans_rv;
}
Expand Down
4 changes: 2 additions & 2 deletions src/dGenGWAS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2252,7 +2252,7 @@ void GWAS::Array_SplitJobs(int nJob, C_Int64 TotalCount, C_Int64 outStart[],
SEXP GWAS::RGetListElement(SEXP list, const char *name)
{
SEXP elmt = R_NilValue;
SEXP names = getAttrib(list, R_NamesSymbol);
SEXP names = Rf_getAttrib(list, R_NamesSymbol);
size_t n = (!Rf_isNull(names)) ? XLENGTH(names) : 0;
for (size_t i = 0; i < n; i++)
{
Expand All @@ -2269,7 +2269,7 @@ bool GWAS::SEXP_Verbose(SEXP Verbose)
{
int flag = Rf_asLogical(Verbose);
if (flag == NA_LOGICAL)
error("'verbose' must be TRUE or FALSE.");
Rf_error("'verbose' must be TRUE or FALSE.");
return (flag == TRUE);
}

Expand Down
2 changes: 1 addition & 1 deletion src/genBeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ COREARRAY_DLL_EXPORT SEXP gnrIBD_Beta(SEXP Inbreeding, SEXP NumThread,
{
int inbreeding = Rf_asLogical(Inbreeding);
if (inbreeding == NA_LOGICAL)
error("'inbreeding' must be TRUE or FALSE.");
Rf_error("'inbreeding' must be TRUE or FALSE.");
bool verbose = SEXP_Verbose(Verbose);

COREARRAY_TRY
Expand Down
6 changes: 3 additions & 3 deletions src/genEIGMIX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,10 +659,10 @@ COREARRAY_DLL_EXPORT SEXP gnrEigMix(SEXP EigenCnt, SEXP NumThread,
const bool verbose = SEXP_Verbose(Verbose);
int diag_adj = Rf_asLogical(RGetListElement(ParamList, "diagadj"));
if (diag_adj == NA_LOGICAL)
error("'diagadj' must be TRUE or FALSE.");
Rf_error("'diagadj' must be TRUE or FALSE.");
int need_ibd = Rf_asLogical(RGetListElement(ParamList, "ibdmat"));
if (need_ibd == NA_LOGICAL)
error("'ibdmat' must be TRUE or FALSE.");
Rf_error("'ibdmat' must be TRUE or FALSE.");

COREARRAY_TRY

Expand Down Expand Up @@ -748,7 +748,7 @@ COREARRAY_DLL_EXPORT SEXP gnrEigMixSNPLoading(SEXP EigenVal, SEXP EigenVect,
CachingSNPData("SNP Loading", verbose);

// scale eigenvectors with eigenvalues
SEXP EigVect = PROTECT(duplicate(EigenVect));
SEXP EigVect = PROTECT(Rf_duplicate(EigenVect));
{
const size_t n = MCWorkingGeno.Space().SampleNum();
for (int i=0; i < LenEig; i++)
Expand Down
Loading

0 comments on commit 1240dd0

Please sign in to comment.