Question: Error converting sam to bam
0
gravatar for valopes
18 months ago by
valopes30
valopes30 wrote:

Hi I am getting a message while converting sam to bam. I used this comand for mapping:

bwa mem -M -R '@RG\tID:sample1' -t 2 ref.fa sample1_R1.fastq
sample1_R2.fastq > sample1.sam

Now I tried to convert sam to bam, using:

samtools view -hSb  PI200492.sam > PI200492.bam

and I got an Error

[W::sam_read1] parse error at line 1
[main_samview] truncated file

It looks the aligment worked!

Could someone help me please?

Thanks

genome • 712 views
ADD COMMENTlink modified 17 months ago by Pierre Lindenbaum117k • written 18 months ago by valopes30

Can you show the content of sam file? you can use head PI200492.sam

ADD REPLYlink modified 18 months ago • written 18 months ago by Renesh1.5k

I got this using

head -n 20 PI200492.sam

[M::bwa_idx_load_from_disk] read 0 ALT contigs [M::process] read 144932 sequences (20000145 bp)... [M::process] read 144502 sequences (20000294 bp)... [M::mem_pestat] # candidate unique pairs for (FF, FR, RF, RR): (1, 37520, 8, 0) [M::mem_pestat] skip orientation FF as there are not enough pairs [M::mem_pestat] analyzing insert size distribution for orientation FR... [M::mem_pestat] (25, 50, 75) percentile: (253, 289, 327) [M::mem_pestat] low and high boundaries for computing mean and std.dev: (105, 475) [M::mem_pestat] mean and std.dev: (290.07, 56.84) [M::mem_pestat] low and high boundaries for proper pairs: (31, 549) [M::mem_pestat] skip orientation RF as there are not enough pairs [M::mem_pestat] skip orientation RR as there are not enough pairs [M::mem_process_seqs] Processed 144932 reads in
79.266 CPU sec, 39.456 real sec @SQ     SN:Chr01        LN:56831624 @SQ     SN:Chr02        LN:48577505 @SQ     SN:Chr03        LN:45779781 @SQ     SN:Chr04        LN:52389146 @SQ     SN:Chr05       LN:42234498 @SQ     SN:Chr06        LN:51416486 @SQ     SN:Chr07       LN:44630646
ADD REPLYlink modified 17 months ago by WouterDeCoster37k • written 18 months ago by valopes30

for some reasons your STDERR and STDOUT are mixed ????

ADD REPLYlink written 17 months ago by Pierre Lindenbaum117k
1

are you sure you've written:

bwa mem -M -R '@RG\tID:sample1' -t 2 ref.fa sample1_R1.fastq sample1_R2.fastq  > sample1.sam

???

ADD REPLYlink written 17 months ago by Pierre Lindenbaum117k

Yes I am sure it was this command.

ADD REPLYlink written 17 months ago by valopes30

Yes I am sure it was this command.

no, it was not. You have used 'nohup'

ADD REPLYlink written 17 months ago by Pierre Lindenbaum117k

Did you use exactly that command or was it embedded into any nohup-like redirection command?

ADD REPLYlink written 17 months ago by ATpoint14k

In fact, I used

nohup  bwa mem -M -R '@RG\tID:sample1' -t 2 ref.fa sample1_R1.fastq sample1_R2.fastq  > sample1.sam &

But I need to use "nohup" because the server here always disconnect for inactivity.

Do you think it can be the problem?

ADD REPLYlink modified 17 months ago by WouterDeCoster37k • written 17 months ago by valopes30
2

You can use GNU screen to be independent from an active terminal session.

Simply open a new screen by screen -S <name>. It can be detached with Ctrl-A Ctrl-D and reattached with screen -r <name>.

ADD REPLYlink modified 17 months ago • written 17 months ago by ATpoint14k

I see. Thank you. It will help a lot. But it works just in one of the servers I've been working.

ADD REPLYlink modified 17 months ago • written 17 months ago by valopes30

I'd recommend avoiding nohup. Append & to the command or interrupt using Ctrl-Z and then use bg to send the job to background and then follow up with disown <jobid> so SIGHUPs don't bother the process. Retain the job ID to monitor the job and check your file on completion.

ADD REPLYlink modified 17 months ago • written 17 months ago by RamRS20k

I am sorry, I did't get it. Could you please explain it better? Thanks

ADD REPLYlink modified 17 months ago • written 17 months ago by valopes30

When you run a command, you can run it either in the foreground or the background. The default is foreground, but you can run it in the background by using an & at the end of the command.

#this is foreground processing
wc -l largefile.fastq
#this is background processing
wc -l largefile.fastq &

But how can you move a running process from the foreground to the background? You interrupt it using Ctrl-Z and then use the bg command to send it to the background. The process will then run in the background.

Even a background process is linked to you, so if you logout or your connection terminates, the job will be killed. You can use nohup to overcome that, but nohup is weird - I stopped using it when it messed with my redirections. You can also use a screen. I use a custom screen script that writes a log to a custom file and has a name attached to it, all done through a custom screenrc file created on the file - but I digress.

A nifty trick is to use disown to remove your ownership of the process. That way, even if the terminal disconnects, your process keeps running as it is not attached to your terminal. But yeah, I was super sleepy when I wrote that answer and screen is a MUCH better way to do it.

ADD REPLYlink written 17 months ago by RamRS20k

I think this should just work without the -S and -h, but I'm not sure which samtools version you are using.

samtools view -b  PI200492.sam > PI200492.bam
ADD REPLYlink written 18 months ago by WouterDeCoster37k

Hi

I already tried this command and I got the same error. The samtools version is 1.5.

ADD REPLYlink modified 18 months ago • written 18 months ago by valopes30
0
gravatar for Pierre Lindenbaum
17 months ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum117k wrote:

use

bwa mem -M -R '@RG\tID:sample1' -t 2 ref.fa sample1_R1.fastq sample1_R2.fastq |  samtools view -hSb   -o PI200492.bam -

nohup would combine stderr and stdout.

ADD COMMENTlink modified 17 months ago • written 17 months ago by Pierre Lindenbaum117k

I will try it and I will let you know.

Thank you very much for helping me.

ADD REPLYlink written 17 months ago by valopes30
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: 1289 users visited in the last hour