Skip to content

Commit

Permalink
Merge branch 'master' into GH363_skip_sets_missing_CNV_HMM
Browse files Browse the repository at this point in the history
  • Loading branch information
alimanfoo authored Aug 9, 2024
2 parents 5296e82 + 2d11916 commit 05052fa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion malariagen_data/anoph/fst.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def _fst_gwss(
random_seed,
inline_array,
chunks,
clip_min,
):
# Compute allele counts.
ac1 = self.snp_allele_counts(
Expand Down Expand Up @@ -79,7 +80,7 @@ def _fst_gwss(
with self._spinner(desc="Compute Fst"):
fst = allel.moving_hudson_fst(ac1, ac2, size=window_size)
# Sometimes Fst can be very slightly below zero, clip for simplicity.
fst = np.clip(fst, a_min=0, a_max=1)
fst = np.clip(fst, a_min=clip_min, a_max=1)
x = allel.moving_statistic(pos, statistic=np.mean, size=window_size)

results = dict(x=x, fst=fst)
Expand Down Expand Up @@ -115,6 +116,7 @@ def fst_gwss(
random_seed: base_params.random_seed = 42,
inline_array: base_params.inline_array = base_params.inline_array_default,
chunks: base_params.chunks = base_params.chunks_default,
clip_min: fst_params.clip_min = 0.0,
) -> Tuple[np.ndarray, np.ndarray]:
# Change this name if you ever change the behaviour of this function, to
# invalidate any previously cached data.
Expand All @@ -131,6 +133,7 @@ def fst_gwss(
min_cohort_size=min_cohort_size,
max_cohort_size=max_cohort_size,
random_seed=random_seed,
clip_min=clip_min,
)

try:
Expand Down Expand Up @@ -175,6 +178,7 @@ def plot_fst_gwss_track(
show: gplt_params.show = True,
x_range: Optional[gplt_params.x_range] = None,
output_backend: gplt_params.output_backend = gplt_params.output_backend_default,
clip_min: fst_params.clip_min = 0.0,
) -> gplt_params.figure:
# compute Fst
x, fst = self.fst_gwss(
Expand All @@ -188,6 +192,7 @@ def plot_fst_gwss_track(
sample_sets=sample_sets,
site_mask=site_mask,
random_seed=random_seed,
clip_min=clip_min,
)

# determine X axis range
Expand Down Expand Up @@ -277,6 +282,7 @@ def plot_fst_gwss(
genes_height: gplt_params.genes_height = gplt_params.genes_height_default,
show: gplt_params.show = True,
output_backend: gplt_params.output_backend = gplt_params.output_backend_default,
clip_min: fst_params.clip_min = 0.0,
) -> gplt_params.figure:
# gwss track
fig1 = self.plot_fst_gwss_track(
Expand All @@ -296,6 +302,7 @@ def plot_fst_gwss(
height=track_height,
show=False,
output_backend=output_backend,
clip_min=clip_min,
)

fig1.xaxis.visible = False
Expand Down
7 changes: 7 additions & 0 deletions malariagen_data/anoph/fst_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
min_cohort_size_default: base_params.min_cohort_size = 15
max_cohort_size_default: base_params.max_cohort_size = 50

clip_min: TypeAlias = Annotated[
Optional[float],
"""
Minimum value for Fst. Values below this are clipped to this value.
""",
]

df_pairwise_fst: TypeAlias = Annotated[
pd.DataFrame,
"""
Expand Down
1 change: 1 addition & 0 deletions malariagen_data/anoph/genome_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ def plot_genes(
data["top"] = data["bottom"] + 0.8

debug("tidy up missing values for presentation")
data = data.drop(["score", "phase"], axis=1)
data.fillna("", inplace=True)

debug("make a figure")
Expand Down

0 comments on commit 05052fa

Please sign in to comment.