Skip to content

Commit a9ba1ff

Browse files
committed
Converting weights to probabilities
1 parent 37130f1 commit a9ba1ff

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

neat/models/models.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class InsertionModel(VariantModel):
5959
def __init__(self,
6060
insert_len_model: dict[int: float, ...],
6161
rng: Generator = None):
62-
# normalize the values
62+
# Creating probabilities from the weights
6363
tot = sum(insert_len_model.values())
6464
self.insertion_len_model = {key: val / tot for key, val in insert_len_model.items()}
6565
self.rng = rng
@@ -92,7 +92,7 @@ class DeletionModel(VariantModel):
9292
def __init__(self,
9393
deletion_len_model: dict[int: float, ...],
9494
rng: Generator = None):
95-
# normalize the values
95+
# Creating probabilities from the weights
9696
tot = sum(deletion_len_model.values())
9797
self.deletion_len_model = {key: val/tot for key, val in deletion_len_model.items()}
9898
self.rng = rng
@@ -284,6 +284,9 @@ def generate_snv(self, trinucleotide: Seq, reference_location: int) -> SingleNuc
284284
transition_matrix = self.trinuc_trans_matrices[DINUC_IND[trinucleotide[0] + "_" + trinucleotide[2]]]
285285
# then determine the trans probs based on the middle nucleotide
286286
transition_probs = transition_matrix[NUC_IND[trinucleotide[1]]]
287+
# Creating probabilities from the weights
288+
transition_sum = sum(transition_probs)
289+
transition_probs = [x/transition_sum for x in transition_probs]
287290
# Now pick a random alternate, weighted by the probabilities
288291
alt = self.rng.choice(ALLOWED_NUCL, p=transition_probs)
289292
temp_snv = SingleNucleotideVariant(reference_location, alt=alt)

0 commit comments

Comments
 (0)