Skip to content
Open
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
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

1 change: 1 addition & 0 deletions docs/source/Ag3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ Inversion karyotypes
:toctree: generated/

karyotype
load_inversion_tags

Phenotype data access
---------------------
Expand Down
1 change: 0 additions & 1 deletion malariagen_data/adar1.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ def __init__(
tqdm_class=tqdm_class,
taxon_colors=TAXON_COLORS,
virtual_contigs=None,
inversion_tag_path=None,
unrestricted_use_only=unrestricted_use_only,
surveillance_use_only=surveillance_use_only,
)
Expand Down
1 change: 0 additions & 1 deletion malariagen_data/adir1.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ def __init__(
tqdm_class=tqdm_class,
taxon_colors=TAXON_COLORS,
virtual_contigs=None,
inversion_tag_path=None,
unrestricted_use_only=unrestricted_use_only,
surveillance_use_only=surveillance_use_only,
)
Expand Down
1 change: 0 additions & 1 deletion malariagen_data/af1.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ def __init__(
tqdm_class=tqdm_class,
taxon_colors=TAXON_COLORS,
virtual_contigs=None,
inversion_tag_path=None,
unrestricted_use_only=unrestricted_use_only,
surveillance_use_only=surveillance_use_only,
)
Expand Down
2 changes: 0 additions & 2 deletions malariagen_data/ag3.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
GENE_NAMES = {
"AGAP004707": "Vgsc/para",
}
INVERSION_TAG_PATH = "karyotype_tag_snps.csv"


def _setup_aim_palettes():
Expand Down Expand Up @@ -213,7 +212,6 @@ def __init__(
aim_species_colors=AIM_SPECIES_COLORS,
virtual_contigs=VIRTUAL_CONTIGS,
gene_names=GENE_NAMES,
inversion_tag_path=INVERSION_TAG_PATH,
unrestricted_use_only=unrestricted_use_only,
surveillance_use_only=surveillance_use_only,
)
Expand Down
1 change: 0 additions & 1 deletion malariagen_data/amin1.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ def __init__(
tqdm_class=tqdm_class,
taxon_colors=TAXON_COLORS,
virtual_contigs=None,
inversion_tag_path=None,
unrestricted_use_only=unrestricted_use_only,
surveillance_use_only=surveillance_use_only,
)
Expand Down
50 changes: 36 additions & 14 deletions malariagen_data/anoph/karyotype.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,59 @@ def _karyotype_tags_n_alt(gt, alts, inversion_alts):
class AnophelesKaryotypeAnalysis(AnophelesSnpData):
def __init__(
self,
inversion_tag_path: Optional[str] = None,
karyotype_analysis: Optional[str] = None,
**kwargs,
):
# N.B., this class is designed to work cooperatively, and
# so it's important that any remaining parameters are passed
# to the superclass constructor.
super().__init__(**kwargs)

self._inversion_tag_path = inversion_tag_path
# If provided, this analysis version will override the
# default value provided in the release configuration.
self._karyotype_analysis_override = karyotype_analysis

@property
def _karyotype_analysis(self) -> Optional[str]:
if self._karyotype_analysis_override:
return self._karyotype_analysis_override
else:
# N.B., this will return None if the key is not present in the
# config.
return self.config.get("DEFAULT_KARYOTYPE_ANALYSIS")

def _require_karyotype_analysis(self):
if not self._karyotype_analysis:
raise NotImplementedError(
"Inversion karyotype analysis is not available for this data resource."
)

@_check_types
@doc(
summary="Load tag SNPs for a given inversion.",
)
def load_inversion_tags(self, inversion: inversion_param) -> pd.DataFrame:
# needs to be modified depending on where we are hosting
import importlib.resources
from .. import resources
self._require_karyotype_analysis()

if self._inversion_tag_path is None:
raise NotImplementedError(
"No inversion tags are available for this data resource."
path = (
f"{self._base_path}/{self._major_version_path}"
f"/snp_karyotype/{self._karyotype_analysis}/karyotype_tag_snps.csv"
)
with self._fs.open(path) as f:
df_tag_snps = pd.read_csv(f, sep=",")

# Validate inversion name.
available = sorted(df_tag_snps["inversion"].unique())
if inversion not in available:
raise ValueError(
f"Unknown inversion '{inversion}'. Available inversions: {available}"
)
else:
with importlib.resources.path(resources, self._inversion_tag_path) as path:
df_tag_snps = pd.read_csv(path, sep=",")
return df_tag_snps.loc[df_tag_snps["inversion"] == inversion].reset_index()

return df_tag_snps.query(f"inversion == '{inversion}'").reset_index(drop=True)

@_check_types
@doc(
summary="Infer karyotype from tag SNPs for a given inversion in Ag.",
summary="Infer karyotype from tag SNPs for a given inversion.",
)
def karyotype(
self,
Expand All @@ -79,7 +101,7 @@ def karyotype(
df_tagsnps = self.load_inversion_tags(inversion=inversion)
inversion_pos = df_tagsnps["position"]
inversion_alts = df_tagsnps["alt_allele"]
contig = inversion[0:2]
contig = df_tagsnps["contig"].iloc[0]

# get snp calls for inversion region
start, end = np.min(inversion_pos), np.max(inversion_pos)
Expand Down
4 changes: 2 additions & 2 deletions malariagen_data/anopheles.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def __init__(
aim_species_colors: Optional[Mapping[str, str]] = None,
virtual_contigs: Optional[Mapping[str, Sequence[str]]] = None,
gene_names: Optional[Mapping[str, str]] = None,
inversion_tag_path: Optional[str] = None,
karyotype_analysis: Optional[str] = None,
unrestricted_use_only: Optional[bool] = None,
surveillance_use_only: Optional[bool] = None,
):
Expand Down Expand Up @@ -180,7 +180,7 @@ def __init__(
aim_species_colors=aim_species_colors,
virtual_contigs=virtual_contigs,
gene_names=gene_names,
inversion_tag_path=inversion_tag_path,
karyotype_analysis=karyotype_analysis,
unrestricted_use_only=unrestricted_use_only,
surveillance_use_only=surveillance_use_only,
)
Expand Down
Loading
Loading