# feature-classifier fit-classifier-naive-bayes optimisation

**URL:** https://forum.qiime2.org/t/feature-classifier-fit-classifier-naive-bayes-optimisation/10680
**Category:** Technical Support
**Created:** [July 15, 2019, 8:48am UTC](https://forum.qiime2.org/t/feature-classifier-fit-classifier-naive-bayes-optimisation/10680 "2019-07-15T08:48:39Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![David\_Pearton](https://forum.qiime2.org/user_avatar/forum.qiime2.org/david_pearton/32/5237_2.png) [@David\_Pearton](https://forum.qiime2.org/u/David_Pearton)
#### Post date: [July 15, 2019, 8:48am UTC](https://forum.qiime2.org/t/feature-classifier-fit-classifier-naive-bayes-optimisation/10680/1 "2019-07-15T08:48:39Z")

</div>

Hello,

I am running into an issue with training my classifiers. I am using qiime2 2019.4 and running it on a node in a cluster (CentOS Linux release 7.3.1611). Each node has 24 cores and 128 GB (and I've requested all of these).

I'm using the MIDORI COI unique reference set ([Home](http://www.reference-midori.info/index.html)) which is very large. The issue is that this takes over 12 hours to run and I keep on running out of wall time (for some reason I can't get it to run as a batch process, so I've been running it in an interactive shell with a max walltime of 12 hours).

qiime feature-classifier fit-classifier-naive-bayes   
--i-reference-reads MIDORI\_UNIQUE\_20180221\_COI.qza   
--i-reference-taxonomy MIDORI\_UNIQUE\_20180221\_COI-ref-taxonomy.qza   
--o-classifier MIDORI\_UNIQUE\_20180221\_COI-classifier.qza   
--verbose

I'm assuming that the process looks at the number of cores available and scales the jobs accordingly. I looked at the forum and previous posters suggested using the --p-n-jobs parameter, but this does not appear to be an option in my version of qiime2... I know I'm not running out of memory and it did work with a smaller database (MIDORI UNIQUE).

Is there any way to optimise threading or chunk size so it is able to run in a shorter time?

Thanks in advance for any suggestions.  
Dave

---

<div class="post-metadata">

### Author: ![Nicholas\_Bokulich](https://forum.qiime2.org/user_avatar/forum.qiime2.org/nicholas_bokulich/32/19937_2.png) [@Nicholas\_Bokulich](https://forum.qiime2.org/u/Nicholas_Bokulich)
#### Post date: [July 15, 2019, 11:33am UTC](https://forum.qiime2.org/t/feature-classifier-fit-classifier-naive-bayes-optimisation/10680/2 "2019-07-15T11:33:23Z")

</div>

> [@David\_Pearton](#):
>
> The issue is that this takes over 12 hours to run and I keep on running out of wall time

Request more time. This command usually takes less time (e.g., ~1hr on 16S and ITS databases that I've worked with) but will take more with a very large database.

> [@David\_Pearton](#):
>
> I’m assuming that the process looks at the number of cores available and scales the jobs accordingly.

No, this step is unfortunately not parallelizable

> [@David\_Pearton](#):
>
> I looked at the forum and previous posters suggested using the --p-n-jobs parameter, but this does not appear to be an option in my version of qiime2

That is a parameter for the `classify-sklearn` method, not for fitting the classifier.

> [@David\_Pearton](#):
>
> Is there any way to optimise threading or chunk size so it is able to run in a shorter time?

Unfortunately not in the current version of QIIME 2 — you will just need to give it more time. The good news is that once the classifier is trained you can keep re-using it, and the classification step can be parallelized/optimized.

---

<div class="post-metadata">

### Author: ![David\_Pearton](https://forum.qiime2.org/user_avatar/forum.qiime2.org/david_pearton/32/5237_2.png) [@David\_Pearton](https://forum.qiime2.org/u/David_Pearton)
#### Post date: [July 15, 2019, 11:55am UTC](https://forum.qiime2.org/t/feature-classifier-fit-classifier-naive-bayes-optimisation/10680/3 "2019-07-15T11:55:16Z")

</div>

Hi,

Thanks for the reply. I managed to wrangle more time and try rerun the job. Unfortunately it does appear as if the issue is memory. I get a memory err after a short running time. The node I'm using has 128 GB of RAM and that doesn't appear to be enough.

I will try with a fat node with 1TB RAM and see how that works...

Cheers,  
Dave

---

<div class="post-metadata">

### Author: ![Nicholas\_Bokulich](https://forum.qiime2.org/user_avatar/forum.qiime2.org/nicholas_bokulich/32/19937_2.png) [@Nicholas\_Bokulich](https://forum.qiime2.org/u/Nicholas_Bokulich)
#### Post date: [July 15, 2019, 12:08pm UTC](https://forum.qiime2.org/t/feature-classifier-fit-classifier-naive-bayes-optimisation/10680/4 "2019-07-15T12:08:12Z")

</div>

> [@David\_Pearton](#):
>
> The node I’m using has 128 GB of RAM and that doesn’t appear to be enough.

Yikes! Midori must be a massive database. You may want to consider dereplicating or clustering this database somehow to remove redundant records. There is not really a way to do this in QIIME 2 yet (well, you can cluster the sequences but not the taxonomies), but you can see some of the discussion in this post for some ideas:

> [@How to create a dereplicated sequence reference database for taxonomy classification: case of COI](https://forum.qiime2.org/t/how-to-create-a-dereplicated-sequence-reference-database-for-taxonomy-classification-case-of-coi/6740):
>
> Sorry for the delayed response @Nicholas_Bokulich - was traveling to and from a conference. It was a great opportunity to talk a bit about the new tools in QIIME2 with other users, and now I'm back to thinking about my reference database construction. I really appreciate your comments above and have already employed the exclude-seqs argument with a bat-reference database (to filter out bat sequences). However, I'm now thinking about the arthropod-only database. This comes from BOLD, but I've bee…

If you are interested in doing that, I actually just thought of a way to do this with QIIME 2:

1. Use q2-vsearch to cluster the reference sequences (or dereplicate)
2. Use q2-feature-classifier's `classify-consensus-vsearch` to assign taxonomy to those sequences based on consensus taxonomy classification. If you use the same percent identity for clustering and taxonomy, then the consensus taxonomy will be assigned using more or less the same sequences that were clustered.
3. You have your new reference sequences and taxonomy to use for classification!

It will take time, but this process can be parallelized.

---

<div class="post-metadata">

### Author: ![devonorourke](https://forum.qiime2.org/user_avatar/forum.qiime2.org/devonorourke/32/3110_2.png) [@devonorourke](https://forum.qiime2.org/u/devonorourke)
#### Post date: [July 15, 2019, 12:18pm UTC](https://forum.qiime2.org/t/feature-classifier-fit-classifier-naive-bayes-optimisation/10680/5 "2019-07-15T12:18:39Z")

</div>

I'm not here to say that your issue is or is not RAM related @David_Pearton, but I can tell you that I was able to generate my own custom COI databases `qiime feature-classifier fit-classivier-naive-bayes` with a single 128 Gb node on our cluster. One reference set had about 1.6 million, the other about 2.1 million. Both took around 16-24 hours.

How many sequences are in `MIDORI_UNIQUE_20180221_COI`?

You might also try using Terry Porter's database (paper [here](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6128447/), database [here](https://github.com/terrimporter/COI_NCBI_2018)), also derived from NCBI, but slightly more curated. It's not dereplicated though.

---

<div class="post-metadata">

### Author: ![David\_Pearton](https://forum.qiime2.org/user_avatar/forum.qiime2.org/david_pearton/32/5237_2.png) [@David\_Pearton](https://forum.qiime2.org/u/David_Pearton)
#### Post date: [July 19, 2019, 7:12am UTC](https://forum.qiime2.org/t/feature-classifier-fit-classifier-naive-bayes-optimisation/10680/6 "2019-07-19T07:12:57Z")

</div>

Hi Devon,

Thank you for the feedback.

I am also unsure why I had a memory error. It doesn't make sense to me. I eventually got it to run on the fat node (1TB RAM) - it took 31 hours but only used 75GB of memory according to the job report...

There are only 927386 sequences in the dataset, but they are a mix of sizes. I have (eventually) managed to do an "extract reads" to cut it down to the region targeted by the primers I used and will see if (a) this helps with accuracy and (b) will speed up the training.

I will have a look at the links you provided - thank you.

I am also trying to build a more targeted training database from BOLD - we are working on marine benthos so are not interested in terrestrial vertebrates or invertebrates so that might help improve things.

It there any way of conveniently making a quiime2 taxon file from sequences derived from BOLD? I'm sure there must be a way to do this, but I'm not a programmer. Does anyone know of a script to do this?

Thanks,  
Dave

---

<div class="post-metadata">

### Author: ![Nicholas\_Bokulich](https://forum.qiime2.org/user_avatar/forum.qiime2.org/nicholas_bokulich/32/19937_2.png) [@Nicholas\_Bokulich](https://forum.qiime2.org/u/Nicholas_Bokulich)
#### Post date: [July 24, 2019, 8:26pm UTC](https://forum.qiime2.org/t/feature-classifier-fit-classifier-naive-bayes-optimisation/10680/7 "2019-07-24T20:26:20Z")

</div>

> [@David\_Pearton](#):
>
> It there any way of conveniently making a quiime2 taxon file from sequences derived from BOLD? I’m sure there must be a way to do this, but I’m not a programmer. Does anyone know of a script to do this?

what format are the BOLD taxonomies in? Is there a separate taxonomy file or do these appear in the header line of the FASTA?

---

<div class="post-metadata">

### Author: ![jasongallant](https://forum.qiime2.org/user_avatar/forum.qiime2.org/jasongallant/32/20182_2.png) [@jasongallant](https://forum.qiime2.org/u/jasongallant)
#### Post date: [August 3, 2020, 2:34pm UTC](https://forum.qiime2.org/t/feature-classifier-fit-classifier-naive-bayes-optimisation/10680/8 "2020-08-03T14:34:11Z")

</div>

Hi @David_Pearton, we are now trying to do the same in my lab.  
With the latest MIDORI reference, it's been running for about 24h on a 256GB RAM machine, using about 75GB of RAM steadily, no sign of completion yet.

-Did you have any hints or scripts to facilitate this?

- qiime feature-classifier fit-classifier-naive-bayes is essentially silent about progress when working on the MIDORI reference, so its hard to say its "progressing". Did you observe this?  
-Did you ever succeed with BOLD? Any hints or scripts to help with loading this into qiime2?

Thanks!

---

<div class="post-metadata">

### Author: ![Nicholas\_Bokulich](https://forum.qiime2.org/user_avatar/forum.qiime2.org/nicholas_bokulich/32/19937_2.png) [@Nicholas\_Bokulich](https://forum.qiime2.org/u/Nicholas_Bokulich)
#### Post date: [August 3, 2020, 3:19pm UTC](https://forum.qiime2.org/t/feature-classifier-fit-classifier-naive-bayes-optimisation/10680/9 "2020-08-03T15:19:27Z")

</div>

Welcome to the forum, @jasongallant,  
Thanks for digging up this old topic... some of the info I wrote in there a year ago is impacted by recent updates.

> [@jasongallant](#):
>
> qiime feature-classifier fit-classifier-naive-bayes is essentially silent about progress when working on the MIDORI reference, so its hard to say its “progressing”. Did you observe this?

That is correct — fit-classifier-naive-bayes does not give any "progress update" unfortunately.

> [@jasongallant](#):
>
> -Did you have any hints or scripts to facilitate this?

I'd recommend reducing database size to reduce runtime, if possible:

1. use `extract-reads` to focus on the amplicon region you are using
2. remove any low-quality sequences
3. dereplicate the database (ideally after extracting amplicons) to reduce database size and redundancy. You can use [RESCRIPt](https://forum.qiime2.org/t/processing-filtering-and-evaluating-reference-sequence-data-with-rescript/15494) to dereplicate the sequences together with the taxonomy.

> [@jasongallant](#):
>
> - -Did you ever succeed with BOLD? Any hints or scripts to help with loading this into qiime2?

[RESCRIPt](https://forum.qiime2.org/t/processing-filtering-and-evaluating-reference-sequence-data-with-rescript/15494) also has a "get-ncbi-data" method that you can use to download data from genbank and automatically format it and import it as QIIME 2 artifacts. Since BOLD deposits their public data on genbank (all or most? not sure), it would be possible to use that to grab public BOLD data.

Good luck!
