Thanks Youri,

That's the bit of code I was worrying about (BAM grooming). I've filed an issue for this:

https://github.com/galaxyproject/galaxy/issues/1336

Peter


On Wed, Dec 16, 2015 at 9:47 AM, Y. Hoogstrate <y.hoogstrate@erasmusmc.nl> wrote:
Great news Peter,

This is how Galaxy seems to do it:

        command = "samtools sort %s %s" % ( file_name, tmp_sorted_dataset_file_name_prefix )
        proc = subprocess.Popen( args=command, shell=True, cwd=tmp_dir, stderr=open( stderr_name, 'wb' ) )

https://github.com/galaxyproject/galaxy/blob/dev/lib/galaxy/datatypes/binary.py#L278


Since galaxy ships with a builtin pysam (0.8.3) wheel, I think it would be handier to use pysam for sorting (once updated to the latest HTSlib).
Pysam now also has all samtools c functions directly builtin:

pysam.index( "arg1", "arg2" ) is the equivalent of the command line argument samtools index "arg1" "arg2"

...
Youri