Commit 6b5035f7 authored by Sander Bollen's avatar Sander Bollen

some formatting and numpy over math

parent a3319f09
Pipeline #2504 passed with stage
in 1 minute and 27 seconds
...@@ -7,7 +7,6 @@ vtools.gcoverage ...@@ -7,7 +7,6 @@ vtools.gcoverage
:license: MIT :license: MIT
""" """
import math
import cyvcf2 import cyvcf2
import numpy as np import numpy as np
...@@ -59,11 +58,13 @@ def gq_for_gvcf_record(record: cyvcf2.Variant, maxlen: int = 15000) -> List[int] ...@@ -59,11 +58,13 @@ def gq_for_gvcf_record(record: cyvcf2.Variant, maxlen: int = 15000) -> List[int]
return [gq]*maxlen return [gq]*maxlen
# Credit: def qualmean(quals: np.ndarray) -> float:
# https://gigabaseorgigabyte.wordpress.com/2017/06/26/averaging-basecall-quality-scores-the-right-way/ """
# https://git.lumc.nl/klinische-genetica/capture-lumc/vtools/issues/3 Credit:
def qualmean(quals): https://gigabaseorgigabyte.wordpress.com/2017/06/26/averaging-basecall-quality-scores-the-right-way/
return -10*math.log(sum([10**(q/-10) for q in quals]) / len(quals), 10) https://git.lumc.nl/klinische-genetica/capture-lumc/vtools/issues/3
"""
return -10*np.log10(np.mean(np.power(10, quals/-10)))
class CovStats(object): class CovStats(object):
...@@ -73,7 +74,7 @@ class CovStats(object): ...@@ -73,7 +74,7 @@ class CovStats(object):
self.__gq_qualities = None self.__gq_qualities = None
@property @property
def coverages(self) -> List[int]: def coverages(self) -> np.ndarray:
if self.__coverages is None: if self.__coverages is None:
self.__coverages = np.fromiter( self.__coverages = np.fromiter(
chain.from_iterable( chain.from_iterable(
...@@ -84,7 +85,7 @@ class CovStats(object): ...@@ -84,7 +85,7 @@ class CovStats(object):
return self.__coverages return self.__coverages
@property @property
def gq_qualities(self) -> List[int]: def gq_qualities(self) -> np.ndarray:
if self.__gq_qualities is None: if self.__gq_qualities is None:
self.__gq_qualities = np.fromiter( self.__gq_qualities = np.fromiter(
chain.from_iterable( chain.from_iterable(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment