-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from NII-DG/patch-for-sapporo
Patch for demo using Sapporo
- Loading branch information
Showing
18 changed files
with
405 additions
and
194,840 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
version: "3.5" | ||
services: | ||
nii-dg: | ||
build: | ||
context: .. | ||
dockerfile: Dockerfile-api | ||
image: nii-dg | ||
container_name: nii-dg | ||
ports: | ||
- 0.0.0.0:5000:5000 | ||
restart: on-failure | ||
networks: | ||
- nii-dg-network | ||
sapporo-service: | ||
image: ghcr.io/sapporo-wes/sapporo-service:1.4.9 | ||
container_name: sapporo-service | ||
volumes: | ||
- ${PWD}/run:${PWD}/run | ||
- /var/run/docker.sock:/var/run/docker.sock | ||
- /tmp:/tmp | ||
environment: | ||
- SAPPORO_DEBUG=False | ||
- SAPPORO_RUN_DIR=${PWD}/run | ||
ports: | ||
- 0.0.0.0:1122:1122 | ||
restart: on-failure | ||
networks: | ||
- nii-dg-network | ||
|
||
networks: | ||
nii-dg-network: | ||
name: nii-dg-network |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python3 | ||
# coding: utf-8 | ||
|
||
import argparse | ||
import json | ||
from pathlib import Path | ||
from typing import List | ||
from urllib.request import urlopen | ||
|
||
|
||
def fetch_output_file_list(run_id: str, endpoint: str) -> List[str]: | ||
with urlopen(f"{endpoint.rstrip('/')}/runs/{run_id}") as response: | ||
result = json.load(response) | ||
return [output["file_name"] for output in result["outputs"]] | ||
|
||
|
||
def download_results(endpoint: str, run_id: str, output_dir: Path) -> None: | ||
output_dir.mkdir(parents=True, exist_ok=True) | ||
output_file_list = fetch_output_file_list(run_id, endpoint) | ||
|
||
for output_file in output_file_list: | ||
with urlopen(f"{endpoint.rstrip('/')}/runs/{run_id}/data/outputs/{output_file}") as response: | ||
file_path = output_dir.joinpath("outputs").joinpath(output_file).resolve() | ||
file_path.parent.mkdir(parents=True, exist_ok=True) | ||
with open(file_path, "wb") as f: | ||
f.write(response.read()) | ||
|
||
# download run_request.json | ||
with urlopen(f"{endpoint.rstrip('/')}/runs/{run_id}/data/run_request.json") as response: | ||
file_path = output_dir.joinpath("run_request.json").resolve() | ||
with open(file_path, "wb") as f: | ||
f.write(response.read()) | ||
|
||
|
||
def main() -> None: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("endpoint", help="The endpoint to send the request (default: http://localhost:1122)", | ||
default="http://localhost:1122", nargs="?") | ||
parser.add_argument("run_id", help="The RUN_ID of the executed workflow") | ||
parser.add_argument("output_dir", help="The output directory to save the results (default: ./results)", | ||
default="./results", nargs="?") | ||
args = parser.parse_args() | ||
|
||
download_results(args.endpoint, args.run_id, Path(args.output_dir).resolve()) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python3 | ||
# coding: utf-8 | ||
|
||
import argparse | ||
import json | ||
from urllib.parse import urlencode | ||
from urllib.request import Request, urlopen | ||
|
||
|
||
def execute_workflow(endpoint: str) -> None: | ||
data = { | ||
"workflow_params": json.dumps({ | ||
"fastq_1": {"location": "ERR034597_1.small.fq.gz", "class": "File"}, | ||
"fastq_2": {"location": "ERR034597_2.small.fq.gz", "class": "File"}, | ||
"nthreads": 2 | ||
}), | ||
"workflow_type": "CWL", | ||
"workflow_type_version": "v1.0", | ||
"workflow_url": "https://raw.githubusercontent.com/sapporo-wes/sapporo-service/main/tests/resources/cwltool/trimming_and_qc.cwl", | ||
"workflow_engine_name": "cwltool", | ||
"workflow_attachment": json.dumps([ | ||
{"file_url": "https://raw.githubusercontent.com/sapporo-wes/sapporo-service/main/tests/resources/cwltool/ERR034597_2.small.fq.gz", "file_name": "ERR034597_2.small.fq.gz"}, | ||
{"file_url": "https://raw.githubusercontent.com/sapporo-wes/sapporo-service/main/tests/resources/cwltool/ERR034597_1.small.fq.gz", "file_name": "ERR034597_1.small.fq.gz"} | ||
]) | ||
} | ||
|
||
data = urlencode(data).encode("utf-8") # type: ignore | ||
headers = {"Content-Type": "application/x-www-form-urlencoded"} | ||
# remove trailing slash from endpoint | ||
request = Request(f"{endpoint.rstrip('/')}/runs", data=data, headers=headers) # type: ignore | ||
|
||
with urlopen(request) as response: | ||
result = json.load(response) | ||
print(result) | ||
|
||
|
||
def main() -> None: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("endpoint", help="The endpoint to send the request (default: http://localhost:1122)", | ||
default="http://localhost:1122", nargs="?") | ||
args = parser.parse_args() | ||
execute_workflow(args.endpoint) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.