@@ -311,21 +311,22 @@ def adjust_smn1_cn(self, smn1_cn, smn2_cn, hcn, ass_haps, read_counts, smn1_haps
311311 haploid_depth = genome_depth / 2
312312 depth1 = self .smn1_reads_splice
313313 copy_number_probs = self .depth_prob (depth1 , haploid_depth )
314- if smn1_cn == 1 :
315- # when there is only one haplotype, check if depth is
316- # consistent with haploid depth
317- copy_one_prob = copy_number_probs [0 ]
318- if copy_one_prob < 0.05 :
319- two_cp_haps = list (smn1_haps .values ())
320- return 2 , two_cp_haps
321- if copy_one_prob < 0.25 :
322- new_smn1_cn = None
323- elif smn1_cn == 2 :
324- # scenario where two two-copy alleles are identical
325- copy_four_prob = copy_number_probs [3 ]
326- if copy_four_prob > 0.75 :
327- two_cp_haps = list (smn1_haps .values ())
328- return 4 , two_cp_haps
314+ if copy_number_probs is not None :
315+ if smn1_cn == 1 :
316+ # when there is only one haplotype, check if depth is
317+ # consistent with haploid depth
318+ copy_one_prob = copy_number_probs [0 ]
319+ if copy_one_prob < 0.05 :
320+ two_cp_haps = list (smn1_haps .values ())
321+ return 2 , two_cp_haps
322+ if copy_one_prob < 0.25 :
323+ new_smn1_cn = None
324+ elif smn1_cn == 2 :
325+ # scenario where two two-copy alleles are identical
326+ copy_four_prob = copy_number_probs [3 ]
327+ if copy_four_prob > 0.75 :
328+ two_cp_haps = list (smn1_haps .values ())
329+ return 4 , two_cp_haps
329330 if smn1_cn in [2 , 3 ] and read_counts is not None and self .targeted is False :
330331 # check if one smn1 haplotype has more reads than others
331332 haps = list (read_counts .keys ())
@@ -335,7 +336,7 @@ def adjust_smn1_cn(self, smn1_cn, smn2_cn, hcn, ass_haps, read_counts, smn1_haps
335336 if cp2_hap in smn1_haps :
336337 others_max = sorted (counts , reverse = True )[1 ]
337338 probs = self .depth_prob (max_count , others_max )
338- if probs [0 ] < 0.0005 and others_max >= 10 :
339+ if probs is not None and probs [0 ] < 0.0005 and others_max >= 10 :
339340 two_cp_haps .append (smn1_haps [cp2_hap ])
340341 return smn1_cn + 1 , two_cp_haps
341342
@@ -346,12 +347,13 @@ def adjust_smn1_cn(self, smn1_cn, smn2_cn, hcn, ass_haps, read_counts, smn1_haps
346347 copy_number_probs = self .depth_prob (depth1 , haploid_depth )
347348 # when there is only one haplotype, check if depth is
348349 # consistent with haploid depth
349- copy_one_prob = copy_number_probs [0 ]
350- if copy_one_prob < 0.25 :
351- new_smn1_cn = None
352- if smn2_cn > 1 and copy_one_prob < 0.05 :
353- two_cp_haps = list (smn1_haps .values ())
354- return 2 , two_cp_haps
350+ if copy_number_probs is not None :
351+ copy_one_prob = copy_number_probs [0 ]
352+ if copy_one_prob < 0.25 :
353+ new_smn1_cn = None
354+ if smn2_cn > 1 and copy_one_prob < 0.05 :
355+ two_cp_haps = list (smn1_haps .values ())
356+ return 2 , two_cp_haps
355357 # if we see more haplotypes in other regions of the gene
356358 if smn1_cn == 1 and hcn > len (ass_haps ):
357359 if self .has_smn2 is False :
@@ -361,7 +363,7 @@ def adjust_smn1_cn(self, smn1_cn, smn2_cn, hcn, ass_haps, read_counts, smn1_haps
361363 new_smn1_cn = None
362364 return new_smn1_cn , two_cp_haps
363365
364- def adjust_smn2_cn (self , smn1_cn , smn2_cn , smn2_haps ):
366+ def adjust_smn2_cn (self , smn1_cn , smn2_cn , read_counts , smn2_haps ):
365367 """
366368 Adjust SMN2 CN if there is only one haplotype found.
367369 """
@@ -377,19 +379,43 @@ def adjust_smn2_cn(self, smn1_cn, smn2_cn, smn2_haps):
377379 depth1 = self .smn2_reads_splice
378380 copy_number_probs = self .depth_prob (depth1 , haploid_depth )
379381 # if smn1 cn is 3, then no need to adjust smn2 cn
380- if (
381- smn2_cn == 1
382- and len (self .smn2_del_reads_partial ) <= 1
383- and (smn1_cn is None or smn1_cn <= 2 )
384- ):
385- # when there is only one haplotype, check if depth is
386- # consistent with haploid depth
387- copy_one_prob = copy_number_probs [0 ]
388- if copy_one_prob < 0.25 :
389- new_smn2_cn = None
390- if copy_one_prob < 0.05 :
382+ if copy_number_probs is not None :
383+ if (
384+ smn2_cn == 1
385+ and len (self .smn2_del_reads_partial ) <= 1
386+ and (smn1_cn is None or smn1_cn <= 2 )
387+ ):
388+ # when there is only one haplotype, check if depth is
389+ # consistent with haploid depth
390+ copy_one_prob = copy_number_probs [0 ]
391+ if copy_one_prob < 0.25 :
392+ new_smn2_cn = None
393+ if copy_one_prob < 0.05 :
394+ two_cp_haps = list (smn2_haps .values ())
395+ return 2 , two_cp_haps
396+ if smn1_cn == 0 and smn2_cn == 2 :
397+ # scenario where two two-copy alleles are identical
398+ copy_four_prob = copy_number_probs [3 ]
399+ if copy_four_prob > 0.75 :
391400 two_cp_haps = list (smn2_haps .values ())
392- return 2 , two_cp_haps
401+ return 4 , two_cp_haps
402+ if (
403+ smn1_cn in [0 , 1 ]
404+ and smn2_cn in [2 , 3 ]
405+ and read_counts is not None
406+ and self .targeted is False
407+ ):
408+ # check if one smn2 haplotype has more reads than others
409+ haps = list (read_counts .keys ())
410+ counts = list (read_counts .values ())
411+ max_count = max (counts )
412+ cp2_hap = haps [counts .index (max_count )]
413+ if cp2_hap in smn2_haps :
414+ others_max = sorted (counts , reverse = True )[1 ]
415+ probs = self .depth_prob (max_count , others_max )
416+ if probs is not None and probs [0 ] < 0.0005 and others_max >= 10 :
417+ two_cp_haps .append (smn2_haps [cp2_hap ])
418+ return smn2_cn + 1 , two_cp_haps
393419 if smn1_cn is not None :
394420 if smn2_cn == 1 and smn1_cn == 2 and len (self .smn2_del_reads_partial ) <= 1 :
395421 haploid_depth = self .smn1_reads_splice / smn1_cn
@@ -398,12 +424,13 @@ def adjust_smn2_cn(self, smn1_cn, smn2_cn, smn2_haps):
398424 copy_number_probs = self .depth_prob (depth1 , haploid_depth )
399425 # when there is only one haplotype, check if depth is
400426 # consistent with haploid depth
401- copy_one_prob = copy_number_probs [0 ]
402- if copy_one_prob < 0.25 :
403- new_smn2_cn = None
404- if copy_one_prob < 0.05 :
405- two_cp_haps = list (smn2_haps .values ())
406- return 2 , two_cp_haps
427+ if copy_number_probs is not None :
428+ copy_one_prob = copy_number_probs [0 ]
429+ if copy_one_prob < 0.25 :
430+ new_smn2_cn = None
431+ if copy_one_prob < 0.05 :
432+ two_cp_haps = list (smn2_haps .values ())
433+ return 2 , two_cp_haps
407434 return new_smn2_cn , two_cp_haps
408435
409436 def get_best_match (
@@ -629,7 +656,7 @@ def call(self):
629656 cp2_hap = haps [counts .index (max_count )]
630657 others_max = sorted (counts , reverse = True )[1 ]
631658 probs = self .depth_prob (max_count , others_max )
632- if probs [0 ] < 0.05 and others_max >= 10 :
659+ if probs is not None and probs [0 ] < 0.05 and others_max >= 10 :
633660 two_cp_haps .append (haps_to_compare [cp2_hap ])
634661 for hap in two_cp_haps :
635662 if "smn1hap" in hap :
@@ -645,7 +672,9 @@ def call(self):
645672 for hap in two_cp_haps_smn1 :
646673 if hap not in two_cp_haps :
647674 two_cp_haps .append (hap )
648- smn2_cn , two_cp_haps_smn2 = self .adjust_smn2_cn (smn1_cn_old , smn2_cn , smn2_haps )
675+ smn2_cn , two_cp_haps_smn2 = self .adjust_smn2_cn (
676+ smn1_cn_old , smn2_cn , read_counts , smn2_haps
677+ )
649678 for hap in two_cp_haps_smn2 :
650679 if hap not in two_cp_haps :
651680 two_cp_haps .append (hap )
0 commit comments