Skip to content

Commit

Permalink
uninitialized dosage_ct fix
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchang committed Jan 22, 2025
1 parent eaf1616 commit bcd968d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
8 changes: 4 additions & 4 deletions 1.9/plink.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@

static const char ver_str[] =
#ifdef STABLE_BUILD
"PLINK v1.9.0-b.7.8"
"PLINK v1.9.0-b.7.7.a"
#else
"PLINK v1.9.0-b.8"
#endif
Expand All @@ -110,14 +110,14 @@ static const char ver_str2[] =
// include leading space if day < 10, so character length stays the same
""
#ifdef STABLE_BUILD
" " // (don't want this when version number has two trailing digits)
" " // adjust based on length of version number
#else
" "
" "
#endif
#ifndef NOLAPACK
" "
#endif
" cog-genomics.org/plink/1.9/\n"
" cog-genomics.org/plink/1.9/\n"
"(C) 2005-2025 Shaun Purcell, Christopher Chang GNU General Public License v3"
#if SPECIES_DEFAULT > 0
"\nRecompiled with default species = "
Expand Down
11 changes: 7 additions & 4 deletions 2.0/Tests/TEST_PHASED_VCF/glm_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ def float_compare_ok(val1, val2, tol):
def main():
cmd_args = parse_commandline_args()
pc_ct = 0
line_num = 0
tol = cmd_args.tolerance
with open(cmd_args.plink1, 'r') as plink1_file, open(cmd_args.plink2, 'r') as plink2_file:
reader1 = csv.reader(plink1_file, delimiter=' ', skipinitialspace=True)
reader2 = csv.reader(plink2_file, delimiter='\t')
first_line1 = next(reader1)
first_line2 = next(reader2)
line_num += 1
if first_line2.index('#CHROM') != 0:
eprint('Unsupported plink2 association file format (this script requires #CHROM in front, even though plink2 can omit it).')
sys.exit(1)
Expand Down Expand Up @@ -95,6 +97,7 @@ def main():

for row1 in reader1:
row2 = next(reader2)
line_num += 1
if row1[0] != row2[0] or \
row1[2] != row2[pos_col2] or \
row1[1] != row2[id_col2] or \
Expand All @@ -109,7 +112,7 @@ def main():
# very unlikely to happen on random data, so error out and then
# manually pass if necessary.
if row2[errcode_col2] == 'INVALID_RESULT':
eprint('Unexpected INVALID_RESULT.')
eprint('Unexpected INVALID_RESULT, line', line_num)
sys.exit(1)
if row2[betaor_col2] != 'NA':
val1 = float(row1[6])
Expand All @@ -119,21 +122,21 @@ def main():
val1 = math.log(val1)
val2 = math.log(val2)
if not float_compare_ok(val1, val2, tol):
eprint('BETA/OR mismatch.')
eprint('BETA/OR mismatch, line', line_num)
sys.exit(1)
if row1[7] != 'NA' and row1[7] != 'inf' and row2[stat_col2] != 'NA':
val1 = float(row1[7])
val2 = float(row2[stat_col2])
if row1[4][-2:] != 'DF':
# skip GENO_2DF, USER_xDF due to transition to F-statistics
if not float_compare_ok(val1, val2, tol):
eprint('STAT mismatch.')
eprint('STAT mismatch, line', line_num)
sys.exit(1)
if row1[8] != 'NA' and row2[p_col2] != 'NA':
val1 = math.log(float(row1[8]))
val2 = math.log(float(row2[p_col2]))
if not float_compare_ok(val1, val2, tol):
eprint('P-value mismatch.')
eprint('P-value mismatch, line', line_num)
sys.exit(1)


Expand Down
9 changes: 6 additions & 3 deletions 2.0/Tests/TEST_PHASED_VCF/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,13 @@ $1/plink2 --bfile plink1_data --clump cols=+f plink2_glm.PHENO1.glm.linear --clu
cat plink2_test.clumps | tail -n +2 | awk '{print $3"\t"$6"\t"$7"\t"$8"\t"$9"\t"$10"\t"$11"\t"$12}' > plink2_test.clump_compare
diff -q plink1_test.clump_compare plink2_test.clump_compare

plink --bfile plink1_data --maf 0.02 --pheno pheno_cc.txt --logistic genotypic --covar plink1_pca.eigenvec --allow-no-sex --out plink1_glm
$1/plink2 $2 $3 --bfile plink1_data --maf 0.02 --pheno pheno_cc.txt --glm no-firth single-prec-cc genotypic --covar plink2_pca.eigenvec --out plink2_glm
# exclude rs368311657 for now since possible ARM/x86 mismatch seems to be
# spurious (driven by floating-point rounding), though this is worth looking at
# more closely
plink --bfile plink1_data --maf 0.02 --pheno pheno_cc.txt --logistic genotypic --covar plink1_pca.eigenvec --allow-no-sex --out plink1_glm --exclude-snp rs368311657
$1/plink2 $2 $3 --bfile plink1_data --maf 0.02 --pheno pheno_cc.txt --glm no-firth single-prec-cc genotypic --covar plink2_pca.eigenvec --out plink2_glm --exclude-snp rs368311657
python3 glm_compare.py -1 plink1_glm.assoc.logistic -2 plink2_glm.PHENO1.glm.logistic -t 0.1
$1/plink2 $2 $3 --bfile plink1_data --maf 0.02 --pheno pheno_cc.txt --glm no-firth genotypic --covar plink2_pca.eigenvec --out plink2_glm_dbl
$1/plink2 $2 $3 --bfile plink1_data --maf 0.02 --pheno pheno_cc.txt --glm no-firth genotypic --covar plink2_pca.eigenvec --out plink2_glm_dbl --exclude-snp rs368311657
python3 glm_compare.py -1 plink1_glm.assoc.logistic -2 plink2_glm_dbl.PHENO1.glm.logistic -t 0.3
plink --bfile plink1_data --maf 0.02 --pheno pheno_qt.txt --linear genotypic --covar plink1_pca.eigenvec --allow-no-sex --out plink1_glm
$1/plink2 $2 $3 --bfile plink1_data --maf 0.02 --pheno pheno_qt.txt --glm genotypic --covar plink2_pca.eigenvec --out plink2_glm
Expand Down
4 changes: 2 additions & 2 deletions 2.0/plink2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
namespace plink2 {
#endif

static const char ver_str[] = "PLINK v2.0.0-a.6.7.a"
static const char ver_str[] = "PLINK v2.0.0-a.6.8"
#ifdef NOLAPACK
"NL"
#elif defined(LAPACK_ILP64)
Expand Down Expand Up @@ -100,7 +100,7 @@ static const char ver_str2[] =
# endif
#endif

" cog-genomics.org/plink/2.0/\n"
" cog-genomics.org/plink/2.0/\n"
"(C) 2005-2025 Shaun Purcell, Christopher Chang GNU General Public License v3\n";
static const char errstr_append[] = "For more info, try \"" PROG_NAME_STR " --help <flag name>\" or \"" PROG_NAME_STR " --help | more\".\n";

Expand Down
4 changes: 4 additions & 0 deletions 2.0/plink2_glm_linear.cc
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ THREAD_FUNC_DECL GlmLinearThread(void* raw_arg) {
pgv.genovec = common->genovecs[tidx];
pgv.dosage_present = nullptr;
pgv.dosage_main = nullptr;
// bugfix (22 Jan 2025): this could be uninitialized when
// PgrGetDifflistOrGenovec was used
pgv.dosage_ct = 0;
if (common->dosage_presents) {
pgv.dosage_present = common->dosage_presents[tidx];
pgv.dosage_main = common->dosage_mains[tidx];
Expand Down Expand Up @@ -2538,6 +2541,7 @@ THREAD_FUNC_DECL GlmLinearSubbatchThread(void* raw_arg) {
pgv.genovec = common->genovecs[tidx];
pgv.dosage_present = nullptr;
pgv.dosage_main = nullptr;
pgv.dosage_ct = 0;
if (common->dosage_presents) {
pgv.dosage_present = common->dosage_presents[tidx];
pgv.dosage_main = common->dosage_mains[tidx];
Expand Down

0 comments on commit bcd968d

Please sign in to comment.