This is a test version of Biostars. For the public version, visit https://www.biostars.org.
importing .SAM files into R (Rstudio)

Hi

I have some .sam files as output of bowtie run. i want to read them into Rstudio. i searched for it but all i can find is about importing .bam files. some suggest converting .sam into .bam. is it the only way? and is this convertion lossless?

thanks

r sam bowtie

The main question is "why would you want to do that?" Sam and bam contain the same information, bam is just binary of sam.

1 answer

Sam file is a text file. So you can read it directly in R. But there is no point.

Best way is to convert sam to bam and then use a library like RSamtools to read the bam files.

so why i should convert it ? if i can read it directly ?

You could read it. Its a text file. But to have an easy and quick access the information it has, better to use some libraries, rather than writing something from scratch. Converting to bam file has many other advantages, which is not the question here.

This might be useful, http://davetang.org/wiki/tiki-index.php?page=SAMTools

Log in to answer this question.