-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGenerate_junction_BEDTracks.py
executable file
·62 lines (44 loc) · 2.02 KB
/
Generate_junction_BEDTracks.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""
@authors: Juan L. Trincado
@email: [email protected]
Generate_junction_BEDTracks.py: Generate bed tracks for visualizing the information in the genome browser of the final results
"""
import sys
import time
from argparse import ArgumentParser, RawTextHelpFormatter
import pandas as pd
description = \
"Description:\n\n" + \
"generate bed tracks for visualizing the information in the genome browser of the final results\n"
parser = ArgumentParser(description=description, formatter_class=RawTextHelpFormatter,
add_help=True)
parser.add_argument("-p", "--psi_samples", required=True,
help="PSI of the clustered junctions.")
parser.add_argument("-o", "--output_folder", required=True, help="Output folder")
def main():
args = parser.parse_args()
try:
print("Starting execution: "+time.strftime('%H:%M:%S')+"\n")
# 1. Load the file with the psi_samples
print("Loading "+args.psi_samples+"...")
psi_samples = pd.read_table(args.psi_samples, delimiter="\t")
# psi_samples = pd.read_table("/genomics/users/juanluis/FastQTL_analysis/SCLC/Junctions/data/INTRON/psi_all_samples.txt", delimiter="\t")
# 2. Generate junction_id tracks
print("Generating junction_id tracks...")
# Create the output file
path = args.output_folder + "/Junction_BED_tracks.bed"
# path = "/home/juanluis/Desktop/Junction_BED_track.bed"
output_file = open(path, 'w')
df_aux = psi_samples[['chr', 'start', 'end', 'Index']]
output_file.write("track name=Cluster_Junctions description=\"Cluster junctions id info\" color=160,160,160\n")
df_aux.to_csv(output_file, sep="\t", index=False, header=False, mode='a')
# 3. Close the file handler
print("Saved " + path)
output_file.close()
print("Done. Exiting program. "+time.strftime('%H:%M:%S')+"\n\n")
exit(0)
except Exception:
print(sys.exc_info()[0])
sys.exit(1)
if __name__ == '__main__':
main()