Skip to content

Commit

Permalink
Add number of homologs to summary table
Browse files Browse the repository at this point in the history
  • Loading branch information
memgonzales committed Dec 17, 2023
1 parent f26df83 commit a05af5a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 17 deletions.
9 changes: 9 additions & 0 deletions callbacks/general_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ def get_num_entries(table, column):
return table[column].count()


def count_non_empty_vals(array):
ctr = 0
for elem in array:
if elem != NULL_PLACEHOLDER:
ctr += 1

return ctr


def purge_html_export_table(table):
for row in table:
for key in row.keys():
Expand Down
1 change: 0 additions & 1 deletion callbacks/lift_over/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from dash.exceptions import PreventUpdate

from .util import *
from ..constants import Constants
from ..general_util import *


Expand Down
34 changes: 20 additions & 14 deletions callbacks/summary/callbacks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from dash import Input, Output, State, html, ctx
from dash.exceptions import PreventUpdate

from .util import *
from ..lift_over import util as lift_over_util
from ..coexpression import util as coexpression_util

Expand Down Expand Up @@ -165,25 +166,30 @@ def display_summary_submitted_input(summary_is_submitted, coexpression_is_submit
# Table-related
# =================

# @app.callback(
# Output('summary-results-table', 'data'),
# Output('summary-results-table', 'columns'),
@app.callback(
Output('summary-results-table', 'data'),
Output('summary-results-table', 'columns'),
# State('homepage-submitted-genomic-intervals', 'data'),
State('homepage-submitted-genomic-intervals', 'data'),
# Input('summary-combined-genes', 'data'),
# Input('summary-submitted-addl-genes', 'data'),
Input('summary-combined-genes', 'data'),
Input('summary-submitted-addl-genes', 'data'),
# State('homepage-is-submitted', 'data'),
# State('tfbs-is-submitted', 'data')
# )
# def display_enrichment_results(genomic_intervals, combined_genes, submitted_addl_genes,
# homepage_submitted, tfbs_is_submitted):
# # if homepage_submitted and tfbs_is_submitted:
State('homepage-is-submitted', 'data'),
State('summary-is-submitted', 'data')
)
def display_summary_results(genomic_intervals, combined_genes, submitted_addl_genes,
homepage_submitted, summary_is_submitted):
if homepage_submitted and summary_is_submitted:
summary_results_df = make_summary_table(
genomic_intervals, combined_genes)

# # return enrichment_results_df.to_dict('records'), columns, stats
columns = [{'id': x, 'name': x, 'presentation': 'markdown'}
for x in summary_results_df.columns]

# raise PreventUpdate
return summary_results_df.to_dict('records'), columns

raise PreventUpdate

@app.callback(
Output('summary-results-table', 'filter_query', allow_duplicate=True),
Expand Down
36 changes: 34 additions & 2 deletions callbacks/summary/util.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,34 @@
def get_liftover_summary():
pass
from ..lift_over.util import *
from ..general_util import *

from collections import defaultdict


def get_liftover_summary(genomic_interval, implicated_genes):
all_genes = get_all_genes(other_ref_genomes.keys(),
genomic_interval).values.tolist()

NB_IDX = 1
NB_PREFIX = 'LOC_Os'

gene_to_homologs_map = defaultdict(set)
for row in all_genes:
if row[NB_IDX].startswith(NB_PREFIX):
# Subtract 2 (i.e., subtract OGI)
for gene in row:
if gene != NULL_PLACEHOLDER:
gene_to_homologs_map[row[NB_IDX]].add(gene)

print(gene_to_homologs_map)
gene_to_count = []
for gene, homologs in gene_to_homologs_map.items():
# Subtract 2 to remove OGI and Nipponbare
gene_to_count.append([gene, len(homologs) - 2])

gene_to_count_df = pd.DataFrame(
gene_to_count, columns=['Gene', '# Homologs'])
return gene_to_count_df


def make_summary_table(genomic_interval, implicated_genes):
return get_liftover_summary(genomic_interval, implicated_genes)

0 comments on commit a05af5a

Please sign in to comment.