-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.py
188 lines (157 loc) · 4.62 KB
/
ui.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
"""
This module contains functions that display the UI when running the program
without the flags necessary for automated BED generation.
"""
import os
def determine_if_show_ui(args):
"""Determines whether the ui should be shown, based on the arguments
provided. If the user has provided a file, lrgid or geneid argument flag
to the program, the UI is NOT shown, unless required for safety reasons
(selecting the transcript or genome build when one has not been provided).
Args:
args (dict): Dictionary containing command line arguments
Returns:
show_ui (bool): True or False whether the UI should be shown
"""
if (args['file'] == None and
args['lrgid'] == None and
args['geneid'] == None):
show_ui = True
else:
show_ui = False
return show_ui
def splashscreen():
"""Displays the intial startscreen"""
os.system('cls' if os.name == 'nt' else 'clear')
print("="*40)
print("")
print(" LRG File Parsing Program")
print(" Authors: A. Toutoudaki, J. Mahon")
print("")
print("="*40)
def ask_what_gene():
"""Prompts the user to input a desired HGNC Gene Name
Returns:
selection (str): The gene name obtained from user input
"""
print("")
print(" Please enter a HGNC Gene Name")
print("")
selection = input()
return selection
def ask_which_genome_build(genomebuilds):
"""Prompts the user to select the desired genome build. These are
extracted from the XML file.
Args:
genomebuilds (list): List of different genome builds
Returns:
genome_choice (str): The genome build the user has selected
"""
print("")
print(" Which genome build would you like to use?")
counter = 1
for genomebuild in genomebuilds:
print(" " + str(counter)+ " " + genomebuild)
counter +=1
print("")
validinput = False
# This loops unless the user provides a valid input
while validinput == False:
choice = input()
try:
choice_int = int(choice)
if choice_int >= 1 and choice_int <= len(genomebuilds):
validinput = True
else:
print("Please enter a valid choice")
except:
print("Please enter a valid choice")
print("")
print(" Genome Build choice: " + genomebuilds[choice_int-1])
print("")
# The user input (1 or 2 or 3 etc) is matched to the genome build.
# 1 is subtracted as the list is 0-indexed.
genome_choice = genomebuilds[choice_int-1]
return genome_choice
def ask_which_transcript(transcripts):
"""Prompts the user to select the desired transcript. These are
extracted from the XML file.
Args:
transcripts (list): List of different transcripts
Returns:
transcript_choice (str): The transcript the user has selected
"""
print("")
print(" Please select the desired transcript")
counter = 1
for transcript in transcripts:
print(" " + str(counter)+ " " + transcript)
counter +=1
print("")
validinput = False
# This loops unless the user provides a valid input
while validinput == False:
choice = input()
try:
choice_int = int(choice)
if choice_int >= 1 and choice_int <= len(transcripts):
validinput = True
else:
print("Please enter a valid choice")
except:
print("Please enter a valid choice")
print("")
print(" Transcript choice: " + transcripts[choice_int-1])
print("")
# The user input (1 or 2 or 3 etc) is matched to the transcript.
# 1 is subtracted as the list is 0-indexed.
transcript_choice = transcripts[choice_int-1]
return transcript_choice
def ask_include_introns():
"""Asks the user whether they require introns in the BED file.
Returns:
choice (bool): True or False whether introns are to be included
"""
print("")
print(" Would you like to include whole introns?")
print("")
print(" Y/N")
print("")
validinput = False
# This loops unless the user provides a valid input
while validinput == False:
choice = input()
if choice == "Y" or choice == "y":
choice = True
validinput = True
elif choice == "N" or choice == "n":
choice = False
validinput = True
else:
print("Please enter a valid choice")
return choice
def ask_flank_size():
"""Asks the user whether they require introns in the BED file.
Returns:
choice (int): The size of the flanking region required
"""
print("")
print(" What size of flanking region is required?")
print("")
print(" Enter a flanking length")
print(" e.g 10 for a 10bp flank")
print(" e.g 0 for no flanking region")
print("")
validinput = False
# This loops unless the user provides a valid input
while validinput == False:
choice = input()
try:
choice_int = int(choice)
if choice_int >= 0:
validinput = True
else:
print("Please enter a valid choice")
except:
print("Please enter a valid choice")
return choice