Skip to content

Commit 6e7df60

Browse files
Jonathan Manningiontorrent-dev
authored andcommitted
Allow max_mem for sort to be specified with units.
Signed-off-by: Nils Homer <[email protected]>
1 parent f12ebca commit 6e7df60

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

bam_sort.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,31 @@ void bam_sort_core(int is_by_qname, const char *fn, const char *prefix, size_t m
418418
bam_sort_core_ext(is_by_qname, fn, prefix, max_mem, 0);
419419
}
420420

421+
422+
size_t bam_sort_get_max_mem(char *max_mem_string)
423+
{
424+
char c;
425+
size_t max_mem;
426+
size_t multiplier=1;
427+
c=max_mem_string[strlen(max_mem_string)-1];
428+
switch(c) {
429+
case 'G':
430+
multiplier*=1024;
431+
case 'M':
432+
multiplier*=1024;
433+
case 'K':
434+
multiplier*=1024;
435+
case 'B':
436+
max_mem_string[strlen(max_mem_string)-1]='\0';
437+
break;
438+
default:
439+
break;
440+
}
441+
max_mem = multiplier * atol(max_mem_string);
442+
// max_mem should be checked that it was not zero after atol!
443+
return max_mem;
444+
}
445+
421446
int bam_sort(int argc, char *argv[])
422447
{
423448
size_t max_mem = 500000000;
@@ -426,7 +451,7 @@ int bam_sort(int argc, char *argv[])
426451
switch (c) {
427452
case 'o': is_stdout = 1; break;
428453
case 'n': is_by_qname = 1; break;
429-
case 'm': max_mem = atol(optarg); break;
454+
case 'm': max_mem = bam_sort_get_max_mem(optarg); break;
430455
}
431456
}
432457
if (optind + 2 > argc) {

0 commit comments

Comments
 (0)