it does not work for me! why?!
Any suggestions?
4 answers
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:
$ samtools view -h file.bam > file.sam
You should include -h option to include the header in the SAM output.
And to convert SAM to BAM:
$ samtools view -b file_copy.sam > file_copy.bam
-b is the option to output BAM.
Where is the command line? I'm sorry I don't know what I am doing and I just downloaded samtools but I cannot figure out where to input the $ samtools view -h file.bam > file.sam code, as I need to turn a file that is bam to a sam file for my mother.
Have you tried Googling "where is the command line"? Also, the fact that you need to convert a file for your mother is irrelevant here, so why mention it?
When you do find the command line, ensure you don't enter the $ at the beginning; that's just the symbol for the command line prompt and is not meant to be part of the command.
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
Log in to answer this question.
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?
Hi manish. You should open a new question for this. When you put your question in as an answer, people are unlikely to respond.
when converting from sam to bam the default method compresses the resulting bam file. Compression could result in data loss.
"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.