@@ -466,6 +466,7 @@ def create_tree(bitmap):
466
466
)
467
467
tree_tmp2 = hierarchy .to_tree (matrix , False )
468
468
treedata = get_newick (tree_tmp2 , tree_tmp2 .dist , index .genome_names )
469
+ print (treedata )
469
470
470
471
palette = sns .color_palette ("RdPu" , 130 ).as_hex ()
471
472
total_kmers = max (kmer_num_tmp ) #[-1] #kmer_num_tmp["Solqui2"]
@@ -595,7 +596,7 @@ def make_anns(x,y, text, kmer_num, i):
595
596
b = 10 ,
596
597
l = 10 ,
597
598
r = 10 ))
598
- return fig
599
+ return fig , label_legend
599
600
600
601
def get_local_info (bar_sum_regional , anchor_name , chrs ):
601
602
fig = make_subplots (
@@ -652,7 +653,7 @@ def plot_interactive(anchor_name, chrom, start_coord, end_coord, step, pancounts
652
653
rows = 4 , cols = 1 ,
653
654
shared_xaxes = True ,
654
655
vertical_spacing = 0.01 ,
655
- row_heights = [1 ,2 , 4 , 4 ],
656
+ row_heights = [1 ,4 , 8 , 8 ],
656
657
#subplot_titles=("Ref. Sequence Position","", "", "Conserved K-mers","" )
657
658
)
658
659
#start_coord = bitmap_counts
@@ -673,7 +674,6 @@ def plot_interactive(anchor_name, chrom, start_coord, end_coord, step, pancounts
673
674
t0 = t1
674
675
675
676
cntr = 0
676
- anno = index .query_anno (anchor_name , chrom , start_coord , end_coord )
677
677
678
678
t1 = time .perf_counter ()
679
679
print (f"\t Anno Query { t1 - t0 :0.4f} seconds" )
@@ -708,8 +708,12 @@ def plot_interactive(anchor_name, chrom, start_coord, end_coord, step, pancounts
708
708
709
709
anno_names = ["gene" ]
710
710
711
+ anno = index .query_anno (anchor_name , chrom , start_coord , end_coord )#.set_index("type_id").sort_index()
711
712
anno ["break" ] = np .nan
713
+ grp = anno .groupby ("type_id" )
712
714
for t , df in anno .groupby ("type_id" ):
715
+ #for i,t in enumerate(anno_types):
716
+ # df = anno.loc[t]
713
717
xs = df [["start" ,"end" ,"break" ]].to_numpy ().flatten ()
714
718
ys = np .full (len (xs ),- t * 2 )
715
719
name = df ["type" ].iloc [0 ]
@@ -732,15 +736,29 @@ def plot_interactive(anchor_name, chrom, start_coord, end_coord, step, pancounts
732
736
mode = "lines+markers"
733
737
), row = 2 , col = 1 )
734
738
735
- ys = np .arange (- len (ann_colors ),0 )+ 1
736
- names = anno_names [::- 1 ]
737
- if len (ys ) > 10 :
738
- n = len (ys )// 10
739
- ys = ys [::n ]
740
- names = names [::n ]
739
+ #ys = np.arange(-len(ann_colors),0)+1
740
+ #names = anno_types[::-1]+["gene"] #anno_names[::-1]
741
+ #if len(ys) > 10:
742
+ # n = len(ys)//10
743
+ # ys = ys[::n]
744
+ # names = names[::n]
745
+ #print(ys)
746
+ #print(names)
747
+
748
+ ticks = index .genomes [anchor_name ].anno_type_ids .reset_index ()
749
+ ticks .columns = ["name" ,"idx" ]
750
+ ticks .loc [0 ,"name" ] = "gene"
751
+ ticks ["y" ] = - ticks ["idx" ]
752
+ print (ticks )
753
+ #ticks.index[0] = "gene"
754
+
755
+ if len (ticks ) > 5 :
756
+ n = len (ticks )// 5
757
+ ticks = ticks .iloc [::n ]
758
+ print (ticks )
741
759
742
760
fig .update_yaxes (
743
- tickvals = ys , ticktext = names ,
761
+ ticktext = ticks [ "name" ], tickvals = ticks [ "y" ] ,
744
762
range = [- len (ann_colors )- 0.5 ,1.5 ], #title="Annotation",
745
763
row = 2 , col = 1
746
764
)
@@ -777,30 +795,48 @@ def plot_interactive(anchor_name, chrom, start_coord, end_coord, step, pancounts
777
795
778
796
#This is the conserved kmer plotting section
779
797
fig .append_trace (go .Bar (x = x , y = pancounts .loc [0 ], name = str (0 ),
780
- legendgroup = "group1" ,
781
- legendgrouptitle_text = "Conserved K-mers" ,
798
+ #legendgroup="group1",
799
+ #legendgrouptitle_text="Conserved K-mers",
800
+ showlegend = False ,
782
801
marker = dict (color = 'grey' ),
783
802
marker_line = dict (color = 'grey' )
784
- ),
785
- row = 3 , col = 1 )
803
+ ), row = 3 , col = 1 )
786
804
787
805
t1 = time .perf_counter ()
788
806
print (f"\t Conserved k-mers (grey) { t1 - t0 :0.4f} seconds" )
789
807
t0 = t1
808
+
809
+ fig .add_trace (go .Scattergl (
810
+ x = [1 ,2 ],y = [1 ,2 ],
811
+ marker = dict (
812
+ color = [1 , index .ngenomes ],
813
+ coloraxis = "coloraxis" ,
814
+ colorscale = "viridis" ,
815
+ colorbar_title = "Pan-Count"
816
+ ), showlegend = False ,opacity = 0
817
+ ),row = 3 ,col = 1 )
790
818
791
819
for i in pancounts .index [1 :]:
792
820
fig .append_trace (go .Bar (x = x , y = pancounts .loc [i ], name = str (i ),
793
821
legendgroup = "group1" ,
794
822
legendgrouptitle_text = "Conserved K-mers" ,
795
- marker = dict (color = colors [i - 1 ]),
796
- marker_line = dict (color = colors [i - 1 ])
797
- ),
798
- row = 3 , col = 1 )
823
+ marker = dict (
824
+ color = colors [i - 1 ],
825
+ line_color = colors [i - 1 ],
826
+ #colorscale="viridis",
827
+ #coloraxis="coloraxis",colorbar_title="Pan-Count",
828
+ ),
829
+ #marker_line=dict(color=colors[i-1]),
830
+ showlegend = False ,
831
+ ), row = 3 , col = 1 )
799
832
800
833
fig .update_layout (barmode = 'stack' , bargap = 0.0 )
801
834
fig .update_xaxes (showticklabels = False , row = 3 , col = 1 )
802
835
803
- fig .add_trace (go .Heatmap (z = paircounts , x = paircounts .columns , y = paircounts .index , coloraxis = "coloraxis" ),
836
+ fig .add_trace (go .Heatmap (
837
+ z = paircounts , x = paircounts .columns , y = paircounts .index ,
838
+ coloraxis = "coloraxis2"
839
+ ),
804
840
row = 4 , col = 1 )
805
841
806
842
t1 = time .perf_counter ()
@@ -826,8 +862,23 @@ def plot_interactive(anchor_name, chrom, start_coord, end_coord, step, pancounts
826
862
fig .update_yaxes (title_text = "# of k-mers" , range = [0 ,adjusted_bin_size ] , row = 3 , col = 1 )
827
863
828
864
#TODO don't use template, manually set background to white
829
- cax = {"colorscale" :"plasma_r" ,"colorbar" :{"title" :"Pair Cons." ,"y" :0 ,"len" :0.35 ,"yanchor" :"bottom" }}
830
- fig .update_layout (xaxis_range = [start_coord ,end_coord ], font = dict (size = 16 ),coloraxis = cax )
865
+ pan_cax = {
866
+ "colorscale" : "viridis" ,
867
+ "colorbar" : {"title" :"Pangenome Conservation" ,"y" :0.72 ,"len" :0.35 ,"yanchor" :"top" ,"title_side" :"right" }
868
+ }
869
+
870
+ pair_cax = {
871
+ "colorscale" :"plasma_r" ,
872
+ "colorbar" : {
873
+ "title" :"Pairwise Conservation" ,"y" :0 ,"len" :0.35 ,"yanchor" :"bottom" ,"title_side" :"right" }
874
+ }
875
+
876
+ fig .update_layout (
877
+ xaxis_range = [start_coord ,end_coord ],
878
+ font = dict (size = 16 ),
879
+ coloraxis = pan_cax ,
880
+ coloraxis2 = pair_cax ,
881
+ )
831
882
832
883
t1 = time .perf_counter ()
833
884
print (f"\t Truly finishing touches { t1 - t0 :0.4f} seconds" )
@@ -1486,10 +1537,21 @@ def update_all_figs( chr_num, chrom, anchor_name, redo_wg, start_coord, end_coor
1486
1537
t1 = time .perf_counter ()
1487
1538
print (f"query bitmap { t1 - t0 :0.4f} seconds" )
1488
1539
t0 = t1
1540
+
1541
+ b = bitmap .sample (n = min (len (bitmap ),50000 ))
1542
+ fig3 ,genome_order = create_tree (b )
1543
+
1544
+ t1 = time .perf_counter ()
1545
+ print (f"tree plot in { t1 - t0 :0.4f} seconds" )
1546
+ t0 = t1
1489
1547
1490
1548
bin_size = ((end_coord - start_coord ) // params .max_chr_bins ) + 1
1491
1549
pan , pair = index .bitmap_to_bins (bitmap , bin_size )
1492
1550
1551
+ if params .order is not None :
1552
+ genome_order = params .order
1553
+ pair = pair .loc [genome_order ]
1554
+
1493
1555
t1 = time .perf_counter ()
1494
1556
print (f"transform bitmap { t1 - t0 :0.4f} seconds" )
1495
1557
toc_tmp_1 = t1
@@ -1523,17 +1585,11 @@ def update_all_figs( chr_num, chrom, anchor_name, redo_wg, start_coord, end_coor
1523
1585
fig2 = get_local_info (bar_sum_regional , anchor_name , chrom )
1524
1586
toc_tmp_33 = time .perf_counter ()
1525
1587
print (f"fig 2 plot in { toc_tmp_33 - toc_tmp_32 :0.4f} seconds" )
1526
-
1527
- b = bitmap .sample (n = min (len (bitmap ),50000 ))
1528
- fig3 = create_tree (b )
1529
-
1530
- toc_tmp_4 = time .perf_counter ()
1531
- print (f"tree plot in { toc_tmp_4 - toc_tmp_33 :0.4f} seconds" )
1532
1588
1533
1589
#if redo_wg == 1:
1534
1590
big_plot = no_update #plot_whole_genome(anchor_name)
1535
1591
toc_tmp_5 = time .perf_counter ()
1536
- print (f"plots big in { toc_tmp_5 - toc_tmp_4 :0.4f} seconds" )
1592
+ print (f"plots big in { toc_tmp_5 - toc_tmp_33 :0.4f} seconds" )
1537
1593
1538
1594
pg_sizes_fig = make_genome_size_plot (anchor_name )
1539
1595
toc_tmp_6 = time .perf_counter ()
0 commit comments