File: split_bed_into_multiple_files.py

package info (click to toggle)
python-deeptools 3.5.6%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 34,456 kB
  • sloc: python: 14,503; xml: 4,212; sh: 33; makefile: 5
file content (35 lines) | stat: -rwxr-xr-x 819 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/python3
# -*- coding: utf-8 -*-

"""
This script is use to split a bed file into
smaller beds following the convention that I introduced
in which a # indicates a group in the bed file

Each bed group is saved under a different name
corresponding to the name of the group

Useful to split the results of heatmapper when the clustering
option is used.

:Authors: fidel.ramirez@gmail.com
"""

import sys

i = 0
tempArray = []

for line in sys.stdin:
    if line[0] == '#':
        clusterName = line[1:].strip()
        tempArray.append("#" + clusterName + "\n")
        open(clusterName + ".bed", 'w').write("".join(tempArray))
        tempArray = []
        continue

    tempArray.append(line)

if len(tempArray) > 0:
    clusterName = "no_name"
    open(clusterName + ".bed", 'w').write("".join(tempArray))