This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Can I sort my bam files with Picard MergeSamFiles?

Hi!

I noticed this in the picard MergeSamFiles help:

--SORT_ORDER,-SO:SortOrder Sort order of output file Default value: coordinate. Possible values: {unsorted, queryname, coordinate, duplicate, unknown}

Does this mean that it is unnecessary to use picard SortSam before? can MergeSamFiles do the same job?

if so, is it faster to do the sorting together with merging in MergeSamFiles or is it better to do run Sortsam first?

thanks in advance!

best / Jonas

mergesamfiles picard-tools sortsam

If you're merging a set of sorted SAM/BAM files, you will get a sorted file in the end. So no need to sort it then.

If you're merging (basically concatenating) unsorted files, you'll have to sort it after.

You can check if the file is sorted by indexing it with samtools

2 answers

thx for your answer!

so If I have the default value of --SORT_ORDER coordinate in MergeSamFiles, that doesn't mean that MergeSamFiles also will sort the unsorted files when merging?

I have to sort them with e.g. sortsam either before or after the merge?

I don't think so - I think it refers to the sort order in the input files. But you can check using two small bam files :)

Log in to answer this question.