From 63228eb13cce522aae4e1cccfdf373e40c5b0b50 Mon Sep 17 00:00:00 2001 From: Moritz Schaefer Date: Mon, 8 Mar 2021 12:37:12 +0100 Subject: [PATCH] Fix sorting with header row; Solution is to use a subshell to combine the outputs of a head and tail | sort --- src/FitHiC_SigInt.r | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FitHiC_SigInt.r b/src/FitHiC_SigInt.r index b6e6730..2797a3a 100644 --- a/src/FitHiC_SigInt.r +++ b/src/FitHiC_SigInt.r @@ -1748,7 +1748,7 @@ if (0) { } # now sort the file contents and write that in the final specified output file - system(paste('sort -k1,1 -k2,2n -k5,5n', paste0('-k',opt$cccol,',',opt$cccol,'nr'), temp_outfile, '>', opt$OutFile)) + system(paste('(head -n 1', temp_outfile, '&& tail -n +2', temp_outfile, '| sort -k1,1 -k2,2n -k5,5n', paste0('-k',opt$cccol,',',opt$cccol,'nr'), ')>', opt$OutFile)) } # end dummy if @@ -1772,7 +1772,7 @@ if (1) { system(paste("rm", temp_outfile_2)) # now sort the file contents and write that in the final specified output file - system(paste('sort -k1,1 -k2,2n -k5,5n', paste0('-k',opt$cccol,',',opt$cccol,'nr'), temp_outfile, '>', opt$OutFile)) + system(paste('(head -n 1', temp_outfile, '&& tail -n +2', temp_outfile, '| sort -k1,1 -k2,2n -k5,5n', paste0('-k',opt$cccol,',',opt$cccol,'nr'), ')>', opt$OutFile)) } # end dummy if