# Bug with n\_metagenome\_reads

**URL:** <https://forum.biobakery.org/t/bug-with-n-metagenome-reads/914>\
**Category:** MetaPhlAn\
**Created:** [August 27, 2020, 12:03pm UTC](https://forum.biobakery.org/t/bug-with-n-metagenome-reads/914 "2020-08-27T12:03:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeanmng](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/jeanmng/32/362_2.png) [@jeanmng](https://forum.biobakery.org/u/jeanmng)\
**Post date:** [August 27, 2020, 12:03pm UTC](https://forum.biobakery.org/t/bug-with-n-metagenome-reads/914/1 "2020-08-27T12:03:02Z")

</div>

Hi,

I hope you are doing well, Thank you fro your work on metaphan3. I think I found a bug

I use metaphan3 with the `--nreads`, `--unknown_estimation` and `--input_type sam`, I have the following error message:

```auto
fraction_mapped_reads = min(tot_nreads/float(n_metagenome_reads), 1.0) if ESTIMATE_UNK else 1.0
  TypeError: float() argument must be a string or a number, not 'NoneType'

```

I did a bit of digging in the code and found that the

- `n_metagenome_reads` variable is instantiated by the `map2bbh` function
- this function instantiate an internal `n_metagenome_reads` variable with None ([https://github.com/biobakery/MetaPhlAn/blob/446ee61b05a5063365a315ddba8c54bf45fcae66/metaphlan/metaphlan.py#L796](https://github.com/biobakery/MetaPhlAn/blob/446ee61b05a5063365a315ddba8c54bf45fcae66/metaphlan/metaphlan.py#L796)) but doesn’t change the at any point when `input_type == 'sam'` [https://github.com/biobakery/MetaPhlAn/blob/446ee61b05a5063365a315ddba8c54bf45fcae66/metaphlan/metaphlan.py#L804-L813](https://github.com/biobakery/MetaPhlAn/blob/446ee61b05a5063365a315ddba8c54bf45fcae66/metaphlan/metaphlan.py#L804-L813). So the returned value is indeed `None`.
- later here [https://github.com/biobakery/MetaPhlAn/blob/446ee61b05a5063365a315ddba8c54bf45fcae66/metaphlan/metaphlan.py#L1003-L1009](https://github.com/biobakery/MetaPhlAn/blob/446ee61b05a5063365a315ddba8c54bf45fcae66/metaphlan/metaphlan.py#L1003-L1009) there is a check on `n_metagenome_reads` (None) and `pars['nreads']` (the value I gave via the command line) but it only exit with an error (which is doesn’t because ars[‘nreads’]` has a value
- Come [https://github.com/biobakery/MetaPhlAn/blob/446ee61b05a5063365a315ddba8c54bf45fcae66/metaphlan/metaphlan.py#L1059-L1060](https://github.com/biobakery/MetaPhlAn/blob/446ee61b05a5063365a315ddba8c54bf45fcae66/metaphlan/metaphlan.py#L1059-L1060), where the error happens, `n_metagenome_reads` is still None, then it fails

Maybe pars[‘nreads’] should be used instead. This issue doesn’t occur when I omit the `--unknown_estimation` tag

---

<div class="post-metadata">

**Author:** ![fbeghini](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/fbeghini/32/81_2.png) [@fbeghini](https://forum.biobakery.org/u/fbeghini)\
**Post date:** [August 27, 2020, 12:46pm UTC](https://forum.biobakery.org/t/bug-with-n-metagenome-reads/914/2 "2020-08-27T12:46:22Z")

</div>

Thank you for spotting this, I may have forgotten to specify to use the pars[‘nreads’] value when a SAM file is used as input. The latest commit fixes this.

---

<div class="post-metadata">

**Author:** ![jeanmng](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/jeanmng/32/362_2.png) [@jeanmng](https://forum.biobakery.org/u/jeanmng)\
**Post date:** [August 27, 2020, 12:52pm UTC](https://forum.biobakery.org/t/bug-with-n-metagenome-reads/914/3 "2020-08-27T12:52:46Z")

</div>

Thank you very much! That was quick.

Hopefully the conda/singularity/docker container will be updated soon.
