Skip to content

Conversation

@sanjaysgk
Copy link
Collaborator

@sanjaysgk sanjaysgk commented Jun 24, 2025

Summary by Sourcery

Improve peptigram plotting to handle empty groups as empty rows, accept explicit group lists, standardize console logging, and refresh the README example image.

Enhancements:

  • Render empty peptide groups as consistent empty rows instead of hiding axes
  • Allow passing an explicit groups parameter to plot_peptigram for custom grouping
  • Replace console.print with console.log when reporting protein list usage

Documentation:

  • Update example visualization image link in the README to a new protein ID

Chores:

  • Remove commented debug prints and unused code in viz.py
  • Add a placeholder comment for console log saving in logger.py

@sourcery-ai
Copy link

sourcery-ai bot commented Jun 24, 2025

Reviewer's Guide

This PR refactors the peptide plotting routine to handle empty groups with consistent axes rather than hiding them, adds debugging scaffolding for group extraction, updates the runner to use structured logging and pass explicit group context, introduces console log persistence hooks in the logger, and synchronizes the README’s example image with the latest identifier.

Sequence diagram for peptide group plotting with empty group handling

sequenceDiagram
    participant User
    participant Runner as run_pipeline
    participant Viz as plot_peptigram
    participant Matplotlib as ax
    User->>Runner: run_pipeline()
    Runner->>Viz: plot_peptigram(proteins, groups, ...)
    Viz->>Viz: For each group
    alt Group has peptides
        Viz->>Matplotlib: Plot peptides with color and layout
    else Group is empty
        Viz->>Matplotlib: Set xlim, ylim for empty plot
    end
    Viz->>Runner: Return figure
    Runner->>User: Output visualization
Loading

Class diagram for logging and plotting changes

classDiagram
    class Logger {
        +configure_logging(level, log_to_file)
        +save_console_log(output_dir, file_name)
    }
    class Runner {
        +run_pipeline(...)
    }
    class Viz {
        +plot_peptigram(...)
        -_calculate_plot_height(...)
    }
    Logger <.. Runner : uses
    Runner <.. Viz : uses
Loading

File-Level Changes

Change Details Files
Refactored empty-group handling in plot_peptigram to display consistent empty plots rather than hiding axes
  • Replace ax.set_visible(False)/continue with explicit empty‐plot setup (xlim, ylim, max_height)
  • Enclose main peptide‐plot loop under an else branch for non‐empty groups
ProtPeptigram/viz.py
Added commented debug scaffolding for group determination in plot_peptigram
  • Insert alternative flattening expression as comment
  • Add commented print statements for groups and proteins to plot
ProtPeptigram/viz.py
Updated runner script to improve logging and pass group context
  • Replace console.print with console.log for messages
  • Include unique_samples as the groups argument when calling plot_peptigram
ProtPeptigram/runner.py
Introduced console logging capability in logger module
  • Add comment marker for console logging in save_console_log function
ProtPeptigram/logger.py
Updated README example image reference
  • Change image URL/filename in README.md to match updated example
README.md

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 9e0720a into main Jun 24, 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 and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `ProtPeptigram/viz.py:573` </location>
<code_context>
-                    space_start = max(0, start - xlim[0])
-                    space_end = min(end - xlim[0], xlim[1] - xlim[0])
-
-                    if space_start >= spaces.shape[1] or space_end >= spaces.shape[1]:
-                        continue
-
-                    space_needed = spaces[height, space_start:space_end+1]
</code_context>

<issue_to_address>
Skipping peptides with out-of-bounds indices may silently drop data.

Currently, peptides outside the plotting range are skipped without notification, which can hinder debugging. Please add a warning or indicator when peptides are omitted for this reason.

Suggested implementation:

```python
+                    space_start = max(0, start - xlim[0])
+                    space_end = min(end - xlim[0], xlim[1] - xlim[0])
+
+                    if space_start >= spaces.shape[1] or space_end >= spaces.shape[1]:
+                        import warnings
+                        warnings.warn(
+                            f"Peptide ({start}, {end}) at height {height} is out of plotting range ({xlim[0]}, {xlim[1]}) and will be skipped.",
+                            UserWarning
+                        )
+                        continue

```

If the `warnings` module is already imported at the top of the file, you can remove the inline `import warnings` and use the existing import. Otherwise, for best practice, add `import warnings` at the top of the file.
</issue_to_address>

### Comment 2
<location> `README.md:12` </location>
<code_context>
 ProtPeptigram provides a comprehensive visualization platform for mapping immunopeptides to their source proteins across different biological samples. This tool can enables to identify peptide coverage patterns, analyze density distributions, and compare peptide presentations between experimental conditions.

 <p align="center">
</code_context>

<issue_to_address>
Grammatical error: 'can enables to identify' should be corrected.

Consider revising to 'can enable identification of', 'enables identification of', or 'can enable users to identify' for clarity and correctness.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
ProtPeptigram provides a comprehensive visualization platform for mapping immunopeptides to their source proteins across different biological samples. This tool can enables to identify peptide coverage patterns, analyze density distributions, and compare peptide presentations between experimental conditions.
=======
ProtPeptigram provides a comprehensive visualization platform for mapping immunopeptides to their source proteins across different biological samples. This tool enables identification of peptide coverage patterns, analysis of density distributions, and comparison of peptide presentations between experimental conditions.
>>>>>>> REPLACE

</suggested_fix>

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.

@@ -480,119 +483,121 @@ def plot_peptigram(
lambda x: group in x)]

Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): Skipping peptides with out-of-bounds indices may silently drop data.

Currently, peptides outside the plotting range are skipped without notification, which can hinder debugging. Please add a warning or indicator when peptides are omitted for this reason.

Suggested implementation:

+                    space_start = max(0, start - xlim[0])
+                    space_end = min(end - xlim[0], xlim[1] - xlim[0])
+
+                    if space_start >= spaces.shape[1] or space_end >= spaces.shape[1]:
+                        import warnings
+                        warnings.warn(
+                            f"Peptide ({start}, {end}) at height {height} is out of plotting range ({xlim[0]}, {xlim[1]}) and will be skipped.",
+                            UserWarning
+                        )
+                        continue

If the warnings module is already imported at the top of the file, you can remove the inline import warnings and use the existing import. Otherwise, for best practice, add import warnings at the top of the file.

@@ -12,7 +12,7 @@
ProtPeptigram provides a comprehensive visualization platform for mapping immunopeptides to their source proteins across different biological samples. This tool can enables to identify peptide coverage patterns, analyze density distributions, and compare peptide presentations between experimental conditions.
Copy link

Choose a reason for hiding this comment

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

issue (typo): Grammatical error: 'can enables to identify' should be corrected.

Consider revising to 'can enable identification of', 'enables identification of', or 'can enable users to identify' for clarity and correctness.

Suggested change
ProtPeptigram provides a comprehensive visualization platform for mapping immunopeptides to their source proteins across different biological samples. This tool can enables to identify peptide coverage patterns, analyze density distributions, and compare peptide presentations between experimental conditions.
ProtPeptigram provides a comprehensive visualization platform for mapping immunopeptides to their source proteins across different biological samples. This tool enables identification of peptide coverage patterns, analysis of density distributions, and comparison of peptide presentations between experimental conditions.

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