def filter_candidates(self, candidates,
                          comp_het_counter=[0]):
        """
        Refine candidate heterozygote pairs based on user's filters.
        """
        args = self.args
        # once we are in here, we know that we have a single gene.

        requested_fams = None if args.families is None else set(args.families.split(","))
        for idx, comp_het in enumerate(candidates):
            comp_het_counter[0] += 1

            for fam_ch in candidates[comp_het]:
                if fam_ch['priority'] > args.max_priority:
                    continue
                # when to use affected_unphased?
                for subject in (fam_ch['candidates'] if args.pattern_only else fam_ch['affected_phased'] + fam_ch['affected_unphased']):
                    family_id = subject.family_id

                    if requested_fams is not None and not family_id in requested_fams:
                        continue

                    ch_id = str(comp_het_counter[0])
                    cid = "%s_%d_%d" % (ch_id, comp_het[0].row['variant_id'],
                                        comp_het[1].row['variant_id'])
                    for i in (0, 1):
                        pdict = comp_het[i].row.print_fields.copy()
                        # set these to keep order in the ordered dict.
                        pdict["family_id"] = family_id
                        pdict["family_members"] = None
                        pdict["family_genotypes"] = None
                        pdict["samples"] = None
                        pdict["family_count"] = None
                        pdict["comp_het_id"] = cid
                        pdict['priority'] = fam_ch['priority']

                        comp_het[i].row.print_fields = pdict
                        # TODO: check this yield.
                        yield comp_het[i].row
dataset/ETHPy150Open arq5x/gemini/gemini/gim.py/CompoundHet.filter_candidates/original