FASTQ to BAM
1
0
Entering edit mode
9.1 years ago
kumbarov ▴ 10

I am trying to convert some SRA files to BAM format but I have a problem. How do I convert a FASTQ file to BAM file? I've been trying for some time and I wrote the following script:

#!/bin/bash
bin/fastq-dump $1 -Z > $1.fastq
picard-tools FastqToSam F1=$1.fastq O=$1.bam SM=sampleName SO=unsorted Validation_STRINGENCY=LENIENT

DIR=`dirname $1`
NAME=`basename $1 .sra`

samtools sort $1.bam ${DIR}/foo
samtools index ${DIR}/foo.bam

rm $1.fastq $1.bam

I get a BAM file but it has no header:

samtools view -H foo.bam
@HD    VN:1.4    SO:coordinate
@RG    ID:A    SM:sampleName

How do I fix a header? I guess I have to give a reference sequence when converting from FASTQ to BAM?

bam fastq sra • 3.4k views
ADD COMMENT
0
Entering edit mode
9.1 years ago
piet ★ 1.9k

I am trying to convert some SRA files to BAM format

You can convert SRA directly into SAM. The SRA toolkit offers the program sam-dump for this purpose, see here.

As fastq-dump is intended to extract fastq from SRA files, sam-dump can be used to convert SRA into SAM. An SRA file is already much like a SAM file, it comprises a mapping of some reads to a reference sequence.

ADD COMMENT
0
Entering edit mode

I tried this but I got no output. It had something to do with the SRA not being aligned.

ADD REPLY
0
Entering edit mode

I have made a test run with SRR1927226 (download size about 400 MB) and it worked flawlessly. The reads in SRR1927226 are not aligned to a refsequence. Due to the download size, the command needs more than 5 minutes to finish.

/usr/local/lib/SRA-toolkit/sam-dump.2.5.4 SRR1927226 | samtools view -bS - > SRR1927226.bam
ADD REPLY
0
Entering edit mode

I tried this with SRR1302886.sra but got only this:

sam-dump SRR1302886.sra | /usr/bin/samtools view -bS - > SRR1302886.bam
[samopen] no @SQ lines in the header.
[sam_read1] missing header? Abort!
ADD REPLY
0
Entering edit mode

add manually from some SAM file. Shouldn't really mess anything if you look closely what is in the header

ADD REPLY

Login before adding your answer.

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