Samtools Parse error at line 1
1
0
Entering edit mode
3.7 years ago
storm1907 ▴ 30

Hello, I am trying to convert sam to bam and keep getting an error:

The input file must be coordinate sorted and must have gone through fixmates with the mate scoring option on.
[W::sam_read1] Parse error at line 1
[bam_flagstat_core] Truncated file? Continue anyway.

Before this I was doing PE Trimmomatics with following BWA - MEM. Here is my code. I would appreciate any help :( Thank you!

#!/bin/bash -x

INPATH=/dir/subdir
reference=/dir/refseq.fasta
cd /mnt/home/usr/tools/samtools-1.9
./samtools faidx $reference
cd $INPATH

for file in $INPATH/*.sam ;
do
        bname=$(basename $file ".sam")
        echo $bname
        echo file: $file
        bamfile=$INPATH/$bname".bam"
        namesort=$INPATH/$bname"_sorted.bam"
        fixmate=$INPATH/$bname"_sorted_fixmate.bam"
        positionsort=$INPATH/$bname"_sorted_fixmate_position.bam"
        markdup=$INPATH/$bname"_sorted_fixmate_position_markdup.bam"
        bai=$INPATH/$bname".bai"
        stats=$INPATH/$bname".txt"
        echo $bamfile $namesort $fixmate $positionsort $markdup
        cd /mnt/home/usr/tools/samtools-1.9

        ./samtools view -bT $reference $file > $bamfile
        ls -lh
        ./samtools sort -@ 12 -n $bamfile > $namesort
        ./samtools fixmate -m $namesort > $fixmate
        ./samtools sort -@ 12 $fixmate > $positionsort
        ./samtools markdup $positionsort > $markdup
        ./samtools index > $markdup
        ./samtools flagstat $markdup > $stats
done
alignment • 2.7k views
ADD COMMENT
0
Entering edit mode
3.7 years ago

Are you completely sure that the samtools view command is working completely correctly, including the header?

Modern versions of samtools will sort a sam; you don't have to convert to bam first, so you can just skip the view step.

And of course, once you get each step working right, you can pipe them all together.

I'm also not sure that it's considered wise to be changing directories in the middle of your script. Probably safer to stay put, write to where you want to write to.

ADD COMMENT

Login before adding your answer.

Traffic: 3170 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