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

speed up panphlan_map.py with intervaltree? #26

Open
nick-youngblut opened this issue Dec 20, 2020 · 0 comments
Open

speed up panphlan_map.py with intervaltree? #26

nick-youngblut opened this issue Dec 20, 2020 · 0 comments

Comments

@nick-youngblut
Copy link

In the code:

        with open(reads_file, mode='r') as IN:
            for line in IN:
                words = line.strip().split('\t')
                # words = CONTIG, POSITION, REFERENCE BASE, COVERAGE, READ BASE, QUALITY
                contig, position, abundance = words[0], int(words[1]), int(words[3])
                # For each gene in the contig, if position in range of gene, increase its abundance
                if contig in contig2gene.keys():
                    for gene, (fr,to) in contig2gene[contig].items():
                        if position in range(fr, to+1):
                            genes_abundances[gene] += abundance
        # WRITE
        if args.output == None:
            for g in genes_abundances:
                if genes_abundances[g] > 0:
                    sys.stdout.write(str(g) + '\t' + str(genes_abundances[g]) + '\n')

you are searching for positions in a range via if position in range(fr, to+1). Changing contig2gene to an intervaltree data structure will likely substantially speed this up.

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