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

Refactors make_nr loop with SeqIO.write call #106

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ShriramK
Copy link

@ShriramK ShriramK commented May 24, 2018

TODO: Refactor as generator with single SeqIO.write(...) call

ShriramK added 3 commits May 25, 2018 00:42
Moves/handles the records processing logic and seqIO write call in a separate function
Incorrect processing logic's fixed
@peterjc
Copy link
Owner

peterjc commented May 25, 2018

I'm not sure if you understand how generator functions work, so it is hard for me to explain this without writing all the code, but if you want to work on this a bit more that's fine.

The goal is something like this:

    if duplicates:
        count = SeqIO.write(pick_records(input_fasta), output_fasta, "fasta")
        print("%i unique entries; removed %i duplicates leaving %i representative records"
              % (unique, len(duplicates), len(representatives)))
        assert count == unique + len(representatives)

where you have defined a generator function:

def pick_records(input_fasta_file):
    global representatives
    global duplicates
    for record in SeqIO.parse(input_fasta, "fasta"):
        # TODO, sometimes yield a record

@ShriramK
Copy link
Author

Thanks Peter for your comment. It helped.
I had the right idea for the generator but lacked clarity on how it fits into the refactoring, or focus of the refactoring here, and SeqIO methods and their input arguments.
I'll come up with a revised fix.

Adds the generator function pick_records and modifies make_nr accordingly.
Adds an assertion as per peterjc#106 (comment)
@peterjc
Copy link
Owner

peterjc commented Jun 12, 2018

As an aside, one of the reasons for making this change goes away in Biopython 1.72, see biopython/biopython#1223

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