Question: How To Extract Unaligned Sequences From Bam Files Obtainend From Bwa
4
gravatar for joaslucas
6.1 years ago by
joaslucas70
joaslucas70 wrote:

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.

fasta gene fastq bam counts • 12k views
ADD COMMENTlink modified 6.1 years ago • written 6.1 years ago by joaslucas70
7
gravatar for Istvan Albert
6.1 years ago by
Istvan Albert ♦♦ 80k
University Park, USA
Istvan Albert ♦♦ 80k wrote:

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 COMMENTlink modified 6.1 years ago • written 6.1 years ago by Istvan Albert ♦♦ 80k

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

ADD REPLYlink written 6.1 years ago by Istvan Albert ♦♦ 80k
0
gravatar for joaslucas
6.1 years ago by
joaslucas70
joaslucas70 wrote:

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 COMMENTlink written 6.1 years ago by joaslucas70

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

ADD REPLYlink written 6.1 years ago by Istvan Albert ♦♦ 80k
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: 1492 users visited in the last hour