Question: Convert SAM to BAM
1
gravatar for marina-orlova
5.1 years ago by
Russian Federation
marina-orlova70 wrote:

Hello!

Can't convert SAM to BAM.

My SAM-file has a header:

@SQ    SN:2L    AS:FlyBase r5    LN:23011544    SP:Drosophila melanogaster
@SQ    SN:2LHet    AS:FlyBase r5    LN:368872    SP:Drosophila melanogaster
@SQ    SN:2R    AS:FlyBase r5    LN:21146708    SP:Drosophila melanogaster
@SQ    SN:2RHet    AS:FlyBase r5    LN:3288761    SP:Drosophila melanogaster
@SQ    SN:3L    AS:FlyBase r5    LN:24543557    SP:Drosophila melanogaster
@SQ    SN:3LHet    AS:FlyBase r5    LN:2555491    SP:Drosophila melanogaster
@SQ    SN:3R    AS:FlyBase r5    LN:27905053    SP:Drosophila melanogaster
@SQ    SN:3RHet    AS:FlyBase r5    LN:2517507    SP:Drosophila melanogaster
@SQ    SN:4    AS:FlyBase r5    LN:1351857    SP:Drosophila melanogaster
@SQ    SN:X    AS:FlyBase r5    LN:22422827    SP:Drosophila melanogaster
@SQ    SN:XHet    AS:FlyBase r5    LN:204112    SP:Drosophila melanogaster
@SQ    SN:YHet    AS:FlyBase r5    LN:347038    SP:Drosophila melanogaster
@SQ    SN:M    AS:FlyBase r5    LN:19517    SP:Drosophila melanogaster
@SQ    SN:U    AS:FlyBase r5    LN:10049159    SP:Drosophila melanogaster
@SQ    SN:Uextra    AS:FlyBase r5    LN:29004788    SP:Drosophila melanogaster
HWI-EAS146:8:1:3:289#0    16    Uextra    11516293    255    36M    *    0    0    NGGAGNCAAATGCCTCGTCATCTAATTAGTGACGCG    aaa^_aa\^TG\\LYLY`_`aBBBBBBBBBBBBBBB
HWI-EAS146:8:1:3:289#0    16    Uextra    10227800    255    36M    *    0    0    NGGAGNCAAATGCCTCGTCATCTAATTAGTGACGCG    aaa^_aa\^TG\\LYLY`_`aBBBBBBBBBBBBBBB
HWI-EAS146:8:1:3:289#0    16    Uextra    20746385    255    36M    *    0    0    NGGAGNCAAATGCCTCGTCATCTAATTAGTGACGCG    aaa^_aa\^TG\\LYLY`_`aBBBBBBBBBBBBBBB

 

 

I write a command: 

samtools view -bS file.sam > file.bam

No error is displayed, program stops working successfully but created BAM file can't be opened (The error is: type of archive is not supported).

 

rna-seq sam bam • 12k views
ADD COMMENTlink modified 5.1 years ago by Ian5.5k • written 5.1 years ago by marina-orlova70
1

BAM file can't be opened : by which software ?

ADD REPLYlink written 5.1 years ago by Pierre Lindenbaum122k

Usually I can see content of bam file just with gedit

ADD REPLYlink written 5.1 years ago by marina-orlova70
3

"Usually I can see content of bam file just with gedit" :  god kills a kitten every time you're doing this :-)

ADD REPLYlink modified 5.1 years ago • written 5.1 years ago by Pierre Lindenbaum122k

Thank you for the help) The problem was in running samtools from root (doesn't allow to write files).

ADD REPLYlink written 5.1 years ago by marina-orlova70
2

You may be talking about sam file.  Try running: samtools view -H file.bam . This command will show the header of the bam file. 

ADD REPLYlink written 5.1 years ago by Ashutosh Pandey11k

Thank you, I saw that the bam file is ok.

But I can't convert it to sorted bam file (and I thought that the mistake was at step of sam-to-bam converting).

I wrote a command: samtools sort file.bam file_sorted. the mistake is:

[bam_sort_core] merging from 4 files...
open: No such file or directory
[bam_merge_core] fail to open file 2024-sorted.0000.bam

 

ADD REPLYlink written 5.1 years ago by marina-orlova70
1

As Pierre indicated take some time to go through the samtools manual because most of these are basic stuff. About your sort errror: samtools splits the big bam file for sort purpose. It seems that you may have deleted those intermediate files and when samtools tried to merge them it ddint find them. Dont delete any intermediate files until the sort process is done. 

ADD REPLYlink written 5.1 years ago by Ashutosh Pandey11k

Don't ever delete anything while any program is working)

Thank you for your help. The error was that I run program while being in root and it doesn't allow to write files. Too little experience with Linux..

ADD REPLYlink written 5.1 years ago by marina-orlova70
1

Hi,

I'd suggest mentioning that you're a "linux beginner" in your questions. That would help us tweak our geek levels suitably :-)

ADD REPLYlink written 5.1 years ago by RamRS24k
1
gravatar for Ian
5.1 years ago by
Ian5.5k
University of Manchester, UK
Ian5.5k wrote:

The command line should be:

samtools view -bS -o file.bam file.sam

without the '>' redirect

samtools view -bS file.sam > file.bam

This is fine, I had just never done run it without the -o flag before.

ADD COMMENTlink modified 5.1 years ago • written 5.1 years ago by Ian5.5k

Why? The OPs command like works as well, doesn't it?

ADD REPLYlink written 5.1 years ago by lelle800

You are right!

ADD REPLYlink written 5.1 years ago by Ian5.5k
0
gravatar for Caddymob
5.1 years ago by
Caddymob950
United States
Caddymob950 wrote:

Try `samtools import`.

~> samtools import
Usage: bamtk import <in.ref_list> <in.sam> <out.bam>


 

ADD COMMENTlink written 5.1 years ago by Caddymob950

I think that command might be deprecated.

ADD REPLYlink written 5.1 years ago by swbarnes26.5k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 657 users visited in the last hour