-
Notifications
You must be signed in to change notification settings - Fork 0
/
covert_coordinates.py
32 lines (24 loc) · 967 Bytes
/
covert_coordinates.py
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
import os
import pandas as pd
import sys
fasta_file = sys.argv[1]
with open(fasta_file) as fin:
l = fin.readline().split()[1][6:]
chrm = l.split(":")[0]
start = int(l.split(":")[1].split("-")[0])
end = int(l.split(":")[1].split("-")[1])
# print (chrm, start)
webservice_out_folder = sys.argv[2]
webservice_out_folder = webservice_out_folder.replace("\\","/")
with open(os.path.join(webservice_out_folder,"roi.converted.bed"), "w") as fout:
fout.write("\t".join([chrm, str(start), str(end), "ROI"]))
files = os.listdir(webservice_out_folder)
for file in files:
file = os.path.join(webservice_out_folder,file)
if file.endswith(".bed") and not file.endswith(".converted.bed"):
data = pd.read_csv(file,skiprows=1,
header=None, sep="\s", engine='python')
data.iloc[:,0] = [chrm]*len(data)
data.iloc[:,1] = data.iloc[:,1] + start
data.iloc[:,2] = data.iloc[:,2] + start
data.to_csv(file+".converted.bed",header=False, index=False, sep="\t")