<commit_before>from itertools import izip

import numpy as np

import pydigree as pyd
from pydigree.io import smartopen
from pydigree.sgs.sgs import intervals_to_array

ms=1000

peds = pyd.io.plink.read_plink('null-1.ped','null.map')
ped = peds['1']
s = pyd.sgs.sgs_population(ped, min_seg=ms)


with smartopen('null-1.ibd.gz') as f:
    trueibd = {}
    for line in f:
        fam, id1, id2, ibd_states = line.strip().split(None, 3)
        trueibd[frozenset({id1,id2})] = np.array([int(x) for x in ibd_states.split()])

a = intervals_to_array(s[frozenset({ped['3'],ped['4']})][0], ped.chromosomes[0].nmark())
b = trueibd[frozenset({'3','4'})]

from pydigree.common import table, runs
print table(a)
print table(b)
print

for start, stop in runs(a, lambda x: x>0, ms):
    print 'Predicted segment: {}-{}'.format(start, stop)

print

for start, stop in runs(b, lambda x: x>0, ms):
    print 'True IBD Segment: {}-{}'.format(start, stop)

#for i,data  in enumerate(izip(a,b)):
#    pred, actual = data
#    print i, pred, actual<commit_msg>switch to first cousin for testing and give accuracy<commit_after>import sys

from itertools import izip

import numpy as np

import pydigree as pyd
from pydigree.io import smartopen
from pydigree.sgs.sgs import intervals_to_array
from pydigree.misc import ibs

replicate = sys.argv[1]
ms = int(sys.argv[2])

peds = pyd.io.plink.read_plink('autodom-{}.ped'.format(replicate),'autodom.map')
ped = peds['1']
s = pyd.sgs.sgs_population(ped, min_seg=ms)


with smartopen('autodom-{}.ibd.gz'.format(replicate)) as f:
    trueibd = {}
    for line in f:
        fam, id1, id2, ibd_states = line.strip().split(None, 3)
        trueibd[frozenset({id1,id2})] = np.array([int(x) for x in ibd_states.split()])

a = intervals_to_array(s[frozenset({ped['7'],ped['8']})][0], ped.chromosomes[0].nmark())
b = trueibd[frozenset({'7','8'})]


genos1 = izip(*ped['7'].genotypes[0])
genos2 = izip(*ped['8'].genotypes[0])
identical = [ibs(x,y) for x,y in izip(genos1, genos2)]

from pydigree.common import table, runs


for start, stop in runs(list(a), lambda x: x>0, ms):
    print 'Predicted segment: {}-{}'.format(start, stop)

print

for start, stop in runs(list(b), lambda x: x>0, 2):
    print 'True IBD Segment: {}-{}'.format(start, stop)

correct_calls = a == b
print 'Accuracy: {}'.format(correct_calls.sum() / float(correct_calls.shape[0]))
{'fraction_non_alphanumeric': 0.17053609117771212, 'fraction_numerical': 0.019417475728155338, 'mean_word_length': 4.683453237410072, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1427854', 'n_tokens_mistral': 969, 'n_tokens_neox': 932, 'n_words': 228}