Repository navigation
Auto-detect BAM lists and directories; fix CRAM decoding; clearer input errors (2.1.2) - #5
Merged
Merged
Conversation
…input errors - Drop the 2.1.0 deprecation warning for auto-detected path lists. It said "pass --bam_list", which reads as `--bam_list FILE` and fails because the option is a flag (#4). Content-based list detection is the supported path; --bam_list/--bed_list stay as optional overrides. - Decode CRAM against the -r reference via a shared open_alignment() helper. Without it, a CRAM whose UR: reference was unreachable failed every slice and EASTR reported zero junctions while exiting 0. - Move list resolution into input_detect so it is unit-tested, and replace "File not found: <first line>" with a diagnosis: headerless SAM (by content or .sam extension), .bam/.cram without a valid signature, or an unrecognized file. Use non-throwing fs::exists so long data lines no longer raise ENAMETOOLONG. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
--bam <dir> now processes every BAM/CRAM/SAM directly inside the directory in one run, sorted by filename. Files are selected with htslib format detection (hts_detect_format2), not by extension, so .bai/.csi indexes, gzipped FASTA and other files can sit alongside; hidden files and subdirectories are ignored. Previously a directory was silently read as an empty path list and EASTR exited 0 with no junctions. --bed with a directory and --bam_list with a directory now give clear errors. Bump the version to 2.1.2 (CMake + conda/meta.yaml). The conda source sha256 still refers to the v2.1.1 tarball and must be updated once v2.1.2 is tagged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
They were on/off flags rather than options taking a file, and list files are detected automatically, so they had no practical effect; their help text was also the source of the confusion in #4. Dropping them removes the force_list path in resolve_input_files() and its two error branches. Breaking: commands that still pass --bam_list/--bed_list now fail with "The following argument was not expected"; drop the flag. tests/test_input_detect.cpp also moves to the shared test TempDir helper (tests/test_temp.hpp), which this commit adds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Drop tests/test_main.cpp: Catch2::Catch2WithMain already provides main(). - Drop the standalone test_alignment_score executable (a manual comparison harness against the Python implementation, not run by CTest). - Use the shared eastr_test::TempDir helper so tests do not collide when CTest runs them in parallel. - Consolidate and tighten several bed_parser, junction, path_utils and strand-handling tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… macOS htscodecs' NEON rANS-Nx16 order-1 decoder (rans_uncompress_O1_32x16_neon) keeps s3[256][1024] (1 MiB) and fb[256][256] (256 KiB) on the stack. macOS gives secondary threads a 512 KiB stack, so decoding CRAM 3.1 on EASTR's std::thread/std::async workers overflowed into adjacent thread memory: with 2+ CRAM inputs and -p > 1 EASTR crashed (SIGSEGV/SIGBUS in htscodecs_tls_free) or reported 0 junctions for a sample. open_alignment() now takes the htslib thread count and always attaches an htslib thread pool (>= 1 thread) to CRAM inputs, so slices are decoded on htslib's worker threads, which get >= 3 MiB stacks (HTS_MIN_THREAD_STACK). The input-side hts_set_threads() calls move into open_alignment(), since htslib ignores a second pool on a CRAM handle. Verified on arm64 macOS: 3 CRAM 3.1 inputs at -p 1/2/3/4/6/8 give byte-identical removed junctions to the BAM inputs (previously -p 2..4 crashed or lost samples); BAM output unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…irectory - Two inputs whose filenames share a stem (a/S1.bam, b/S1.cram) got the same sample name, so their per-sample outputs overwrote each other. This is now an error, for lists and directories alike. - With --bam <dir> and --out_filtered_bam pointing at that same directory, a re-run picked up EASTR's own *_EASTR_filtered.bam files as extra samples and silently changed the pooled junction counts. This is now an error. Both checks run before any alignment work. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t CRAMs - tests/test_alignment_io.cpp writes a small CRAM against a reference, deletes that reference (so the header UR: path is gone), and checks that open_alignment() decodes every record with the -r reference and fails without it. Runs in CI without the LFS test data. - scripts/make_test_crams.sh builds CRAM copies of test_data/chr4_subset/*.bam in test_data/chr4_subset_cram/ (git-ignored; ~190 MB) for end-to-end CRAM vs BAM comparisons, encoded against a temporary reference that is deleted afterwards. Usage is documented in test_data/README.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Restore the two flags removed in ba6bad6 with their 2.1.x behavior (skip auto-detection and read the argument as a list), so commands written for 2.1.0/2.1.1 keep working with identical output. They stay in --help, worded as optional since list files are detected automatically. Verified against v2.1.0 with the same commands (single BAM, BAM list with and without --bam_list, BED, BED list with and without --bed_list, GTF): removed and kept junction BEDs are byte-identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4.
The issue
When
--bamwas given a text file of BAM paths, 2.1.0 printed:--bam_listis a flag (--bam bam_list.txt --bam_list), but the message reads like--bam_list bam_list.txt. That form fails withThe following argument was not expected, so the flag looked like it didn't exist.Changes
List files no longer warn. A text file of paths is detected from its contents (each line must be an existing file), whatever it is named. That is the supported way to pass several BAMs.
--bam_list/--bed_listkeep their 2.1.x behavior (skip auto-detection and read the argument as a list) but are optional; their help text now says so.No breaking changes. Commands written for 2.1.0/2.1.1 run unchanged. Single BAM, BAM list with and without
--bam_list, BED, BED list with and without--bed_list, and GTF all give byte-identical removed/kept junction BEDs to v2.1.0. Output changes only where 2.1.x output was wrong: CRAM inputs that gave 0 junctions or crashed, and inputs with colliding sample names, which now error instead of silently overwriting.--bamaccepts a directory. Every BAM/CRAM/SAM file directly inside it is processed in one run, sorted by filename. Files are chosen by htslib's format detection (hts_detect_format2), not by extension. Index files (.bai,.csi), gzipped FASTA and other files can sit alongside them; hidden files and subdirectories are ignored. Before, a directory was silently read as an empty path list: EASTR wrote empty output and exited 0.--bed <dir>gives a clear error.Input/output collisions are rejected up front:
a/S1.bam,b/S1.cram), EASTR gives both the same sample name and their outputs overwrite each other. This is now an error, for lists and directories.--bam <dir>with--out_filtered_bampointing at that same directory is now an error. Before, a re-run picked up EASTR's own*_EASTR_filtered.bamfiles as extra samples and silently changed the pooled read counts.CRAM is decoded with
-r. The reference was never passed to htslib. If the reference path stored in a CRAM's header (UR:) wasn't reachable, for example because the CRAM was made on another machine, every slice failed to decode withUnable to fetch reference. EASTR then reported zero junctions while exiting 0. A newopen_alignment()helper sets the reference (hts_set_fai_filename) at all 7 places that open an input file for reading.CRAM 3.1 crash on arm64 macOS fixed. With 2+ CRAM 3.1 inputs and
-p> 1, EASTR crashed (SIGSEGV/SIGBUS) or a sample silently got 0 junctions. This also happens in 2.1.0. htscodecs' NEON rANS-Nx16 order-1 decoder keeps ~1.25 MiB of tables on the stack, more than the 512 KiB macOS givesstd::thread/std::asyncthreads.open_alignment()now always gives CRAM inputs an htslib thread pool, so decoding runs on htslib's own threads (stacks of at least 3 MiB). x86_64 and CRAM 3.0 were not affected.Clearer errors for unrecognized input. These replace
File not found: <entire first line>and, for lines longer than the filesystem's name limit, an uncaughtfilesystem error ... File name too long:.sam,.dat, …)looks like a SAM file without a header … samtools view -h ….bam/.cramwithout a valid signaturehas a .bam extension but is not a valid BAM file … truncated, corrupt …--bam_liston an actual BAM, or on a directoryis an alignment file, not a list of paths. Drop --bam_list …is not a BAM/CRAM/SAM file, and its first line is not an existing file path … First line: /data/missing.bamThe headerless-SAM case is detected from the file's contents (11+ tab-separated fields with integer FLAG/POS/MAPQ), so it works for Galaxy-style names. The extension is only used to pick the right wording, never to decide what a file is.
Refactor and tests:
main.cppintoinput_detect.cppso it can be unit-tested.TempDirhelper, safe under parallel CTesttest_main.cppdropped, sinceCatch2WithMainprovidesmaintest_alignment_scoreharness removedtests/test_alignment_io.cpp: builds a CRAM, deletes its reference, and checks it decodes with-rand fails without it.scripts/make_test_crams.shbuilds CRAM copies of the chr4 test BAMs, for end-to-end checks. The output is git-ignored, about 190 MB.Version 2.1.2. CMake and
conda/meta.yamlare bumped. The condasha256still refers to the v2.1.1 tarball and must be updated afterv2.1.2is tagged, as was done for 2.1.0 in 19132fe. CI only checks that the two version numbers match.Testing
ctest: 45/45 pass locally (macOS arm64). CI covers Linux x86_64/aarch64 and macOS.test_data/chr4_subset(3 BAMs, 1202 removed junctions as the baseline):--bam test_data/chr4_subset(directory) gives byte-identical removed junctions and identical filtered BAMs to the list run.scripts/make_test_crams.sh, reference removed,REF_PATH/REF_CACHEdisabled) at-p1, 2, 4 and 8: byte-identical removed junctions. Filtered reads match (1,973,511 for one sample), except TLEN, which CRAM recomputes when a read and its mate start at the same position.-p2-4 it crashes even when it can.eastr --bam bam_list.txt -r $REF -i $INDEX --out_filtered_bam .) exits 0 and writes the same three*_EASTR_filtered.bamfiles as v2.1.0, with identical contents and no warning.--bam_list), BED, BED list (with and without--bed_list) and GTF all give byte-identical removed and kept junction BEDs. A list file can still write filtered BAMs next to its input BAMs.Not fixed here (follow-up)
The read loops treat any
sam_read1()error (return value < -1) as end of file. A corrupt BAM, or a CRAM that fails to decode for some other reason, can still finish with exit 0 and no junctions. That needs its own change to error handling.🤖 Generated with Claude Code