Minimap2: How to keep unmapped reads

Created on 13 May 2018  Â·  11Comments  Â·  Source: lh3/minimap2

Hi! I want to subtract the PacBio reads that map to a given genome and keep only the unmapped reads for subsequent assembly. Can this be done?

Thanks

question

Most helpful comment

Excellent, thanks for the help. So then minimap2 contaminant filtering becomes:
minimap2 -ax map-ont contaminant.fasta nanopore.fastq.gz | samtools fastq -n -f 4 - > nano_clean.fastq.gz

All 11 comments

Output in the SAM format (option "-a"). You can get unmapped records in SAM.

@ssilva1 minimap2 -a REF R1 R2 | samtools sort | samtools view -f 4 | samtools fastq -s R0' -1 R1' -2 R2' or something similar

(you might not need to sort step!)

Thanks all, output to sam and then samtools view -f 4 worked well.

@ssilva1 can you close this issue now? thanks!

I am trying to use minimap2 to filter contaminant nanopore reads with a contaminant fasta. I tried the above, plus several similar syntaxes, but I cannot get the samtools fastq command to work.
minimap2 -ax map-ont contaminant.fasta nanopore.fastq.gz | samtools sort | samtools view -f 4 | samtools fastq -1 clean.fastq.gz

Hi,

I had the same problem and “fixed" it by not piping (basically just separating samtools from the minimap2 command.

On 25 Jul 2018, at 06:38, Robert Butler notifications@github.com wrote:

I am trying to use minimap2 to filter contaminant nanopore reads with a contaminant fasta. I tried the above, plus several similar syntaxes, but I cannot get the samtools fastq command to work.
minimap2 -ax map-ont contaminant.fasta nanopore.fastq.gz | samtools sort | samtools view -f 4 | samtools fastq -1 clean.fastq.gz

—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub https://github.com/lh3/minimap2/issues/163#issuecomment-407639166, or mute the thread https://github.com/notifications/unsubscribe-auth/AgYmTGDWFYfd3-VriNTjNq1EMmet6hTdks5uKARFgaJpZM4T87rs.

It looks like from some checking, the samtools fastq cannot accept a piped input. In v1.9 it lets you know no input specified. I was able to pipe it through samtools view, but then no further. However, newer versions of samtools fastq allow you to specify the -f 4 or -F 4 flags for unmapped and mapped, respectively. So I ended up with:

minimap2 -ax map-ont contaminant.fasta nanopore.fastq.gz > nano.contam.sam
samtools fastq -n -f 4 nano.contam.sam | pigz > nano_clean.fastq.gz

Samtools fastq can accept a piped input. Use - or /dev/stdin as the file name like:

some_tools | samtools fastq - > output.fq

I am always hesitant to skip file names because most tools don't automatically test if stdin is available.

Excellent, thanks for the help. So then minimap2 contaminant filtering becomes:
minimap2 -ax map-ont contaminant.fasta nanopore.fastq.gz | samtools fastq -n -f 4 - > nano_clean.fastq.gz

Could anybody please explain what the 4 in samtools -n -f 4 means?

Could anybody please explain what the 4 in samtools -n -f 4 means?

"4" means unmapped reads, see more details at https://www.samformat.info/sam-format-flag

Was this page helpful?
0 / 5 - 0 ratings

Related issues

llevar picture llevar  Â·  4Comments

Adamtaranto picture Adamtaranto  Â·  5Comments

sjackman picture sjackman  Â·  3Comments

dangchenyuan picture dangchenyuan  Â·  5Comments

fbemm picture fbemm  Â·  5Comments