def report_candidates(self):
        args = self.args
        req_cols = ['gt_types', 'gts']
        if args.min_sample_depth and self.args.min_sample_depth > 0:
            req_cols.append('gt_depths')
        if getattr(args, 'gt_phred_ll', False) or self.model == "mendel_violations":

            for col in ['gt_phred_ll_homref', 'gt_phred_ll_het',
                        'gt_phred_ll_homalt']:
                if col in self.gt_cols:
                    req_cols.append(col)
        if args.min_gq != 0 and 'gt_quals' in self.gt_cols:
            req_cols.append('gt_quals')

        is_mendel = False

        if any(isinstance(m, dict) for m in self.family_masks):
            assert self.model == "mendel_violations"
            is_mendel = True
            masks = []
            # mdict contains filter for 'de novo', 'LOH', etc.
            for mdict in self.family_masks:
                if isinstance(mdict, basestring):
                    masks.append(mdict)
                    continue
                m = {}
                for k, mask in mdict.items():
                    m[k] = 'False' if mask is None or mask.strip("(").strip(")") == 'False' else mask
                    if m[k] != 'False':
                        m[k] = compiler.compile(m[k], m[k], 'eval')

                masks.append(m)
        else:
            # 1 mask per family
            masks = ['False' if m is None or m is False or m.strip('(').strip(')') in
                     ('empty', 'False') else m for m in self.family_masks]
            masks = [compiler.compile(m, m, 'eval') if m != 'False' else 'False' for m in masks]

        requested_fams = None if not args.families else set(args.families.split(","))

        for gene, li in self.candidates():

            kindreds = set()
            to_yield = []

            seen = set()
            for row in li:
                # comp_het sets a family_id that met the filter. so we use it
                # for this check instead of checking all families.
                cur_fam = row.print_fields.get('family_id')
                for col in self.added:
                    try:
                        del row.print_fields[col]
                    except ValueError:
                        pass

                cols = dict((col, row[col]) for col in req_cols)
                fams_to_test = enumerate(self.families) if cur_fam is None \
                                else [(i, f) for i, f in enumerate(self.families) if f.family_id == cur_fam]
                # limit to families requested by the user.
                if requested_fams is not None:
                    fams_to_test = ((i, f) for i, f in fams_to_test if f.family_id in requested_fams)

                fams, models = [], []
                if is_mendel:
                    for i, f in fams_to_test:
                        mask_dict = masks[i]
                        for inh_model, mask in mask_dict.items():
                            if masks[i] != 'False' and eval(mask, cols):
                                if f in fams:
                                    models[-1] += ";" + inh_model
                                else:
                                    fams.append(f)
                                    models.append(inh_model)
                else:
                    fams = [f for i, f in fams_to_test
                            if masks[i] != 'False' and eval(masks[i], cols)]
                kindreds.update(f.family_id for f in fams)

                for fam in fams:
                    pdict = row.print_fields.copy()
                    kindreds.add(fam.family_id)
                    # get a *shallow* copy of the ordered dict.
                    # populate with the fields required by the tools.
                    pdict["family_id"] = fam.family_id
                    pdict["family_members"] = ",".join("%s" % m for m in fam.subjects)
                    pdict["family_genotypes"] = ",".join(eval(str(s), cols) for s in fam.gts)
                    pdict["samples"] = ",".join(x.name or x.sample_id for x in fam.subjects if x.affected)
                    pdict["family_count"] = len(fams)
                    if is_mendel:
                        pdict["violation"] = ";".join(models)
                        # TODO: check args, may need fam.subjects_with_parent
                        pdict['samples'] = fam.affecteds_with_parent if args.only_affected else fam.samples_with_parent
                        vs = []

                        if all(c in self.gt_cols for c in ('gt_phred_ll_homref', 'gt_phred_ll_het', 'gt_phred_ll_homalt')):
                            pdict["violation_prob"] = ""
                            for s in pdict['samples']:
                                # mom, dad, kid
                                mdk = str(s.mom.genotype_lls + s.dad.genotype_lls + s.genotype_lls)
                                # get all 3 at once so we just do 1 eval.
                                vals = eval(mdk, cols)
                                vs.append(mendelian_error(vals[:3], vals[3:6], vals[6:], pls=True))

                            pdict["violation_prob"] = ",".join("%.5f" % v for v in vs if v is not None)
                        pdict['samples'] = ",".join(s.name or str(s.sample_id) for s in pdict['samples'])

                    s = str(pdict)
                    if s in seen:
                        continue
                    seen.add(s)

                    to_yield.append(pdict)

            if 0 < len(kindreds) >= self.args.min_kindreds:
                if 'comp_het_id' in to_yield[0]:
                    counts = Counter((item['comp_het_id'], item['family_id']) for item in to_yield)
                    # remove singletons.
                    to_yield = [item for item in to_yield if counts[(item['comp_het_id'], item['family_id'])] > 1]
                    # re-check min_kindreds
                    if len(set(item['family_id'] for item in to_yield)) < self.args.min_kindreds:
                        continue

                for item in to_yield:
                    item['family_count'] = len(kindreds)
                    yield item
dataset/ETHPy150Open arq5x/gemini/gemini/gim.py/GeminiInheritanceModel.report_candidates/original