<p>In general, this answer wouldn't be more correct than @Ram RS' answer but here is how I would approach:</p>
<ul>
<li><p>I would start everything from scratch, at the end of the day you will most probably need to document the exact genome version and its associated annotation file. It looks like you do not have this information at present.</p>
</li>
<li><p>I don't know the experimental set-up but if you are worried about &quot;contaminants&quot;, you can have an extra alignment step using <code>BBSplit</code> (<a href="https://www.seqanswers.com/forum/bioinformatics/bioinformatics-aa/35881-introducing-bbsplit-read-binning-tool-for-metagenomes-and-contaminated-libraries" rel="nofollow noreferrer">link</a>), it is capable of mapping to multiple genomes simultaneously.</p>
</li>
<li><p>I would give a try with <code>nfcore/rnaseq</code>, it abstracts away a lot of complex bioinformatics steps so that you can focus on understanding what these tools do instead of dealing with installing and running these tools. For example you can just use the <code>--bbsplit-fasta-list</code> argument to get rid of your contaminants.</p>
</li>
</ul>

CC BY-SA 4.0
2024-02-19T18:59:21.987Z
2024-02-19T20:17:37.720Z
2024-02-19T20:17:37.720Z
haci
<p>Your post has multiple questions but one of them is not really a question so I'll address everything here:</p>
<p>1. &quot;Some of them could be contaminants, so I'd like to filter them out and get only the ones that align to the reference genome&quot;</p>
<p>Just align the reads. Contaminants should not align well and should be discarded owing to poor mapping quality score.</p>
<p>2. How to figure out if the FASTA file was used for the alignment</p>
<p>This is not really a 100% perfect solution but the BAM header should contain the exact command used for the alignment, which should contain the ref FASTA with path. You can also compare contig names and lengths between the FASTA and the BAM <code>@SQ</code> lines.</p>

CC BY-SA 4.0
2024-02-19T18:47:42.350Z
"Contaminants should not align well" assumption would not quite hold all the time, for example if the data is from a PDX model involving mouse as well as human reads!
haci
CC BY-SA 4.0
2024-02-19T20:16:43.097Z
That's true. I was about to suggest something like Xenome or BBSplit but thought these might be simple bacterial contaminants that may not require preprocessing.
Ram RS
CC BY-SA 4.0
2024-02-19T17:49:19.640Z
2024-02-19T17:49:19.640Z
Ram RS
<p>I'm new to bioinformatics. I have a problem in which I have a FASTA reference genome and lots of reads in FASTQ files. Some of them could be contaminants, so I'd like to filter them out and get only the ones that align to the reference genome. I also have access to the BAM/BAM.BAI files associated with each FASTQ, although I can't know how they were aligned.</p>
<p>Thanks</p>

<phylogenetics><fasta><fastq><read-mapping>
How to know if FASTQ/BAM is from reference genome (FASTA)?
# How to know if FASTQ/BAM is from reference genome (FASTA)?

(Asked by: username_0 on 2024-02-19)

I'm new to bioinformatics. I have a problem in which I have a FASTA reference genome and lots of reads in FASTQ files. Some of them could be contaminants, so I'd like to filter them out and get only the ones that align to the reference genome. I also have access to the BAM/BAM.BAI files associated with each FASTQ, although I can't know how they were aligned.

Thanks

**Tags:** phylogenetics, fasta, fastq, read-mapping

---

## 2 answers

### Answer by username_2 on 2024-02-19. Score: 4 | Accepted answer

Your post has multiple questions but one of them is not really a question so I'll address everything here:

1. "Some of them could be contaminants, so I'd like to filter them out and get only the ones that align to the reference genome"

Just align the reads. Contaminants should not align well and should be discarded owing to poor mapping quality score.

2. How to figure out if the FASTA file was used for the alignment

This is not really a 100% perfect solution but the BAM header should contain the exact command used for the alignment, which should contain the ref FASTA with path. You can also compare contig names and lengths between the FASTA and the BAM `@SQ` lines.

> **Comments:**
> **username_1**: "Contaminants should not align well" assumption would not quite hold all the time, for example if the data is from a PDX model involving mouse as well as human reads!  
> **username_2**: That's true. I was about to suggest something like Xenome or BBSplit but thought these might be simple bacterial contaminants that may not require preprocessing.  

---

### Answer by username_1 on 2024-02-19. Score: 2

In general, this answer wouldn't be more correct than @Ram RS' answer but here is how I would approach:

* I would start everything from scratch, at the end of the day you will most probably need to document the exact genome version and its associated annotation file. It looks like you do not have this information at present.
* I don't know the experimental set-up but if you are worried about "contaminants", you can have an extra alignment step using `BBSplit` ([link](https://www.seqanswers.com/forum/bioinformatics/bioinformatics-aa/35881-introducing-bbsplit-read-binning-tool-for-metagenomes-and-contaminated-libraries)), it is capable of mapping to multiple genomes simultaneously.
* I would give a try with `nfcore/rnaseq`, it abstracts away a lot of complex bioinformatics steps so that you can focus on understanding what these tools do instead of dealing with installing and running these tools. For example you can just use the `--bbsplit-fasta-list` argument to get rid of your contaminants.


---

