-
Notifications
You must be signed in to change notification settings - Fork 1
/
ciceroToBed
executable file
·55 lines (41 loc) · 1.15 KB
/
ciceroToBed
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
#! /usr/bin/env python3
#
# Vivek Rai
# (c) Parker Lab
#
# Jul 15, 2019
# GPLv3
import docopt
import sys
import signal
import pathlib
doc = """
ciceroToBed
Convert cicero connections to BED file. Writes to STDOUT.
Usage: ciceroToBed <cicero>
Options:
<cicero> Cicero output file
-h, --help Show help
"""
def convert_to_bed(cicero):
conns = dict()
with open(cicero, "r") as f:
for line in f:
loop1 = line.split("\t")[0]
conns[loop1.strip()] = 1
for k in conns.keys():
tab = "\t"
sys.stdout.write(f"{tab.join(k.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))
# Simple argument parsing
opts = docopt.docopt(doc, version="0.1.0")
cicero_path = pathlib.Path(opts["<cicero>"])
# Exit early if the path does not exist
if not cicero_path.exists():
print("Error: File not found. Exit", file=sys.stderr)
sys.exit(1)
convert_to_bed(cicero_path)