Skip to content

Commit

Permalink
calculate_delta_frequency: Adjust --delta-pivots for fewer pivots
Browse files Browse the repository at this point in the history
This avoids an uncaught IndexError that had occurred with
pivots[first_pivot_index] when first_pivot_index was out of bounds.
  • Loading branch information
victorlin committed Nov 3, 2022
1 parent 0675316 commit c220e1d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion scripts/calculate_delta_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ def read_frequencies(frequencies_file):
)
parser.add_argument("--tree", required=True, help="Newick tree")
parser.add_argument("--frequencies", required=True, help="frequencies JSON")
parser.add_argument("--delta-pivots", type=int, default=1, help="number of frequency pivots to look back in time for change in frequency calculation")
parser.add_argument(
"--delta-pivots",
type=int,
default=1,
help="""number of frequency pivots to look back in time for change in frequency calculation.
If fewer pivots are available, all of them will be used.
""")
parser.add_argument(
"--method",
default="linear",
Expand Down Expand Up @@ -80,6 +86,12 @@ def read_frequencies(frequencies_file):
frequencies, parameters = read_frequencies(args.frequencies)
pivots = np.array(parameters["pivots"])

# Lower `delta_pivots` if there are not enough pivots.
max_delta_pivots = len(pivots) - 1
if args.delta_pivots > max_delta_pivots:
print(f"WARNING: Requested {args.delta_pivots} but there are only {max_delta_pivots} available. Using all available pivots.", file=sys.stderr)
args.delta_pivots = max_delta_pivots

# Determine the total time that elapsed between the current and past timepoint.
first_pivot_index = -(args.delta_pivots + 1)
last_pivot_index = -1
Expand Down

0 comments on commit c220e1d

Please sign in to comment.