Skip to content

Commit

Permalink
Merge pull request GlobalPneumoSeq#139 from GlobalPneumoSeq/hotfix/li…
Browse files Browse the repository at this point in the history
…mit-samtools-sort-max-thread

Cap maximum thread usage to samtools sort due to diminishing return and to avoid excessive memory request
  • Loading branch information
HarryHung authored Jan 14, 2025
2 parents b8d1bcd + bca6efc commit f7560ae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions bin/convert_sam_to_sorted_bam.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Convet SAM to sorted BAM file
# Remove source SAM file if $LITE is true

samtools view -@ "$(nproc)" -b "$SAM" > "$BAM"
# Thread usage is capped as memory usage is per thread, and the speed gain level-off as thread count increases
AVAILABLE_THREAD=$(nproc)
THREAD=$(( AVAILABLE_THREAD > MAX_THREAD ? MAX_THREAD : AVAILABLE_THREAD ))

samtools sort -@ "$(nproc)" -o "$SORTED_BAM" "$BAM"
samtools view -@ "$THREAD" -b "$SAM" > "$BAM"

samtools sort -@ "$THREAD" -o "$SORTED_BAM" "$BAM"
rm "$BAM"

if [ "$LITE" = true ]; then
Expand Down
2 changes: 2 additions & 0 deletions modules/mapping.nf
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ process SAM_TO_SORTED_BAM {

script:
sorted_bam="${sample_id}_mapped_sorted.bam"
max_thread="8"
"""
SAM="$sam"
BAM="mapped.bam"
SORTED_BAM="$sorted_bam"
LITE="$lite"
MAX_THREAD="$max_thread"
source convert_sam_to_sorted_bam.sh
source get_ref_coverage.sh
Expand Down

0 comments on commit f7560ae

Please sign in to comment.