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

Consider more advanced views into the alignments in Template #207

Open
clintval opened this issue Dec 30, 2024 · 1 comment
Open

Consider more advanced views into the alignments in Template #207

clintval opened this issue Dec 30, 2024 · 1 comment
Assignees

Comments

@clintval
Copy link
Member

clintval commented Dec 30, 2024

After fixing an issue in Template where records were added twice to different internal fields in this PR:

We might want to consider more specific "views" into the different categories of alignments for multi-mapping chimeric use cases.

Some ideas for useful ways to view the alignments for either the R1 or R2 ordinal:

  • Only primary (not secondary, not supplemental)
  • Only not primary (all secondary and supplementary)
  • Only secondary including "secondary supplementals"
  • Only secondary not including "secondary supplementals"
  • Only supplementary including "secondary supplementals"
  • Only supplementary not including "secondary supplementals"
@clintval clintval self-assigned this Jan 17, 2025
@clintval
Copy link
Member Author

clintval commented Feb 20, 2025

One mockup for a new class:

@dataclass(frozen=True)
class Template(Iterable):
    r1: AlignedSegment | None = None
    r2: AlignedSegment | None = None
    r1_auxiliaries: list[AlignedSegment] = field(default_factory=list)
    r2_auxiliaries: list[AlignedSegment] = field(default_factory=list)

    def primaries(self) -> Iterator[AlignedSegment]:
        yield from ([] if self.r1 is None else [self.r1])
        yield from ([] if self.r2 is None else [self.r2])

    def r1_supplementals(self) -> Iterator[AlignedSegment]:
        yield from (rec for rec in self.all_r1() if rec.is_supplementary and not rec.is_secondary)
    
    def r2_supplementals(self) -> Iterator[AlignedSegment]:
        yield from (rec for rec in self.all_r2() if rec.is_supplementary and not rec.is_secondasry)
    
    def r1_secondaries(self) -> Iterator[AlignedSegment]:
        yield from (rec for rec in self.all_r1() if rec.is_secondary and not rec.is_supplementary)
    
    def r2_secondaries(self) -> Iterator[AlignedSegment]:
        yield from (rec for rec in self.all_r2() if rec.is_secondary and not rec.is_supplementary)

    def r1_secondary_supplementals(self) -> Iterator[AlignedSegment]:
        yield from (rec for rec in self.all_r1() if rec.is_secondary and rec.is_supplementary)
    
    def r2_secondary_supplementals(self) -> Iterator[AlignedSegment]:
        yield from (rec for rec in self.all_r2() if rec.is_secondary and rec.is_supplementary)

    def r1_primary_and_supplementals(self) -> Iterator[AlignedSegment]:
        yield from ([] if self.r1 is None else [self.r1])
        yield from self.r1_supplementals()

    def r2_primary_and_supplementals(self) -> Iterator[AlignedSegment]:
        yield from ([] if self.r2 is None else [self.r2])
        yield from self.r2_supplementals()

    def r1_secondary_and_supplementals(self) -> Iterator[AlignedSegment]:
        yield from self.r1_secondaries()
        yield from self.r1_secondary_supplementals()
        
    def r2_secondary_and_supplementals(self) -> Iterator[AlignedSegment]:
        yield from self.r2_secondaries()
        yield from self.r2_secondary_supplementals()

    def all_r1(self) -> Iterator[AlignedSegment]:
        yield from ([] if self.r1 is None else [self.r1])
        yield from self.r1_auxiliaries

    def all_r2(self) -> Iterator[AlignedSegment]:
        yield from ([] if self.r2 is None else [self.r2])
        yield from self.r2_auxiliaries

    def __iter__(self) -> Iterator[AlignedSegment]:
        yield from self.all_r1()
        yield from self.all_r2()

If the namespace is too cluttered we could shim a TemplateView class under a Template.view cached property that has a reference back to the template and provides different iterators upon the dataclass data. For example:

template.r1
template.r2
template.r1_auxiliaries
template.r2_auxiliaries

template.view.all_r1()
template.view.all_r2()
template.view.r1_secondaries()
template.view.r2_secondaries()
...

Additionally, I think we should make Template an iterable so you can do list(template) and for rec in template: ... and get back all of the alignments. Previously you had to do all_recs().

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

No branches or pull requests

1 participant