예제 #1
0
 def _aggregate(self, covgs, threshold=5):
     del_phylo_groups = []
     for phylo_group, covg_dict in covgs.items():
         percent_coverage = covg_dict["percent_coverage"]
         length = covg_dict["length"]
         bases_covered = self._bases_covered(percent_coverage, length)
         total_bases = covg_dict["total_bases"]
         total_percent_covered = round(bases_covered / total_bases, 3)
         _median = covg_dict.get("median", [0])
         minimum_percentage_coverage_required = percent_coverage_from_expected_coverage(
             self.expected_depth) * self.threshold.get(
                 phylo_group, DEFAULT_THRESHOLD)
         if total_percent_covered < minimum_percentage_coverage_required or median(
                 _median) < 0.1 * self.expected_depth:
             # Remove low coverage nodes
             _index = [
                 i for i, d in enumerate(_median)
                 if d > 0.1 * self.expected_depth
             ]
             percent_coverage = [percent_coverage[i] for i in _index]
             length = [length[i] for i in _index]
             bases_covered = self._bases_covered(percent_coverage, length)
             _median = [_median[i] for i in _index]
             total_percent_covered = round(bases_covered / total_bases, 3)
         if total_percent_covered > threshold:
             if phylo_group == "Mycobacterium_llatzerense":  # Mistake in panel
                 phylo_group = "Mycobacterium_mucogenicum"
             covgs[phylo_group] = {
                 "percent_coverage": total_percent_covered,
                 "median_depth": median(_median)
             }
         else:
             del_phylo_groups.append(phylo_group)
     for phylo_group in del_phylo_groups:
         del covgs[phylo_group]
예제 #2
0
 def estimate_depth(self):
     depth = []
     for variant_covg in self.variant_covgs.values():
         if variant_covg.reference_coverage.median_depth > 0:
             depth.append(variant_covg.reference_coverage.median_depth)
     for spcs in self.gene_presence_covgs.values():
         __median_depth = median(
             [spc.median_depth for spc in spcs.values()])
         if __median_depth > 0:
             depth.append(__median_depth)
     _median = median(depth)
     if _median < 1:
         return 1
     else:
         return _median
예제 #3
0
 def calc_expected_depth(self):
     # Get all of the panels with % coverage > 30
     _median = []
     for phylo_group, coverage_dict in self.phylo_group_covgs.items():
         _median.extend(coverage_dict["median"])
     if _median:
         return median(_median)
     else:
         return 0