Skip to content

Commit

Permalink
added mt molecules and percent (#77)
Browse files Browse the repository at this point in the history
* added mt molecules and percent

* added mt molecules and percent

* Update src/sctools/metrics/aggregator.py

Co-authored-by: Jessica Way <[email protected]>

* Update src/sctools/metrics/aggregator.py

Co-authored-by: Jessica Way <[email protected]>

Co-authored-by: Jessica Way <[email protected]>
  • Loading branch information
kishorikonwar and jessicaway authored May 21, 2020
1 parent 9e198aa commit 0a8c4df
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/sctools/metrics/aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@ class CellMetrics(MetricAggregator):
The number of genes that are observed by more than one read in this cell
n_mitochondrial_genes: int
The number of mitochondrial genes detected by this cell
n_mitochondrial_molecules: int
The number of molecules from mitochondrial genes detected for this cell
pct_mitochondrial_molecules: int
The percentage of molecules from mitochondrial genes detected for this cell
"""

Expand Down Expand Up @@ -453,6 +457,8 @@ def __init__(self):
self.n_genes: int = None
self.genes_detected_multiple_observations: int = None
self.n_mitochondrial_genes: int = None
self.n_mitochondrial_molecules: int = None
self.pct_mitochondrial_molecules: float = None

def finalize(self, mitochondrial_genes=set()):
super().finalize()
Expand All @@ -471,6 +477,18 @@ def finalize(self, mitochondrial_genes=set()):
1 for g in self._genes_histogram.keys() if g in mitochondrial_genes
)

self.n_mitochondrial_molecules: int = sum(
c for g, c in self._genes_histogram.items() if g in mitochondrial_genes
)

if self.n_mitochondrial_molecules:
tot_molecules = sum(self._genes_histogram.values())
self.pct_mitochondrial_molecules = (
self.n_mitochondrial_molecules / tot_molecules * 100.0
)
else:
self.pct_mitochondrial_molecules = 0.00

def parse_extra_fields(
self, tags: Sequence[str], record: pysam.AlignedSegment
) -> None:
Expand Down

0 comments on commit 0a8c4df

Please sign in to comment.