-
Notifications
You must be signed in to change notification settings - Fork 1
/
formatHiCtoCicero
executable file
·53 lines (40 loc) · 1.07 KB
/
formatHiCtoCicero
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
#! /usr/bin/env python3
#
# Vivek Rai
# mail@raivivek.in
# (c) Parker Lab
#
# Jul 8, 2019
# GPLv3
import docopt
import sys
import signal
import pathlib
doc = """
formatHiCtoCicero
Prints to STDOUT.
Usage: formatHiCtoCicero <file>
Options:
<file> input
-h, --help Show help
"""
def convert_to_bedpe(file):
# conns = dict()
with open(file, "r") as f:
for line in f:
loop1, loop2, _ = line.split("\t")
tab = "\t"
sys.stdout.write(
f"{tab.join(loop1.split('_'))}" "\t" f"{tab.join(loop2.split('_'))}\n"
)
if __name__ == "__main__":
# Register SIGNIT handler for graceful exit
# See: https://stackoverflow.com/questions/4205317
signal.signal(signal.SIGINT, lambda s, f: sys.exit(0))
opts = docopt.docopt(doc, version="0.1.0")
file_path = pathlib.Path(opts["<file>"])
# Exit early if the path does not exist
if not file_path.exists():
print("Error: File not found. Exit", file=sys.stderr)
sys.exit(1)
convert_to_bedpe(file_path)