Skip to content

Commit

Permalink
Add Post runs examples
Browse files Browse the repository at this point in the history
  • Loading branch information
suecharo committed May 7, 2020
1 parent 5878fcd commit 85dfe8a
Show file tree
Hide file tree
Showing 13 changed files with 222 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,4 @@ cython_debug/

.gitkeep
run/
tests/resources/outputs/
54 changes: 54 additions & 0 deletions tests/post_runs_examples/access_remote_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python3
# coding: utf-8
import json
from pathlib import Path
from typing import BinaryIO, Dict, Tuple

import requests
from requests import Response

from genpei.type import RunRequest

URL: str = "localhost:8080"
SCRIPT_DIR: Path = \
Path(__file__).parent.resolve()
RES_D: Path = \
SCRIPT_DIR.parent.joinpath("resources").resolve()


def main() -> None:
data: RunRequest = {
"workflow_params": json.dumps({
"fastq_1": {
"class": "File",
"location": "https://raw.githubusercontent.com/suecharo/" +
"genpei/master/tests/resources/" +
"ERR034597_1.small.fq.gz"
},
"fastq_2": {
"class": "File",
"location": "https://raw.githubusercontent.com/suecharo/" +
"genpei/master/tests/resources/" +
"ERR034597_2.small.fq.gz"
}
}),
"workflow_type": "CWL",
"workflow_type_version": "v1.0",
"tags": json.dumps({
"workflow_name": "trimming_and_qc_remote"
}),
"workflow_engine_parameters": json.dumps({}),
"workflow_url": "https://raw.githubusercontent.com/suecharo/" +
"genpei/master/tests/resources/" +
"trimming_and_qc_remote.cwl"
}
files: Dict[str, Tuple[str, BinaryIO]] = {}
response: Response = \
requests.post(f"http://{URL}/runs", data=data, files=files)

print(response.status_code)
print(json.dumps(json.loads(response.text), indent=2))


if __name__ == "__main__":
main()
59 changes: 59 additions & 0 deletions tests/post_runs_examples/attach_all_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python3
# coding: utf-8
import json
from pathlib import Path
from typing import BinaryIO, Dict, Tuple

import requests
from requests import Response

from genpei.type import RunRequest

URL: str = "localhost:8080"
SCRIPT_DIR: Path = \
Path(__file__).parent.resolve()
RES_D: Path = \
SCRIPT_DIR.parent.joinpath("resources").resolve()


def main() -> None:
data: RunRequest = {
"workflow_params": json.dumps({
"fastq_1": {
"class": "File",
"path": "./ERR034597_1.small.fq.gz"
},
"fastq_2": {
"class": "File",
"path": "./ERR034597_1.small.fq.gz"
}
}),
"workflow_type": "CWL",
"workflow_type_version": "v1.0",
"tags": json.dumps({
"workflow_name": "trimming_and_qc_remote"
}),
"workflow_engine_parameters": json.dumps({}),
"workflow_url": "./trimming_and_qc.cwl"
}
files: Dict[str, Tuple[str, BinaryIO]] = {
"fastq_1": ("ERR034597_1.small.fq.gz",
RES_D.joinpath("ERR034597_1.small.fq.gz").open(mode="rb")),
"fastq_2": ("ERR034597_2.small.fq.gz",
RES_D.joinpath("ERR034597_2.small.fq.gz").open(mode="rb")),
"workflow": ("trimming_and_qc.cwl",
RES_D.joinpath("trimming_and_qc.cwl").open(mode="rb")),
"tool_1": ("fastqc.cwl",
RES_D.joinpath("fastqc.cwl").open(mode="rb")),
"tool_2": ("trimmomatic_pe.cwl",
RES_D.joinpath("trimmomatic_pe.cwl").open(mode="rb"))
}
response: Response = \
requests.post(f"http://{URL}/runs", data=data, files=files)

print(response.status_code)
print(json.dumps(json.loads(response.text), indent=2))


if __name__ == "__main__":
main()
48 changes: 48 additions & 0 deletions tests/post_runs_examples/get_inputs_from_mount.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python3
# coding: utf-8
import json
from pathlib import Path
from typing import BinaryIO, Dict, Tuple

import requests
from requests import Response

from genpei.type import RunRequest

URL: str = "localhost:8080"
SCRIPT_DIR: Path = \
Path(__file__).parent.resolve()
RES_D: Path = \
SCRIPT_DIR.parent.joinpath("resources").resolve()


def main() -> None:
data: RunRequest = {
"workflow_params": json.dumps({
"fastq_1": {
"class": "File",
"location": str(RES_D.joinpath("ERR034597_1.small.fq.gz"))
},
"fastq_2": {
"class": "File",
"location": str(RES_D.joinpath("ERR034597_2.small.fq.gz"))
}
}),
"workflow_type": "CWL",
"workflow_type_version": "v1.0",
"tags": json.dumps({
"workflow_name": "trimming_and_qc"
}),
"workflow_engine_parameters": json.dumps({}),
"workflow_url": str(RES_D.joinpath("trimming_and_qc.cwl"))
}
files: Dict[str, Tuple[str, BinaryIO]] = {}
response: Response = requests.post(
f"http://{URL}/runs", data=data, files=files)

print(response.status_code)
print(json.dumps(json.loads(response.text), indent=2))


if __name__ == "__main__":
main()
56 changes: 56 additions & 0 deletions tests/post_runs_examples/put_outputs_on_mount.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python3
# coding: utf-8
import json
from pathlib import Path
from typing import BinaryIO, Dict, Tuple

import requests
from requests import Response

from genpei.type import RunRequest

URL: str = "localhost:8080"
SCRIPT_DIR: Path = \
Path(__file__).parent.resolve()
RES_D: Path = \
SCRIPT_DIR.parent.joinpath("resources").resolve()


def main() -> None:
data: RunRequest = {
"workflow_params": json.dumps({
"fastq_1": {
"class": "File",
"location": "https://raw.githubusercontent.com/suecharo/" +
"genpei/master/tests/resources/" +
"ERR034597_1.small.fq.gz"
},
"fastq_2": {
"class": "File",
"location": "https://raw.githubusercontent.com/suecharo/" +
"genpei/master/tests/resources/" +
"ERR034597_2.small.fq.gz"
}
}),
"workflow_type": "CWL",
"workflow_type_version": "v1.0",
"tags": json.dumps({
"workflow_name": "trimming_and_qc_remote"
}),
"workflow_engine_parameters": json.dumps({
"--outdir": str(RES_D.joinpath("outputs"))
}),
"workflow_url": "https://raw.githubusercontent.com/suecharo/" +
"genpei/master/tests/resources/" +
"trimming_and_qc_remote.cwl"
}
files: Dict[str, Tuple[str, BinaryIO]] = {}
response: Response = \
requests.post(f"http://{URL}/runs", data=data, files=files)

print(response.status_code)
print(json.dumps(json.loads(response.text), indent=2))


if __name__ == "__main__":
main()
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/test_get_run_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_get_run_id(tmpdir: LocalPath) -> None:
app: Flask = create_app(Path(tmpdir))
app.testing = True
client: FlaskClient[Response] = app.test_client()
from .post_runs.test_access_remote_files import access_remote_files
from .post_runs_tests.test_access_remote_files import access_remote_files
posts_res: Response = access_remote_files(client)
posts_res_data: RunId = posts_res.get_json()

Expand Down
2 changes: 1 addition & 1 deletion tests/test_get_run_id_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_get_runs(tmpdir: LocalPath) -> None:
app: Flask = create_app(Path(tmpdir))
app.testing = True
client: FlaskClient[Response] = app.test_client()
from .post_runs.test_access_remote_files import access_remote_files
from .post_runs_tests.test_access_remote_files import access_remote_files
posts_res: Response = access_remote_files(client)
posts_res_data: RunId = posts_res.get_json()

Expand Down
2 changes: 1 addition & 1 deletion tests/test_get_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_get_runs(tmpdir: LocalPath) -> None:
app: Flask = create_app(Path(tmpdir))
app.testing = True
client: FlaskClient[Response] = app.test_client()
from .post_runs.test_access_remote_files import access_remote_files
from .post_runs_tests.test_access_remote_files import access_remote_files
posts_res: Response = access_remote_files(client)
posts_res_data: RunId = posts_res.get_json()

Expand Down
2 changes: 1 addition & 1 deletion tests/test_post_run_id_cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_post_run_id_cancel(tmpdir: LocalPath) -> None:
app: Flask = create_app(Path(tmpdir))
app.testing = True
client: FlaskClient[Response] = app.test_client()
from .post_runs.test_access_remote_files import access_remote_files
from .post_runs_tests.test_access_remote_files import access_remote_files
posts_res: Response = access_remote_files(client)
posts_res_data: RunId = posts_res.get_json()

Expand Down

0 comments on commit 85dfe8a

Please sign in to comment.