Commit 692e453a authored by Piotr Gawron's avatar Piotr Gawron
Browse files

transformation to bed implemented

parents
.idea/
venv/
*.bed
*.txt.gz
import gzip
import ntpath
import sys
def transform(input_line):
chromosome = input_line[2]
chromosome_start = input_line[4]
chromosome_end = input_line[5]
name = input_line[12]
score = input_line[11]
strand = input_line[3]
thick_start = input_line[6]
thick_end = input_line[7]
item_rgb = "255,0,0"
block_count = input_line[8]
block_starts = []
block_sizes = []
block_starts_tmp = input_line[9].split(",")
block_ends_tmp = input_line[10].split(",")
for i in range(0, int(block_count)):
block_starts.append(block_starts_tmp[i])
block_sizes.append(str(int(block_ends_tmp[i]) - int(block_starts_tmp[i])))
output = [chromosome, chromosome_start, chromosome_end, name, score, strand, thick_start, thick_end, item_rgb,
block_count, ",".join(block_sizes), ",".join(block_starts)]
return output
inputFile = sys.argv[1]
outputFile = ntpath.basename(inputFile).replace(".txt.gz", "") + ".bed"
output = open(outputFile, "w")
with gzip.open(inputFile, 'rt') as hIN:
for line in hIN:
F = line.rstrip('\n').split('\t')
output_line = transform(F)
print("\t".join(output_line), file=output)
output.close()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment