Question: problem in conversion of sam to bam file
0
gravatar for priya120195
6 months ago by
priya1201950 wrote:

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.
ADD COMMENTlink modified 6 months ago by Pierre Lindenbaum122k • written 6 months ago by priya1201950

what is the output of

head newoutputERX676467.sam

?

ADD REPLYlink written 6 months ago by Pierre Lindenbaum122k
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 REPLYlink modified 6 months ago by WouterDeCoster40k • written 6 months ago by priya1201950

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 REPLYlink written 6 months ago by WouterDeCoster40k

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 REPLYlink written 6 months ago by ATpoint22k

yes I always use nohup

ADD REPLYlink written 6 months ago by priya1201950

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 REPLYlink written 6 months ago by WouterDeCoster40k

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

ADD REPLYlink written 6 months ago by priya1201950

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

ADD REPLYlink written 6 months ago by WouterDeCoster40k

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 REPLYlink written 6 months ago by ATpoint22k

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 REPLYlink modified 6 months ago • written 6 months ago by michael.ante3.3k

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 REPLYlink written 6 months ago by ATpoint22k
2
gravatar for ATpoint
6 months ago by
ATpoint22k
Germany
ATpoint22k wrote:

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 COMMENTlink modified 6 months ago • written 6 months ago by ATpoint22k
1
gravatar for Pierre Lindenbaum
6 months ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum122k wrote:
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 COMMENTlink written 6 months ago by Pierre Lindenbaum122k

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

ADD REPLYlink written 6 months ago by priya1201950
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: 2689 users visited in the last hour