How To Extract Unaligned Sequences From Bam Files Obtainend From Bwa
2
4
Entering edit mode
11.5 years ago
joaslucas ▴ 90

Hi everyone, I aligned my RNA sequences against 16s and 23s using BWA. How can I extract my unmapped reads (the ones that really matters) into a fastq or fasta file? I want these sequences to run against bacterial genome and get gene counts.

I already tried using

samtools view -f 4 sample.bam > sample.unmapped.sam,

but it seems that the unmapped.sam is missing something because when I try convert it to bam, samtools show me the following error:

$ samtools view -S -b S_2_unmapped.sam > S_2_unmapped.BAM
[samopen] no @SQ lines in the header.
[sam_read1] missing header? Abort!

So, I am wondering if there is a way to get the unaligned files right from the first bam file ( the one containing aligned and unaligned files) and make my fatsq or fasta file to continue the analysis.

Thanks to those available to help me.

P.S I am a biologist.

bam fasta fastq gene counts • 16k views
ADD COMMENT
7
Entering edit mode
11.5 years ago

When a SAM file is created for viewing (with the view command) then it is meant for visual inspection and as such it is missing for example the header information.

To generate the header you need to pass the -h flag. But the right solution is to keep the output as BAM file in the first place by giving it the -b flag on the first view

samtools view -b -f 4 sample.bam > sample.unmapped.bam
ADD COMMENT
0
Entering edit mode

search the site for tips of converting bam file to fastq for example converting BAM to fastq

ADD REPLY
0
Entering edit mode
11.5 years ago
joaslucas ▴ 90

But can I use the BAM file as the imput for BWA alignment. I want to align these sequences against a bacterial genome for gene count using BWA. I have only seen the fa and fq files as the imput.

Thanks

ADD COMMENT
0
Entering edit mode

make sure to add these as comments to the original answer and not as a new answer to you post

ADD REPLY

Login before adding your answer.

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