plot
- tangermeme.plot.plot_logo(X_attr, ax=None, color=None, annotations=None, start=None, end=None, ylim=None, spacing=4, n_tracks=4, score_key='score', show_extra=True, show_score=True, annot_cmap='Set1')
Make a logo plot and optionally annotate it.
This function will take in a matrix of weights for each character in a sequence and produce a plot where the characters have heights proportional to those weights. Attribution values from a predictive model are commonly used to weight the characters, but the weights can come from anywhere.
Optionally, annotations can be provided in the form of a dataframe with contents described below in the parameters section. These annotations will be displayed underneath the characters in a manner that tries to avoid overlap across annotations.
This function is largely a thin-wrapper around logomaker.
Parameters
- X_attr: torch.tensor, shape=(4, -1)
A tensor of the attributions. Can be either the hypothetical attributions, where the entire matrix has values, or the projected attributions, where only the actual bases have their attributions stored, i.e., 3 values per column are zero.
- ax: matplotlib.pyplot.subplot or None, optional
The art board to draw on. If None, choose the current artboard.
- color: str or None, optional
The color to plot all characters as. If None, plot according to standard coloring. Default is None.
- annotations: pandas.DataFrame, optional
A set of annotations with the following columns in any order except for motif_name, which can be called anything but must come first:
motif_name: the name of the motif
start: the start of the hit relative to the window provided
end: the end of the hit relative to the window provided
strand: the strand the hit is on (optional)
score: the score of the hit
These will probably come from the output of the hit caller. Default is None.
- start: int or None, optional
The start of the sequence to visualize. Must be non-negative and cannot be longer than the length of X_attr. If None, visualize the full sequence. Default is None.
- end: int or None, optional
The end of the sequence to visuaize. Must be non-negative and cannot be longer than the length of X_attr. If start is provided, end must be larger. If None, visualize the full sequence. Default is None.
- ylim: tuple or None, optional
The lower and upper bounds of the plot. Pass the bounds in here rather than setting them after calling this function if you want the annotation spacing to adjust to it. If None, use the default bounds. Default is None.
- n_tracks: int, optional
The number of rows of annotation labels to plot with bars before simply putting the name of the motif. Default is 4.
- score_key: str, optional
When annotations are provided, the name of the key to use as a score. Must have the semantics that a higher value means a “better” annotation. Default is ‘score’.
- show_extra: bool, optional
Whether to show motif names past the n_tracks number of rows. If False, do not show those motifs. Default is True.
- show_score: bool, optional
Whether to show the score of the hit. Sometimes, the annotation can take up too much space already and the scoring information is not as helpful, so disabling this will only display the motif hit name. Default is True.
- annot_cmap: str, list, or matplotlib.colors.ListedColormap, optional
The colormap to use for the annotations. Rows of annotation labels receive distinct colors, bars are colored according to their corresponding label. If a string, must be a valid matplotlib qualitative colormap name If a list, must be a list of colors (list of colornames or list of RGB tuples). Labels are colorcoded if there is more than 1 row of annotations, otherwise black.
Returns
- ax: plt.subplot
A subplot that contains the plot.