.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_data_transform.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_data_transform.py: ================================================ Apply data transformation to the original signal ================================================ .. GENERATED FROM PYTHON SOURCE LINES 8-43 .. image-sg:: /auto_examples/images/sphx_glr_plot_data_transform_001.png :alt: chr1 :srcset: /auto_examples/images/sphx_glr_plot_data_transform_001.png, /auto_examples/images/sphx_glr_plot_data_transform_001_2_00x.png 2.00x :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/pygv/checkouts/latest/pygv/tracks/track.py:840: RuntimeWarning: invalid value encountered in multiply x = (x >= 0) * x + (x < 0) * x * a | .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from pygv.viewer import GenomeViewer from pygv.tracks.bigwig_track import PairedStrandSpecificTracks gv = GenomeViewer() # For this track, we don't apply any transformation notrans_track = PairedStrandSpecificTracks( "../examples/data/K562_GROcap_hg38_pl.chr1.bw", "../examples/data/K562_GROcap_hg38_mn.chr1.bw", draw_y_independently=True, name="Original", y_label_rotation="vertical", y_label_ha="center") gv.add_track(notrans_track) # For this track, we apply inverse hyperbolic sine transformation # this transformation is similar to log, but it allows for negative values asinh_track = PairedStrandSpecificTracks( "../examples/data/K562_GROcap_hg38_pl.chr1.bw", "../examples/data/K562_GROcap_hg38_mn.chr1.bw", draw_y_independently=True, name="Asinh", y_label_rotation="vertical", y_label_ha="center") asinh_track.data_transform = "asinh" gv.add_track(asinh_track) # Finally, we apply a customized function (sliding sum) sliding_sum_track = PairedStrandSpecificTracks( "../examples/data/K562_GROcap_hg38_pl.chr1.bw", "../examples/data/K562_GROcap_hg38_mn.chr1.bw", draw_y_independently=True, name="Customized\nfunc", y_label_rotation="vertical", y_label_ha="center") # Define a function to calculate the sliding sum (window size: 49) # the following function requires numpy version >= 1.20.0 sliding_sum_track.data_transform = lambda x: np.pad( np.lib.stride_tricks.sliding_window_view(x, 49).sum(axis=-1), (24, 24)) gv.add_track(sliding_sum_track) gv.plot("chr1", 201954851, 201955948) plt.tight_layout() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.247 seconds) .. _sphx_glr_download_auto_examples_plot_data_transform.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_data_transform.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_data_transform.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_data_transform.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_