Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -162,31 +162,33 @@ def run_blast(arguments_string: str) -> str:
|
|
| 162 |
return result_response.text
|
| 163 |
|
| 164 |
if __name__ == "__main__":
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
print("Usage: python blast_tool.py program database query_sequence", file=sys.stderr)
|
| 167 |
print(" query_sequence should be the sequence itself, not a file.", file=sys.stderr)
|
| 168 |
sys.exit(1)
|
| 169 |
|
| 170 |
-
arguments_string = " ".join(sys.argv[1:]) # Reconstruct arguments string from command line
|
| 171 |
-
results = run_blast(arguments_string)
|
| 172 |
-
|
| 173 |
-
if results.startswith("Error:"):
|
| 174 |
-
print(results, file=sys.stderr) # Print errors to stderr
|
| 175 |
-
if results == "Error: Invalid arguments. Usage: program database query_sequence":
|
| 176 |
-
sys.exit(1)
|
| 177 |
-
elif results == "No hits found.":
|
| 178 |
-
sys.exit(2)
|
| 179 |
-
elif results.startswith("Search ") and results.endswith("expired."):
|
| 180 |
-
sys.exit(3)
|
| 181 |
-
elif results.startswith("Search ") and results.endswith("failed; please report to blast-help@ncbi.nlm.nih.gov."):
|
| 182 |
-
sys.exit(4)
|
| 183 |
-
else: # Catch-all for other errors
|
| 184 |
-
sys.exit(5)
|
| 185 |
-
else:
|
| 186 |
-
print(results)
|
| 187 |
-
sys.exit(0)
|
| 188 |
-
|
| 189 |
-
|
| 190 |
|
| 191 |
final_answer = FinalAnswerTool()
|
| 192 |
|
|
|
|
| 162 |
return result_response.text
|
| 163 |
|
| 164 |
if __name__ == "__main__":
|
| 165 |
+
import os
|
| 166 |
+
if os.path.basename(sys.argv[0]) == os.path.basename(__file__) and len(sys.argv) > 1:
|
| 167 |
+
arguments_string = " ".join(sys.argv[1:]) # Reconstruct arguments string from command line
|
| 168 |
+
results = run_blast(arguments_string)
|
| 169 |
+
|
| 170 |
+
if results.startswith("Error:"):
|
| 171 |
+
print(results, file=sys.stderr) # Print errors to stderr
|
| 172 |
+
if results == "Error: Invalid arguments. Usage: program database query_sequence":
|
| 173 |
+
sys.exit(1)
|
| 174 |
+
elif results == "No hits found.":
|
| 175 |
+
sys.exit(2)
|
| 176 |
+
elif results.startswith("Search ") and results.endswith("expired."):
|
| 177 |
+
sys.exit(3)
|
| 178 |
+
elif results.startswith("Search ") and results.endswith("failed; please report to blast-help@ncbi.nlm.nih.gov."):
|
| 179 |
+
sys.exit(4)
|
| 180 |
+
else: # Catch-all for other errors
|
| 181 |
+
sys.exit(5)
|
| 182 |
+
else:
|
| 183 |
+
print(results)
|
| 184 |
+
sys.exit(0)
|
| 185 |
+
elif os.path.basename(sys.argv[0]) == os.path.basename(__file__):
|
| 186 |
+
print("This script is intended to be used as a tool function.", file=sys.stderr)
|
| 187 |
+
print("When run directly, it requires command-line arguments:", file=sys.stderr)
|
| 188 |
print("Usage: python blast_tool.py program database query_sequence", file=sys.stderr)
|
| 189 |
print(" query_sequence should be the sequence itself, not a file.", file=sys.stderr)
|
| 190 |
sys.exit(1)
|
| 191 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
final_answer = FinalAnswerTool()
|
| 194 |
|