Skip to content
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

DRAFT of AuxAlignment for parsing secondary/supplementary alignments #208

Closed
wants to merge 1 commit into from

Conversation

clintval
Copy link
Member

@clintval clintval commented Dec 31, 2024

This is a draft PR to explore a common hierarchy for "alignments from SAM tags".

Motivated by:

The diff is ugly but there are only 3 classes. I suggest reviewing like:

I was able to make almost everything backwards compatible except:

  • SupplementaryAlignment is now a dataclass vs attrs
  • SupplementaryAlignment had a few init fields renamed

@tfenne what do you think?

I'm looking for a quick 👍 👎 so I can abandon the idea, or merge it into my actual feature branch for additional polish and a real round of review.

Copy link

codecov bot commented Dec 31, 2024

Codecov Report

Attention: Patch coverage is 88.88889% with 20 lines in your changes missing coverage. Please review.

Project coverage is 90.84%. Comparing base (b0b4227) to head (6d887a1).

Files with missing lines Patch % Lines
fgpyo/sam/__init__.py 88.88% 16 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #208      +/-   ##
==========================================
- Coverage   91.06%   90.84%   -0.22%     
==========================================
  Files          18       18              
  Lines        2283     2437     +154     
  Branches      337      355      +18     
==========================================
+ Hits         2079     2214     +135     
- Misses        133      149      +16     
- Partials       71       74       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@nh13 nh13 left a comment

Choose a reason for hiding this comment

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

I did not duplicate my comments from #206, so please incorporate those too as appropriate.

Instead of two sub-classes of AuxAlignment, what about storing an optional enum for if the alignment is secondary or supplementary (or None if neither or unknown)? Then for the from_tag(value: str) method, you could condition on if it's 4 values (XA), or 6 values with strand as the third item (SA), or 6 values with the cigar as the third item (XB). Alternatively, could you explain the motivation for the three classes beyond how they parse differently (which I think is resolved above)? Do we want to match on the class/type?

fgpyo/sam/__init__.py Outdated Show resolved Hide resolved
fgpyo/sam/__init__.py Outdated Show resolved Hide resolved
fgpyo/sam/__init__.py Outdated Show resolved Hide resolved
Comment on lines 1232 to 1233
if self.alignment_score is not None and self.alignment_score < 0:
errors.append(f"Alignment score cannot be less than 0! Found: {self.alignment_score}")
Copy link
Member

Choose a reason for hiding this comment

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

why not? I think a negative alignment score is aligned, especially in a global alignment.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd like to learn more about this concern! I haven't seen a score below zero for any output from bwa so I figured it would be a sign that data was corrupt. Couple questions:

  1. Is there a way to run bwa in which the score can go below zero?
  2. Knowing that this code will probably parse bwa tags for the forseeable future, do you think keeping the strict check is better for safety-sake or would hinder someone in the future with a popular or custom global aligner putting auxiliary alignments in SAM tags?

@clintval clintval changed the title feat: secondary/supplementary alignments inherit from AuxAlignment feat: add AuxAlignment for parsing secondary/supplementary alignments in SAM tags Jan 10, 2025
@clintval clintval changed the title feat: add AuxAlignment for parsing secondary/supplementary alignments in SAM tags Add AuxAlignment for parsing secondary/supplementary alignments in SAM tags Jan 10, 2025
@clintval clintval force-pushed the cv_aux_alignment_hierarchy branch from 5277047 to 6d887a1 Compare January 10, 2025 14:53
@clintval clintval changed the base branch from cv_secondary_from_xb to main January 10, 2025 14:54
@clintval clintval force-pushed the cv_aux_alignment_hierarchy branch from 6d887a1 to 2369449 Compare January 10, 2025 16:48
@clintval clintval force-pushed the cv_aux_alignment_hierarchy branch from 2369449 to 302bf2a Compare January 10, 2025 16:51
@clintval clintval changed the title Add AuxAlignment for parsing secondary/supplementary alignments in SAM tags DRAFT of AuxAlignment for parsing secondary/supplementary alignments Jan 10, 2025
@clintval
Copy link
Member Author

Closing this and will open a clean PR with a refactor.

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.

3 participants