Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -35,33 +35,34 @@ def read_dna_sequence(dna_text, fasta_file):
|
|
35 |
if dna_text and dna_text.strip():
|
36 |
dna_sequence = dna_text.strip().replace("\n", "")
|
37 |
|
38 |
-
#
|
39 |
if fasta_file is not None:
|
40 |
if dna_sequence:
|
41 |
-
warning = "Warning: Both pasted DNA and FASTA file provided. Using
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
61 |
|
62 |
if dna_sequence and not dna_sequence.isupper():
|
63 |
dna_sequence = dna_sequence.upper()
|
64 |
-
warning += "\
|
65 |
|
66 |
return dna_sequence, warning.strip(), error
|
67 |
|
@@ -85,18 +86,18 @@ def validate_inputs(dna_sequence: str, custom_question: str):
|
|
85 |
placeholders = custom_question.count("<DNA>")
|
86 |
|
87 |
if not custom_question.strip():
|
88 |
-
return False, "Please provide a question."
|
89 |
|
90 |
if dna_sequence and placeholders == 0:
|
91 |
log_message("Error: DNA sequence provided but no <DNA> token.")
|
92 |
-
return False, "Your question must contain the <DNA> token if you provide a DNA sequence."
|
93 |
|
94 |
if not dna_sequence and placeholders == 1:
|
95 |
log_message("Error: <DNA> token but no sequence.")
|
96 |
-
return False, "You must provide a DNA sequence if you use the <DNA> token."
|
97 |
|
98 |
if placeholders > 1:
|
99 |
-
return False, "Only one <DNA> token is allowed."
|
100 |
|
101 |
return True, ""
|
102 |
|
@@ -128,6 +129,8 @@ def run_chatnt(dna_text, fasta_file, custom_question):
|
|
128 |
if warning:
|
129 |
feedback_msgs.append(warning)
|
130 |
|
|
|
|
|
131 |
return result, "\n".join(feedback_msgs)
|
132 |
|
133 |
|
@@ -138,8 +141,8 @@ css = """
|
|
138 |
footer { display: none !important; }
|
139 |
"""
|
140 |
|
141 |
-
example_dna = "
|
142 |
-
example_question = "
|
143 |
|
144 |
with gr.Blocks(css=css) as demo:
|
145 |
gr.Markdown(
|
@@ -205,20 +208,34 @@ You can either paste a sequence or upload a FASTA file.
|
|
205 |
|
206 |
---
|
207 |
|
208 |
-
###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
- "Does this sequence `<DNA>` contain a donor splice site?"
|
210 |
- "Is it possible for you to identify whether there's a substantial presence of H3 histone protein occupancy in the nucleotide sequence `<DNA>` in yeast?"
|
211 |
- "Determine the degradation rate of the mouse RNA sequence `<DNA>` within the -5 to 5 range."
|
212 |
|
213 |
-
|
|
|
|
|
214 |
- "What is the length of this sequence `<DNA>`?"
|
215 |
-
- "Replace the all 'A' nucleotides by 'G' in this sequence `<DNA
|
216 |
|
217 |
For more examples, you can refer to the [training dataset](https://huggingface.co/datasets/InstaDeepAI/ChatNT_training_data).
|
218 |
"""
|
219 |
)
|
220 |
with gr.Column(scale=1):
|
221 |
-
gr.Image(
|
|
|
|
|
|
|
|
|
222 |
|
223 |
gr.Markdown("""
|
224 |
### 📚 Citation
|
|
|
35 |
if dna_text and dna_text.strip():
|
36 |
dna_sequence = dna_text.strip().replace("\n", "")
|
37 |
|
38 |
+
# Text overrides uploaded FASTA
|
39 |
if fasta_file is not None:
|
40 |
if dna_sequence:
|
41 |
+
warning = "⚠️ Warning: Both pasted DNA and FASTA file provided. Using the pasted DNA only."
|
42 |
|
43 |
+
else:
|
44 |
+
try:
|
45 |
+
with open(fasta_file.name, "r") as f:
|
46 |
+
content = f.read()
|
47 |
+
|
48 |
+
if not content.startswith(">"):
|
49 |
+
error = "❌ Invalid FASTA: must start with '>' header line."
|
50 |
+
return "", warning, error
|
51 |
+
|
52 |
+
sequence = ""
|
53 |
+
for line in content.splitlines():
|
54 |
+
if not line or line.startswith(">"):
|
55 |
+
continue
|
56 |
+
sequence += line.strip()
|
57 |
+
|
58 |
+
dna_sequence = sequence
|
59 |
+
|
60 |
+
except Exception:
|
61 |
+
error = "❌ Could not read the FASTA file."
|
62 |
|
63 |
if dna_sequence and not dna_sequence.isupper():
|
64 |
dna_sequence = dna_sequence.upper()
|
65 |
+
warning += "\n⚠️ Note: DNA sequence was converted to uppercase (lowercase nucleotides are not supported)."
|
66 |
|
67 |
return dna_sequence, warning.strip(), error
|
68 |
|
|
|
86 |
placeholders = custom_question.count("<DNA>")
|
87 |
|
88 |
if not custom_question.strip():
|
89 |
+
return False, "❌ Please provide a question."
|
90 |
|
91 |
if dna_sequence and placeholders == 0:
|
92 |
log_message("Error: DNA sequence provided but no <DNA> token.")
|
93 |
+
return False, "❌ Your question must contain the <DNA> token if you provide a DNA sequence."
|
94 |
|
95 |
if not dna_sequence and placeholders == 1:
|
96 |
log_message("Error: <DNA> token but no sequence.")
|
97 |
+
return False, "❌ You must provide a DNA sequence if you use the <DNA> token."
|
98 |
|
99 |
if placeholders > 1:
|
100 |
+
return False, "❌ Only one <DNA> token is allowed."
|
101 |
|
102 |
return True, ""
|
103 |
|
|
|
129 |
if warning:
|
130 |
feedback_msgs.append(warning)
|
131 |
|
132 |
+
if len(feedback_msgs) == 0:
|
133 |
+
feedback_msgs.append("✅ Execution was succesful.")
|
134 |
return result, "\n".join(feedback_msgs)
|
135 |
|
136 |
|
|
|
141 |
footer { display: none !important; }
|
142 |
"""
|
143 |
|
144 |
+
example_dna = "AGGCGGTGGCAACAGCAACGATAGTTGCATCAGCGCTAACTGCTGCTGCTGCTGCGTGTTCTGCCGGAGGCTGCCGGGAGGGTACAGTAATGACTGTAGGGAGCGCACAGCCGCTGCGGCGGCAGGTTCCCTGGATCAGGAAATTAGGACAGGCACCCGGGATTGGAGGCGAGGGCGGCGCGCGAGCCAACCAGCGGTCGCCCCGGGCCCCCGTGAGCCCCAGGCGAACGCGCGGAGCAGCCGGGCCCCTAGAGCGGTCCGGGTGGCGGCGGCGGCAGCCACGACCACGACCGCGGTCAC"
|
145 |
+
example_question = "Is there a promoter element in human or mouse cells present in the nucleotide sequence <DNA>?"
|
146 |
|
147 |
with gr.Blocks(css=css) as demo:
|
148 |
gr.Markdown(
|
|
|
208 |
|
209 |
---
|
210 |
|
211 |
+
### Limitations and Disclaimer
|
212 |
+
ChatNT can only handle questions related to the 27 tasks it has been trained on, including the same format of DNA sequences. ChatNT is not a clinical or diagnostic tool. It can produce incorrect or “hallucinated” answers, particularly on out‑of‑distribution inputs, and its numeric predictions may suffer digit‑level errors. Confidence estimates require post‑hoc calibration. Users should always validate critical outputs against experiments or specialized bioinformatics pipelines.
|
213 |
+
|
214 |
+
### How to query the model ?
|
215 |
+
ChatNT works like an advanced assistant for analyzing DNA sequences — but it has some important rules.
|
216 |
+
|
217 |
+
#### ✅ What works well
|
218 |
+
ChatNT is good at answering biological questions about the meaning or function of the DNA sequence.
|
219 |
+
Examples of good queries:
|
220 |
- "Does this sequence `<DNA>` contain a donor splice site?"
|
221 |
- "Is it possible for you to identify whether there's a substantial presence of H3 histone protein occupancy in the nucleotide sequence `<DNA>` in yeast?"
|
222 |
- "Determine the degradation rate of the mouse RNA sequence `<DNA>` within the -5 to 5 range."
|
223 |
|
224 |
+
#### ❌ What does not work properly
|
225 |
+
ChatNT does not have direct access to the raw nucleotides of the DNA. Instead, it works with an internal representation of the sequence. This means it cannot answer questions about the exact nucleotides or modify the sequence for you.
|
226 |
+
Examples of bad queries:
|
227 |
- "What is the length of this sequence `<DNA>`?"
|
228 |
+
- "Replace the all 'A' nucleotides by 'G' in this sequence `<DNA>`".
|
229 |
|
230 |
For more examples, you can refer to the [training dataset](https://huggingface.co/datasets/InstaDeepAI/ChatNT_training_data).
|
231 |
"""
|
232 |
)
|
233 |
with gr.Column(scale=1):
|
234 |
+
gr.Image(
|
235 |
+
"https://media.springernature.com/w440/springer-static/cover-hires/journal/42256/7/6",
|
236 |
+
label=None,
|
237 |
+
show_label=False
|
238 |
+
)
|
239 |
|
240 |
gr.Markdown("""
|
241 |
### 📚 Citation
|