problem in conversion of sam to bam file
2
0
Entering edit mode
5.2 years ago
priya120195 ▴ 20

hi, I used Bwa tool for mapping to get .sam file in output.Now I used samtools view to convert this .sam file into .bam file but it is not running.It gets exit within a second. Can anyone suugest why this is happening?

The command I am using is

samtools view -bS newoutputERX676467.sam > newoutputERX676467.bam

the head of the output is

head  newoutputERX676467.bam
[W::sam_read1] parse error at line 1
[main_samview] truncated file.
software error next-gen alignment • 1.6k views
ADD COMMENT
0
Entering edit mode

what is the output of

head newoutputERX676467.sam

?

ADD REPLY
0
Entering edit mode
head newoutputERX676467.sam 
[M::bwa_idx_load_from_disk] read 0 ALT contigs
@SQ SN:NC_000001.11 LN:248956422
@SQ SN:NT_187361.1  LN:175055
@SQ SN:NT_187362.1  LN:32032
@SQ SN:NT_187363.1  LN:127682
@SQ SN:NT_187364.1  LN:66860
@SQ SN:NT_187365.1  LN:40176
@SQ SN:NT_187366.1  LN:42210
@SQ SN:NT_187367.1  LN:176043
@SQ SN:NT_187368.1  LN:40745
ADD REPLY
0
Entering edit mode

I added markup to your post for increased readability. You can do this by selecting the text and clicking the 101010 button. When you compose or edit a post that button is in your toolbar, see image below:

101010 Button

ADD REPLY
0
Entering edit mode

Do you use nohup? Stderr and stdout seem to be mixed. I would always do bwa mem (options) in.fq | samtools view -o out.bam

ADD REPLY
0
Entering edit mode

yes I always use nohup

ADD REPLY
0
Entering edit mode

Likely not the source of your problem, but please use the new samtools syntax (with a recent version of samtools):

samtools view newoutputERX676467.sam -o newoutputERX676467.bam

Samtools recognizes file extensions.

ADD REPLY
0
Entering edit mode

i tried with this also,but still it is not working.

ADD REPLY
0
Entering edit mode

The problem is that you aligned with nohup. Don't do that. You'll have to repeat your alignment.

ADD REPLY
0
Entering edit mode

Agreed. As I told you already, your SAM file is corrputed because STDERR messages are in it. Start over with the alignment and use any of the suggested solutions, or simply your script without nohup.

ADD REPLY
0
Entering edit mode

You are just missing to include the header in your samtools view command:

samtools view -bSh newoutputERX676467.sam > newoutputERX676467.bam

(It's the old samtools syntax, you may want to update it as Wouter suggested)

ADD REPLY
0
Entering edit mode

I moved your answer to the comment section as it would not help given the error message of OP, indicating that stderr and stdout are mixed in the same file.

ADD REPLY
2
Entering edit mode
5.2 years ago
ATpoint 82k

I recommend against nohup as it mixes stdout and stderr which can be problematic, corrupting the output. If you want to capture stderr in a file, better wrap your code into a function like

function Alignment {

  FASTQ=$1
  bwa (...) (code...) | samtools view -o ${1%.fq}.bam

}

and then run it like Alignment In.fq 2> stderr.log Wrapping in a function is useful because as soon as your code gets longer you can simply catch all stderr in a file with a single 2> and do not run into trouble with mixing stderr/stdout. Also consider using GNU screen.

ADD COMMENT
1
Entering edit mode
5.2 years ago
head newoutputERX676467.sam 
[M::bwa_idx_load_from_disk] read 0 ALT contigs
@SQ SN:NC_000001.11 LN:248956422
@SQ SN:NT_187361.1  LN:175055
@SQ SN:NT_187362.1  LN:32032
@SQ SN:NT_187363.1  LN:127682
@SQ SN:NT_187364.1  LN:66860
@SQ SN:NT_187365.1  LN:40176
@SQ SN:NT_187366.1  LN:42210
@SQ SN:NT_187367.1  LN:176043
@SQ SN:NT_187368.1  LN:40745

you're using bwa the wrong way. You're mixing the standard error and the standard outpout in the same stream

your command should be something like

bwa mem ref.fa f1.fq f2.fq > out.sam

or

bwa mem ref.fa f1.fq f2.fq > out.sam 2> messages.txt
ADD COMMENT
0
Entering edit mode

I used this command only,which u have mentioned above.

ADD REPLY

Login before adding your answer.

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