samtools sort: couldn't allocate memory for bam_mem

Summary

samtools sort: couldn't allocate memory for bam_mem occasionally

Steps to reproduce

Keep running until it happens?

Observed bug behavior

samtools sort: couldn't allocate memory for bam_mem`, size: 448 (max: 255)

Expected behavior

Relevant logs and/or screenshots

Potential fixes

add -m param for memory (but keep in mind, this is per thread and doesn't include overhead
consider detecing amount of memory available eg: grep MemTotal /proc/meminfo | grep -o '[0-9]*' then divide by nproc and a scaling factor so not to hog all node memory (maybe 0.85)
stolen from https://github.com/MonashBioinformaticsPlatform/RNAsik-pipe/issues/39

/cc @ghenry @venkat.malladi @s181706

Edited by Gervaise Henry