Code Monkey home page Code Monkey logo

pyseqlogo's Introduction

pyseqlogo

Python package to plot sequence logos

from pyseqlogo.pyseqlogo import draw_logo, setup_axis
ALL_SCORES1 = [[('C', 0.02247014831444764),
              ('T', 0.057903843733384308),
              ('A', 0.10370837683591219),
              ('G', 0.24803586793255664)],
             [('T', 0.046608227674354567),
              ('G', 0.048827667087419063),
              ('A', 0.084338697696451109),
              ('C', 0.92994511407402669)],
             [('G', 0.0),
              ('T', 0.011098351287382456),
              ('A', 0.022196702574764911),
              ('C', 1.8164301607015951)],
             [('C', 0.020803153636453006),
              ('T', 0.078011826136698756),
              ('G', 0.11268374886412044),
              ('A', 0.65529933954826969)],
             [('T', 0.017393530660176126),
              ('A', 0.030438678655308221),
              ('G', 0.22611589858228964),
              ('C', 0.45078233627623127)],
             [('G', 0.022364103549245576),
              ('A', 0.043412671595594352),
              ('T', 0.097349627214363091),
              ('C', 0.1657574733649966)],
             [('C', 0.03264675899941203),
              ('T', 0.045203204768416654),
              ('G', 0.082872542075430544),
              ('A', 1.0949220710572034)],
             [('C', 0.0),
              ('T', 0.0076232429756614498),
              ('A', 0.011434864463492175),
              ('G', 1.8867526364762088)],
             [('C', 0.0018955903000026028),
              ('T', 0.0094779515000130137),
              ('A', 0.35637097640048931),
              ('G', 0.58005063180079641)],
             [('A', 0.01594690817903021),
              ('C', 0.017541598996933229),
              ('T', 0.2774762023151256),
              ('G', 0.48638069946042134)],
             [('A', 0.003770051401807444),
              ('C', 0.0075401028036148881),
              ('T', 0.011310154205422331),
              ('G', 1.8624053924928772)],
             [('C', 0.036479877757360731),
              ('A', 0.041691288865555121),
              ('T', 0.072959755514721461),
              ('G', 1.1517218549109602)],
             [('G', 0.011831087684038642),
              ('T', 0.068620308567424126),
              ('A', 0.10174735408273231),
              ('C', 1.0009100180696691)],
             [('C', 0.015871770937774379),
              ('T', 0.018757547471915176),
              ('A', 0.32176408355669878),
              ('G', 0.36505073156881074)],
             [('A', 0.022798100897300954),
              ('T', 0.024064662058262118),
              ('G', 0.24571286522646588),
              ('C', 0.34070495229855319)]]

Default mode is bits

plt.rcParams['figure.dpi'] = 300
fig, axarr = draw_logo(ALL_SCORES1)
fig.tight_layout()
examples/output_3_0.png

Colorscheme

plt.rcParams['figure.dpi'] = 300
fig, axarr = draw_logo(ALL_SCORES1, data_type='bits', colorscheme='meme')
fig.tight_layout()
docs/images/output_5_0.png

Counts as input

counts = {'A' : [3,4,5,6], 'C': [2,3,1,1], 'T': [2,1,3,1], 'G': [3,2,1,2]}
fig, axarr = draw_logo(counts, data_type='counts', yaxis='probability')
fig.tight_layout()
docs/images/output_7_0.png

Different font!

fig, axarr = draw_logo(counts, data_type='counts', yaxis='probability', fontfamily='Comic Sans MS')
fig.tight_layout()
docs/images/output_9_0.png

Plot conservation scores

ALL_SCORES = [[('G', 0.1),
              ('A', 0.1),
              ('C', 0.31312908494534769),
              ('T', 0.84220926295645249)]] * 4
stem_scores = np.random.rand(4)
fig, axarr = draw_logo(ALL_SCORES, data_type='bits', nrow= 2,ncol=1)
axarr[1,0].stem(range(1, len(ALL_SCORES)+1), stem_scores)
setup_axis(axarr[1,0], axis='y', majorticks=1, minorticks=0.1)
fig.tight_layout()
docs/images/output_11_0.png

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

pyseqlogo's People

Contributors

biogeek avatar dependabot[bot] avatar saketkc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pyseqlogo's Issues

Hello, can't the position weight matrix be 0?

counts = {'A' : [0,4,5,0], 'C': [2,3,5,0], 'T': [2,1,0,1], 'G': [0,2,1,2]}
fig, axarr = draw_logo(counts, data_type='counts', yaxis='probability')
fig.tight_layout()
plt.show()

Hello, can't the position weight matrix be 0? When I run a file containing 0 matrix, I get the following warning. What should I do ? ? ?

warning is this

RuntimeWarning: divide by zero encountered in log2
-pfm[b][l] * np.nan_to_num(np.log2(pfm[b][l])) for b in bases

Failure to plot logos when using pdf renderer

  • pyseqlogo version: commit bda975f
  • Python version: Python 3.7.9
  • Operating System: MX Linux 17 (Debian-based distribution)

Description

I wanted to try draw_logo from within an automated pipeline, where, for some reason, I had to set a pdf renderer for matplotlib, and draw_logo crashed on line 127 of pyseqlogo.py:

    126             window_ext = txt.get_window_extent(
--> 127                 txt._renderer)  #(fig.canvas.renderer) #txt._renderer)

What I Did

Here is a minimum example to reproduce the crash:

>>> import matplotlib as mpl
>>> mpl.use("PDF")
>>> from pyseqlogo.pyseqlogo import draw_logo
>>> data = {"A": [5, 5, 5, 5], "C": [5, 5, 5, 5], "G": [5, 5, 5, 5], "T": [5, 5, 5, 5]}
>>> fig, axes = draw_logo(data, data_type="counts")
RuntimeError                              Traceback (most recent call last)
<ipython-input-5-5a59f0cf5a0b> in <module>
----> 1 fig, axes = draw_logo(data, data_type="counts")

/usr/local/lib/python3.7/site-packages/pyseqlogo/pyseqlogo.py in draw_logo(data, data_type, seq_type, yaxis, colorscheme, nrow, ncol, padding, draw_range, coordinate_type, draw_axis, fontfamily, debug, ax)
    364         else:
    365             xshifts_list = _draw_text_data_coord(
--> 366                 ic, ax, fontfamily, colorscheme, draw_axis=draw_axis)
    367     else:
    368         if yaxis == 'probability':

/usr/local/lib/python3.7/site-packages/pyseqlogo/pyseqlogo.py in _draw_text_data_coord(height_matrix, ax, fontfamily, colorscheme, scalex, draw_axis, debug)
    125             fig.canvas.draw()
    126             window_ext = txt.get_window_extent(
--> 127                 txt._renderer)  #(fig.canvas.renderer) #txt._renderer)
    128             if basescore > 0.3:
    129                 yshift = window_ext.height * basescore  #- fontsize/10# fontsize/4#/1.20 #*.85 #* fig.dpi/72.0

/usr/local/lib/python3.7/site-packages/matplotlib/text.py in get_window_extent(self, renderer, dpi)
    895             self._renderer = self.figure._cachedRenderer
    896         if self._renderer is None:
--> 897             raise RuntimeError('Cannot get window extent w/o renderer')
    898 
    899         with cbook._setattr_cm(self.figure, dpi=dpi):

RuntimeError: Cannot get window extent w/o renderer

Unable to draw all seqlogo

When I draw the diagram, I can’t draw all of the sequence, only the first four letters can be displayed

counts = {'A': [1, 10, 17, 13, 3, 7, 0, 27, 27, 27, 0, 27, 16, 7], 'G': [10, 7, 4, 5, 11, 0, 0, 0, 0, 0, 25, 0, 4, 4], 'C': [7, 5, 2, 5, 8, 20, 0, 0, 0, 0, 0, 0, 2, 6], 'T': [9, 5, 4, 5, 0, 0, 27, 0, 0, 0, 2, 0, 5, 10]}
fig, axarr = draw_logo(counts, data_type='counts', yaxis='probability')
fig.tight_layout()

##warning
UserWarning: Tight layout not applied. The left and right margins cannot be made large enough to accommodate all axes decorations.
fig.tight_layout()

set up a dynamic y-axis for applicable data

Hello, pyselogo is very suitable for my drawing needs. I am very happy to be able to quote pygenome. What is the function to change the y-axis scale range? I want to set up a dynamic y-axis for applicable data. I hope to get your help. Thank you very much!

#########
plt.rcParams['figure.dpi'] = 300
fig, axarr = draw_logo(ALL_SCORES1, coordinate_type='data')
fig.tight_layout()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.