BamScaleR 0.99.6
Build
- Only C++ code now uses OpenMP. The parallel block compression of the vendored libBigWig writer moved from C (
bwWrite.c) to C++ (src/bw_compress.cpp), sosrc/Makevarsandsrc/Makevars.winno longer put$(SHLIB_OPENMP_CFLAGS)inPKG_CFLAGS. This removes theR CMD check --as-cranNOTE “SHLIB_OPENMP_CFLAGS is included in PKG_CFLAGS but not in PKG_LIBS”, and follows Writing R Extensions (section 1.2.1.1), which notes that using OpenMP from more than one of C, C++ and Fortran in a package is not portable. bigWig output is unchanged (byte-identical). -
configure(macOS) no longer probes C OpenMP flags, andBAMSCALER_OPENMP_CFLAGSis no longer read. OpenMP flags that a user’s own configuration applies to C code (for exampleCFLAGS += -Xclang -fopenmp) no longer stop the installation.
BamScaleR 0.99.5
- No code changes. Version bump so the Bioconductor submission bot reports the build of this version (its report labelled 0.99.4 showed the 0.99.3 build).
BamScaleR 0.99.4
Bug fixes
- A test of
bam_coverage_bigwig()failed on Windows: it built an output path ending in a separator withfile.path(x, ""), which drops the trailing separator on Windows. The package code is unchanged.
BamScaleR 0.99.3
Changes in response to the Bioconductor review (BiocContributions#226).
Bug fixes
- macOS: BamScaleR could fail to load with
symbol not found in flat namespace '___kmpc_critical'. CRAN’s R for macOS does not enable OpenMP itself; when it is enabled locally with-Xclang -fopenmp(for example in~/.R/Makevars), OpenMP code is generated but the OpenMP runtime (libomp) is not linked. A newconfigurescript now tests candidate compile/link flags by building anddyn.load()ing a small library that uses the same OpenMP constructs as the package (including dynamic loop schedules), and falls back to a build without OpenMP (one thread per file, otherwise fully functional) when none works. With CRAN’s R the runtime linked is always thelibompthat ships with R; an OpenMP install from mac.r-project.org or Homebrew supplies the header. If R’s runtime is too old for the compiler (Apple clang 17 needs LLVM 19 or later), the installation log says so. If the user’s own flags switch OpenMP on for every package, so that a build without OpenMP is impossible,configurestops with a message saying so. Linux and Windows builds are unchanged. Flags can be set by hand with bothBAMSCALER_OPENMP_CXXFLAGSandBAMSCALER_OPENMP_LIBS. - Multi-file calls no longer modify the supplied
BPPARAM. Previously the worker count could be reduced in place withbpworkers<-; becauseBiocParallelParamobjects have reference semantics this changed the caller’s object for later use and, for an already-started cluster, left its reported worker count out of step with the running workers. The files are passed tobplapply()directly, as before, except that aSnowParamthat is not running is started with only the workers needed (no more than the files, or than anauto_threadsplan allows) and stopped again afterwards; that under anauto_threadscap aMulticoreParamthat is not running is replaced by a copy with fewer workers; and that under a cap the files of a running cluster, or of another kind ofBPPARAM, are grouped into that many tasks (an error then names the file, andbptry()returns per-group results). - Linux: once OpenMP threads had been used in the R session (by BamScaleR or another package, such as data.table), a multi-file call with
MulticoreParamandthreads > 1could hang forever, because GCC’s OpenMP runtime cannot start threads in a forked process once its parent has used them. BamScaleR now releases the runtime’s idle threads before eachfork()(with libgomp 9 or later, looked up at run time), so forked workers use the requested threads. This applies to everyfork()in the session and may discard other libraries’ OpenMP thread-private data. With an older libgomp, a worker forked after BamScaleR has used threads reads on one thread, and one forked after another package used OpenMP threads can still hang; useSnowParam(type = "SOCK")there. -
param$whichkept only records whose start position lay in a range, so alignments that start before a range and extend into it were missing. It now keeps every alignment that overlaps a range, asRsamtoolsdoes (each record once, under the first range it overlaps). As inRsamtools, a zero-width range now selects nothing and a range on a sequence that is not in the BAM header is an error (it silently matched nothing). An emptywhichnow means no restriction instead of an error; ranges with missing values, or with an end less than start - 1, are an error; repeated range labels are made unique (so a range given twice gets an empty second batch). -
bam_coverage_bigwig():- compressed blocks on every available core whatever
threadswas; it now usesthreads; - a failure while finishing the file (for example a full disk) left a truncated bigWig and returned normally; it is now an error and the partial file is removed;
- opened the output in text mode on Windows (the vendored libBigWig ignored the binary mode it was given), which would corrupt the file;
- with
parallel = FALSE, a write failure while writing the data (for example a full disk) overran the vendored libBigWig’s write buffer, which could crash R; it is now an error and the partial file is removed; - crashed R for an
outfilein a directory that does not exist or cannot be written. That, anoutfilethat is a directory (or ends in a path separator) or cannot be overwritten, repeatedoutfilepaths (also through symbolic links) and anoutfilethat is one of the input BAMs are now errors before any work. Output paths are made absolute (and~expanded) before they reach the workers.
- compressed blocks on every available core whatever
-
bam_read(as = "GAlignmentPairs")paired the i-th first mate with the i-th last mate of each read name, which mismatched mates when a read had secondary or supplementary alignments. Mates are now matched byGenomicAlignments::makeGAlignmentPairs()(read name, mate position, strand, first/last, proper-pair and secondary flags); withoutwhichthis gives the same pairs asreadGAlignmentPairs(), ordered by first-mate position. When nothing can be paired, an emptyGAlignmentPairsis returned instead of an error. -
mapq_dist()no longer counts unmapped reads (at MAPQ 0), andfragment_sizes()withdrop_mate_unmapped = TRUEnow also drops unmapped reads, asscanBam()reportsNAfor both. - Settings of
ScanBamParamthat are not supported (tagFilter,simpleCigar,reverseComplement, andwhichin the summary functions), and unknown entries of a list-formparam, now give a warning instead of being ignored silently. A list-formparamnow appliesflag(ascanBamFlag()value, which was silently dropped) and matches entry names exactly. -
use.names = TRUEnow namesGAlignmentsoutput even whenwhatdoes not include"qname", andwith.which_label = TRUEadds a column only whenwhichis set. Input paths starting with~are now expanded, and relative input paths (also ofBamFileandBamFileListinputs) are made absolute, soSnowParamworkers started in another directory read the intended files.
Improvements
- The
GAlignmentsfast path no longer calls the non-exportedS4Vectors:::new2(). The object is assembled by slot assignment on a valid prototype, and the C++ reader counts the records whose validity it cannot guarantee by construction (a CIGAR with an op code above 8 or a zero-length op, and an alignment outside its sequence); if there are any,validObject()is run, so an invalid object is never returned and out-of-bound alignments warn as withreadGAlignments(). - Requesting
threads> 1 on a build without OpenMP now warns once per session instead of silently running single-threaded, andauto_threadsthen keeps allBPPARAMworkers.
Documentation
- The main vignette has a new section with evaluated examples of
fragment_sizes(),mapq_dist(),bam_coverage()andbam_coverage_bigwig(), each compared with the standard Bioconductor route; an installation section covering OpenMP on macOS; and a section on what BamScaleR adds to ompBAM. - The benchmark vignette now computes every table and number from CSV files shipped in
inst/extdata/(canonical run of 2026-10-08), with their provenance documented ininst/scripts/make_benchmark_extdata.Rand a table of the ENCODE accessions used. Two thread-scaling statements that had been carried over from an earlier, smaller run were corrected. - Expanded the DESCRIPTION
Descriptionfield.
Dependencies
-
parallelis now declared inImports;testthat(>= 3.1.7) andwithr(used by the test setup) inSuggests. - Removed unused
Suggests:chipseqDBData,dplyr,ExperimentHub,readr,tibble,tidyr. Packages needed only by the benchmark scripts ininst/benchmarks/(includingchipseqDBDataandATACseqQC) are listed ininst/benchmarks/README.mdand are intentionally not declared in DESCRIPTION.
BamScaleR 0.99.2
Documentation
- README and the benchmark vignette now report the canonical benchmark run of 2026-10-08, measured on the full 25-file public ENCODE ATAC-seq corpus (single-file target ENCFF191LNL, 151,057,932 alignments). The previous tables came from a much smaller early run and overstated some results: the
GAlignmentsread speedup was shown as 4.03x against a measured 2.50x, and coverage to an in-memoryRleListas 3.29x against 2.49x. Read-pattern speedups are 1.94-2.50x, ATAC fragment-size QC 4.39x end-to-end, and coverage to bigWig 1.52x. - Added the measured in-reader aggregation results to the README (5.47-7.06x over the standard Bioconductor routes; 3.45x over megadepth at matched core counts) and the memory characteristic of
bam_coverage(). - Documented the rename from BamScale and the distinction from the unrelated NCBI command-line tool BAMscale.
- Installation instructions no longer advertise a Bioconductor install that does not yet work; BamScaleR is still under review.
- Recorded two further limitations: sublinear intra-file thread scaling, and that object-free command-line decoders reach higher raw throughput.
BamScaleR 0.99.1
Bug fixes
-
bam_coverage()andbam_coverage_bigwig()no longer allocate memory proportional to the genome declared in the BAM header. The coverage core previously built a dense per-base difference array for every header sequence before reading a single alignment, so a BAM carrying few alignments still cost several GB whenever its header declared a whole genome – 12.6 GB for a 1.4 MB file with a GRCh38 header – and the collapse pass then walked every base of every contig. Coverage is now accumulated as per-thread interval endpoints and swept per contig, so memory and time scale with the alignments actually present rather than with the reference. Contigs without alignments cost nothing and still emit the correct full-length zero run.Measured on a 2.5 GB ATAC-seq BAM (195 contigs): peak RSS 14.2 GB -> 2.5 GB and 71.0 s -> 14.9 s at 24 threads. On a 1.4 MB BAM with a whole-genome header: 12.6 GB -> 0.55 GB (R’s baseline) and 17.6 s -> 7.8 s. Output is unchanged and remains
identical()tocoverage(readGAlignments())at every thread count.Removing the shared difference array also removes the atomic updates from the read loop, which is where most of the speedup comes from.
BamScaleR 0.99.0
Package rename
- The package has been renamed from BamScale to BamScaleR. The former name collided with the existing NCBI command-line tool BAMscale (https://github.com/ncbi/BAMscale; Pongor et al., Epigenetics & Chromatin 2020, doi:10.1186/s13072-020-00343-x), which performs a different task: normalised (“scaled”) coverage-track generation and peak quantification. The rename removes that ambiguity.
- No user-facing functionality changed. All exported functions keep their names, arguments and behaviour.
- The option
BamScale.ga_fastpathis nowBamScaleR.ga_fastpath. - BamScale was accepted into Bioconductor devel on 4 May 2026 and was never part of a numbered Bioconductor release, so no deprecation cycle applies. BamScaleR is submitted as its renamed continuation and version numbering restarts at 0.99.0, as required for a new submission. The entries below document this package’s history under its former name.
Earlier history (as BamScale)
The entries below document this package’s development under its former name, BamScale, before the rename described above. Those version numbers belong to the former name’s series: BamScale was accepted into Bioconductor devel on 4 May 2026 and never shipped in a numbered release, so version numbering restarts at 0.99.0 under the new name. The code described below is carried forward into BamScaleR unchanged.
BamScale 0.99.14
New features
- Four new exported functions compute common BAM summaries entirely inside the multithreaded C++ reader (per-thread accumulators folded in the OpenMP region; only the compact result crosses into R – no per-read R objects are ever materialised), each verified byte-identical to its standard Bioconductor equivalent:
-
fragment_sizes(): paired-end fragment-size (insert-size) distribution; identical totable(abs(scanBam(isize))).drop_mate_unmapped = TRUE(default) replicatesscanBam’sisize = NArule for mate-unmapped reads. -
mapq_dist(): mapping-quality distribution; identical totable(scanBam(mapq))(MAPQ 255 reported as 255, where scanBam usesNA). -
bam_coverage(): per-base coverage as aSimpleRleList;identical()toGenomicAlignments::coverage(readGAlignments(...)), including the CIGAR conventions (M/=/X/Dcover,Ngaps,drop.D.ranges = FALSE) and the readGAlignments record filter (only unmapped reads dropped). -
bam_coverage_bigwig(): single-pass BAM -> coverage bigWig written natively via the bundled libBigWig – no R-side coverage object, nortracklayer::export.bwround-trip. Data and zoom blocks are compressed across the OpenMP threads (parallel = TRUE, default); the parallel output is bit-for-bit identical to the serial writer. Acompress_levelargument exposes the zlib deflate level, andverbose = TRUEprints a per-phase timing breakdown.
-
-
bam_read(as = "GAlignments")now uses a dedicated fast path that assembles theGAlignmentsslots in C++: seqnames/strand accumulated as run-length pairs inside the parallel region, the cigar column materialised through a CHARSXP cache that exploits CIGAR-string redundancy, and qname decoded only when actually requested. Output isidentical()toGenomicAlignments::readGAlignments()(verified at 226M-read scale) and to the previous construction path.options(BamScale.ga_fastpath = FALSE)restores the old path. - Vendored libBigWig 0.4.8 (MIT, Devon Ryan) under
src/libBigWig/(built with-DNOCURL, local files only). Local modifications, each commented inbwWrite.c: a tunable zlib deflate level, deferred parallel block compression, and zoom-level construction from in-memory coverage runs instead of re-reading the just-written data section.
Performance
- Fixed a quadratic reallocation pattern in the reader’s batch merge: per-batch exact-capacity
reserve()calls copied all accumulated data on every batch. Buffers now grow geometrically. This affects every read path – e.g. on a 229M-read BAM at 48 threads,as = "GAlignments"dropped from ~300 s to ~56 s, and plain data-frame reads improved 2.8-4.4x. - CIGAR strings are formatted with an allocation-free digit writer instead of per-op
std::to_string. - Representative large-file results (229M-read ATAC BAM, 48 threads, warm cache):
bam_coverage()7.2x vscoverage(readGAlignments());bam_coverage_bigwig()2.6x vs megadepth at equal compression;fragment_sizes()5.4x vsscanBam+table();as = "GAlignments"4.8x vsreadGAlignments()(and faster even single-threaded).
Bug fixes
-
bam_coverage_bigwig()now works on Windows: the output stream is opened in binary mode ("w+b"; text mode corrupted the bigWig), and zoom levels are always built from the in-memory coverage runs instead of re-reading the just-written stream (Windows’ C runtime is strict about write-to-read transitions on update streams; the in-memory path is byte-identical to the re-read path, verified at 226M-read scale). Vendored libBigWig diagnostics now go throughREprintf(), clearing the compiled-code check NOTE. - Removed a long-standing
^src/Makevars$entry from.Rbuildignore(dating to the pkgdown setup): built tarballs – including the Bioconductor builds – shipped withoutsrc/Makevarsand therefore compiled WITHOUT OpenMP (and without the explicit-lz), silently running single-threaded when installed from a tarball. In-placeR CMD INSTALL .was unaffected, which is why local installs always threaded. Tarball builds now carry the full build configuration (OpenMP, zlib,-DNOCURL, and the bundled libBigWig objects).
Benchmarks
-
run_workflow_benchmark.Rgains first-class arms for the four new functions (--include-fastcov/-bigwig/-fragsize/-mapq), each behind anidentical()correctness gate, with an optional megadepth context arm (--megadepth-bin). -
run_server_benchmark.R: BiocParallel PSOCK clusters are now started and their namespaces pre-loaded outside the timed region in all multi-file arms (previously cluster spin-up was charged to every iteration, diluting comparator ratios at high worker counts); added--include-singleso single and multi scenarios can run in separate stages. - New reproducible manuscript-benchmark tooling:
select_encode_atac.R(ENCODE portal selection -> accession/md5 manifest), manifest-drivendownload_atac_data.Rwith md5 verification,samtools_reference.sh,merge_runs.R, and the stagedrun_manuscript_final.shorchestrator.
Tests
- New testthat gates: byte-identity of
fragment_sizes()/mapq_dist()/bam_coverage()against their Rsamtools/GenomicAlignments equivalents;bam_coverage_bigwig()value-identity after re-import plus bit-for-bit parallel-vs-serial output; sixGAlignmentsfast-path identity gates (threads 1/4, mcols order,use.names, flag/mapq filters, fast == slow,gctorture).
BamScale 0.99.13
New features
- On the compatible read path,
seqandqualare now built directly in C asDNAStringSet/PhredQualityobjects from the packed BAM byte buffer (via the IRanges/XVector C-callable constructors), avoiding a character round-trip. Output remains byte-identical toRsamtools::scanBam. - Added an end-to-end workflow benchmark harness under
inst/benchmarks/(coverage → bigWig and ATAC fragment-size QC) and a self-containedbenchmark-resultsvignette.
Bug fixes
-
GAlignmentsoutput now carries the BAM-header sequence lengths in itsSeqinfo. Previously the seqlengths wereNA, socoverage()extended each seqlevel only to its maximum end andexport.bw()wrote truncated chromosome sizes, diverging fromGenomicAlignments::readGAlignments. - Force-load the C-callable providers (
S4Vectors,IRanges,XVector,Biostrings) andGenomicAlignmentsin.onLoad, so the compatible seq/qual andGAlignmentspaths resolve their constructors and classes on freshSnowParamSOCK workers.
