Commit a714e91e authored by Piotr Gawron's avatar Piotr Gawron
Browse files

sorting of bed file implemented

parent 692e453a
import gzip
import ntpath
import os
import sys
import subprocess
import urllib.request
from pathlib import Path
def transform(input_line):
......@@ -22,15 +26,18 @@ def transform(input_line):
for i in range(0, int(block_count)):
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,
output_line = [chromosome, chromosome_start, chromosome_end, name, score, strand, thick_start, thick_end, item_rgb,
block_count, ",".join(block_sizes), ",".join(block_starts)]
return output
return output_line
inputFile = sys.argv[1]
outputFile = ntpath.basename(inputFile).replace(".txt.gz", "") + ".bed"
basename = ntpath.basename(inputFile).replace(".txt.gz", "")
output_file_unsorted = basename + ".bed"
output = open(outputFile, "w")
output = open(output_file_unsorted, "w")
print('Generating bed file: ' + output_file_unsorted)
with, 'rt') as hIN:
for line in hIN:
......@@ -38,3 +45,25 @@ with, 'rt') as hIN:
output_line = transform(F)
print("\t".join(output_line), file=output)
if not Path('bin').is_dir():
def downloadUcscFile(filename):
if not Path('bin/' + filename).is_file():
print('Beginning file download ' + filename + '...')
url = '' + filename
urllib.request.urlretrieve(url, 'bin/' + filename)
os.chmod('bin/' + filename, 0o755)
output_file_sorted = basename + "-sorted.bed"
print('Sorting bed file: ')["bin/sortBed", output_file_unsorted, output_file_sorted])
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