示例#1
0
文件: ibd_hmm.py 项目: orenlivne/ober
 def print_table(self):
     '''Print a table of probabilities at each SNP.'''
     options = np.get_printoptions()
     np.set_printoptions(precision=3, suppress=True, threshold=np.nan, linewidth=200)
     print 'lambda = %s, Delta = %s, eps = %.1e' % (self.lam, repr(self.Delta)[6:-1], self.e)
     print 'Viterbi path (frame SNPs): ' + ' -> '.join(map(lambda x: '%d (%d-%d)' % (x[0], x[1][0], x[1][1]),
                                               itemutil.groupby_with_range(self.Q_star + 1)))
     print 'Viterbi path (SNPs):       ' + ' -> '.join(map(lambda x: '%d (%d-%d)' % (x[0], self.snps[x[1][0]], self.snps[x[1][1]]),
                                               itemutil.groupby_with_range(self.Q_star + 1)))
     print '    %-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s' % \
     ('t', 'SNP#', 'Obs', 'G1', 'G2', 'lam*dx', 'p',
      'Gam1', 'Gam2', 'Gam3', 'Gam4', 'Gam5', 'Gam6', 'Gam7', 'Gam8', 'Gam9',
      'p(IBD)', 'Viterbi', 'IBD?')
     print np.concatenate((np.arange(len(self.x))[np.newaxis].transpose(),
                           self.snps[np.newaxis].transpose(),
                           self.Obs[np.newaxis].transpose(),
                           np.array([ProbIbdHmmCalculator._T_STATE_G[t][0] for t in self.Obs])[np.newaxis].transpose(),
                           np.array([ProbIbdHmmCalculator._T_STATE_G[t][1] for t in self.Obs])[np.newaxis].transpose(),
                           np.concatenate((self.lam_x, [0]))[np.newaxis].transpose(),
                           self.p[np.newaxis].transpose(),
                           self.Gamma.transpose(),
                           self.p_ibd_gamma[np.newaxis].transpose(),
                           (self.Q_star + 1)[np.newaxis].transpose(),
                           self.p_ibd_viterbi[np.newaxis].transpose()
                           ), axis=1)
     util.set_printoptions(options)
示例#2
0
 def print_table(self):
     '''Print a table of probabilities at each SNP.'''
     options = np.get_printoptions()
     np.set_printoptions(precision=3,
                         suppress=True,
                         threshold=np.nan,
                         linewidth=200)
     print 'lambda = %.2f, f = %.2f, eps = %.1e' % (self.lam, self.f,
                                                    self.e)
     print 'Viterbi path (frame SNPs): ' + ' -> '.join(
         map(lambda x: '%d (%d-%d)' % (x[0], x[1][0], x[1][1]),
             itemutil.groupby_with_range(self.Q_star)))
     print 'Viterbi path (SNPs):       ' + ' -> '.join(
         map(
             lambda x: '%d (%d-%d)' %
             (x[0], self.snps[x[1][0]], self.snps[x[1][1]]),
             itemutil.groupby_with_range(self.Q_star)))
     print '      %-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s' % \
     ('t', 'SNP#', 'H1', 'H2', 'x', 'lam*dx', 'p', 'Gam0', 'Gam1', 'p(IBD)', 'Viterbi', 'IBD?')
     print np.concatenate(
         (np.arange(len(self.x))[np.newaxis].transpose(),
          self.snps[np.newaxis].transpose(),
          self.Obs[np.newaxis].transpose() / 2,
          self.Obs[np.newaxis].transpose() % 2,
          self.x[np.newaxis].transpose(),
          np.concatenate((self.lam * np.diff(self.x), [
              0
          ]))[np.newaxis].transpose(), self.p[np.newaxis].transpose(),
          self.Gamma.transpose(), self.p_ibd_gamma[np.newaxis].transpose(),
          (self.Q_star)[np.newaxis].transpose(),
          self.p_ibd_viterbi[np.newaxis].transpose()),
         axis=1)
     util.set_printoptions(options)
示例#3
0
 def print_table(self):
     '''Print a table of probabilities at each SNP.'''
     options = np.get_printoptions()
     np.set_printoptions(precision=3,
                         suppress=True,
                         threshold=np.nan,
                         linewidth=200)
     print 'lambda = %s, Delta = %s, eps = %.1e' % (
         self.lam, repr(self.Delta)[6:-1], self.e)
     print 'Viterbi path (frame SNPs): ' + ' -> '.join(
         map(lambda x: '%d (%d-%d)' % (x[0], x[1][0], x[1][1]),
             itemutil.groupby_with_range(self.Q_star + 1)))
     print 'Viterbi path (SNPs):       ' + ' -> '.join(
         map(
             lambda x: '%d (%d-%d)' %
             (x[0], self.snps[x[1][0]], self.snps[x[1][1]]),
             itemutil.groupby_with_range(self.Q_star + 1)))
     print '    %-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s' % \
     ('t', 'SNP#', 'Obs', 'G1', 'G2', 'lam*dx', 'p',
      'Gam1', 'Gam2', 'Gam3', 'Gam4', 'Gam5', 'Gam6', 'Gam7', 'Gam8', 'Gam9',
      'p(IBD)', 'Viterbi', 'IBD?')
     print np.concatenate(
         (np.arange(len(self.x))[np.newaxis].transpose(),
          self.snps[np.newaxis].transpose(),
          self.Obs[np.newaxis].transpose(),
          np.array(
              [ProbIbdHmmCalculator._T_STATE_G[t][0]
               for t in self.Obs])[np.newaxis].transpose(),
          np.array([
              ProbIbdHmmCalculator._T_STATE_G[t][1] for t in self.Obs
          ])[np.newaxis].transpose(), np.concatenate(
              (self.lam_x, [0]))[np.newaxis].transpose(),
          self.p[np.newaxis].transpose(), self.Gamma.transpose(),
          self.p_ibd_gamma[np.newaxis].transpose(),
          (self.Q_star + 1)[np.newaxis].transpose(),
          self.p_ibd_viterbi[np.newaxis].transpose()),
         axis=1)
     util.set_printoptions(options)
示例#4
0
 def print_table(self):
     '''Print a table of probabilities at each SNP.'''
     options = np.get_printoptions()
     np.set_printoptions(precision=3, suppress=True, threshold=np.nan, linewidth=200)
     print 'lambda = %.2f, f = %.2f, eps = %.1e' % (self.lam, self.f, self.e)
     print 'Viterbi path (frame SNPs): ' + ' -> '.join(map(lambda x: '%d (%d-%d)' % (x[0], x[1][0], x[1][1]),
                                               itemutil.groupby_with_range(self.Q_star)))
     print 'Viterbi path (SNPs):       ' + ' -> '.join(map(lambda x: '%d (%d-%d)' % (x[0], self.snps[x[1][0]], self.snps[x[1][1]]),
                                               itemutil.groupby_with_range(self.Q_star)))
     print '      %-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s' % \
     ('t', 'SNP#', 'H1', 'H2', 'x', 'lam*dx', 'p', 'Gam0', 'Gam1', 'p(IBD)', 'Viterbi', 'IBD?')
     print np.concatenate((np.arange(len(self.x))[np.newaxis].transpose(),
                           self.snps[np.newaxis].transpose(),
                           self.Obs[np.newaxis].transpose() / 2,
                           self.Obs[np.newaxis].transpose() % 2,
                           self.x[np.newaxis].transpose(),
                           np.concatenate((self.lam * np.diff(self.x), [0]))[np.newaxis].transpose(),
                           self.p[np.newaxis].transpose(),
                           self.Gamma.transpose(),
                           self.p_ibd_gamma[np.newaxis].transpose(),
                           (self.Q_star)[np.newaxis].transpose(),
                           self.p_ibd_viterbi[np.newaxis].transpose()
                           ), axis=1)
     util.set_printoptions(options)
示例#5
0
    # After: q, hh
    p = im.io.read_npz(im.itu.FAMILY225_STAGE1)
    q = im.io.read_npz(im.itu.FAMILY225_STAGE1)
    phaser = family_child_comparison_phaser(debug=True)
    (g, h) = p.data
    (gg, hh) = q.data
    f = p.families(genotyped=True)[0]
    (father, mother) = f.parents
    children = np.array(f.children_list)
    
    phaser.run(q)
    
    # Print a portion of the father and corresponding children haplotypes
    snps = np.arange(2094, 2118) #np.arange(0, p.num_snps)
    for parent_type in ALLELES:
        print_haps(h, hh, parent_type, snps)
    
    # Recombinations
    comparator = im.ic.ChildComparator(p, f)
    template = {PATERNAL: 5, MATERNAL: 3}
    for parent_type in ALLELES:
        (_, _, info) = comparator.child_recombinations(parent_type, template[parent_type], remove_errors=False)
        print 'Recombinations, parent_type', parent_type
        print info.recombination_snp
    
    # Plot recombinations
    #im.plots.plot_all_family_comparisons(q, f) 

    util.set_printoptions(old_printoptions)
    
示例#6
0
Created on September 7, 2012
@author: Oren Livne <*****@*****.**>
============================================================
'''
import numpy as np, matplotlib.pyplot as plt, util
from impute import impute_test_util as itu
from impute.plot import plots
from impute.data import io

if __name__ == '__main__':
    '''
    --------------------------------------------------
    Main program
    --------------------------------------------------
    '''

    # Load nuclear family data
    p = io.read_npz(itu.FAMILY2003_STAGE3)
    f = p.families(genotyped=False)[0]
    old_printoptions = np.get_printoptions()
    np.set_printoptions(precision=2)

    children = np.array([x for x in f.children_list if p.is_genotyped(x)])
    h = p.haplotype.data
    plots.plot_hap_corr_matrix(h, children, (0, 0))
    plt.savefig('hap00.png')
    plots.plot_hap_corr_matrix(h, children, (0, 1))
    plt.savefig('hap01.png')

    util.set_printoptions(old_printoptions)