Use samtools from the command line:
samtools view -h -o out.sam in.bam
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
when converting from sam to bam the default method compresses the resulting bam file. Compression could result in data loss.
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?
With parallel, remember to cite the paper, it's remarkable work.
parallel --plus 'samtools view -h {} -o {...}.sam' ::: *.bam
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
it does not work for me! why?!
oh I understand guys. before this command, we should install samtools in the bash. http://www.htslib.org/download/
You can use this:
To convert BAM to SAM you can use:
You should include
-h
option to include the header in the SAM output.And to convert SAM to BAM:
-b
is the option to output BAM.