def create_het_distribution( seqs, distrib_fhand=None, plot_fhand=None, summary_fhand=None, group_kind=None, groups=None, ploidy=2 ): """It creates the distribution of the heterozygosity (not takes in account ref allele)""" title = "heterozygosity" if groups and group_kind: title = "heterozygosity (%s: %s)" % (group_kind, ",".join(groups)) hets = CachedArray("f") for seq in seqs: for snv in seq.get_features("snv"): if not group_kind and "heterozygosity" in snv.qualifiers: het = snv.qualifiers["heterozygosity"] else: het = calculate_heterozygosity(snv, ploidy, group_kind=group_kind, groups=groups) if het is not None: hets.append(het) if list(hets): create_distribution( hets, labels={"title": title}, distrib_fhand=distrib_fhand, bins=None, plot_fhand=plot_fhand, range_=None, summary_fhand=summary_fhand, calculate_freqs=False, remove_outliers=False, )
def calculate_hets_group(seqs, groups=None, group_kind=None, ploidy=2): 'It calculates the snv heterozygosity of a given group' het_profile = {} for seq in seqs: for snv in seq.get_features('snv'): het = calculate_heterozygosity(snv, ploidy, group_kind=group_kind, groups=groups) if het is not None: location = snv.location.start.position seq_name = seq.name if seq_name not in het_profile: het_profile[seq_name] = [] het_profile[seq_name].append((location, het)) return het_profile