Extend samtools sort -M to distinguish between mapped and unmapped files#2110
Conversation
|
While we're here, I notice that samtools-sort.1 (line 78) says that |
I think it's wrong and probably written forgetting that it can do partially mapped files still. Rather curiously, It's not something we can determine up-front whether it is entirely unmapped, but actually that's not a problem anyway as we can still build an index and still query it via things like (As an aside, bizarrely |
|
Also sadly, the decision of making minhash either coordinate or unsorted is making the index statement invalid. Fortunately our index doesn't check as it validates on the alignments rather than trusting the header (but it could and maybe some do). However the man page for sort explicitly states we must use coordinate sort if we want an index, which isn't true as we can build an index on the unsorted data (because technically it's still coordinate sorted, as noted above). I'll try picard. Once I find a version of java that works. Edit: as I expected. Samtools sort -M on develop produces a bam file which picard can index, while this PR produces a file that it cannot index as it's not This is the problem really with adjusting things to look "nice". We now have a decision to make. Do we want this data to be obvious to users, or do we want to retain the (admittedly minor) ability of being able to query index stats on an unaligned file? I think probably it's OK, as Edit: ah there's another reason for indexing unaligned data. In CRAM it directly translates to the ability to sub-set using |
|
Updated as a separate commit for ease of review. I'll squash later (it won't make it into this upcoming release, sorry). Also this talk of indexing reminds me of the original inspiration which came from Illumina's Tony Cox. His code was computing a minimiser and actually having that minimiser as a coordinate on a fake chromosome (which sadly limits the size due to BAM indexing capabilities, unless we have many fake chromosomes). An index then is obviously more sensible. The benefit of this is then you can provide a query sequence, produce minimisers from that query, and then do random access to pull out sequences that share that minimiser. It's a crude way of finding data that may potentially align to a query sequence without first assembling or aligning it all. The hit rate wasn't that great though as you can only place a sequence in one location, so you can't have proper sequence sketches consisting of multiple minimisers. That also limits it to short read data. A cool idea though. :) I just took the locality => better compression component of it and ran with that. |
| but unaligned) and helps to improve compression with LZ algorithms. | ||
| This can be improved by supplying a known reference to build a | ||
| minimiser index (\fB-I\fR and \fB-w\fR options). | ||
| When sorting by minimisier (\fB-M\fR), the sort order for unplaced |
There was a problem hiding this comment.
Indeed not. Good spot. That was in the original too. Now corrected
The code to set the sort order, group order and sub-sort is pulled into its own function, to reduce the very lengthy function a bit.
Files with some mapped data and some unmapped (in chr "*") still get a sort order of "coordinate" and sub-sort of "coordinate:minhash" as before. However input that is entirely unmapped with everything in chr "*" now use "SO:unsorted SS:unsorted:minhash" to avoid confusion. Fixes samtools#2105
ecd77da to
9a9ebce
Compare
Files with some mapped data and some unmapped (in chr "*") still get a sort order of "coordinate" and sub-sort of "coordinate:minhash" as before. However input that is entirely unmapped with everything in chr "*" now use "SO:unsorted SS:unsorted:minhash" to avoid confusion.
Fixes #2105
Note that due to moving the header manipulation the temporary files produced have the original sort order and not the new sort order, but this is irrelevant as their headers are unused and it's correct in the final merged file. (They're also the source of some bugs, so they may at some go away entirely at some later date.)