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

Refactor fragment_iterator() #96

Open
Tracked by #64
ns-rse opened this issue Nov 29, 2024 · 0 comments
Open
Tracked by #64

Refactor fragment_iterator() #96

ns-rse opened this issue Nov 29, 2024 · 0 comments
Labels

Comments

@ns-rse
Copy link
Contributor

ns-rse commented Nov 29, 2024

Currently we have...

    def fragment_iterator(read_iterator):
        read_list = list()
        last_read = None

        for read in read_iterator:
            if last_read is not None and last_read != read.query_name:
                yield read_list
                read_list = list()
                last_read = read.query_name
            last_read = read.query_name
            read_list.append(read)

        yield read_list

Where read_iterator is the bamfile.

Need to think through the logic here......

  1. last_read always starts as None so on the first pass last_read is set to the current read.query_name and
    nothing is run. What does this first read look like, do we need it?
  2. Loop then runs unless read.query_name matches last_read, yielding read (as a list) which will actually be the
    value from the previous pass.

Following switches to passing the bam_file path, adds typehints and docstring.

from isoslam import io

def fragment_iterator(bam_file: str | Path) -> Generator[?, None, None]:
    """
    Iterate over fragments from a `.bam` file.

    Parameters
    ----------
    bam_file : str | Path

    Returns
    -------
    Generator
        Iterable of reads from BAM file.
    """
    ...
    for read in io.load_file(bam_file):
        ...

I need to work through what this is doing and get a better understanding. Tests here we come!

@ns-rse ns-rse mentioned this issue Nov 29, 2024
26 tasks
@ns-rse ns-rse added the isoslam label Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant