Skip to content

Commit

Permalink
Bug fixing of phasing default values, now uses HP and PS
Browse files Browse the repository at this point in the history
  • Loading branch information
lfpaulin committed Jul 5, 2024
1 parent cde3138 commit 1c2b121
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/sniffles/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ def __init__(self, *args, **kwargs):

# Genotyping
self.genotype_format = "GT:GQ:DR:DV"
self.genotype_none = (".", ".", 0, 0, 0, None)
self.genotype_null = (0, 0, 0, 0, 0, None)
self.genotype_none = (".", ".", 0, 0, 0, (None, None))
self.genotype_null = (0, 0, 0, 0, 0, (None, None))
self.genotype_min_z_score = 5
if self.genotype_ploidy != 2:
util.fatal_error("Currently only --genotype-ploidy 2 is supported")
Expand Down
2 changes: 1 addition & 1 deletion src/sniffles/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def execute(self) -> Optional[GenotypeResult]:
coverage = round(sum(coverage_list) / len(coverage_list))
svcall.genotypes = {}
if coverage > 0:
svcall.genotypes[0] = (0, 0, 0, coverage, 0, None)
svcall.genotypes[0] = (0, 0, 0, coverage, 0, (None, None))
else:
svcall.genotypes[0] = config.genotype_none

Expand Down
4 changes: 2 additions & 2 deletions src/sniffles/postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,5 +488,5 @@ def phase_sv(svcall, config):
ps_filter = "PASS"

svcall.set_info("PHASE", f"{hp},{ps},{hp_support},{ps_support},{hp_filter},{ps_filter}")
return (config.phase_identifiers.index(hp) if hp in config.phase_identifiers else None if hp_filter == "PASS" else \
None, ps if "PASS" == ps_filter else None)
return (config.phase_identifiers.index(hp) if hp in config.phase_identifiers else None if hp_filter == "PASS" else
None, ps if "PASS" == ps_filter else None)
6 changes: 3 additions & 3 deletions src/sniffles/sv.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def call(self, config, task) -> Optional[SVCall]:
rnames.extend(cand.rnames)

if 0 not in cand.genotypes:
cand.genotypes[0] = (".", ".", 0, 0, cand.support, None)
cand.genotypes[0] = (".", ".", 0, 0, cand.support, (None, None))
if cand.sample_internal_id in genotypes:
# Intra-sample merging
a, b, gt_qual, dr, dv, ps = cand.genotypes[0]
Expand All @@ -231,9 +231,9 @@ def call(self, config, task) -> Optional[SVCall]:
continue
coverage = self.coverages_nonincluded[sample_internal_id]
if coverage >= config.combine_null_min_coverage:
genotypes[sample_internal_id] = (0, 0, 0, coverage, 0, None, "NULL")
genotypes[sample_internal_id] = (0, 0, 0, coverage, 0, (None, None), "NULL")
else:
genotypes[sample_internal_id] = (".", ".", 0, coverage, 0, None, "NULL")
genotypes[sample_internal_id] = (".", ".", 0, coverage, 0, (None, None), "NULL")

if config.combine_consensus:
genotypes_consensus = {}
Expand Down
20 changes: 17 additions & 3 deletions src/sniffles/vcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from sniffles import sv
from sniffles import util
from sniffles.config import SnifflesConfig


log = logging.getLogger(__name__)
Expand All @@ -29,6 +30,19 @@ def format_info(k, v):
return f"{k}={v}"


def unpack_phase(phase) -> tuple:
try:
hp_i, ps = phase
except TypeError:
if phase is None:
log.warning(f"Single 'None'-valued phase: {phase}")
hp_i, ps = None, None
else:
log.warning(f"Single not 'None'-valued phase: {phase}")
hp_i, ps = phase, phase
return hp_i, ps


def format_genotype(gt):
"""
hp_i is the index of the haplotype in config.phase_identifiers:
Expand All @@ -37,7 +51,7 @@ def format_genotype(gt):
"""
if len(gt) == 6:
a, b, qual, dr, dv, phase = gt
hp_i, ps = phase
hp_i, ps = unpack_phase(phase)
if hp_i is not None and (a, b) == (0, 1):
gt_sep = "|"
if hp_i == 0:
Expand All @@ -47,7 +61,7 @@ def format_genotype(gt):
return f"{a}{gt_sep}{b}:{qual}:{dr}:{dv}" if ps is None else f"{a}{gt_sep}{b}:{qual}:{dr}:{dv}:{ps}"
else:
a, b, qual, dr, dv, phase, svid = gt
hp_i, ps = phase
hp_i, ps = unpack_phase(phase)
if hp_i is not None and (a, b) == (0, 1):
gt_sep = "|"
if hp_i == 0:
Expand All @@ -59,7 +73,7 @@ def format_genotype(gt):


class VCF:
def __init__(self, config, handle):
def __init__(self, config: SnifflesConfig, handle):
self.config = config
self.handle = handle
self.call_count = 0
Expand Down

0 comments on commit 1c2b121

Please sign in to comment.