Mercurial > repos > melissacline > ucsc_cancer_utilities
comparison seg2matrix/CGData/SegToMatrix.py @ 31:ab20c0d04f4a
add seg2matrix tool
author | jingchunzhu |
---|---|
date | Fri, 24 Jul 2015 13:10:11 -0700 |
parents | |
children | 8ef79bd0be9a |
comparison
equal
deleted
inserted
replaced
30:7a7a52e9b019 | 31:ab20c0d04f4a |
---|---|
1 | |
2 | |
3 import ctypes | |
4 import os | |
5 | |
6 base = os.path.dirname(os.path.abspath(__file__)) | |
7 libFile = base + "/CsegToMatrix.so" | |
8 if os.path.exists(libFile): | |
9 segLib = ctypes.cdll.LoadLibrary(libFile) | |
10 | |
11 | |
12 def seg_to_matrix(seg_handle, out_handle): | |
13 """ | |
14 Turn a segment file into a segmented matrix. | |
15 | |
16 seg_handle -- CGData.GenomicSegment object | |
17 out_handle -- File handle to write to | |
18 """ | |
19 s = segLib.new_segment() | |
20 t = segLib.new_target_set() | |
21 for target in seg_handle.get_key_list(): | |
22 for seg in seg_handle.get_by(target): | |
23 segLib.add_segment(s, t, target, seg.chrom, seg.chrom_start, seg.chrom_end, ctypes.c_float(seg.value)) | |
24 | |
25 def printback(s): | |
26 out_handle.write(s) | |
27 return 0 | |
28 | |
29 printbackTYPE = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_char_p) | |
30 segLib.print_matrix(s, t, printbackTYPE(printback)) |