Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Including number of samples in mutations in lineage plot #184

Merged
merged 17 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions dashboard/utils/var_needle_mutation_graph_by_lineage.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,20 @@ def get_variant_data_from_lineages(graphic_name=None, lineage=None, chromosome=N
# lineage_fieldID__property_name__iexact="lineage_name"
# ).exists():
# return None

all_lineages = core.models.LineageValues.objects.filter(
lineage_fieldID__property_name__iexact="lineage_name"
).values_list("value", flat=True)
if lineage is None:
lineage = (
core.models.LineageValues.objects.filter(
lineage_fieldID__property_name__iexact="lineage_name"
)
.values_list("value", flat=True)
.first()
)

lineage = all_lineages.first()
mdata = json_data[lineage]
n_samples = len([x for x in all_lineages if x == lineage])

return mdata, lineage
return mdata, lineage, n_samples


def create_needle_plot_graph_mutation_by_lineage(lineage_list, lineage, mdata):
def create_needle_plot_graph_mutation_by_lineage(
lineage_list, lineage, mdata, n_samples
):
options = []
for lin in lineage_list:
options.append({"label": lin, "value": lin})
Expand Down Expand Up @@ -80,10 +78,18 @@ def create_needle_plot_graph_mutation_by_lineage(lineage_list, lineage, mdata):
clearable=False,
multi=False,
value=lineage,
style={"width": "150px"},
style={"width": "150px", "margin-right": "30px"},
),
]
),
html.Div(
children=[
dcc.Markdown(
id="samples_markdown",
children=f"Showing mutations for {n_samples} samples",
)
]
),
],
style={
"display": "flex",
Expand All @@ -98,7 +104,7 @@ def create_needle_plot_graph_mutation_by_lineage(lineage_list, lineage, mdata):
mutationData=mdata,
rangeSlider=True,
xlabel="Genome Position",
ylabel="Population Allele Frequency ",
ylabel="Population Allele Frequency samples",
domainStyle={
# "textangle": "45",
"displayMinorDomains": False,
Expand All @@ -111,15 +117,17 @@ def create_needle_plot_graph_mutation_by_lineage(lineage_list, lineage, mdata):
@app.callback(
Output("dashbio-needleplot", "mutationData"),
Output("dashbio-needleplot", "lineage"),
Output("samples_markdown", "children"),
Input("needleplot-select-lineage", "value"),
)
def update_sample(selected_lineage):
mdata, lineage = get_variant_data_from_lineages(
mdata, lineage, n_samples = get_variant_data_from_lineages(
graphic_name="variations_per_lineage",
lineage=selected_lineage,
chromosome=None,
)
return mdata, lineage
markdown_text = f"Showing mutations for {n_samples} samples"
return mdata, lineage, markdown_text

@app.callback(
Output("dashbio-needleplot", "rangeSlider"),
Expand Down
4 changes: 2 additions & 2 deletions dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def mutations_in_lineage(request):
# mutations in lineages by lineage
def_chrom = core.utils.variants.get_default_chromosome()
lineages_list = core.utils.lineage.get_lineages_list()
mdata, lineage = (
mdata, lineage, n_samples = (
dashboard.utils.var_needle_mutation_graph_by_lineage.get_variant_data_from_lineages(
graphic_name="variations_per_lineage", lineage=None, chromosome=def_chrom
)
Expand All @@ -45,7 +45,7 @@ def mutations_in_lineage(request):
{"ERROR": dashboard.dashboard_config.ERROR_NO_LINEAGES_ARE_DEFINED_YET},
)
dashboard.utils.var_needle_mutation_graph_by_lineage.create_needle_plot_graph_mutation_by_lineage(
lineages_list, lineage, mdata
lineages_list, lineage, mdata, n_samples
)
return render(
request,
Expand Down
Loading