Exemple #1
0
def _hap_comparator_ibdld(a, b):
    '''Return a confidence measure in [0,1] of the equality of the haplotypes a and b.
    Defines the confidence of equality based on a model of IBDLD posterior probabilities.'''
    # TODO: replace this temporary implementation by ibdld_confidence()
    d = diff.hap_diff(a, b)
    return (1.0 * np.size(np.where(d == 0))) / max(
        1, np.size(np.where(d != INDETERMINATE)))
Exemple #2
0
def plot_comparison(template,
                    haps,
                    snps=None,
                    title=None,
                    xlabel=None,
                    x=None,
                    y=None,
                    template_y='TEMP',
                    colors=DEFAULT_COLORS):
    '''Generate a recombination coloring plot of the difference between template
    and each element in the list haps..'''
    # Read or re-generate differences data
    num_snps = len(template)
    if np.size(haps.shape) == 1:
        haps = np.transpose(np.array([haps]))
    num_haps = haps.shape[1]
    # d = (haps != np.transpose(np.tile(template, (num_haps,1)))).astype('int8')
    d = np.transpose(
        np.array([
            diff.hap_diff(haps[:, j], template).astype('int8')
            for j in xrange(0, num_haps)
        ]))

    # Restrict view to snps, if specified
    x = x if x is not None else np.arange(0, num_snps)
    if snps is not None:
        (x, d) = (x[snps], d[snps, :])

    # Generate haplotype plots
    P.clf()
    P.hold(True)
    hap_ticks = range(0, num_haps)
    for j in hap_ticks:
        difference = d[:, j]
        for (value, color) in colors.iteritems():
            hap = np.where(difference == value)
            if hap:
                P.plot(x[hap[0]],
                       np.zeros((np.size(hap), )) + j,
                       color,
                       markeredgecolor='gray'
                       if value == INDETERMINATE else color[0])

    if title is not None:
        P.title(title)
    P.xlim([min(x) - 1, max(x) + 1])
    P.ylim([-0.5, num_haps - 0.5])
    P.xlabel(xlabel if xlabel else 'SNP #')
    P.ylabel('Sample')
    if y is not None:
        P.yticks(hap_ticks, [template_y] + list(y))
    return d
Exemple #3
0
def plot_comparison(template, haps, snps=None,
                    title=None, xlabel=None, x=None, y=None, template_y='TEMP',
                    colors=DEFAULT_COLORS):
    '''Generate a recombination coloring plot of the difference between template
    and each element in the list haps..'''
    # Read or re-generate differences data
    num_snps = len(template)
    if np.size(haps.shape) == 1:
        haps = np.transpose(np.array([haps]))
    num_haps = haps.shape[1]
    # d = (haps != np.transpose(np.tile(template, (num_haps,1)))).astype('int8')
    d = np.transpose(np.array([diff.hap_diff(haps[:, j], template).astype('int8') 
                               for j in xrange(0, num_haps)]))
        
    # Restrict view to snps, if specified
    x = x if x is not None else np.arange(0, num_snps)
    if snps is not None:
        (x, d) = (x[snps], d[snps, :])
        
    # Generate haplotype plots
    P.clf()
    P.hold(True)
    hap_ticks = range(0, num_haps)
    for j in hap_ticks:
        difference = d[:, j]
        for (value, color) in colors.iteritems():
            hap = np.where(difference == value)
            if hap:
                P.plot(x[hap[0]], np.zeros((np.size(hap),)) + j, color,
                         markeredgecolor='gray' if value == INDETERMINATE else color[0])
            
    if title is not None:
        P.title(title)
    P.xlim([min(x) - 1, max(x) + 1])
    P.ylim([-0.5, num_haps - 0.5])
    P.xlabel(xlabel if xlabel else 'SNP #')
    P.ylabel('Sample')
    if y is not None:
        P.yticks(hap_ticks, [template_y] + list(y))
    return d
Exemple #4
0
 def test_hap_diff(self):
     '''Check haplotype difference functionality.'''
     a = np.array([2, 2, 2, 1, 2, 1, 1, 0], dtype=np.byte)
     b = np.array([0, 2, 2, 2, 1, 1, 1, 2], dtype=np.byte)
     d = np.array([-1, 0, 0, 1, 1, 0, 0, -1], dtype=np.byte)
     assert_equal(diff.hap_diff(a, b), d, 'Wrong haplotype difference')
Exemple #5
0
def _hap_comparator_ibdld(a, b):
    '''Return a confidence measure in [0,1] of the equality of the haplotypes a and b.
    Defines the confidence of equality based on a model of IBDLD posterior probabilities.'''
    # TODO: replace this temporary implementation by ibdld_confidence()
    d = diff.hap_diff(a, b)
    return (1.0 * np.size(np.where(d == 0))) / max(1, np.size(np.where(d != INDETERMINATE)))
Exemple #6
0
 def test_hap_diff(self):
     '''Check haplotype difference functionality.'''
     a = np.array([2, 2, 2, 1, 2, 1, 1, 0], dtype=np.byte)
     b = np.array([0, 2, 2, 2, 1, 1, 1, 2], dtype=np.byte)
     d = np.array([-1, 0, 0, 1, 1, 0, 0, -1], dtype=np.byte)
     assert_equal(diff.hap_diff(a, b), d, 'Wrong haplotype difference')