Closed peterjc closed 1 year ago
Something like this is what I have in mind, which records 'PRIMER_LEFT_0': (46, 21)
etc 'START': 46
since the length seemed redundant.
def nest_primers(results):
"""Returns lists of dicts for LEFT, RIGHT, INTERNAL and PAIR entries."""
left = []
right = []
internal = []
pair = []
for target, name in ((left, "LEFT"), (right, "RIGHT"), (internal, "INTERNAL"), (pair, "PAIR")):
for i in range(results[f"PRIMER_{name}_NUM_RETURNED"]):
prefix = f"PRIMER_{name}_{i}_"
primer = {k[len(prefix):]:v for k, v in results.items() if k.startswith(prefix)}
try:
start, length = results[f"PRIMER_{name}_{i}"]
primer["START"] = start
assert length == len(primer["SEQUENCE"])
except KeyError:
# Does not apply to PAIR
pass
target.append(primer)
return left, right, internal, pair
If we can assume the left, right, pair (and if requested internal oligo) results are always the same length, then there are other options which might be even easier to use?
make sense
fixed in PR #110
That sounds good, I'll try to remember to try this next time I'm designing primers. Thank you.
sound great!
Consider this example adapted from the one of your test cases:
This is a single flat dictionary, but there is obvious nested structure here with the five primers sets 0 to 4, could we not have a (optional) nested dict?:
These make sense as top level entries:
These would be redundant under my idea:
All the rest have an index and would be better a list of dicts or named tuples:
Here the
PRIMER_PAIR
entry could be:And the
PRIMER_LEFT
entry could be:(You'd need a key for
'PRIMER_LEFT_0': (46, 21),
though - maybeCOORDS
?)etc.
This could be requested by a keyword argument to preserve backward compatibility?