Help with Samtools
3
0
Entering edit mode
7.0 years ago
oma219 ▴ 40

Hi,

I am trying to sort my paired-end data so all the read pairs are adjacent and I'm trying to use the sort function of samtools but I'm getting errors? Does samtools sort not work with .sam files?

samtools sort -n DICDvenus1_STARAligned.out.sam DICDvenus1_SortedReads.sam [bam_header_read] EOF marker is absent. The input is probably truncated. [bam_header_read] invalid BAM binary header (this is not a BAM file). Segmentation fault (core dumped)

samtools sort -n -o sam DICDvenus1_STARAligned.out.sam DICDvenus1_SortedReads.sam open: No such file or directory [bam_sort_core] fail to open file sam

rna-seq software error • 2.1k views
ADD COMMENT
1
Entering edit mode
7.0 years ago
Derek Guan ▴ 20

samtools sort doesn't support sam files now, you may use the following command to transfer SAM to BAM:

samtools view -b DICDvenus1_SortedReads.sam > DICDvenus1_SortedReads.bam

Then you could use DICDvenus1_SortedReads.bam to run "samtools sort"

ADD COMMENT
1
Entering edit mode
7.0 years ago
mforde84 ★ 1.4k

I think this should work so long as the sam file has headers:

samtools view -Sb file.sam | samtools sort -n - file.sort

ADD COMMENT
0
Entering edit mode
7.0 years ago

Not a samtools answer, but BBMap has a program which will do it, "sortbyname.sh". Usage:

sortbyname.sh in=DICDvenus1_STARAligned.out.sam out=DICDvenus1_SortedReads.sam

I'm sure there's a way to do it with samtools, but I don't know what it is offhand.

Edit: In light of Derek's answer, no, it's not possible, which makes the name "samtools" seem weird.

P.S. And incidentally, sortbyname supports sam, fasta, fastq, and also (if samtools is installed) bam files. It also has various other sorting modes.

ADD COMMENT
0
Entering edit mode

Do you know if the repair utility of featureCounts is another way to sort the reads?

ADD REPLY
0
Entering edit mode

It wouldn't surprise me, but I have not used that program.

ADD REPLY

Login before adding your answer.

Traffic: 3119 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6