1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
import pyranges as pr
gr = pr.load_dataset("epigenome_roadmap")
rle = gr["chr1"].coverage()
print(list(rle.runs)[:20])
print(list(rle.values)[:20])
raise
import numpy as np
from pyrle import Rle
import pandas as pd
r = pd.Series([1, 2, 3, 4], dtype=np.int16)
# v = pd.Series([-1, 2.3, 3, 4.976], dtype=np.float)
r1 = Rle(r, r)
r2 = Rle(r * 2, r * 2)
# > r2
# numeric-Rle of length 20 with 4 runs
# Lengths: 2 4 6 8
# Values : 2 4 6 8
# > r4
# numeric-Rle of length 20 with 5 runs
# Lengths: 1 2 3 4 10
# Values : 1 2 3 4 0
# > r2 + r4
# numeric-Rle of length 20 with 7 runs
# Lengths: 1 1 1 3 4 2 8
# Values : 3 4 6 7 10 6 8
r3 = r1 + r2
print(r3.runs)
print(r3.values)
print(r3.runs.dtype)
print(r3.values.dtype)
print(r3.runs.shape)
print(r3.values.shape)
r4 = r2 + r1
print(r4.runs)
print(r4.values)
print(r4.runs.dtype)
print(r4.values.dtype)
print(r4.runs.shape)
print(r4.values.shape)
def resize_test():
"""
test of workign with a numpy array that needs to be re-sized.
"""
# create an ndarray and a memview to work with it.
# cdef cnp.ndarray[double, ndim=1, mode="c"] arr
# cdef double[:] memview
# ## allocate the array:
# arr = np.zeros( (1,) )
# ## Assign the memview to it:
# memview = arr
# ## manipulate it
# memview[0] = 3.14
# ## resize the array
# arr.resize((4,), refcheck = False)
# ## re-assign the memview -- so you get the new post-resize pointer
# memview = arr
# ## now use it
# memview[1] = 5.6
# memview[2] = 7.1
# memview[3] = 4.3
# ## return the numpy array
# return arr
|