Example #1
0
    def validate(self, vcf_path, plot=False, king=False):
        if king:
            from .king import run_king
            run_king(vcf_path, self)

        else:
            from cyvcf2 import VCF
            vcf = VCF(vcf_path, gts012=True, lazy=True)
            rels = list(
                vcf.relatedness(min_af=0.02,
                                n_variants=39000,
                                gap=10000,
                                linkage_max=1.5))
            if plot:
                fig = vcf.plot_relatedness(rels[:])
                fig.show()
                fig.savefig('t.png')

            print("sample_1\tsample_2\tped_relation\tvcf_relation\trel\tIBS")
            for rel in rels:
                sample_a, sample_b = rel['pair']
                ped_rel = self.relation(sample_a, sample_b)
                if ped_rel is None: continue
                out_line = "%s\t%s\t%s\t%s\t%.2f\t%.3f" % (
                    sample_a, sample_b, ped_rel, "|".join(
                        rel['tags']), rel['rel'], rel['ibs'])
                if rel['rel'] < 0.04:  # likely unrelated
                    if ped_rel not in ('related level 2', 'unrelated'):
                        print(out_line)
                    continue

                if rel['rel'] < 0.15:
                    if ped_rel not in ('unrelated', 'related level 2',
                                       'distant relations'):
                        print(out_line)
                    continue

                if 0.26 < rel['rel'] < 0.78:
                    if ped_rel not in ('parent-child', 'full siblings'):
                        print(out_line)
                    continue

                if 0.15 < rel['rel'] < 0.3:
                    if ped_rel not in ('related level 2', 'unrelated'):
                        print(out_line)
                    continue

                if ped_rel > 0.78:
                    if ped_rel not in ('identical twins', 'self'):
                        print(out_line)
                    continue
Example #2
0
    def validate(self, vcf_path, plot=False, king=False):
        if king:
            from .king import run_king
            run_king(vcf_path, self)

        else:
            from cyvcf2 import VCF
            vcf = VCF(vcf_path, gts012=True, lazy=True)
            rels = list(vcf.relatedness(min_af=0.02, n_variants=39000, gap=10000, linkage_max=1.5))
            if plot:
                fig = vcf.plot_relatedness(rels[:])
                fig.show()
                fig.savefig('t.png')

            print("sample_1\tsample_2\tped_relation\tvcf_relation\trel\tIBS")
            for rel in rels:
                sample_a, sample_b = rel['pair']
                ped_rel = self.relation(sample_a, sample_b)
                if ped_rel is None: continue
                out_line = "%s\t%s\t%s\t%s\t%.2f\t%.3f" % (sample_a, sample_b,
                        ped_rel, "|".join(rel['tags']), rel['rel'], rel['ibs'])
                if rel['rel'] < 0.04:  # likely unrelated
                    if ped_rel not in ('related level 2', 'unrelated'):
                        print(out_line)
                    continue

                if rel['rel'] < 0.15:
                    if ped_rel not in ('unrelated', 'related level 2', 'distant relations'):
                        print(out_line)
                    continue

                if 0.26 < rel['rel'] < 0.78:
                    if ped_rel not in ('parent-child', 'full siblings'):
                        print(out_line)
                    continue

                if 0.15 < rel['rel'] < 0.3:
                    if ped_rel not in ('related level 2', 'unrelated'):
                        print(out_line)
                    continue

                if ped_rel > 0.78:
                    if ped_rel not in ('identical twins', 'self'):
                        print(out_line)
                    continue