Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3be6e9c
Claude suggestions for pulling VCFs from zarr datasets
Sep 25, 2026
73f547f
claude suggestions for BAM-replacement, not really possible for data …
Sep 28, 2026
b2651bc
don't allow None for sample_sets or sample_query in to_vcf
Sep 28, 2026
837260d
remove optional from sample_Sets and sample_query
Sep 28, 2026
8d0d336
claude fixes for tests making sample_sets and sample_Wuery non-optional
Sep 28, 2026
a302a13
updated doctring re sample_sets and sample_query
Sep 28, 2026
bc181ea
claude draft input validation
Sep 28, 2026
317c2b0
updated docstring to specify only one sample can be used- can revisit…
Sep 28, 2026
cf3e6b6
claude suggested changes to batch call rather than separate for each …
Sep 29, 2026
50d620e
removed the numpy array that is edited through a loop- i.e. not a vec…
Sep 29, 2026
6802977
fix field order to hopefully enable analysis of outputs from bcftools
Sep 29, 2026
6428c98
more format fixing
Sep 29, 2026
b7ec7c7
more twiddling with header due to bcftools warning, still looking int…
Sep 29, 2026
aeab100
Claude draft to output only heterozygous sites in VCF
Sep 29, 2026
050415a
Claude draft of bug fix with removing homozygous sites
Sep 30, 2026
8e4b62e
still trying to get to_vcf correct Claude thinks its something to to …
Sep 30, 2026
417ddb7
removing Claudes allele remapping to see if that improves results
Sep 30, 2026
b4876a6
claudes last attempt, problems persisted, going to revert to a better…
Sep 30, 2026
67f4ed6
removed leftover bits from to_vcf_cnv
Sep 30, 2026
5aabdfd
try simple if statement to exclude homozygous sites
Sep 30, 2026
b23e4b6
fixed indentation to only output heterozygous sites
Sep 30, 2026
4203d04
reverted igv to original version and removed to_coverage as bam urls …
Oct 1, 2026
c22b1b5
removed OrderedDict
Oct 1, 2026
f2e074f
trying pysam so bgzf compression can be used so index needed for IGV …
Oct 1, 2026
e126912
wired through to IGV, checked with notebook
Oct 1, 2026
04f6c83
fixed type annotaitons and moved homozygous check
Oct 5, 2026
b9db52d
removed the to_vcf_cnf draft for now
Oct 5, 2026
03f8fb3
getting ready for PR, removing unused functions that were drafter pre…
Oct 5, 2026
f96236f
make site_masks=None default, updated doctring
Oct 5, 2026
209411a
merged newest changes from master
Oct 5, 2026
b018131
remove pysam as with it, either Windows install of malariagen_data wo…
Oct 6, 2026
ba281e1
slight changes after running pytest with coverage
Oct 6, 2026
96f0590
added some extra tests
Oct 6, 2026
a18921d
ran pre-commit run --all-files
Oct 6, 2026
a0cf6b8
think i fixed tests failing under CI
Oct 6, 2026
4e20404
limit region size to ensure it will load in IGV
Oct 7, 2026
98ad89a
fixed vcf paths for jupyter lab
Oct 7, 2026
debaed8
shown 5bp region with SNPs, and same region with original VCF, plus s…
Oct 7, 2026
5791196
hopefully restored notebooks to previous state and commented nbstripo…
Oct 13, 2026
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
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ repos:
- "--fix"
# Run the formatter.
- id: ruff-format
# - repo: https://github.com/kynan/nbstripout
# rev: 0.9.1
# hooks:
# # Strip outputs, execution counts and volatile metadata (kernel
# # display name, language version — these change depending on
# # which local environment a notebook was last run under, not on
# # any real edit) from notebooks before they're committed, so
# # `git diff` only shows real cell-source changes.
# - id: nbstripout
# args:
# - "--extra-keys"
# - "metadata.kernelspec.display_name metadata.language_info.version"
54 changes: 41 additions & 13 deletions malariagen_data/anoph/igv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from typing import List, Optional
import base64
import os
from typing import List, Optional, Union

import igv_notebook # type: ignore
from numpydoc_decorator import doc # type: ignore
Expand All @@ -8,6 +10,15 @@
from .snp_data import AnophelesSnpData


def _vcf_data_uri(path: Union[str, os.PathLike]) -> str:
"""Read a local VCF file and return it as a data URI."""
with open(path, "rb") as f:
data = f.read()
is_gzip = data[:2] == b"\x1f\x8b"
media_type = "application/gzip" if is_gzip else "text/plain"
return f"data:{media_type};base64,{base64.b64encode(data).decode()}"


class AnophelesIgv(
AnophelesSnpData,
):
Expand Down Expand Up @@ -82,6 +93,7 @@ def _igv_view_alignments_tracks(
region: Region,
sample: str,
visibility_window: int = 20_000,
snp_vcf_path: Optional[Union[str, os.PathLike]] = None,
):
# Look up sample set for sample.
try:
Expand All @@ -99,7 +111,6 @@ def _igv_view_alignments_tracks(
# Locate record for sample.
cat_rec = df_cat.set_index("sample_id").loc[sample]
bam_url = cat_rec["alignments_bam"]
vcf_url = cat_rec["snp_genotypes_vcf"]

# Set up site filters tracks.
contig = region.contig
Expand All @@ -109,17 +120,25 @@ def _igv_view_alignments_tracks(
)

# Add SNPs track.
tracks.append(
{
"name": "SNPs",
"url": vcf_url,
"indexURL": f"{vcf_url}.tbi",
"format": "vcf",
"type": "variant",
"visibilityWindow": visibility_window, # bp
"height": 50,
}
)
snp_track = {
"name": "SNPs",
"format": "vcf",
"type": "variant",
"visibilityWindow": visibility_window, # bp
"height": 50,
}
if snp_vcf_path is not None:
# Embed the local VCF, e.g. from snp_calls_to_vcf(), in the track
# as a data URI, so it doesn't need to be served over HTTP (which
# isn't possible in all notebook environments, e.g. VS Code). It
# has no index, so IGV loads it in full.
snp_track["url"] = _vcf_data_uri(snp_vcf_path)
snp_track["indexed"] = False
else:
vcf_url = cat_rec["snp_genotypes_vcf"]
snp_track["url"] = vcf_url
snp_track["indexURL"] = f"{vcf_url}.tbi"
tracks.append(snp_track)

# Add alignments track.
tracks.append(
Expand Down Expand Up @@ -183,6 +202,13 @@ def igv(
visible.
""",
init="If True, call igv_notebook.init().",
snp_vcf_path="""
Optional path to a local VCF file (`.vcf` or `.vcf.gz`), e.g. one
written by `snp_calls_to_vcf()`, to show as the SNPs track. The
file is embedded in the notebook and loaded in full, so it should
be small (e.g. a single sample over a region). If omitted, use
the catalog VCF.
""",
),
)
def view_alignments(
Expand All @@ -191,6 +217,7 @@ def view_alignments(
sample: str,
visibility_window: int = 20_000,
init: bool = True,
snp_vcf_path: Optional[Union[str, os.PathLike]] = None,
):
# Parse region.
region_prepped: Region = _parse_single_region(self, region)
Expand All @@ -201,6 +228,7 @@ def view_alignments(
region=region_prepped,
sample=sample,
visibility_window=visibility_window,
snp_vcf_path=snp_vcf_path,
)

# Create IGV browser.
Expand Down
Loading
Loading