This is a test version of Biostars. For the public version, visit https://www.biostars.org.
samtools sort error

I am having a problem with samtools.

It looks like I successfully created a .bam file. When I enter:

samtools view Y13.bam | head

I get a file that is formatted like this:

TCTGGCGCAGTATGTCACACCTGCATTGGACAGAGCTTGTTTTCATGGCAGACAAAC   AAFAFJFAJJFJJ<JJJJAJJJJF7F7FJJJJJ<FJJJJFJ-FJFJ<<JFJJJF-7JFJ-7FJ-F-AF7FF---<7<-7FFF--77F-F-A-777F<F<JF<---77FF-7A7A<-AA7--A<F-7FJ<77A7<--7-7--A-777F<-F  YT:Z:UP
E00558:452:H3WH2CCX2:1:1101:21572:5739  141 *   0   0   *   *   0   0

But when I run:

samtools sort Y13.bam -o Y13.sorted.bam

the output printed in terminal looks like this:

     W�����x��O�U�e�$ytL��S�#�_ɧN���Ie��ifz����!��nW���c�f54���HE���m^O��u;\���m���&8VTZ>���X0�I�#�X�
             g��}��J��y�e�����ܲ4� 7`�I��Iݼ�ʉLOՏ����!^H�=��d< Oj/��5ȩ"�܉�g��~����So4�mY�dd�z��|��WD��k9���ɵ�̎@<�t�pG��^O4d����S�(d"{ߗ���#��1�%��aA�x  �nt��

Also, there is no Y13.sorted.bam file being created.

Any suggestions as to what might be going on here?

snp alignment

Please use the formatting bar (especially the code option) to present your post better. You can use backticks for inline code (`text` becomes text), or select a chunk of text and use the highlighted button to format it as a code block. I've done it for you this time.
code_formatting

JC : Please upgrade your samtools to the latest version, which is now 1.9. Version you are using is really ancient.

it is working with v.1.9. Thanks!

1 answer

What version of samtools are you running? It looks like an older version that wants a ">" instead of "-o" to redirect output to a file instead of the terminal.

Version: 0.1.19-44428cd

it looks like -o is the option for this version based on the options available:

$ samtools sort

Usage:   samtools sort [options] <in.bam> <out.prefix>

Options: -n        sort by read name
         -f        use <out.prefix> as full file name instead of prefix
         -o        final output to stdout
         -l INT    compression level, from 0 to 9 [-1]
         -@ INT    number of sorting and compression threads [1]
         -m INT    max memory per thread; suffix K/M/G recognized [768M]

-o final output to stdout looks like exactly what is happening. I used that ancient version for a long time, I'm pretty sure I used > sorted.bam

It looks like it was a version issue. I have this step working now with the new version. Thanks!

Log in to answer this question.