This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Samtools-remove host reads

We are working with Nanopore reads using the rapid barcoding kit. We are interested in the bacterial and fungal microbiome of our samples so need to remove host (human) reads (single reads not paired)

For one barcode/sample I have mapped the reads to the human genome using minimap2 and generated the output aln.sam

I am now a little lost on how to use SamTools to remove the host reads -any help greatly appreciated!

samtools

1 answer

samtools view -buSh -f 4 aln.sam | samtools fastq - | gzip -c - > non_human.fastq.gz

should write all the unaligned (-f 4) reads into a fastq.gz file.

Edit: changed formatting from blockquote to code

Thank you so much!

Can i check my understanding... -buSh i am unsure what this indicates.

-f extracts only those reads which match the specified SAM flag the flag here is 4 which indicates un-mapped reads samtools fastq =output fasta and gzip to zip the file

-b: bam output, -u: uncompressed bam output (saves time when passing data to a downstream app), -S: sam input, -h: include the header in output (which might not be necessary for samtools fastq downstream, but better to be on the safe side)

Edit: added missing colon

Log in to answer this question.