Do you know if the repair utility of featureCounts is another way to sort the reads?
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
3 answers
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"
I think this should work so long as the sam file has headers:
samtools view -Sb file.sam | samtools sort -n - file.sort
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.
It wouldn't surprise me, but I have not used that program.
Log in to answer this question.