Skip to content

Commit

Permalink
Switch from list to deque for faster inserts and pops during mutation…
Browse files Browse the repository at this point in the history
… separation (#653)
  • Loading branch information
atc3 authored Dec 10, 2024
1 parent ef095bd commit 52ce705
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions workflow_main/scripts/extract_aa_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import json
import pandas as pd

from collections import deque
from util import translate

# Number of codons to look ahead for resolving frameshifts
Expand Down Expand Up @@ -107,7 +108,7 @@ def extract_aa_mutations(
# )
# ].reset_index(drop=True)

aa_mutations = []
aa_mutations = deque()
aa_seqs = {}

# For each reference
Expand Down Expand Up @@ -520,7 +521,7 @@ def extract_aa_mutations(

# 2. SPLIT SUBSTITUTIONS
old_aa_mutation_inds = []
new_aa_mutations = [] # (new_mutation, insertion_index)
new_aa_mutations = [] # (new_mutation, insertion_index)
for i, aa_mutation in enumerate(aa_mutations):
# (reference, Accession ID, gene/protein, pos, ref, alt)
ref = aa_mutation[4]
Expand All @@ -531,16 +532,19 @@ def extract_aa_mutations(

# Split the substitution into individual substitutions
for j, (a, b) in enumerate(zip(ref, alt)):
new_aa_mutations.append((
new_aa_mutations.append(
(
aa_mutation[0],
aa_mutation[1],
aa_mutation[2],
aa_mutation[3] + j,
a,
b,
), i + j
))
(
aa_mutation[0],
aa_mutation[1],
aa_mutation[2],
aa_mutation[3] + j,
a,
b,
),
i + j,
)
)

old_aa_mutation_inds.append(i)

Expand Down

0 comments on commit 52ce705

Please sign in to comment.