Skip to content

Samtools split to open/close output files sequentially if file is ordered by split key #2276

Description

@clintval

Is your feature request related to a problem? Please specify.

From how I understand samtools split to work, it will create a new output file for each of the "splits" it encounters which may result in more open file handles than the system will allow. I suspect the --max-split NUM flag was added to manage this situation more carefully. I would like to split a BAM file by tag in which that tag has very high cardinality and I don't want to be limited by tool or system limits.

Describe the solution you would like.

My ideal solution is to collate/sort the BAM file by that tag (samtools sort -t TAG) then create the splits using samtools split -d TAG.

Could there be a way to tell samtools split the BAM is sorted/ordered so that file handles can be closed as the next one is opened and I don't need to worry about definiing --max-split nor raising/changing system limits?

Perhaps this could work without adding a new CLI flag if the header could describe the file as being grouped/sorted by the tag? I don't think that's currently possible since samtools sort by tag doesn't encode that information in the SO or GO of the header even though I wish it did. If a CLI flag is necessary, then maybe an --assume-ordered which would trigger this behavior and turn "off" --max-splits?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions