Skip to content

Commit

Permalink
mode-0x11 forward-compatibility patch
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchang committed May 3, 2024
1 parent 7c586b6 commit ddc52d9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
22 changes: 12 additions & 10 deletions 2.0/include/pgenlib_read.cc
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,10 @@ PglErr PgfiInitPhase1(const char* fname, const char* pgi_fname, uint32_t raw_var
// This isn't Golang.
char pgi_fname_buf[kPglFnamesize];

if (file_type_code != 0x20) {
if (unlikely(file_type_code == 0x30)) {
// since this branch is getting long-term support, include mode 0x11 / 0x21
// forward-compatibility patch
if ((file_type_code != 0x20) && (file_type_code != 0x21)) {
if (unlikely((file_type_code == 0x30) || (file_type_code == 0x31))) {
snprintf(errstr_buf, kPglErrstrBufBlen, "Error: %s is a .pgen.pgi index file, rather than a .pgen file.\n", fname);
return kPglRetMalformedInput;
}
Expand Down Expand Up @@ -920,8 +922,7 @@ PglErr PgfiInitPhase1(const char* fname, const char* pgi_fname, uint32_t raw_var
*pgfi_alloc_cacheline_ct_ptr = 0;
return kPglRetSuccess;
}
if (unlikely((file_type_code >= 0x11) && (file_type_code != 0x20))) {
// possible todo: 0x11 phase sets (unlikely before 2023, though)
if (unlikely((file_type_code >= 0x12) && (file_type_code != 0x20) && (file_type_code != 0x21))) {
snprintf(errstr_buf, kPglErrstrBufBlen, "Error: Third byte of %s does not correspond to a storage mode supported by this version of pgenlib.\n", fname);
return kPglRetNotYetSupported;
}
Expand Down Expand Up @@ -1412,7 +1413,7 @@ PglErr PgfiInitPhase2(PgenHeaderCtrl header_ctrl, uint32_t allele_cts_already_lo
const uint64_t actual_fpos = ftello(pgfip->shared_ff);
if (actual_fpos != pgfip->var_fpos[0]) {
// now > instead of != to allow additional information to be stored between
// header and first variant record
// header and first variant record (e.g. mode 0x11).
if (unlikely(actual_fpos > pgfip->var_fpos[0])) {
snprintf(errstr_buf, kPglErrstrBufBlen, "Error: Invalid .pgen%s.\n", is_pgi? ".pgi file" : " header");
return kPglRetMalformedInput;
Expand Down Expand Up @@ -10053,11 +10054,12 @@ PglErr PgrValidate(PgenReader* pgr_ptr, uintptr_t* genovec_buf, char* errstr_buf
}
fsize = ftello(ff);
pgrp->fp_vidx = 1; // force fseek when loading first variant
// todo: modify this check when phase sets are implemented
const uint64_t expected_fsize = pgrp->fi.var_fpos[variant_ct];
if (unlikely(expected_fsize != fsize)) {
char* write_iter = strcpya_k(errstr_buf, "Error: .pgen header indicates that file size should be ");
write_iter = i64toa(expected_fsize, write_iter);
// todo: verify equality if no mode-0x11 footer; and if there is a footer,
// validate it
const uint64_t expected_fsize_min = pgrp->fi.var_fpos[variant_ct];
if (unlikely(expected_fsize_min > fsize)) {
char* write_iter = strcpya_k(errstr_buf, "Error: .pgen header indicates that file size should be at least ");
write_iter = i64toa(expected_fsize_min, write_iter);
write_iter = strcpya_k(write_iter, " bytes, but actual file size is ");
write_iter = i64toa(fsize, write_iter);
strcpy_k(write_iter, " bytes.\n");
Expand Down
6 changes: 3 additions & 3 deletions 2.0/include/pgenlib_read.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ typedef struct PgenReaderMainStruct {
uintptr_t* workspace_dosage_present;
uintptr_t* workspace_dphase_present;

// phase set loading (mode 0x11) unimplemented for now; should be a sequence
// of (sample ID, [uint32_t phase set begin, set end), [set begin, set end),
// ...).
// phase set loading (footer track in mode 0x11) unimplemented for now;
// should be a sequence of (sample ID, [uint32_t phase set begin, set end),
// [set begin, set end), ...).
} PgenReaderMain;

typedef struct PgenReaderStruct {
Expand Down
2 changes: 1 addition & 1 deletion 2.0/plink2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static const char ver_str[] = "PLINK v2.00a5.11"
#elif defined(USE_AOCL)
" AMD"
#endif
" (xx Apr 2024)";
" (xx May 2024)";
static const char ver_str2[] =
// include leading space if day < 10, so character length stays the same
""
Expand Down

0 comments on commit ddc52d9

Please sign in to comment.