Skip to content

Conversation

@sanjaysgk
Copy link
Collaborator

@sanjaysgk sanjaysgk commented Jun 23, 2025

…n options; improve handling of x-tick labels across subplots

Summary by Sourcery

Enhance the plot_peptigram function with extensive axis label and legend customization, sample labeling options including wrapping and colored bars, streamline sample name extraction, and update package versioning and entrypoint handling

New Features:

  • Allow configuring x-axis and y-axis tick and label font sizes, colors, and rotation
  • Support wrapping and styling long sample names with custom font size, color, and maximum length
  • Enable optional colored vertical bars for samples with configurable colors and bar width
  • Provide parameters to adjust legend font size, legend title font size, and display color-by method subtitles

Bug Fixes:

  • Normalize sample names by stripping leading special characters during data processing

Enhancements:

  • Capitalize DataProcessor column names on load
  • Improve handling and formatting of x-tick labels across subplots

Chores:

  • Bump package version to 1.1.0-dev
  • Remove standalone main.py and add fallback main() stub in init

…n options; improve handling of x-tick labels across subplots
@sourcery-ai
Copy link

sourcery-ai bot commented Jun 23, 2025

Reviewer's Guide

This PR enriches the plot_peptigram function in viz.py with extensive label and legend customization (font sizes, colors, rotations, wrapping, sample bars and subtitles), refactors its internal styling logic, updates documentation, fixes CSV column handling in DataProcessor, adjusts the default runner pipeline to use sample color bars, and tweaks package initialization including a version bump.

Sequence diagram for sample color bar legend creation in plot_peptigram

sequenceDiagram
    participant User
    participant plot_peptigram
    participant Matplotlib
    User->>plot_peptigram: Call with use_sample_color_bars=True, sample_colors, etc.
    plot_peptigram->>Matplotlib: Add vertical colored bars for each sample
    plot_peptigram->>Matplotlib: Create sample legend below protein legend
    plot_peptigram->>Matplotlib: Add notes for coloring method and regions
    Matplotlib-->>User: Display plot with sample color bars and enhanced legend
Loading

Class diagram for updated plot_peptigram function parameters

classDiagram
    class plot_peptigram {
        +color_by: str
        +figsize: Tuple[int, int]
        +title: Optional[str]
        +y_desnity_forntsize: int
        +y_desnity_forntcolour: str
        +y_lab_ticksize: int
        +y_sample_fontsize: int
        +y_sample_color: Optional[Union[list, str]]
        +max_sample_name_length: int
        +sample_name_wrap: bool
        +use_sample_color_bars: bool
        +sample_colors: Optional[List[str]]
        +sample_bar_width: float
        +x_lab_forntsize: int
        +xticks_font: int
        +xticks_color: str
        +xticks_rotation: int
        +annotate: bool
        +legend_titleFontsize: int
        +legend_fontsize: int
        +min_intensity: Optional[float]
        +highlight_regions: Optional[List[Tuple[int, int]]]
        +auto_highlight: bool
        +auto_highlight_threshold: float
        +highlight: bool
        +color_by_protein_and_intensity: bool
        +colour_by_text: bool
        +intensity_color_scale: float
        +intensity_cmaps: Union[str, List[str]]
        +protein_cmap: str
        ...
    }
Loading

Class diagram for DataProcessor CSV handling changes

classDiagram
    class DataProcessor {
        +peaks_data: pd.DataFrame
        +intensity_cols: List[str]
        +load_peaks_data(file_path: str) : pd.DataFrame
        +filter_and_format_data(...)
    }
    DataProcessor : load_peaks_data() renames columns to capitalized
    DataProcessor : filter_and_format_data() strips sample_prefix and leading symbols from sample names
Loading

File-Level Changes

Change Details Files
Extended plot_peptigram API signature with new styling parameters
  • Added arguments for y-density and sample font size/color and tick size
  • Introduced sample_name_wrap, use_sample_color_bars, sample_colors, sample_bar_width
  • Added legend_titleFontsize, legend_fontsize and colour_by_text flags
ProtPeptigram/viz.py
Refactored plot_peptigram internals to apply dynamic styling and sample bars
  • Replaced hard-coded density color and y-label settings with parameterized font/color
  • Updated y-tick label styling and unified legend creation using new font settings
  • Implemented optional vertical sample color bars, dynamic name wrapping and conditional subtitles
ProtPeptigram/viz.py
Updated docstrings and parameter names to match new API
  • Renamed x_lab_forntsize to x_lab_fontsize and removed outdated y_lab_forntsize
  • Documented all new font, color, wrapping and bar options in function docstring
  • Corrected typos and aligned default values in parameter descriptions
ProtPeptigram/viz.py
Enhanced DataProcessor CSV handling and sample name extraction
  • Renamed input columns to capitalize headers after loading CSV
  • Stripped leading special characters from intensity column names via regex
ProtPeptigram/DataProcessor.py
Enabled sample color bars by default in pipeline runner
  • Set use_sample_color_bars=True and sample_bar_width in run_pipeline defaults
  • Adjusted trailing comma and formatting for clarity
ProtPeptigram/runner.py
Adjusted package initialization and bumped version
  • Added placeholder main import and sys.path hack in root init.py
  • Updated version from 1.0.1-dev to 1.1.0-dev in package init.py
__init__.py
ProtPeptigram/__init__.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sanjaysgk sanjaysgk merged commit 451f999 into main Jun 23, 2025
3 checks passed
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @sanjaysgk - I've reviewed your changes - here's some feedback:

  • The plot_peptigram signature has grown to 30+ parameters—consider grouping related style options into a config object or named dict to reduce signature bloat and improve usability.
  • There are multiple typos in parameter names (e.g. “y_desnity_forntsize”, “forntcolour”)—renaming them to correct spellings will avoid confusion and ensure consistency.
  • The large inline logic for sample color bars, label wrapping, and legend positioning could be extracted into smaller helper functions to improve readability and maintainability.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The plot_peptigram signature has grown to 30+ parameters—consider grouping related style options into a config object or named dict to reduce signature bloat and improve usability.
- There are multiple typos in parameter names (e.g. “y_desnity_forntsize”, “forntcolour”)—renaming them to correct spellings will avoid confusion and ensure consistency.
- The large inline logic for sample color bars, label wrapping, and legend positioning could be extracted into smaller helper functions to improve readability and maintainability.

## Individual Comments

### Comment 1
<location> `ProtPeptigram/viz.py:51` </location>
<code_context>
         color_by: str = None,
         figsize: Tuple[int, int] = (12, 10),
         title: Optional[str] = None,
+        y_desnity_forntsize: int = 8,
+        y_desnity_forntcolour: str = "#333333",
+        y_lab_ticksize: int = 8,
+        y_sample_fontsize: int = 8,
+        y_sample_color: Optional[Union[list, str]] = "#333333",
+        max_sample_name_length: int = 15,
+        sample_name_wrap: bool = True,
</code_context>

<issue_to_address>
Several new parameter names contain typos ('forntsize', 'desnity', etc.).

Please correct the spelling of parameter names to avoid confusion and maintain consistency.

Suggested implementation:

```python
        y_density_fontsize: int = 8,
        y_density_fontcolor: str = "#333333",

```

```python
        x_lab_fontsize: int = 12,

```

You will also need to update all usages of these parameters within the function body and any calls to this function elsewhere in the codebase to use the corrected names:
- `y_density_fontsize` instead of `y_desnity_forntsize`
- `y_density_fontcolor` instead of `y_desnity_forntcolour`
- `x_lab_fontsize` instead of `x_lab_forntsize`
</issue_to_address>

### Comment 2
<location> `ProtPeptigram/viz.py:56` </location>
<code_context>
+        y_lab_ticksize: int = 8,
+        y_sample_fontsize: int = 8,
+        y_sample_color: Optional[Union[list, str]] = "#333333",
+        max_sample_name_length: int = 15,
+        sample_name_wrap: bool = True,
+        use_sample_color_bars: bool = False,
+        sample_colors: Optional[List[str]] = None,
+        sample_bar_width: float = 0.5,
         x_lab_forntsize: int = 12,
-        y_lab_forntsize: int = 12,
</code_context>

<issue_to_address>
Default value for max_sample_name_length in docstring does not match function signature.

Please update the docstring to reflect the correct default value for max_sample_name_length.
</issue_to_address>

### Comment 3
<location> `ProtPeptigram/viz.py:60` </location>
<code_context>
+        sample_name_wrap: bool = True,
+        use_sample_color_bars: bool = False,
+        sample_colors: Optional[List[str]] = None,
+        sample_bar_width: float = 0.5,
         x_lab_forntsize: int = 12,
-        y_lab_forntsize: int = 12,
</code_context>

<issue_to_address>
sample_bar_width is described as a float but used as a linewidth in axvline, which expects points.

Clarify in the docstring that sample_bar_width is in points, and consider increasing the default value for better visibility.

Suggested implementation:

```python
        sample_bar_width: float = 2.0,

```

You must also update the docstring for the function or class where these parameters are defined. Add or modify the description for `sample_bar_width` to clarify that it is in points (as used by `axvline`). For example:

    sample_bar_width (float): Width of the sample color bars in points (as used by matplotlib's axvline). Default is 2.0.

Make sure this clarification is present in the docstring.
</issue_to_address>

### Comment 4
<location> `ProtPeptigram/viz.py:603` </location>
<code_context>
+            
+            # Add colored vertical bar for each sample if requested
+            if use_sample_color_bars:
+                if sample_colors is None:
+                    # Generate colors automatically
+                    sample_cmap = plt.cm.get_cmap('tab10')
+                    sample_color = sample_cmap(i % sample_cmap.N)
+                else:
+                    sample_color = sample_colors[i % len(sample_colors)]
+                
+                # Add vertical colored bar on the left
</code_context>

<issue_to_address>
sample_legend_handles is initialized inside the loop, which may cause issues.

If the loop is skipped or i != 0 initially, sample_legend_handles may be undefined, causing a NameError. Initialize it before the loop to avoid this issue.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +51 to +55
y_desnity_forntsize: int = 8,
y_desnity_forntcolour: str = "#333333",
y_lab_ticksize: int = 8,
y_sample_fontsize: int = 8,
y_sample_color: Optional[Union[list, str]] = "#333333",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (typo): Several new parameter names contain typos ('forntsize', 'desnity', etc.).

Please correct the spelling of parameter names to avoid confusion and maintain consistency.

Suggested implementation:

        y_density_fontsize: int = 8,
        y_density_fontcolor: str = "#333333",
        x_lab_fontsize: int = 12,

You will also need to update all usages of these parameters within the function body and any calls to this function elsewhere in the codebase to use the corrected names:

  • y_density_fontsize instead of y_desnity_forntsize
  • y_density_fontcolor instead of y_desnity_forntcolour
  • x_lab_fontsize instead of x_lab_forntsize

Comment on lines +56 to +60
max_sample_name_length: int = 15,
sample_name_wrap: bool = True,
use_sample_color_bars: bool = False,
sample_colors: Optional[List[str]] = None,
sample_bar_width: float = 0.5,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Default value for max_sample_name_length in docstring does not match function signature.

Please update the docstring to reflect the correct default value for max_sample_name_length.

sample_name_wrap: bool = True,
use_sample_color_bars: bool = False,
sample_colors: Optional[List[str]] = None,
sample_bar_width: float = 0.5,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: sample_bar_width is described as a float but used as a linewidth in axvline, which expects points.

Clarify in the docstring that sample_bar_width is in points, and consider increasing the default value for better visibility.

Suggested implementation:

        sample_bar_width: float = 2.0,

You must also update the docstring for the function or class where these parameters are defined. Add or modify the description for sample_bar_width to clarify that it is in points (as used by axvline). For example:

sample_bar_width (float): Width of the sample color bars in points (as used by matplotlib's axvline). Default is 2.0.

Make sure this clarification is present in the docstring.

Comment on lines +603 to +608
if sample_colors is None:
# Generate colors automatically
sample_cmap = plt.cm.get_cmap('tab10')
sample_color = sample_cmap(i % sample_cmap.N)
else:
sample_color = sample_colors[i % len(sample_colors)]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): sample_legend_handles is initialized inside the loop, which may cause issues.

If the loop is skipped or i != 0 initially, sample_legend_handles may be undefined, causing a NameError. Initialize it before the loop to avoid this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants