Wish list - automatic merging and/or concatenation.
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 20/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- c
- Domain
- bioinformatics, data
Research direction
Start by reviewing the existing BCF synced-reader behavior and the samtools cat, merge, and view workflows mentioned in the issue. The design still needs a decision on one manifest syntax and the scope of on-the-fly concatenation, merging, and filtering; done would mean an agreed specification and implementation plan.
Written by the indexing model from the issue text.
Description
We have the BCF synched reader code which can on-the-fly merge (and dedup / intersect) multiple BCF files.
I'm thinking there is room for a similar action in the SAM (et al) world. Specifically:
- Open a file referencing other files; manifest, fofn, whatever we wish to call it.
- Specify files to be either concatenated to previous in the list or merged with previous in the list.
- Specifying data filtering rules
Example concatenation use case.
- Run some data-processing pipeline (eg local realignment) on a per-chromosome fashion.
- Then read the data without having to do a "samtools cat" to physically merge back into a single file.
- Run some analysis on the reconstituted file.
Example merge use case.
- Produce a bunch of BAMs per sample.
- Merge BAMs into a single file
- Run a joint caller on the multi-sample BAM.
In both examples step 2 and 3 could be done together. They are solved right now via use of pipes, so it's not critical, but this may make life simpler.
Note I'm not advocating replacing samtools cat and samtools merge. They have extra specialisms and I think inside htslib this should only be the most mundane and simplest of functions - ones where the SAM headers must match and there's no "magic" to do. If you like making lots of files each with different headers, then you're not looking for an easy solution ;-)
What could the input file look like? Many possibilities. Some examples:
chr1_samp1.bam
chr1_samp2.bam merge
chr1_samp3.bam merge
chr2_samp1.bam
chr2_samp2.bam merge
chr2_samp3.bam merge
Fofn, defaults to file concatenation, but "merge" command indicates it's merged into the previous file (like "squash" vs "pick" on git commits during rebase). So this concatenates chr1 with chr2 while merging the samp[123] files together.
[ chr1_samp1.bam chr1_samp2.bam chr1_samp3.bam ] [ chr2_samp1.bam chr2_samp2.bam chr2_samp3 ]
If we wish to merge we include them in square brackets, otherwise each file is just whitespace separated and assumed to be concatenation. This I think is my favoured one. It still means the naive traditonal "fofn" just works as concatenation.
Or json style:
{
"merge": [
"chr1_samp1.bam",
"chr1_samp2.bam",
"chr1_samp3.bam"
],
"merge": [
"chr2_samp1.bam",
"chr2_samp2.bam",
"chr2_samp3 "
]
}
Yet more syntaxes could be invented, eg #includes, etc. Ideas welcomed, but I envisage supporting one only. It's the concept right now that I think is important to discuss.
The expectation is we'd just do a samtools view bams.fofn (or bams.json?) and it'd simply Do The Right Thing (TM).
It could be further extended to support on-the-fly filtering. Eg say we want to merge samp1.bam and samp2.bam with secondaries removed, maybe something like:
[
samp1.bam {flag != secondary}
samp2.bam {flag != secondary}
]
Here clearly an example use is avoiding having foo.bam and foo.rmdup.bam on disk at the same time, but wanting the instructions written down with the data rather than internal knowledge of having to do filtering. Note filtering via this way is an easy win over piping too as we can index and do random access on our file while still filtering.
Thoughts?
- Dominant language
- C
- Stars
- 950
- Forks
- 475
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 11
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from samtools/htslib
-
Difficulty 3/5 1-2 days Newbie friendliness 74/100
-
Difficulty 3/5 1-2 days Newbie friendliness 76/100
-
tabix performance Open
Similar issues
-
[adam] AdamNet network read doesn't cap to MAX_ADAM_PACKET_LEN, overflows client receive buffers Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
FujiNetWIFI/fujinet-firmware#1649 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
HarbourMasters/Shipwright#7229 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
riscv-software-src/riscv-isa-sim#2435 · 1 comment ·
-
bug Self Built Image SNAPSHOT Supported Device target/ramips
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100