MACS3.Signal.PileupV2 module
Module Description:
New pileup algorithm based on p-v array idea. It’s modified from original algorithm in MACS2 proposed by Jie Wang. Now we allow different weights for different genomic ranges, and simplify the approach. The basic idea is to remember for each position, how we modify the ‘pileup’ value while walking on the chromosome.
For a genomic range r_i covering genomic positions from s_i to e_i to be piled up, we assign the start position a value w_i, and the end -w_i, so we will use a tuple of position and weight to remember these operations: (s_i, w_i) and (e_i, -w_i). Then all N ranges will be made into an array (2D) of position and weights as:
- PV = [ (s_0, w_0), (e_0, -w_0), (s_1, w_1), (e_1, -w_1), … (s_i, w_i),
(e_i, -w_i), …, (s_N, w_N), (e_N, -w_N) ]
Then the array PV will be sorted by the first dimension, aka the position, no matter the position is from start or end positions from ranges.
PV_sorted = [ (p_0, v_0), (p_1, v_1), … , (p_i, v_i), …, (p_{2N}, v_{2N}) ]
The pileup algorithm to produce a bedGraph style pileup (another p-v array as in Pileup.py) can be simply described as:
set the initial pileup z as 0 or a given value, and a start position s as 0, and an end position e as not-defined.
- for i from 0 to 2N in PV_sorted:
1: z = z + v_i 2: e = p_i 3: save the pileup from position s to e is z,
in bedGraph style is to only save (e, z)
4: s = e
This code is free software; you can redistribute it and/or modify it under the terms of the BSD License (see the file LICENSE included with the distribution).
- MACS3.Signal.PileupV2.mapping_function_always_1(L, R)
- MACS3.Signal.PileupV2.naive_call_peaks(pv_array, min_v, max_v=1e+30, max_gap=50, min_length=200)
Identify peak summits from a legacy [p, v] pileup array.
- MACS3.Signal.PileupV2.naive_quick_pileup(sorted_poss, extension)
Simple pileup by extending each sorted tag symmetrically.
- MACS3.Signal.PileupV2.over_two_pv_array(pv_array1, pv_array2, func='max')
Merge two legacy [p, v] arrays with a pointwise reducer.
- MACS3.Signal.PileupV2.pileup_LRC_as_list_equal(LRC_array, scale_factor, baseline_value, left_sorted)
What pileup_from_LRC_as_list returns, for an LRC array whose ranges all have one count, from int32 sorts instead of argsorts and float32 weight arrays. With one weight only the sorted positions matter: the starts are taken as they are when
left_sorted(as pileup_from_LRC_as_list takes them) and sorted otherwise, and the ends are sorted. Returns None when the array is empty or not one of LRC_DTYPE, its counts differ, its total weight is above 2^24, or pileup_from_LRC_as_list would raise; the caller then runs pileup_from_LRC_as_list.
- MACS3.Signal.PileupV2.pileup_LRC_centers_as_list_equal(LRC_array, d, scale_factor, baseline_value)
What pileup_from_LRC_centers_as_list returns, for an LRC array whose ranges all have one count, from int32 sorts instead of argsorts and float32 weight arrays. The starts are the left and right ends minus d // 2, sorted; the ends are the sorted starts plus d, which are the sorted ends unless one of them wraps around int32 (then they are sorted on their own). Returns None when the array is empty or not one of LRC_DTYPE, its counts differ,
dis not an int32, or its total weight, twice the counts, is above 2^24; the caller then runs pileup_from_LRC_centers_as_list.
- MACS3.Signal.PileupV2.pileup_and_write_pe(petrackI, output_filename, scale_factor=1.0, baseline_value=0.0)
Pile up a paired-end track and write a bedGraph file.
- MACS3.Signal.PileupV2.pileup_and_write_se(trackI, output_filename, d, scale_factor, baseline_value=0.0, directional=True, halfextension=True)
Pile up a single-end track and write a bedGraph file.
- MACS3.Signal.PileupV2.pileup_from_LR(LR_array, mapping_func=<cyfunction mapping_function_always_1>)
This function will pile up the ndarray containing left and right positions, which is typically from PETrackI object. It’s useful when generating the pileup of a single chromosome is needed.
User needs to provide a numpy array of left and right positions, with dtype=[(‘l’,’i4’),(‘r’,’i4’)]. User also needs to provide a mapping function to map the left and right position to certain weight.
- MACS3.Signal.PileupV2.pileup_from_LRC(LRC_array, mapping_func=<cyfunction mapping_function_always_1>)
This function will pile up the ndarray containing left and right positions and the counts, which is typically from PETrackII object. It’s useful when generating the pileup of a single chromosome is needed.
User needs to provide a numpy array of left and right positions and the counts, with dtype=[(‘l’,’i4’),(‘r’,’i4’),(‘c’,’u2’)]. User also needs to provide a mapping function to map the left and right position to certain weight.
- MACS3.Signal.PileupV2.pileup_from_LRC_as_list(LRC_array, scale_factor=1.0, baseline_value=0.0, left_sorted=False)
Pile up count-weighted fragments and return compact
[p, v]arrays.
- MACS3.Signal.PileupV2.pileup_from_LRC_centers_as_list(LRC_array, d, scale_factor=1.0, baseline_value=0.0)
Pile up count-weighted intervals centered on left and right ends.
- MACS3.Signal.PileupV2.pileup_from_LR_as_list(LR_array, scale_factor=1.0, baseline_value=0.0)
Pile up LR fragments and return the legacy
[p, v]shape.
- MACS3.Signal.PileupV2.pileup_from_LR_hmmratac(LR_array, mapping_dict)
Pile up LR fragments using HMMRATAC
- MACS3.Signal.PileupV2.pileup_from_PN(P_array, N_array, extsize)
This function will pile up the ndarray containing plus (positive) and minus (negative) positions of all reads, which is typically from FWTrackI object. It’s useful when generating the pileup of a single chromosome is needed.
- MACS3.Signal.PileupV2.pileup_from_PN_shifted(P_array, N_array, five_shift, three_shift, rlength, scale_factor=1.0, baseline_value=0.0)
Pile up plus/minus read ends using V1-compatible shifts.
Returns the legacy
[positions, values]shape used by track methods.