This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Custom sam sort

[UPDATE]: Thanks for the suggestions. It turns out I don't need to perform the custom sort after all though

Hi everyone,

I hoping someone may be able to point towards a tool for custom sorting a sam/bam file? Essentially I want to sort by a meta-contig feature which will not be encoded within the samfile. The resultant sorted sam will not need to be sorted on contig or position whatsoever.

I can perform the sort myself using pysam to extract the contigs associated with each meta-contig and then outputting to the sorted sam, but I'm hoping this functionality may exists already elsewhere?

A fuller explanation of the motivation can be found here

Cheers

sam bam sort rna-seq

Link to the fuller explanation seems to require a github account and is not otherwise visible.

Thanks. Link updated in the questions.

2 answers

You can easily implement a new sorting algorithm using java+ and the class 'SortingCollection' from the htsjdk library. See https://github.com/lindenb/jvarkit/blob/master/src/main/java/com/github/lindenb/jvarkit/tools/misc/SortSamRefName.java for an example (sorts reads on REF and then on NAME)

Bamtools allows different sorting schemes. If i remember correctly it allows users to specify their own sort functions... maybe?

I am not sure if bamtools sort can do that but maybe bamtools filter could help.

Log in to answer this question.