Пример #1
0
def _fix_real_lt_zero(x):
    """Convert `x` to complex if it has real, negative components.

    Otherwise, output is just the array version of the input (via asarray).

    Parameters
    ----------
    x : array_like

    Returns
    -------
    array

    Examples
    --------
    >>> np.lib.scimath._fix_real_lt_zero([1,2])
    array([1, 2])

    >>> np.lib.scimath._fix_real_lt_zero([-1,2])
    array([-1.+0.j,  2.+0.j])
    """
    x = asarray(x)
    if any(isreal(x) & (x<0)):
        x = _tocomplex(x)
    return x
Пример #2
0
def _fix_int_lt_zero(x):
    """Convert `x` to double if it has real, negative components.

    Otherwise, output is just the array version of the input (via asarray).

    Parameters
    ----------
    x : array_like

    Returns
    -------
    array

    Examples
    --------
    >>> _fix_int_lt_zero([1,2])
    array([1, 2])

    >>> _fix_int_lt_zero([-1,2])
    array([-1.,  2.])
    """
    x = asarray(x)
    if any(isreal(x) & (x < 0)):
        x = x * 1.0
    return x
Пример #3
0
def _fix_real_abs_gt_1(x):
    """Convert `x` to complex if it has real components x_i with abs(x_i)>1.

    Otherwise, output is just the array version of the input (via asarray).

    Parameters
    ----------
    x : array_like

    Returns
    -------
    array

    Examples
    --------
    >>> np.lib.scimath._fix_real_abs_gt_1([0,1])
    array([0, 1])

    >>> np.lib.scimath._fix_real_abs_gt_1([0,2])
    array([ 0.+0.j,  2.+0.j])
    """
    x = asarray(x)
    if any(isreal(x) & (abs(x)>1)):
        x = _tocomplex(x)
    return x
Пример #4
0
def manhattan(subplot, p_values, p=0.05, threshold='bonferroni', title=None, colors=('r', 'g', 'b'),
              min_p_value=1e-16):
    '''Generate a Manahattan plot from a list of 22 p-value data sets. Entry data[i] corresponds
    to chromosome i-1, and should be tuple (snp_bp_coordinate, p_value).'''         
    # Prepare plot
    subplot.set_yscale('log')
    if title:
        P.title(title)
    P.xlabel('Chromosome')
    P.ylabel(r'$p^{-1}$')
    P.hold(True)

    offset = genome_bp_offset()[:NUM_CHROMOSOMES]
    (xmin, xmax) = (np.inf, -np.inf)
    chr_label = []
    for (index, (snp_chr, p_chr)) in enumerate(p_values):
        x = snp_chr + offset[index]
        color = colors[np.mod(index, len(colors))]
        P.scatter(x, 1.0 / np.maximum(min_p_value, p_chr), c=color, marker='o', edgecolor=color)
        xmin = min(xmin, np.min(x))
        xmax = max(xmax, np.max(x))
        chr_label.append('%s' % (index + 1,))
    P.xlim((xmin, xmax))
    # Set the locations and labels of the x-label ticks
    P.xticks(ndimage.convolve(offset, [0.5, 0.5]), chr_label)    
    
    # Calculate significance threshold    
    if threshold == 'bonferroni':
        # Bonferroni correction: divide by the number of SNPs we are considering
        num_snps = sum(len(chr_data[0]) for chr_data in p_values)
        threshold = p / num_snps
    elif isreal(threshold):
        # Custom threshold
        pass
    elif not threshold:
        raise ValueError('Unsupported threshold %s' % (threshold,))
    if threshold is not None:
        # Draw threshold
        P.axhline(y=1.0 / threshold, color='red')
Пример #5
0
 def test_fail(self):
     z = np.array([-1j, 1, 0])
     res = isreal(z)
     assert_array_equal(res, [0, 1, 1])
Пример #6
0
 def test_pass(self):
     z = np.array([-1, 0, 1j])
     res = isreal(z)
     assert_array_equal(res, [1, 1, 0])
Пример #7
0
def _fix_real_abs_gt_1(x):
    x = asarray(x)
    if any(isreal(x) & (abs(x) > 1)):
        x = _tocomplex(x)
    return x
Пример #8
0
def _fix_int_lt_zero(x):
    x = asarray(x)
    if any(isreal(x) & (x < 0)):
        x = x * 1.0
    return x
Пример #9
0
def _fix_real_lt_zero(x):
    x = asarray(x)
    if any(isreal(x) & (x < 0)):
        x = _tocomplex(x)
    return x
Пример #10
0
 def test_pass(self):
     z = np.array([-1, 0, 1j])
     res = isreal(z)
     assert_array_equal(res, [1, 1, 0])
Пример #11
0
 def test_fail(self):
     z = np.array([-1j, 1, 0])
     res = isreal(z)
     assert_array_equal(res, [0, 1, 1])