Plot function

Pyranges Plot main function.

pyranges_plot.plot(data, *, id_col=None, warnings=None, max_shown=25, packed=True, color_col=None, thickness_col=None, depth_col=None, shrink=False, limits=None, thick_cds=False, text=True, legend=False, title_chr='Chromosome {chrom}', y_labels=None, tooltip=None, to_file=None, theme=None, **kargs)

Create genes plot from 1/+ PyRanges objects.

Parameters:
  • data ({pyranges.PyRanges or list of pyranges.PyRanges}) – Pyranges, derived dataframe or list of them with annotation data.

  • id_col (str, default None) – Name of the column containing gene ID.

  • warnings (bool, default True) – Whether the warnings should be shown or not.

  • max_shown (int, default 20) – Maximum number of genes plotted in the dataframe order.

  • packed (bool, default True) – Disposition of the genes in the plot. Use True for a packed disposition (genes in the same line if they do not overlap) and False for unpacked (one row per gene).

  • color_col (str, default None) – Name of the column used to color the genes. If not specified, id_col will be used.

  • thickness_col (str, default None) – Name of the data column with max 2 different values to plot the intervals correspondig to one value to thicker than the others. The first value by alphabetical order will have the height specified as ‘exon_height’, and the second will be 0.3*’exon_height’. Note that this parameter will be overseen if the ‘thick_cds’ parameter is set to True.

  • depth_col (str, default None) – Name of the data column to be used for setting the order to plot the intervals. The intervals with the lowest value in this column will be plotted first and the ones with higher values will plotted on top of them.

  • shrink (bool, default False) – Whether to compress the intron ranges to facilitate visualization or not.

  • limits ({None, dict, tuple, pyranges.pyranges_main.PyRanges}, default None) –

    Customization of coordinates for the chromosome plots.

    • None: minimum and maximum exon coordinate plotted plus a 5% of the range on each side.

    • dict: {chr_name1: (min_coord, max coord), chr_name2: (min_coord, max_coord), …}. Not

    all the plotted chromosomes need to be specified in the dictionary and some coordinates can be indicated as None, both cases lead to the use of the default value.

    • tuple: the coordinate limits of all chromosomes will be defined as indicated.

    • pyranges.pyranges_main.PyRanges: for each matching chromosome between the plotted data

    and the limits data, the limits will be defined by the minimum and maximum coordinates in the pyranges object defined as limits. If some plotted chromosomes are not present they will be left as default.

  • thick_cds (bool, default False) – Display differentially transcript regions belonging and not belonging to CDS. The CDS/exon information must be stored in the ‘Feature’ column of the PyRanges object or the dataframe. Note that any other Feature value other than exon and CDS will be discarded for plotting.

  • text ({bool, '{string}'}, default True) – Whether an annotation should appear beside the gene in the plot. If True, the id/index will be used. To customize the annotation use the ‘{string}’ option to choose another data column. Providing the text as a ‘{data_column_name}’ allows slicing in the case of strings by using ‘{data_column_name[:4]}’.

  • legend (bool, default False) – Whether the legend should appear in the plot.

  • title_chr (str, default "Chromosome {chrom}") – String providing the desired title for the chromosome plots. It should be given in a way where the chromosome value in the data is indicated as {chrom}.

  • y_labels (list, default None) – Name to identify the PyRanges object/s in the plot.

  • tooltip (str, default None) – Dataframe information to show in a tooltip when placing the mouse over a gene, the given information will be added to the default: strand, start-end coordinates and id. This must be provided as a string containing the column names of the values to be shown within curly brackets. For example if you want to show the value of the pointed gene for the column “col1” a valid tooltip string could be: “Value of col1: {col1}”. Note that the values in the curly brackets are not strings. If you want to introduce a newline you can use a newline character “” + “n”.

  • to_file ({str, tuple}, default None) – Name of the file to export specifying the desired extension. The supported extensions are ‘.png’ and ‘.pdf’. Optionally, a tuple can be privided where the file name is specified as a str in the first position and in the second position there is a tuple specifying the height and width of the figure in px.

  • theme (str, default "light") – General color appearance of the plot. Available modes: “light”, “dark”, “Mariotti_lab”, “swimming_pool”.

  • **kargs – Customizable plot features can be defined using kargs. Use print_options() function to check the variables’ nomenclature, description and default values.

Examples

>>> import pyranges as pr, pyranges_plot as prp
>>> prp.set_engine('plotly')
>>> p = pr.PyRanges({"Chromosome": [1]*5, "Strand": ["+"]*3 + ["-"]*2, "Start": [10,20,30,25,40], "End": [15,25,35,30,50], "transcript_id": ["t1"]*3 + ["t2"]*2}, "feature1": ["A", "B", "C", "A", "B"])
>>> plot(p, id_col="transcript_id",  max_shown=25, colormap='Set3', text=False)
>>> plot(p, id_col="transcript_id", color_col='Strand', colormap={'+': 'green', '-': 'red'})
>>> plot(p, limits = {'1': (1000, 50000), '2': None, '3': (10000, None)}, title_chr="Chrom: {chrom}")
>>> plot([p, p], id_col="transcript_id", shrink=True, tooltip = "Feature1: {feature1}")
>>> plot([p, p], id_col="transcript_id", y_labels=["first_p", "second_p"], packed=False, to_file='my_plot.pdf')