23
23
cnv_params ,
24
24
)
25
25
from .snp_frq import AnophelesSnpFrequencyAnalysis
26
- from .cnv_data import AnophelesCnvData
26
+ from .cnv_frq import AnophelesCnvFrequencyAnalysis
27
27
28
28
AA_CHANGE_QUERY = (
29
29
"effect in ['NON_SYNONYMOUS_CODING', 'START_LOST', 'STOP_LOST', 'STOP_GAINED']"
30
30
)
31
31
32
32
33
- class AnophelesDipClustAnalysis (AnophelesSnpFrequencyAnalysis , AnophelesCnvData ):
33
+ class AnophelesDipClustAnalysis (
34
+ AnophelesCnvFrequencyAnalysis , AnophelesSnpFrequencyAnalysis
35
+ ):
34
36
def __init__ (
35
37
self ,
36
38
** kwargs ,
@@ -190,7 +192,7 @@ def plot_diplotype_clustering(
190
192
else :
191
193
return {
192
194
"figure" : fig ,
193
- "dendro_sample_id_order" : leaf_data ["sample_id" ].to_list (),
195
+ "dendro_sample_id_order" : np . asarray ( leaf_data ["sample_id" ].to_list () ),
194
196
"n_snps" : n_snps_used ,
195
197
}
196
198
@@ -319,7 +321,7 @@ def _dipclust_het_bar_trace(
319
321
sample_sets : Optional [base_params .sample_sets ],
320
322
sample_query : Optional [base_params .sample_query ],
321
323
sample_query_options : Optional [base_params .sample_query_options ],
322
- site_mask : base_params .site_mask ,
324
+ site_mask : Optional [ base_params .site_mask ] ,
323
325
cohort_size : Optional [base_params .cohort_size ],
324
326
random_seed : base_params .random_seed ,
325
327
color_continuous_scale : Optional [plotly_params .color_continuous_scale ],
@@ -547,11 +549,52 @@ def _dipclust_concat_subplots(
547
549
548
550
return fig
549
551
552
+ def _insert_dipclust_snp_trace (
553
+ self ,
554
+ * ,
555
+ figures ,
556
+ subplot_heights ,
557
+ snp_row_height : plotly_params .height = 25 ,
558
+ transcript : base_params .transcript ,
559
+ snp_query : Optional [base_params .snp_query ] = AA_CHANGE_QUERY ,
560
+ sample_sets : Optional [base_params .sample_sets ],
561
+ sample_query : Optional [base_params .sample_query ],
562
+ sample_query_options : Optional [base_params .sample_query_options ],
563
+ site_mask : Optional [base_params .site_mask ],
564
+ dendro_sample_id_order : np .ndarray ,
565
+ snp_filter_min_maf : float ,
566
+ snp_colorscale : Optional [plotly_params .color_continuous_scale ],
567
+ chunks : base_params .chunks = base_params .native_chunks ,
568
+ inline_array : base_params .inline_array = base_params .inline_array_default ,
569
+ ):
570
+ snp_trace , n_snps_transcript = self ._dipclust_snp_trace (
571
+ transcript = transcript ,
572
+ sample_sets = sample_sets ,
573
+ sample_query = sample_query ,
574
+ sample_query_options = sample_query_options ,
575
+ snp_query = snp_query ,
576
+ site_mask = site_mask ,
577
+ dendro_sample_id_order = dendro_sample_id_order ,
578
+ snp_filter_min_maf = snp_filter_min_maf ,
579
+ snp_colorscale = snp_colorscale ,
580
+ chunks = chunks ,
581
+ inline_array = inline_array ,
582
+ )
583
+
584
+ if snp_trace :
585
+ figures .append (snp_trace )
586
+ subplot_heights .append (snp_row_height * n_snps_transcript )
587
+ else :
588
+ print (
589
+ f"No SNPs were found below { snp_filter_min_maf } allele frequency. Omitting SNP genotype plot."
590
+ )
591
+ return figures , subplot_heights
592
+
550
593
@doc (
551
594
summary = "Perform diplotype clustering, annotated with heterozygosity, gene copy number and amino acid variants." ,
552
595
parameters = dict (
553
596
heterozygosity = "Plot heterozygosity track." ,
554
- snp_transcript = "Plot amino acid variants for this transcript ." ,
597
+ snp_transcript = "Plot amino acid variants for these transcripts ." ,
555
598
cnv_region = "Plot gene CNV calls for this region." ,
556
599
snp_filter_min_maf = "Filter amino acid variants with alternate allele frequency below this threshold." ,
557
600
),
@@ -561,7 +604,7 @@ def plot_diplotype_clustering_advanced(
561
604
region : base_params .regions ,
562
605
heterozygosity : bool = True ,
563
606
heterozygosity_colorscale : plotly_params .color_continuous_scale = "Greys" ,
564
- snp_transcript : Optional [base_params . transcript ] = None ,
607
+ snp_transcript : Optional [dipclust_params . snp_transcript ] = None ,
565
608
snp_colorscale : plotly_params .color_continuous_scale = "Greys" ,
566
609
snp_filter_min_maf : float = 0.05 ,
567
610
snp_query : Optional [base_params .snp_query ] = AA_CHANGE_QUERY ,
@@ -682,9 +725,11 @@ def plot_diplotype_clustering_advanced(
682
725
figures .append (cnv_trace )
683
726
subplot_heights .append (cnv_row_height * n_cnv_genes )
684
727
685
- if snp_transcript :
686
- snp_trace , n_snps_transcript = self ._dipclust_snp_trace (
728
+ if isinstance ( snp_transcript , str ) :
729
+ figures , subplot_heights = self ._insert_dipclust_snp_trace (
687
730
transcript = snp_transcript ,
731
+ figures = figures ,
732
+ subplot_heights = subplot_heights ,
688
733
sample_sets = sample_sets ,
689
734
sample_query = sample_query ,
690
735
sample_query_options = sample_query_options ,
@@ -696,13 +741,22 @@ def plot_diplotype_clustering_advanced(
696
741
chunks = chunks ,
697
742
inline_array = inline_array ,
698
743
)
699
-
700
- if snp_trace :
701
- figures .append (snp_trace )
702
- subplot_heights .append (snp_row_height * n_snps_transcript )
703
- else :
704
- print (
705
- f"No SNPs were found below { snp_filter_min_maf } allele frequency. Omitting SNP genotype plot."
744
+ elif isinstance (snp_transcript , list ):
745
+ for st in snp_transcript :
746
+ figures , subplot_heights = self ._insert_dipclust_snp_trace (
747
+ transcript = st ,
748
+ figures = figures ,
749
+ subplot_heights = subplot_heights ,
750
+ sample_sets = sample_sets ,
751
+ sample_query = sample_query ,
752
+ sample_query_options = sample_query_options ,
753
+ snp_query = snp_query ,
754
+ site_mask = site_mask ,
755
+ dendro_sample_id_order = dendro_sample_id_order ,
756
+ snp_filter_min_maf = snp_filter_min_maf ,
757
+ snp_colorscale = snp_colorscale ,
758
+ chunks = chunks ,
759
+ inline_array = inline_array ,
706
760
)
707
761
708
762
# Calculate total height based on subplot heights, plus a fixed
0 commit comments