This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Can the input file name be the same as the output file in `samtools sort`?

Hi

I am confusing what is happening if the input file name is the same as the output file in samtools sort?

samtools sort -n file1.bam -o file1.bam

This command can run successfully, but is it correct?

Thanks a lot

Best
Dan

samtools

This command can run successfully

may be, because the output is written after all the reads have been read and sorted.

but is it correct?

no. It's not the unix way, it looks weird, and there is no advantage compared to

samtools sort -n file1.bam -o file2.bam
mv file2.bam file1.bam

It is also prone to disaster. If the job gets killed while the new file is being written then the data are lost and you have to repeat alignment. It’s bad practice don’t get used doing that.

0 answers

No answers yet.

Log in to answer this question.