SEQanswers

Go Back   SEQanswers > Bioinformatics > Bioinformatics



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to extract uniquely mapped reads from bam/sam produced by bwa-mem? Yamol Bioinformatics 11 08-14-2015 09:47 AM
how to convert sorted.txt files from the Illumina pipeline v1.3.4 to bam or sam? crazyhottommy Bioinformatics 7 04-20-2015 06:54 AM
BWA sam and Samtools sam->bam conversion problem maasha Bioinformatics 6 06-05-2013 07:39 AM
possible to bwa -> sam -> bam via pipe? Kotoro Bioinformatics 5 07-19-2011 02:34 AM
BWA: specifying SAM/BAM file header fields before read alignment? nora Bioinformatics 3 12-04-2010 09:11 PM

Reply
 
Thread Tools
Old 05-16-2017, 02:41 AM   #1
Virome
Junior Member
 
Location: norwich

Join Date: May 2017
Posts: 3
Default BWA sam -> bam in pipeline

I am trying to use BWA mem to align pair-end reads to a single genome and pipe the sam file output to a bam and then a bedfile. The pipeline doesn't seem to be working.

It creates the output sam, bam and bed files but the bam and bed files are empty. It completes the alignment but an error message keeps appearing: Failed to open BAM file stdin.

Here is the code I am using:
Code:
bwa mem NC_005148.fa ./seqtk_1/subsample_1/sub_NC_005148_1.fq ./seqtk_1/subsample_1/sub_NC_005148_2.fq > NC_005148_BWA.sam | \
samtools view -S -h -u - | \
samtools sort - | \
samtools rmdup -s - | \
tee NC_005148_BWA_sorted.bam | \
bamToBed > NC_005148_BWA_sorted.bed
I am new to coding so any help would be appreciated.
Virome is offline   Reply With Quote
Old 05-16-2017, 03:48 AM   #2
GenoMax
Senior Member
 
Location: East Coast USA

Join Date: Feb 2008
Posts: 6,440
Default

This is probably based on this Biostars thread. Compare your command with the one there and you will notice that you are missing a couple of inputs (-).
GenoMax is online now   Reply With Quote
Old 05-17-2017, 04:26 AM   #3
Virome
Junior Member
 
Location: norwich

Join Date: May 2017
Posts: 3
Default

That the thread that I used for the basis of the pipeline. I tried with the '- -' like it said in the thread the first time but it didn't work also.

Also, do I need to index the resulting bam files?
Virome is offline   Reply With Quote
Old 05-17-2017, 05:49 AM   #4
GenoMax
Senior Member
 
Location: East Coast USA

Join Date: Feb 2008
Posts: 6,440
Default

Since new version of samtools has slightly different options try this variation

Quote:
bwa mem index R1.fq.gz R2.fq.gz | samtools view -Shu - | samtools sort - | samtools rmdup -s - - | tee NC_005148_BWA_sorted.bam | bamToBed > NC_005148_BWA_sorted.bed
When using pipes you should keep adding one additional operation to see where things are going wrong to debug starting at left side of the command.

Last edited by GenoMax; 05-17-2017 at 05:52 AM.
GenoMax is online now   Reply With Quote
Old 05-17-2017, 06:00 AM   #5
Virome
Junior Member
 
Location: norwich

Join Date: May 2017
Posts: 3
Default

Thank you. I've tried the code that was posted. It provided the sam file and a sorted bam file. However, it appears to be empty.

I used samtools flagstat on the sorted bam file to just to check the alignment. This was the output:
0 + 0 in total (QC-passed reads + QC-failed reads)
0 + 0 secondary
0 + 0 supplementary
0 + 0 duplicates
0 + 0 mapped (N/A : N/A)
0 + 0 paired in sequencing
0 + 0 read1
0 + 0 read2
0 + 0 properly paired (N/A : N/A)
0 + 0 with itself and mate mapped
0 + 0 singletons (N/A : N/A)
0 + 0 with mate mapped to a different chr
0 + 0 with mate mapped to a different chr (mapQ>=5)

If I use samtools on flagstat on the sam file. This is the output:
2000000 + 0 in total (QC-passed reads + QC-failed reads)
0 + 0 secondary
0 + 0 supplementary
0 + 0 duplicates
2000000 + 0 mapped (100.00% : N/A)
2000000 + 0 paired in sequencing
1000000 + 0 read1
1000000 + 0 read2
1999996 + 0 properly paired (100.00% : N/A)
2000000 + 0 with itself and mate mapped
0 + 0 singletons (0.00% : N/A)
0 + 0 with mate mapped to a different chr
0 + 0 with mate mapped to a different chr (mapQ>=5)


I am struggling to think what is happening to the bam file.
Virome is offline   Reply With Quote
Old 05-17-2017, 06:26 AM   #6
GenoMax
Senior Member
 
Location: East Coast USA

Join Date: Feb 2008
Posts: 6,440
Default

The command is working for me with Samtools v.1.4 and BedTools v.2.25.0. If you are using older version of these packages then try to upgrade.

As for debugging why the command is not working for you, start at the left and keep adding one pipe at a time to figure out which component fails. I assume you are using real index/file names as applicable in your case.

Last edited by GenoMax; 05-17-2017 at 06:28 AM.
GenoMax is online now   Reply With Quote
Reply

Tags
bam, bwa, sam, samtools

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off




All times are GMT -8. The time now is 10:42 AM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Single Sign On provided by vBSSO