How Can I Convert Bam To Sam?
5
23
Entering edit mode
10.8 years ago
Biomed 4.7k

Any suggestions?

next-gen sequencing bam sam conversion • 130k views
ADD COMMENT
54
Entering edit mode
10.8 years ago

Use samtools from the command line:

samtools view -h -o out.sam in.bam
ADD COMMENT
0
Entering edit mode

it does not work for me! why?!

ADD REPLY
1
Entering edit mode

oh I understand guys. before this command, we should install samtools in the bash. http://www.htslib.org/download/

ADD REPLY
8
Entering edit mode
8.5 years ago
A. Domingues ★ 2.5k

If you want to do it in batch:

# convert BAM to SAM
for file in ./*.bam
do
    echo $file 
    samtools view -h $file > ${file/.bam/.sam}
done
ADD COMMENT
3
Entering edit mode
9.7 years ago
Stephen 2.8k

Galaxy also does this.

ADD COMMENT
1
Entering edit mode
9.7 years ago
Fred Wang ▴ 10

when converting from sam to bam the default method compresses the resulting bam file. Compression could result in data loss.

ADD COMMENT
10
Entering edit mode

"Compression could result in data loss." This is only correct if a lossy compression algorithm is used. BAM natively employs zlib (~LZ77) compression, which is a _lossless_ compression algorithm. Thus, no data is lost.

ADD REPLY
0
Entering edit mode
10.1 years ago
Manish • 0

Hi ,

When i am converting Sam to Bam and back to Sam.I am loosing quality score of the Sam file. i.e. Input sam and the reversed sam does not match.Is this expected?

ADD COMMENT
10
Entering edit mode

Hi manish. You should open a new question for this. When you put your question in as an answer, people are unlikely to respond.

ADD REPLY

Login before adding your answer.

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