PhDFlo commited on
Commit
0a38dda
·
1 Parent(s): 71b6cd0

Modif func fasta and example

Browse files
Files changed (1) hide show
  1. app.py +27 -24
app.py CHANGED
@@ -12,36 +12,39 @@ from modal_app import app, chai1_inference, download_inference_dependencies, her
12
  # Definition of the tools for the MCP server
13
 
14
  # Function to return a fasta file
15
- def return_fasta_file() -> str:
16
- """Create a FASTA file from a protein sequence string.
17
 
18
  Args:
19
- sequence (str): The protein sequence string
20
  name (str, optional): The name/identifier for the sequence. Defaults to "PROTEIN"
21
- output_file (str, optional): Path to save the FASTA file. If None, saves to default location.
22
 
23
  Returns:
24
- str: Path to the created FASTA file
25
  """
26
- # Clean the sequence by removing whitespace and newlines
27
- sequence = ''.join(sequence.split())
28
 
29
- # Set default name if none provided
30
- if name is None:
31
- name = "PROTEIN"
 
 
 
32
 
33
- # Create FASTA content
34
- fasta_content = f">{name}\n{sequence}\n"
35
 
36
- # Set default output path if none provided
37
- if output_file is None:
38
- output_file = here / "inputs" / "chai1_custom_input.fasta"
 
39
 
40
  # Write the FASTA file
41
- with open(output_file, "w") as f:
42
  f.write(fasta_content)
43
 
44
- return str(output_file)
45
 
46
  # Function to create a custom JSON config file
47
  def create_custom_config(
@@ -105,7 +108,7 @@ def compute_Chai1(
105
  if not fasta_file:
106
  fasta_file = here / "inputs" / "chai1_default_input.fasta"
107
  print(f"🧬 running Chai inference on {fasta_file}")
108
- print("titi")
109
  print(fasta_file)
110
  fasta_content = Path(fasta_file).read_text()
111
 
@@ -151,10 +154,10 @@ with gr.Blocks() as demo:
151
  """)
152
 
153
  with gr.Tab("Configuration 📦"):
154
- text_input = gr.Textbox()
155
- text_output = gr.Textbox()
156
- text_button = gr.Button("Generate Configuration")
157
- text_button.click(fn=create_custom_config, inputs=[text_input], outputs=[text_output])
158
 
159
  gr.Markdown(
160
  """
@@ -176,8 +179,8 @@ with gr.Blocks() as demo:
176
  For any issues or questions, please contact the developer or refer to the documentation.
177
  ## Example Fasta File
178
  ```
179
- >sp|P12345|EXAMPLE_HUMAN Example protein
180
- MSEQNNTEMTFQIQRIYTKDISFEAPNAPHVQKLLLQGQGQGQGQGQGQGQGQGQGQ
181
  """)
182
 
183
  with gr.Tab("Run folding simulation 🚀"):
 
12
  # Definition of the tools for the MCP server
13
 
14
  # Function to return a fasta file
15
+ def create_fasta_file(sequence: str, name: Optional[str] = None) -> str:
16
+ """Create a FASTA file from a protein sequence string with a unique name.
17
 
18
  Args:
19
+ sequence (str): The protein sequence string with optional line breaks
20
  name (str, optional): The name/identifier for the sequence. Defaults to "PROTEIN"
 
21
 
22
  Returns:
23
+ str: Name of the created FASTA file
24
  """
25
+ # Remove any trailing/leading whitespace but preserve line breaks
26
+ lines = sequence.strip().split('\n')
27
 
28
+ # Check if the first line is a FASTA header
29
+ if not lines[0].startswith('>'):
30
+ # If no header provided, add one
31
+ if name is None:
32
+ name = "PROTEIN"
33
+ sequence = f">{name}\n{sequence}"
34
 
35
+ # Create FASTA content (preserving line breaks)
36
+ fasta_content = sequence
37
 
38
+ # Generate a unique file name
39
+ unique_id = hashlib.sha256(uuid4().bytes).hexdigest()[:8]
40
+ file_name = f"chai1_{unique_id}_input.fasta"
41
+ file_path = here / "inputs" / file_name
42
 
43
  # Write the FASTA file
44
+ with open(file_path, "w") as f:
45
  f.write(fasta_content)
46
 
47
+ return file_name
48
 
49
  # Function to create a custom JSON config file
50
  def create_custom_config(
 
108
  if not fasta_file:
109
  fasta_file = here / "inputs" / "chai1_default_input.fasta"
110
  print(f"🧬 running Chai inference on {fasta_file}")
111
+ fasta_file = here / "inputs" / fasta_file
112
  print(fasta_file)
113
  fasta_content = Path(fasta_file).read_text()
114
 
 
154
  """)
155
 
156
  with gr.Tab("Configuration 📦"):
157
+ text_input = gr.Textbox(placeholder="Fasta format sequences", label="Fasta content", lines=10)
158
+ text_output = gr.Textbox(placeholder="Fasta file name", label="Fasta file name")
159
+ text_button = gr.Button("Create Fasta file")
160
+ text_button.click(fn=create_fasta_file, inputs=[text_input], outputs=[text_output])
161
 
162
  gr.Markdown(
163
  """
 
179
  For any issues or questions, please contact the developer or refer to the documentation.
180
  ## Example Fasta File
181
  ```
182
+ >protein|name=example-protein
183
+ AGSHSMRYFSTSVSRPGRGEPRFIAVGYVDDTQFVRFD
184
  """)
185
 
186
  with gr.Tab("Run folding simulation 🚀"):