From 5988eb6442aa2ca1ffb6555d69002acff9e7fcc8 Mon Sep 17 00:00:00 2001
From: "Gervaise H. Henry" <gervaise.henry@utsouthwestern.edu>
Date: Mon, 18 Jan 2021 19:20:28 -0600
Subject: [PATCH] Add -m to samtools sort

---
 workflow/rna-seq.nf | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/workflow/rna-seq.nf b/workflow/rna-seq.nf
index fb7158f..5eebace 100644
--- a/workflow/rna-seq.nf
+++ b/workflow/rna-seq.nf
@@ -1451,7 +1451,9 @@ process alignData {
 
     # sort the bam file using Samtools
     echo -e "LOG: sorting the bam file" >> ${repRID}.align.log
-    samtools sort -@ `nproc` -O BAM -o ${repRID}.sorted.bam ${repRID}.bam
+    mem=\$(vmstat -s -S K | grep 'total memory' | grep -o '[0-9]*')
+    mem=\$(expr \${mem} / `nproc` \* 85 / 100)
+    samtools sort -@ `nproc` -m \${mem}K -O BAM -o ${repRID}.sorted.bam ${repRID}.bam
 
     # index the sorted bam using Samtools
     echo -e "LOG: indexing sorted bam file" >> ${repRID}.align.log
-- 
GitLab