-
Notifications
You must be signed in to change notification settings - Fork 46
Handle mixed CDR3 lengths in logoplots #692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,13 +32,14 @@ def logoplot_cdr3_motif( | |||||||||
| ax: plt.Axes | None = None, | ||||||||||
| fig_kws: dict | None = None, | ||||||||||
| **kwargs, | ||||||||||
| ) -> Logo: | ||||||||||
| ) -> Logo | list[Logo]: | ||||||||||
| """ | ||||||||||
| Generates logoplots of CDR3 sequences | ||||||||||
|
|
||||||||||
| This is a user friendly wrapper function around the logomaker python package. | ||||||||||
| Enables the analysis of potential amino acid motifs by displaying logo plots. | ||||||||||
| Subsetting of AnnData/MuData has to be performed manually beforehand (or while calling) and only cells with equal cdr3 sequence lengths are permitted. | ||||||||||
| Subsetting of AnnData/MuData has to be performed manually beforehand (or while calling). | ||||||||||
| If multiple CDR3 sequence lengths are present, separate logo plots are generated for each length. | ||||||||||
|
|
||||||||||
| Parameters | ||||||||||
| ---------- | ||||||||||
|
|
@@ -72,6 +73,7 @@ def logoplot_cdr3_motif( | |||||||||
| x coordinate span of each character | ||||||||||
| ax | ||||||||||
| Add the plot to a predefined Axes object. | ||||||||||
| Can only be used when all selected sequences have the same CDR3 length. | ||||||||||
| fig_kws | ||||||||||
| Parameters passed to the :func:`matplotlib.pyplot.figure` call | ||||||||||
| if no `ax` is specified. | ||||||||||
|
|
@@ -81,35 +83,75 @@ def logoplot_cdr3_motif( | |||||||||
|
|
||||||||||
| Returns | ||||||||||
| ------- | ||||||||||
| Returns a object of class logomaker.Logo (see here for more information https://logomaker.readthedocs.io/en/latest/implementation.html#matrix-functions) | ||||||||||
| Returns one object of class :class:`logomaker.Logo` if all selected sequences have the | ||||||||||
| same length. If multiple sequence lengths are present, returns a list of | ||||||||||
| :class:`logomaker.Logo` objects, one per length. | ||||||||||
| """ | ||||||||||
| params = DataHandler(adata, airr_mod, airr_key, chain_idx_key) | ||||||||||
|
|
||||||||||
| if isinstance(chains, str): | ||||||||||
| chains = [chains] | ||||||||||
|
|
||||||||||
| if ax is None: | ||||||||||
| fig_kws = {} if fig_kws is None else fig_kws | ||||||||||
| if "figsize" not in fig_kws: | ||||||||||
| fig_kws["figsize"] = (6, 2) | ||||||||||
| ax = _init_ax(fig_kws) | ||||||||||
|
|
||||||||||
| # make sure that sequences are prealigned i.e. they need to have the the same length | ||||||||||
| # sequences need to be aligned for each logo plot, so we split by sequence length | ||||||||||
| airr_df = get_airr(params, [cdr3_col], chains) | ||||||||||
| sequence_list = [] | ||||||||||
| for chain in chains: | ||||||||||
| for sequence in airr_df[chain + "_" + cdr3_col]: | ||||||||||
| if not pd.isnull(sequence): | ||||||||||
| sequence_list.append(sequence) | ||||||||||
| sequences_by_length: dict[int, list[str]] = {} | ||||||||||
| for sequence in sequence_list: | ||||||||||
| sequences_by_length.setdefault(len(sequence), []).append(sequence) | ||||||||||
| n_lengths = len(sequences_by_length) | ||||||||||
|
||||||||||
| n_lengths = len(sequences_by_length) | |
| n_lengths = len(sequences_by_length) | |
| if n_lengths == 0: | |
| raise ValueError("No CDR3 sequences found for the selected chains/column") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring says
fig_kwsis passed tomatplotlib.pyplot.figure, but this function uses_init_ax(fig_kws)/plt.subplots(..., **fig_kws)(and_init_axitself wrapsplt.subplots). Please update the parameter description to match the actual call site (i.e.plt.subplots/figure creation kwargs) so users know which keys are supported.