-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlib.py
More file actions
49 lines (40 loc) · 1.51 KB
/
lib.py
File metadata and controls
49 lines (40 loc) · 1.51 KB
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
from flask import Flask, request, send_file
from flask.helpers import make_response
from werkzeug.utils import secure_filename
import requests
import os, zipfile, tempfile
# Function for the analysis
def analysis(url: str, dest_path: str):
filename = url.split('/')[-1].replace(" ", "_") # be careful with file names
file_path = os.path.join(dest_path, filename)
r = requests.get(url, stream=True)
if r.ok:
print("saving to", os.path.abspath(file_path))
with open(file_path, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024 * 8):
if chunk:
f.write(chunk)
f.flush()
os.fsync(f.fileno())
else:
print("Download failed: status code {}\n{}".format(r.status_code, r.text))
# Command to run the analysis using iBioSim
cmd = r"java -jar analysis/target/iBioSim-analysis-3.1.0-SNAPSHOT-jar-with-dependencies.jar "
print("Running: " + cmd + file_path)
# Running the command
os.system(cmd + file_path)
print('Running ls')
name = filename.replace('.omex','')
nP = file_path[:file_path.rfind('/')] + '/' + name
os.system('ls ' + nP)
# Find the image of the results
for file in os.listdir(nP):
if file.endswith(".png"):
image = os.path.join(nP, file)
print(image)
# Return the image
return image
def call(archive_url):
# Save file locally
with tempfile.TemporaryDirectory() as tempDir:
return analysis(archive_url, tempDir)