Skip to content

Commit 7d9fa24

Browse files
committed
Worked on paircount
1 parent 87d8f9c commit 7d9fa24

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

panagram/index.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,9 @@ def bitmap_to_bins(self, bitmap, binlen):
390390

391391
paircount_bins = df.groupby(level=0).sum()
392392
paircount_bins = paircount_bins.set_index(paircount_bins.index*binlen).T
393-
394393
paircount_bins = paircount_bins.div(paircount_bins.max(axis=1),axis=0)
395394

396-
paircount_bins
397-
398-
return pancount_bins,paircount_bins
395+
return pancount_bins, paircount_bins
399396

400397
def bitmap_to_pancount(self, bitmap):
401398
return pd.Series(bitmap.to_numpy().sum(axis=1),index=bitmap.index)

panagram/view.py

+16-19
Original file line numberDiff line numberDiff line change
@@ -667,13 +667,6 @@ def plot_interactive(anchor_name, chrom, start_coord, end_coord, step, pancounts
667667
bin_size = int((end_coord - start_coord) / params.max_chr_bins) + 1
668668
adjusted_bin_size = int(bin_size / step)
669669

670-
#bin_counts = index.pancount_to_bins(pancnts, bin_size)
671-
#print(start_coord, end_coord, bin_size)
672-
#print(bin_counts)
673-
print(pancounts)
674-
675-
print(paircounts)
676-
677670
x = pancounts.columns * bin_size
678671

679672
t3 = time.perf_counter()
@@ -756,9 +749,7 @@ def plot_interactive(anchor_name, chrom, start_coord, end_coord, step, pancounts
756749
fig.update_layout(barmode='stack', bargap=0.0)
757750
fig.update_xaxes(showticklabels=False, row=3, col=1)
758751

759-
print(paircounts)
760-
fig.add_trace(go.Heatmap(z=paircounts, x=paircounts.columns, y=paircounts.index,
761-
),
752+
fig.add_trace(go.Heatmap(z=paircounts, x=paircounts.columns, y=paircounts.index, coloraxis="coloraxis"),
762753
row=4, col=1 )
763754

764755
t7 = time.perf_counter()
@@ -782,7 +773,8 @@ def plot_interactive(anchor_name, chrom, start_coord, end_coord, step, pancounts
782773
fig.update_yaxes(title_text="# of k-mers", range=[0,adjusted_bin_size] , row=3, col=1)
783774

784775
#TODO don't use template, manually set background to white
785-
fig.update_layout(xaxis_range=[start_coord,end_coord], font=dict(size=16))
776+
cax = {"colorscale":"plasma_r","colorbar":{"title":"Pair Cons.","y":0,"len":0.35,"yanchor":"bottom"}}
777+
fig.update_layout(xaxis_range=[start_coord,end_coord], font=dict(size=16),coloraxis=cax)
786778

787779
t10 = time.perf_counter()
788780
print(f"\tTruly finishing touches {t10 - t9:0.4f} seconds")
@@ -1411,7 +1403,7 @@ def chromosome_callback(tab, start_coord, end_coord, chrs, anchor_name):
14111403
return update_all_figs(chr_num, chrs, anchor_name, 0, start_coord, end_coord,n_skips)
14121404

14131405
def update_all_figs( chr_num, chrom, anchor_name, redo_wg, start_coord, end_coord, n_skips):
1414-
tic = time.perf_counter()
1406+
t_start = time.perf_counter()
14151407

14161408
sys.stderr.write("Quering genes 8\n")
14171409
end = index.chrs.loc[anchor_name, chrom]["size"]
@@ -1430,19 +1422,24 @@ def update_all_figs( chr_num, chrom, anchor_name, redo_wg, start_coord, end_coor
14301422

14311423
gene_names = all_genes["name"] #[g.split(';')[0].split("=")[1] for g in genes['attr']]
14321424

1433-
toc_tmp = time.perf_counter()
1434-
print(f"All_genes in {toc_tmp - tic:0.4f} seconds")
1425+
t1 = time.perf_counter()
1426+
print(f"All_genes in {t1-t_start:0.4f} seconds")
1427+
t0 = t1
14351428
if get_buffer(start_coord, end_coord, index.lowres_step) == 1:
14361429
n_skips = 1
14371430

14381431
bitmap = index.query_bitmap(anchor_name, chrom, start_coord, end_coord, n_skips)
1439-
bitmap_counts = index.bitmap_to_pancount(bitmap) #pd.Series(bitmap.to_numpy().sum(axis=1),index=bitmap.index)
1432+
1433+
t1 = time.perf_counter()
1434+
print(f"query bitmap {t1 - t0:0.4f} seconds")
1435+
t0 = t1
14401436

14411437
bin_size = ((end_coord - start_coord) // params.max_chr_bins) + 1
14421438
pan, pair = index.bitmap_to_bins(bitmap, bin_size)
14431439

1444-
toc_tmp_1 = time.perf_counter()
1445-
print(f"query bitmap {toc_tmp_1 - toc_tmp:0.4f} seconds")
1440+
t1 = time.perf_counter()
1441+
print(f"transform bitmap {t1 - t0:0.4f} seconds")
1442+
toc_tmp_1 = t1
14461443

14471444
fig1 = plot_interactive(
14481445
anchor_name, chrom, start_coord, end_coord, n_skips,
@@ -1469,7 +1466,7 @@ def update_all_figs( chr_num, chrom, anchor_name, redo_wg, start_coord, end_coor
14691466
toc_tmp_32 = time.perf_counter()
14701467
print(f"chr fig in {toc_tmp_32 - toc_tmp_31:0.4f} seconds")
14711468

1472-
bar_sum_regional = bitmap_counts.value_counts().reindex(index.bitsum_index, fill_value=0)
1469+
bar_sum_regional = pan.sum(axis=1) #bitmap_counts.value_counts().reindex(index.bitsum_index, fill_value=0)
14731470
fig2 = get_local_info(bar_sum_regional, anchor_name, chrom)
14741471
toc_tmp_33 = time.perf_counter()
14751472
print(f"fig 2 plot in {toc_tmp_33 - toc_tmp_32:0.4f} seconds")
@@ -1510,7 +1507,7 @@ def update_all_figs( chr_num, chrom, anchor_name, redo_wg, start_coord, end_coor
15101507
print(f"plots sorted in {toc_tmp_11 - toc_tmp_10:0.4f} seconds")
15111508

15121509
toc = time.perf_counter()
1513-
print(f"Update all in {toc - tic:0.4f} seconds")
1510+
print(f"Update all in {toc - t_start:0.4f} seconds")
15141511
return (
15151512
chr_fig,
15161513
fig1, fig2, fig3, fig4,

0 commit comments

Comments
 (0)