Skip to content

Commit

Permalink
PSW-86: Add option to provide a snpobject to convert_to_snp_level
Browse files Browse the repository at this point in the history
  • Loading branch information
miriambt committed Dec 13, 2024
1 parent 40ab5bb commit 3be35f3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions snputils/ancestry/genobj/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ def filter_samples(

def convert_to_snp_level(
self,
snpobject: Optional['SNPObject'] = None,
variants_chrom: Optional[np.ndarray] = None,
variants_pos: Optional[np.ndarray] = None,
variants_ref: Optional[np.ndarray] = None,
Expand All @@ -513,7 +514,11 @@ def convert_to_snp_level(
SNPs uniformly across the start and end positions of each genomic window. Otherwise, the provided SNP
coordinates are used to assign ancestry values based on their respective windows.
If an `SNPObject` is provided, its attributes are used unless explicitly overridden by the function arguments.
Args:
snpobject (SNPObject, optional):
An existing `SNPObject` to extract SNP attributes from.
variants_chrom (array of shape (n_snps,), optional):
An array containing the chromosome for each SNP.
variants_pos (array of shape (n_snps,), optional):
Expand All @@ -533,6 +538,16 @@ def convert_to_snp_level(
SNPObject:
A `SNPObject` containing SNP-level ancestry data, along with optional metadata.
"""
# Extract attributes from SNPObject if provided
if snpobject is not None:
variants_chrom = variants_chrom if variants_chrom is not None else snpobject.variants_chrom
variants_pos = variants_pos if variants_pos is not None else snpobject.variants_pos
variants_ref = variants_ref if variants_ref is not None else snpobject.variants_ref
variants_alt = variants_alt if variants_alt is not None else snpobject.variants_alt
variants_filter_pass = variants_filter_pass if variants_filter_pass is not None else snpobject.variants_filter_pass
variants_id = variants_id if variants_id is not None else snpobject.variants_id
variants_qual = variants_qual if variants_qual is not None else snpobject.variants_qual

n_samples = self.n_samples

# Reshape lai to (n_windows, n_samples, 2)
Expand Down

0 comments on commit 3be35f3

Please sign in to comment.