This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to get unmapped reads in a separate Fasta or Fastq file?

Hi,

I have some fastq files which I mapped to the host genome and get a sam file with 80% mapping rate. Now how can I get the unmapped reads to a separate fastq or fasta file so I can play with that only? Thank you very much everybody!

rna-seq samtools bowtie tophat

I edited the title of post in case anyone is wondering about the comments/answers. Feel free to edit to be more appropriate.

1 answer

Title of your question is different from content of question, anyways,

So you ran tophat, and got bam files , both mapped and unmapped.

and you want to extract reads from unmapped bam file in fastq format, you just run bamToFastq from bedtools

Here is description from their manual :

bedtools bamtofastq (aka bamToFastq)

Summary: Convert BAM alignments to FASTQ files.

Usage: bamToFastq [OPTIONS] -i <BAM> -fq <FQ>

Options:
-fq2 FASTQ for second end. Used if BAM contains paired-end data.
BAM should be sorted by query name is creating paired FASTQ.
-tags Create FASTQ based on the mate info in the BAM R2 and Q2 tags.

Tips:
If you want to create a single, interleaved FASTQ file for paired-end data, you can just write both to /dev/stdout:
bedtools bamtofastq -i x.bam -fq /dev/stdout -fq2 /dev/stdout > x.ilv.fq

Log in to answer this question.