@@ -208,7 +208,6 @@ def generate_variants(
208208
209209 # Begin random mutations for this slice
210210 # Note that any new variant types will need code in this area to handle the functions.
211- debug = 0
212211 while variants_to_add_in_slice > 0 :
213212 # We decrement now because we don't want to get stuck in a never ending loop
214213 variants_to_add_in_slice -= 1
@@ -256,34 +255,25 @@ def generate_variants(
256255 # pick which ploid is mutated
257256 temp_variant .genotype = pick_ploids (options .ploidy , mutation_model .homozygous_freq , 1 , options .rng )
258257
259- # There shouldn't be a ton of overlapping variants, but this is to handle those.
260258 if location in return_variants :
261- """
262- If the location already exists, then we'll need to force it to pick a ploid
263- that currently doesn't have a variant. This overrides the default genotype
264- variable created above, but it shouldn't happen very often.
265- """
266- if return_variants .find_dups (temp_variant ):
267- # This compiles all the variants at this location, giving a 1 for every ploid that has a variant.
268- composite_genotype = return_variants .compile_genotypes_for_location (location )
269- if 0 not in composite_genotype :
270- # Here's a counter to make sure we're not getting stuck on a single location
271- debug += 1
272- if debug > 1000000 :
273- _LOG .error ("Check this if, as it may be causing an infinite loop." )
274- sys .exit (999 )
275- # No suitable place to put this, so we skip.
276- continue
277- # This sets up a probability array with weights 1 for open spots (x==0) and 0 elsewhere
278- probs = np .array ([1 if x == 0 else 0 for x in composite_genotype ])
279- probs = probs / sum (probs )
280- # Pick an index of a position to mutate based on the probabilities, which are uniform for 0s left
281- # in the composite genotype
282- ploid = options .rng .choice (list (range (len (composite_genotype ))), p = probs )
283- genotype = np .zeros (options .ploidy )
284- genotype [ploid ] = 1
285- temp_variant .genotype = genotype
286- # pdb.set_trace()
259+ existing_variants = return_variants .contig_variants [location ]
260+ sv_involved = temp_variant .is_structural or any (
261+ v .is_structural for v in existing_variants
262+ )
263+ if not sv_involved :
264+ # Two independent point mutations at the same anchor occur with
265+ # probability p² — effectively impossible at realistic rates. Skip.
266+ continue
267+ # SV compound-het: assign to a free ploid on the other haplotype.
268+ composite_genotype = return_variants .compile_genotypes_for_location (location )
269+ if 0 not in composite_genotype :
270+ continue
271+ probs = np .array ([1 if x == 0 else 0 for x in composite_genotype ])
272+ probs = probs / sum (probs )
273+ ploid = options .rng .choice (list (range (len (composite_genotype ))), p = probs )
274+ genotype = np .zeros (options .ploidy )
275+ genotype [ploid ] = 1
276+ temp_variant .genotype = genotype
287277 # Make sure this new variant doesn't overlap an existing insertion or deletion
288278 in_deletion = return_variants .check_if_del (temp_variant )
289279 in_insertion = return_variants .check_if_ins (temp_variant )
0 commit comments