widdowquinn / pyani

Application and Python module for average nucleotide identity analyses of microbes.
http://widdowquinn.github.io/pyani/
MIT License
196 stars 55 forks source link

ValueError: math domain error #7

Closed MathGon closed 7 years ago

MathGon commented 9 years ago

Finally I'm back with my issue which wasn't really solved. It appears that it depends of my input dataset. Have you an idea of the cause of the error?

average_nucleotide_identity.py -i /home/mgonnet/Data_GB_try/ -o /home/mgonnet/Data_GB_try/ANI/ -m ANIm -g --gformat png
/usr/lib/python2.7/dist-packages/matplotlib/axes/_base.py:2791: UserWarning: Attempting to set identical bottom==top results
in singular transformations; automatically expanding.
bottom=0, top=0.0
  'bottom=%s, top=%s') % (bottom, top))
/usr/lib/python2.7/dist-packages/matplotlib/axes/_base.py:2544: UserWarning: Attempting to set identical left==right results
in singular transformations; automatically expanding.
left=0.0, right=0
  'left=%s, right=%s') % (left, right))
Traceback (most recent call last):
  File "/usr/local/bin/average_nucleotide_identity.py", line 4, in <module>
    __import__('pkg_resources').run_script('pyani==0.1.2-', 'average_nucleotide_identity.py')
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 534, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1445, in run_script
    exec(script_code, namespace, namespace)
  File "/usr/local/lib/python2.7/dist-packages/pyani-0.1.2_-py2.7.egg/EGG-INFO/scripts/average_nucleotide_identity.py", line 666, in <module>

  File "/usr/local/lib/python2.7/dist-packages/pyani-0.1.2_-py2.7.egg/EGG-INFO/scripts/average_nucleotide_identity.py", line 561, in draw

  File "build/bdist.linux-x86_64/egg/pyani/pyani_graphics.py", line 209, in heatmap_mpl
  File "/usr/lib/python2.7/dist-packages/matplotlib/figure.py", line 1500, in colorbar
    cb = cbar.colorbar_factory(cax, mappable, **kw)
  File "/usr/lib/python2.7/dist-packages/matplotlib/colorbar.py", line 1316, in colorbar_factory
    cb = Colorbar(cax, mappable, **kwargs)
  File "/usr/lib/python2.7/dist-packages/matplotlib/colorbar.py", line 892, in __init__
    ColorbarBase.__init__(self, ax, **kw)
  File "/usr/lib/python2.7/dist-packages/matplotlib/colorbar.py", line 321, in __init__
    self.draw_all()
  File "/usr/lib/python2.7/dist-packages/matplotlib/colorbar.py", line 346, in draw_all
    self._config_axes(X, Y)
  File "/usr/lib/python2.7/dist-packages/matplotlib/colorbar.py", line 440, in _config_axes
    self.update_ticks()
  File "/usr/lib/python2.7/dist-packages/matplotlib/colorbar.py", line 371, in update_ticks
    ticks, ticklabels, offset_string = self._ticker()
  File "/usr/lib/python2.7/dist-packages/matplotlib/colorbar.py", line 591, in _ticker
    formatter.set_locs(b)
  File "/usr/lib/python2.7/dist-packages/matplotlib/ticker.py", line 523, in set_locs
    self._set_format(vmin, vmax)
  File "/usr/lib/python2.7/dist-packages/matplotlib/ticker.py", line 584, in _set_format
    loc_range_oom = int(math.floor(math.log10(loc_range)))
ValueError: math domain error
widdowquinn commented 9 years ago

Hi,

I'm not sure what's going wrong, there - the error is initially thrown by matplotlib in colorbar.py, and is (I think) probably due to trying to take a log of 0 or some negative value.

Do you have a minimal example input dataset which throws this error that I could use for debugging?

Cheers,

L.

widdowquinn commented 9 years ago

Some Googling suggests that the problem could come from trying to set upper and lower limits on a bounding box, where those values are the same. I've been able to replicate part of your error by only running the analysis on two input sequences. I'll try to fix on this dataset, but if you've got an example set, that would be extremely helpful.

L.

widdowquinn commented 9 years ago

Hmm... my test actually just gives a warning, and doesn't fail in the same way as yours - would you be able to indicate your installed version of matplotlib?

MathGon commented 9 years ago

Hi Leighton,

I use matplotlib 1.4.2 You can find a minimal example input here

widdowquinn commented 9 years ago

Thanks - with matplotlib 1.3.1 I don't reproduce your error. I'll upgrade to 1.4.2 and see what happens.

widdowquinn commented 9 years ago

I can reproduce on matplotlib 1.4.3,

widdowquinn commented 9 years ago

Hi MathGon,

The problem seems to be fixed for me now, using your data, on matplotlib 1.4.3. If you could please grab the latest HEAD and test it, then confirm that it's working for you again, I'll close this bug.

The problem seemed to arise from matplotlib code being stricter about the heatmap colorbar range. That was being set automatically from the input data, so if there was only a single value in the heatmap, the range (max - min value) was zero. matplotlib 1.4.2 and 1.4.3 at least didn't like that, so threw an error.

Thanks for the bug report - if you find any other problems, please do report them - I'll try to be a bit quicker with a fix, next time ;)

Cheers,

L.

MathGon commented 9 years ago

I am in the weekend and can not connect to my computer via ssh, I turned it off before you go! I go back Tuesday and I test as soon as I arrive.

Do not worry of the time I think you've been very quick and attentive. Thank you

MathGon commented 9 years ago

After test, the problem persists :(

widdowquinn commented 9 years ago

That's frustrating! I'm sorry about that. I've just tested your data on my work machine, where it failed until I took the whitespace out of the input filenames. Once I did that, the analysis goes to completion:

$ ./average_nucleotide_identity.py -i /Users/lpritc/Development/GitHub/pyani/tests/mgonnet_failing_data -o /Users/lpritc/Development/GitHub/pyani/tests/mgonnet_failing_out -m ANIm -g --gformat png -v
INFO: Namespace(blastall_exe='blastall', blastn_exe='blastn', classes=None, force=False, formatdb_exe='formatdb', fragsize=1020, gformat='png', gmethod='mpl', graphics=True, indirname='/Users/lpritc/Development/GitHub/pyani/tests/mgonnet_failing_data', labels=None, logfile=None, makeblastdb_exe='makeblastdb', maxmatch=False, method='ANIm', noclobber=False, nucmer_exe='nucmer', outdirname='/Users/lpritc/Development/GitHub/pyani/tests/mgonnet_failing_out', scheduler='multiprocessing', skip_blastn=False, skip_nucmer=False, verbose=True, write_excel=False)
INFO: Input directory: /Users/lpritc/Development/GitHub/pyani/tests/mgonnet_failing_data
INFO: Creating directory /Users/lpritc/Development/GitHub/pyani/tests/mgonnet_failing_out
INFO: Output directory: /Users/lpritc/Development/GitHub/pyani/tests/mgonnet_failing_out
INFO: Using ANI method: ANIm
INFO: Using scheduler method: multiprocessing
INFO: Identifying FASTA files in /Users/lpritc/Development/GitHub/pyani/tests/mgonnet_failing_data
INFO: Input files:
    /Users/lpritc/Development/GitHub/pyani/tests/mgonnet_failing_data/B._abortus_90-12178.fas
    /Users/lpritc/Development/GitHub/pyani/tests/mgonnet_failing_data/B._sp._NF2653.fas
INFO: Processing input sequence lengths
INFO: Sequence lengths:
    B._abortus_90-12178: 3528544
    B._sp._NF2653: 3110281
INFO: Carrying out ANIm analysis
INFO: Running ANIm
INFO: Generating NUCmer command-lines
INFO: Running jobs with multiprocessing
INFO: Command pool now running:
INFO: nucmer -mum -p /Users/lpritc/Development/GitHub/pyani/tests/mgonnet_failing_out/B._abortus_90-12178_vs_B._sp._NF2653 /Users/lpritc/Development/GitHub/pyani/tests/mgonnet_failing_data/B._abortus_90-12178.fas /Users/lpritc/Development/GitHub/pyani/tests/mgonnet_failing_data/B._sp._NF2653.fas
INFO: Command pool done.
INFO: Cumulative return value: 0
INFO: All multiprocessing jobs complete.
INFO: Processing NUCmer .delta files.
INFO: Writing ANIm results to /Users/lpritc/Development/GitHub/pyani/tests/mgonnet_failing_out
INFO:   ANIm_alignment_lengths
INFO:   ANIm_percentage_identity
INFO:   ANIm_alignment_coverage
INFO:   ANIm_similarity_errors
INFO: Rendering output graphics
INFO: Graphics format: png
INFO: Graphics method: mpl
INFO: Writing heatmap to /Users/lpritc/Development/GitHub/pyani/tests/mgonnet_failing_out/ANIm_alignment_lengths.png
/Users/lpritc/Virtualenvs/pyani/lib/python2.7/site-packages/matplotlib/collections.py:590: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  if self._edgecolors == str('face'):
INFO: Writing heatmap to /Users/lpritc/Development/GitHub/pyani/tests/mgonnet_failing_out/ANIm_percentage_identity.png
INFO: Writing heatmap to /Users/lpritc/Development/GitHub/pyani/tests/mgonnet_failing_out/ANIm_alignment_coverage.png
INFO: Writing heatmap to /Users/lpritc/Development/GitHub/pyani/tests/mgonnet_failing_out/ANIm_similarity_errors.png
INFO: Done.

anim_alignment_coverage anim_alignment_lengths anim_percentage_identity anim_similarity_errors

I have added a requirements.txt file so, if you're using pip to manage your Python packages, you should be able to get your machine/virtualenv to the same state as mine by running pip install -r requirements.txt from in the top-level pyani directory.

Could you please see if either the file naming or the package installation changes anything for you?