Spaces:
Sleeping
Sleeping
markdown edits
Browse files
app.py
CHANGED
@@ -180,16 +180,18 @@ glycosyltransferase_db = {
|
|
180 |
|
181 |
def get_family_info(family_name):
|
182 |
family_info = glycosyltransferase_db.get(family_name, {})
|
183 |
-
|
184 |
-
|
185 |
for key, value in family_info.items():
|
186 |
if key == "more_info":
|
187 |
-
|
188 |
for link in value:
|
189 |
-
|
190 |
else:
|
191 |
-
|
192 |
-
|
|
|
|
|
193 |
|
194 |
def fig_to_img(fig):
|
195 |
"""Converts a matplotlib figure to a PIL Image and returns it"""
|
@@ -363,7 +365,7 @@ def generate_heatmap(protein_fasta):
|
|
363 |
|
364 |
headers = [line for line in lines if line.startswith('>')]
|
365 |
if len(headers) > 1:
|
366 |
-
return None, "Multiple fasta sequences detected. Please
|
367 |
|
368 |
protein_sequence = ''.join(line for line in lines if not line.startswith('>'))
|
369 |
|
@@ -378,12 +380,14 @@ def generate_heatmap(protein_fasta):
|
|
378 |
with torch.no_grad():
|
379 |
original_output = model(encoded_input["input_ids"], attention_mask=encoded_input["attention_mask"])
|
380 |
original_probabilities = F.softmax(original_output.logits, dim=1).cpu().numpy()[0]
|
381 |
-
|
382 |
# Define the size of each group
|
383 |
-
group_size = 10 #
|
384 |
|
385 |
-
#
|
386 |
num_groups = len(protein_sequence) // group_size + (len(protein_sequence) % group_size > 0)
|
|
|
|
|
387 |
importance_scores = np.zeros((num_groups, len(original_probabilities)))
|
388 |
|
389 |
# Initialize tqdm progress bar
|
@@ -428,7 +432,7 @@ def main_function_upload(protein_file): #, progress=gr.Progress()
|
|
428 |
|
429 |
prediction_imagefam = gr.outputs.Image(type='pil', label="Family prediction graph")
|
430 |
prediction_imagedonor = gr.outputs.Image(type='pil', label="Donor prediction graph")
|
431 |
-
prediction_explain = gr.outputs.Image(type='pil', label="Donor prediction
|
432 |
|
433 |
|
434 |
with gr.Blocks() as app:
|
|
|
180 |
|
181 |
def get_family_info(family_name):
|
182 |
family_info = glycosyltransferase_db.get(family_name, {})
|
183 |
+
|
184 |
+
output = ""
|
185 |
for key, value in family_info.items():
|
186 |
if key == "more_info":
|
187 |
+
output += "**{}:**".format(key.title().replace("_", " ")) + "\n"
|
188 |
for link in value:
|
189 |
+
output += "[{}]({}) ".format(link, link)
|
190 |
else:
|
191 |
+
output += "**{}:** {} ".format(key.title().replace("_", " "), value)
|
192 |
+
|
193 |
+
return output
|
194 |
+
|
195 |
|
196 |
def fig_to_img(fig):
|
197 |
"""Converts a matplotlib figure to a PIL Image and returns it"""
|
|
|
365 |
|
366 |
headers = [line for line in lines if line.startswith('>')]
|
367 |
if len(headers) > 1:
|
368 |
+
return None, "Multiple fasta sequences detected. Please only include a single fasta sequence.", None
|
369 |
|
370 |
protein_sequence = ''.join(line for line in lines if not line.startswith('>'))
|
371 |
|
|
|
380 |
with torch.no_grad():
|
381 |
original_output = model(encoded_input["input_ids"], attention_mask=encoded_input["attention_mask"])
|
382 |
original_probabilities = F.softmax(original_output.logits, dim=1).cpu().numpy()[0]
|
383 |
+
|
384 |
# Define the size of each group
|
385 |
+
group_size = 10 # allow user to change this
|
386 |
|
387 |
+
# Calculate the number of groups
|
388 |
num_groups = len(protein_sequence) // group_size + (len(protein_sequence) % group_size > 0)
|
389 |
+
|
390 |
+
# Initialize an array to hold the importance scores
|
391 |
importance_scores = np.zeros((num_groups, len(original_probabilities)))
|
392 |
|
393 |
# Initialize tqdm progress bar
|
|
|
432 |
|
433 |
prediction_imagefam = gr.outputs.Image(type='pil', label="Family prediction graph")
|
434 |
prediction_imagedonor = gr.outputs.Image(type='pil', label="Donor prediction graph")
|
435 |
+
prediction_explain = gr.outputs.Image(type='pil', label="Donor prediction explanation")
|
436 |
|
437 |
|
438 |
with gr.Blocks() as app:
|