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))
|