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

Allow multiple snp_transcripts in plot_diplotype_clustering_advanced() #703

Merged
20 changes: 11 additions & 9 deletions malariagen_data/anoph/dipclust.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional, Tuple
from typing import Optional, Tuple, Sequence

import allel # type: ignore
import numpy as np
Expand All @@ -23,14 +23,16 @@
cnv_params,
)
from .snp_frq import AnophelesSnpFrequencyAnalysis
from .cnv_data import AnophelesCnvData
from .cnv_frq import AnophelesCnvFrequencyAnalysis

leehart marked this conversation as resolved.
Show resolved Hide resolved
AA_CHANGE_QUERY = (
"effect in ['NON_SYNONYMOUS_CODING', 'START_LOST', 'STOP_LOST', 'STOP_GAINED']"
)


class AnophelesDipClustAnalysis(AnophelesSnpFrequencyAnalysis, AnophelesCnvData):
class AnophelesDipClustAnalysis(
AnophelesCnvFrequencyAnalysis, AnophelesSnpFrequencyAnalysis
):
def __init__(
self,
**kwargs,
Expand Down Expand Up @@ -190,7 +192,7 @@ def plot_diplotype_clustering(
else:
return {
"figure": fig,
"dendro_sample_id_order": leaf_data["sample_id"].to_list(),
"dendro_sample_id_order": np.asarray(leaf_data["sample_id"].to_list()),
"n_snps": n_snps_used,
}

Expand Down Expand Up @@ -319,7 +321,7 @@ def _dipclust_het_bar_trace(
sample_sets: Optional[base_params.sample_sets],
sample_query: Optional[base_params.sample_query],
sample_query_options: Optional[base_params.sample_query_options],
site_mask: base_params.site_mask,
site_mask: Optional[base_params.site_mask],
cohort_size: Optional[base_params.cohort_size],
random_seed: base_params.random_seed,
color_continuous_scale: Optional[plotly_params.color_continuous_scale],
Expand Down Expand Up @@ -551,7 +553,7 @@ def _dipclust_concat_subplots(
summary="Perform diplotype clustering, annotated with heterozygosity, gene copy number and amino acid variants.",
parameters=dict(
heterozygosity="Plot heterozygosity track.",
snp_transcript="Plot amino acid variants for this transcript.",
snp_transcripts="Plot amino acid variants for these transcripts.",
cnv_region="Plot gene CNV calls for this region.",
leehart marked this conversation as resolved.
Show resolved Hide resolved
snp_filter_min_maf="Filter amino acid variants with alternate allele frequency below this threshold.",
),
Expand All @@ -561,7 +563,7 @@ def plot_diplotype_clustering_advanced(
region: base_params.regions,
heterozygosity: bool = True,
heterozygosity_colorscale: plotly_params.color_continuous_scale = "Greys",
snp_transcript: Optional[base_params.transcript] = None,
snp_transcripts: Sequence[base_params.transcript] = [],
snp_colorscale: plotly_params.color_continuous_scale = "Greys",
leehart marked this conversation as resolved.
Show resolved Hide resolved
snp_filter_min_maf: float = 0.05,
snp_query: Optional[base_params.snp_query] = AA_CHANGE_QUERY,
Expand Down Expand Up @@ -601,7 +603,7 @@ def plot_diplotype_clustering_advanced(
chunks: base_params.chunks = base_params.native_chunks,
inline_array: base_params.inline_array = base_params.inline_array_default,
):
if cohort_size and snp_transcript:
if cohort_size and snp_transcripts:
cohort_size = None
print(
"Cohort size is not supported with amino acid heatmap. Overriding cohort size to None."
Expand Down Expand Up @@ -682,7 +684,7 @@ def plot_diplotype_clustering_advanced(
figures.append(cnv_trace)
subplot_heights.append(cnv_row_height * n_cnv_genes)

if snp_transcript:
for snp_transcript in snp_transcripts:
snp_trace, n_snps_transcript = self._dipclust_snp_trace(
transcript=snp_transcript,
sample_sets=sample_sets,
Expand Down
9 changes: 0 additions & 9 deletions malariagen_data/anopheles.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not clear why there are any changes to this file included in this PR?

Copy link
Collaborator Author

@jonbrenas jonbrenas Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AnophelesDipClustAnalysis needs to inherit gene_cnv from AnophelesCnvFrequencyAnalysis (see comment below) which created a loop in the inheritance tree. Because AnophelesDipClustAnalysis is a subclass of AnophelesCnvFrequencyAnalysis and AnophelesSnpFrequencyAnalysis, when AnophelesDataResource inherits AnophelesDipClustAnalysis, it also inherits them so they don't need to be included in the list of inherited classes anymore.

Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
import plotly.graph_objects as go # type: ignore
from numpydoc_decorator import doc # type: ignore

from malariagen_data.anoph.snp_frq import (
AnophelesSnpFrequencyAnalysis,
)

from .anoph.cnv_frq import AnophelesCnvFrequencyAnalysis

from .anoph import (
aim_params,
Expand All @@ -31,7 +26,6 @@
)
from .anoph.aim_data import AnophelesAimData
from .anoph.base import AnophelesBase
from .anoph.cnv_data import AnophelesCnvData
from .anoph.genome_features import AnophelesGenomeFeaturesData
from .anoph.genome_sequence import AnophelesGenomeSequenceData
from .anoph.hap_data import AnophelesHapData, hap_params
Expand Down Expand Up @@ -87,8 +81,6 @@ class AnophelesDataResource(
AnophelesH12Analysis,
AnophelesG123Analysis,
AnophelesFstAnalysis,
AnophelesCnvFrequencyAnalysis,
AnophelesSnpFrequencyAnalysis,
AnophelesHapFrequencyAnalysis,
AnophelesDistanceAnalysis,
AnophelesPca,
Expand All @@ -97,7 +89,6 @@ class AnophelesDataResource(
AnophelesAimData,
AnophelesHapData,
AnophelesSnpData,
AnophelesCnvData,
AnophelesSampleMetadata,
AnophelesGenomeFeaturesData,
AnophelesGenomeSequenceData,
Expand Down
Loading
Loading