Skip to content

Commit

Permalink
fix printf on mac
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanxw committed Jan 31, 2024
1 parent 5d728c1 commit 7b7568f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 36 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2024-01-30 Xiaowei Zhan <zhanxw@bunny.swmed.edu>

* Fix Rprintf() related issues on ARM64 (Mac M1)

2023-11-28 Xiaowei Zhan <zhanxw@bunny.swmed.edu>

* Fix Rprintf() related issues
Expand Down
30 changes: 21 additions & 9 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Package: seqminer
Type: Package
Title: Efficiently Read Sequence Data (VCF Format, BCF Format, METAL
Format and BGEN Format) into R
Version: 9.3
Date: 2023-11-18
Version: 9.4
Date: 2024-01-30
Authors@R: c(person("Xiaowei", "Zhan", email = "zhanxw@gmail.com", role = c("aut", "cre")),
person("Dajiang", "Liu", email = "dajiang.liu@gmail.com", role = "aut"),
person("Attractive Chaos", email = "attractor@live.co.uk", role = "cph", comment = "We have used the following software and made minimal necessary changes: Tabix, Heng Li <lh3@live.co.uk> (MIT license). We removed standard IO related functions, e.g. printf, fprintf ; also changed its un-safe pointer arithmetics."),
Expand All @@ -15,18 +15,30 @@ Maintainer: Xiaowei Zhan <zhanxw@gmail.com>
Description: Integrate sequencing data (Variant call format, e.g. VCF or BCF) or meta-analysis results in R. This package can help you (1) read VCF/BCF/BGEN files by chromosomal ranges (e.g. 1:100-200); (2) read RareMETAL summary statistics files; (3) read tables from a tabix-indexed files; (4) annotate VCF/BCF files; (5) create customized workflow based on Makefile.
Copyright: We have used the following software and made minimal
necessary changes: tabix, Heng Li <lh3@live.co.uk> (MIT
license), SQLite (Public Domain), Zstandard (BSD license).
For tabix, we removed standard IO related functions, e.g.
printf, fprintf ; also changed its un-safe pointer arithmetics.
For zstandard, we removed compiler (clang, MSVC) specific preprocessing flags.
license), SQLite (Public Domain), Zstandard (BSD license). For
tabix, we removed standard IO related functions, e.g. printf,
fprintf ; also changed its un-safe pointer arithmetics. For
zstandard, we removed compiler (clang, MSVC) specific
preprocessing flags.
License: GPL | file LICENSE
URL: http://zhanxw.github.io/seqminer/
BugReports: https://github.com/zhanxw/seqminer/issues
Packaged: 2018-12-04 22:14:20 UTC; zhanxw
Packaged: 2023-11-28 06:37:59 UTC; zhanxw
Repository: CRAN
Suggests: testthat, SKAT
SystemRequirements: C++17, zlib headers and libraries, GNU make, optionally also bzip2
and POSIX-compliant regex functions.
SystemRequirements: C++17, zlib headers and libraries, GNU make,
optionally also bzip2 and POSIX-compliant regex functions.
NeedsCompilation: yes
RoxygenNote: 7.2.3
Encoding: UTF-8
Author: Xiaowei Zhan [aut, cre],
Dajiang Liu [aut],
Attractive Chaos [cph] (We have used the following software and made
minimal necessary changes: Tabix, Heng Li <lh3@live.co.uk> (MIT
license). We removed standard IO related functions, e.g. printf,
fprintf ; also changed its un-safe pointer arithmetics.),
Broad Institute / Massachusetts Institute of Technology [cph],
Genome Research Ltd (GRL) [cph],
Facebook, Inc [cph],
D. Richard Hipp [cph]
Date/Publication: 2023-11-28 09:10:02 UTC
30 changes: 16 additions & 14 deletions src/SingleChromosomeBCFIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ int SingleChromosomeBCFIndex::createIndex() {
const int64_t num_sample =
(int)bcfHeader.sample_names.size() -
9; // vcf header has 9 columns CHROM...FORMAT before actual sample names
#ifndef __MINGW64__
Rprintf("sample size = %ld\n", num_sample);
#if defined(__MINGW64__) || ( defined(__APPLE__) && defined(__arm64__))
Rprintf("sample size = %g\n", (double) num_sample);
#else
Rprintf("sample size = %ld\n", (unsigned long int)num_sample);
#endif
Expand Down Expand Up @@ -167,8 +167,8 @@ int SingleChromosomeBCFIndex::createIndex() {

num_marker++;
if (num_marker % 10000 == 0) {
#ifndef __MINGW64__
Rprintf("\rprocessed %ld markers", num_marker);
#if defined(__MINGW64__) || ( defined(__APPLE__) && defined(__arm64__))
Rprintf("\rprocessed %g markers", (double) num_marker);
#else
Rprintf("\rprocessed %ld markers", (unsigned long int)num_marker);
#endif
Expand All @@ -181,9 +181,10 @@ int SingleChromosomeBCFIndex::createIndex() {
fwrite(&num_sample, sizeof(int64_t), 1, fIndex);
fwrite(&num_marker, sizeof(int64_t), 1, fIndex);
fclose(fIndex);
#ifndef __MINGW64__
Rprintf("Indexing finished with %ld samples and %ld markers\n", num_sample,
num_marker);
#if defined(__MINGW64__) || ( defined(__APPLE__) && defined(__arm64__))
Rprintf("Indexing finished with %g samples and %g markers\n",
(double) num_sample,
(double) num_marker);
#else
Rprintf("Indexing finished with %ld samples and %ld markers\n",
(unsigned long int)num_sample, (unsigned long int)num_marker);
Expand All @@ -209,8 +210,8 @@ int SingleChromosomeBCFIndex::openIndex() {
sizeof(Record) *
(2L + d[1])) { // d[0, 1]: number of sample; number of marker
REprintf("Check file integrity!\n");
#ifndef __MINGW64__
REprintf("d = %ld %ld fsize = %ld\n", d[0], d[1], (long int)fsize);
#if defined(__MINGW64__) || ( defined(__APPLE__) && defined(__arm64__))
REprintf("d = %g %g fsize = %g\n", (double) d[0], (double) d[1], (double) fsize);
#else
REprintf("d = %ld %ld fsize = %ld\n", (unsigned long int)d[0],
(unsigned long int)d[1], (long int)fsize);
Expand Down Expand Up @@ -255,8 +256,8 @@ int SingleChromosomeBCFIndex::query(int chromPosBeg, int chromPosEnd,
comparator); // r[ub].pos > query.pos = chromPosEnd
REprintf("Found %d results\n", (int)(ub - lb));
for (Record* pi = lb; pi != ub; ++pi) {
#ifndef __MINGW64__
REprintf("%ld %ld\n", pi->pos, pi->offset);
#if defined(__MINGW64__) || ( defined(__APPLE__) && defined(__arm64__))
REprintf("%g %g\n", (double) pi->pos, (double) pi->offset);
#else
REprintf("%ld %ld\n", (unsigned long int)pi->pos,
(unsigned long int)pi->offset);
Expand All @@ -269,9 +270,10 @@ int SingleChromosomeBCFIndex::query(int chromPosBeg, int chromPosEnd,
REprintf("Cannot find position!\n");
return -1;
} else {
#ifndef __MINGW64__
REprintf("found %d position, e.g. %ld %ld\n", (int)(ub - lb), (*lb).pos,
(*lb).offset);
#if defined(__MINGW64__) || ( defined(__APPLE__) && defined(__arm64__))
REprintf("found %d position, e.g. %g %g\n", (int)(ub - lb),
(double) (*lb).pos,
(double) (*lb).offset);
#else
REprintf("found %d position, e.g. %ld %ld\n", (int)(ub - lb),
(unsigned long int)(*lb).pos, (unsigned long int)(*lb).offset);
Expand Down
28 changes: 15 additions & 13 deletions src/SingleChromosomeVCFIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,16 @@ int SingleChromosomeVCFIndex::createIndex() {
stringTokenize(line, '\t', &fd);
numSample =
fd.size() - 9; // 9 is CHROM POS ID REF ALT QUAL FILTER INFO FORMAT
#ifndef __MINGW64__
REprintf("header line has %ld samples\n", numSample);
#if defined(__MINGW64__) || ( defined(__APPLE__) && defined(__arm64__))
REprintf("header line has %g samples\n", (double)numSample);
#else
REprintf("header line has %ld samples\n", (unsigned long int)numSample);
REprintf("header line has %ld samples\n", numSample);
#endif
pos = 0;
fwrite(&pos, sizeof(int64_t), 1, fIndex);
fwrite(&offset, sizeof(int64_t), 1, fIndex);
#ifndef __MINGW64__
REprintf("offset = %ld\n", offset);
#if defined(__MINGW64__) || ( defined(__APPLE__) && defined(__arm64__))
REprintf("offset = %g\n", (double)offset);
#else
REprintf("offset = %ld\n", (unsigned long int)offset);
#endif
Expand Down Expand Up @@ -146,9 +146,10 @@ int SingleChromosomeVCFIndex::createIndex() {
// bgzf_close(fp);
fclose(fIndex);

#ifndef __MINGW64__
REprintf("Indexing finished with %ld samples and %ld markers\n", numSample,
numMarker);
#if defined(__MINGW64__) || ( defined(__APPLE__) && defined(__arm64__))
REprintf("Indexing finished with %g samples and %g markers\n",
(double) numSample,
(double) numMarker);
#else
REprintf("Indexing finished with %ld samples and %ld markers\n",
(unsigned long int)numSample, (unsigned long int)numMarker);
Expand All @@ -172,8 +173,8 @@ int SingleChromosomeVCFIndex::openIndex() {
int64_t* d = (int64_t*)data_;
if (fsize != sizeof(Record) * (2L + d[1])) {
REprintf("Check file integrity!\n");
#ifndef __MINGW64__
REprintf("d = %ld %ld fsize = %ld\n", d[0], d[1], (long int)fsize);
#if defined(__MINGW64__) || ( defined(__APPLE__) && defined(__arm64__))
REprintf("d = %g %g fsize = %g\n", (double) d[0], (double) d[1], (double) fsize);
#else
REprintf("d = %ld %ld fsize = %ld\n", (unsigned long int)d[0],
(unsigned long int)d[1], (long int)fsize);
Expand Down Expand Up @@ -248,9 +249,10 @@ int SingleChromosomeVCFIndex::query(int chromPosBeg, int chromPosEnd,
REprintf("Cannot find position!\n");
return -1;
} else {
#ifndef __MINGW64__
REprintf("found %d position, e.g. %ld %ld\n", (int)(ub - lb), (*lb).pos,
(*lb).offset);
#if defined(__MINGW64__) || ( defined(__APPLE__) && defined(__arm64__))
REprintf("found %d position, e.g. %ld %ld\n", (int)(ub - lb),
(double) (*lb).pos,
(double) (*lb).offset);
#else
REprintf("found %d position, e.g. %ld %ld\n", (int)(ub - lb),
(unsigned long int)(*lb).pos, (unsigned long int)(*lb).offset);
Expand Down

0 comments on commit 7b7568f

Please sign in to comment.