Convert SAM to BAM error
1
0
Entering edit mode
2.2 years ago
BeeWork ▴ 10

Hi all,

I have mapped a pair-end SAMPLE_R1.fastq and SAMPLE_R2.fastq to hg.38 in Bowtie2. The mapping is fine as I could see the summary stats from the stederr file.But when I tried to convert the SAM file to BAM file.

samtools view -b -o SAMPLE.bam -S SAMPLE.sam

I have this error message:

[W::sam_read1] Parse error at line 198
samtools view: error reading file "SAMPLE.sam"

This is line 198 in the sam file

@SRR891270.1 
HWI-ST281:266:C1LTTACXX:2:1101:1339:1962/1%0ANTATCACACCCCATCCTAAAGTAAGGTCAGCTAAATAAGCTATCGGGCCC%0A+%0A#41BABDDDHHFHCEEEAAFAFCCCGFF<@?E:*1?DDFDGGFFHGIH<F%0A

What problem of this line would be?

Thanks

BAM SAM samtools • 1.2k views
ADD COMMENT
1
Entering edit mode

I'm currently learning on the SAM to BAM conversion. From my understanding the code line should be;

samtools view -bS ~/<your full directory where the input file is stored>/SAMPLE.sam -o ~/<your full directory where the output file is to be stored>/SAMPLE.bam

instead of samtools view -b -o SAMPLE.bam -S SAMPLE.sam

Have a try on it and let's see if this works (mine works well). Hope this helps!

ADD REPLY
2
Entering edit mode

Any time you see samtools view -bS, it is an indication that the tutorial you are reading is outdated.

Your suggested command line uses the -b, -S, and -o options, which is exactly the same set of options that BeeWork is already using. So it is effectively identical to the OP's version (except that it puts an option after the filename argument SAMPLE.sam, which is a bad habit especially in scripts as it does not work on all Unixes).

Samtools has automatically detected the format of its input files since 2014. The -S option (for samtools view), which previously specified that the input file was SAM rather than BAM, has been ignored since samtools 1.0. There is no reason to use it.

ADD REPLY
1
Entering edit mode

Thanks John,

Suchakan - John is correct. these flags are the same and don't need -S to specific input SAM format, samtools view should be able to detect. in samtools-view manual, it said "ignored" in -S flag.

ADD REPLY
0
Entering edit mode

Oh thank you so much for telling me this invaluable information; I have learned so much from you two John and BeeWork. Sorry for the inconvenience caused.

ADD REPLY
4
Entering edit mode
2.2 years ago

That line is the four lines of a FASTQ record, with the four newlines percent-encoded as %0A. It is very far from being a valid SAM line.

You would need to look at the rest of your “SAM” file and at the commands that produced it to figure out what has gone wrong here.

ADD COMMENT

Login before adding your answer.

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