Add native CRAM output support (unsorted and coordinate-sorted) via HTSlib #2670
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.
Add native CRAM output support to STAR
Overview
This contribution adds full support for CRAM output in STAR, both for unsorted and coordinate-sorted alignments, using HTSlib’s native APIs. The implementation is fully backward compatible and preserves all existing BAM/SAM functionality.
Motivation
Features
New output format:
Users can now specify
--outSAMtype CRAM Unsortedor--outSAMtype CRAM SortedByCoordinateto produce CRAM files directly from STAR.HTSlib integration:
Output is handled via HTSlib’s
htsFileandsam_write1APIs, ensuring compatibility with the CRAM standard and future-proofing for other formats.Automatic format detection:
The output format is detected from the
--outSAMtypeparameter and the correct file mode is used for htslib.Unsorted and sorted output:
sam_write1.Backward compatibility:
Existing BAM/SAM output logic is preserved. If CRAM is not requested, STAR behaves as before.
Implementation Details
BAMoutputclass now supports both legacy BGZF output and htslib-based output (htsFile), with logic to route records to the appropriate backend.ReadAlignChunk.cppandbamSortByCoordinate.cppis updated to usehts_openwith the correct mode for CRAM/SAM/BAM.sam_write1.bam_catlogic is preserved.Usage