betteridiot/seqlogo

Bug fix in _update_pm

Closed this issue · 1 comments

I'm trying to call seqlogo on a pfm with a custom alphabet (which happens to be AA, but in my case I cannot guarantee the order of the alphabets), so I'm using:

df = <a_pandas_dataframe> 
...
pfm = seqlogo.Pfm(df, alphabet_type='custom', alphabet=df.index.values, background=utils._AA_background)
seqlogo.seqlogo(pfm, ic_scale=False, size='xlarge', format='png', filename='logo.png', stacks_per_line=pfm.length, color_scheme='hydrophobicity')

I get the exception:

Traceback (most recent call last):
  File "00_seq.py", line 16, in <module>
    pfm = seqlogo.Pfm(df, alphabet_type='custom', alphabet=df.index.values, background=utils._AA_background)
  File "C:\ProgramData\Anaconda3\envs\chimera\lib\site-packages\seqlogo\core.py", line 454, in __init__
    super().__init__(*args, pm_type='pfm', **kwargs)
  File "C:\ProgramData\Anaconda3\envs\chimera\lib\site-packages\seqlogo\core.py", line 173, in __init__
    self._update_pm(pm_filename_or_array, pm_type, alphabet_type, alphabet, self.background, self.pseudocount)
  File "C:\ProgramData\Anaconda3\envs\chimera\lib\site-packages\seqlogo\core.py", line 196, in _update_pm
    self.background = _check_background(self, alphabet_type = alphabet_type, alphabet= alphabet)
  File "C:\ProgramData\Anaconda3\envs\chimera\lib\site-packages\seqlogo\core.py", line 564, in _check_background
    raise ValueError('alphabet type ({}) not supported by default backgrounds. Please provide your own'.format(pm.alphabet_type))
ValueError: alphabet type (custom) not supported by default backgrounds. Please provide your own

Note that I have explicitly specified the background while creating the pfm object.

This seems to be because the code at:

self.background = _check_background(self, alphabet_type = alphabet_type, alphabet= alphabet)

fails to pass in the background argument that it receives. Changing this to:

self.background = _check_background(self, background = background, alphabet_type = alphabet_type, alphabet= alphabet)

fixes the issue as expected.

Sorry, was in the hospital for a bit and wasn't able to get around to this. It is fixed now