Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jerowe committed Jan 15, 2024
1 parent 7d4f315 commit 0cd297b
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 0 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@ Helper utils for omics

* Free software: MIT license

## Usage

### Prepare the workflow

In order to use a nextflow workflow with AWS Omics, you need to prepare it first.

* All images must be stored in *your* ecr repository. You can use the `create-ecr-repos` command to create the repos and
push the images.
* All parameters must be defined in the `nextflow_schema.json` file. You can use the `create-workflow` command to create
the workflow.
* The workflow must be zipped and uploaded to AWS Omics. You can use the `create-workflow` command to create the
workflow.

```bash
omicsx create-ecr-repos --nf-workflow <your-nextflow-workflow-directory> \
--aws-region <your-aws-region>

omicsx create-workflow --nf-workflow <your-nextflow-workflow-directory> \
--name <your-workflow-name> \
--aws-region <your-aws-region>
```

# CLI

**Usage**:
Expand Down Expand Up @@ -101,6 +123,32 @@ $ omicsx create-workflow [OPTIONS] NF_WORKFLOW NAME
* `--aws-profile TEXT`: [default: default]
* `--help`: Show this message and exit.

## `list-workflows`

List existing omics workflows

**Options**:

* `--aws-region TEXT`: [default: us-east-1]
* `--aws-profile TEXT`: [default: default]
* `--help`: Show this message and exit.

## `list-runs`

List existing omics runs

**Usage**:

```console
$ list-runs [OPTIONS]
```

**Options**:

* `--aws-region TEXT`: [default: us-east-1]
* `--aws-profile TEXT`: [default: default]
* `--help`: Show this message and exit.

## `run-cost`

Calculate the cost of a run. If the run is still running, it will calculate the current cost. If the run is complete, it
Expand Down
32 changes: 32 additions & 0 deletions bioanalyze_omics/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,38 @@ def create_ecr_repos(
return


@app.command()
def list_workflows(
aws_region: Annotated[
Optional[str],
typer.Option(help="AWS Region", default=AWS_REGION),
] = AWS_REGION,
aws_profile: Annotated[
Optional[str], typer.Option(help="AWS Profile", default="default")
] = "default",
):
"""List existing omics workflows"""
omics_workflow = workflows.OmicsWorkflow(aws_region=aws_region)
omics_workflow.list_workflows()
return


@app.command()
def list_runs(
aws_region: Annotated[
Optional[str],
typer.Option(help="AWS Region", default=AWS_REGION),
] = AWS_REGION,
aws_profile: Annotated[
Optional[str], typer.Option(help="AWS Profile", default="default")
] = "default",
):
"""List existing omics runs"""
omics_run = runs.OmicsRun(aws_region=aws_region)
omics_run.list_runs()
return


@app.command()
def create_workflow(
nf_workflow: Annotated[
Expand Down
2 changes: 2 additions & 0 deletions bioanalyze_omics/resources/ecr.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

from bioanalyze_omics.nf import NextflowWorkflow
from bioanalyze_omics.resources.account import get_aws_account_id
from rich.console import Console
from rich.table import Table

import logging
from rich.logging import RichHandler
Expand Down
29 changes: 29 additions & 0 deletions bioanalyze_omics/resources/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import requests
from copy import deepcopy
import pandas as pd
from rich.console import Console
from rich.table import Table

MINIMUM_STORAGE_CAPACITY_GIB = 1200

Expand Down Expand Up @@ -218,6 +220,33 @@ def gen_run_df(self, run: Any) -> pd.DataFrame:
run_df = pd.DataFrame.from_records([run])
return run_df

def list_runs(self):
response = self.omics_client.list_runs()
if 'items' not in response:
return []
table = Table(title="Runs")
table.add_column("RunId")
table.add_column("WorkflowId")
table.add_column("Name")
table.add_column("Status")
table.add_column("CreationTime")
table.add_column("StartTime")
table.add_column("StopTime")
for run in response['items']:
table.add_row(
run['id'],
run['workflowId'],
run['name'],
run['status'],
run['creationTime'].strftime("%Y/%m/%d, %H:%M:%S"),
run['startTime'].strftime("%Y/%m/%d, %H:%M:%S"),
run['stopTime'].strftime("%Y/%m/%d, %H:%M:%S"),

)
console = Console()
console.print(table)
return response['items']


def calculate_cost(
run_id: str,
Expand Down
23 changes: 23 additions & 0 deletions bioanalyze_omics/resources/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from urllib.parse import urlparse
from zipfile import ZipFile, ZIP_DEFLATED
from typing import Dict, List, Any
from rich.console import Console
from rich.table import Table

import boto3
import botocore.exceptions
Expand Down Expand Up @@ -144,3 +146,24 @@ def create_workflow(
name=name,
)
return workflow

def list_workflows(self):
response = self.omics_client.list_workflows()
if 'items' not in response:
return []
table = Table(title="Workflows")
table.add_column("ID")
table.add_column("Name")
table.add_column("CreationTime")
for workflow in response['items']:
table.add_row(workflow['id'], workflow['name'], workflow['creationTime'].strftime("%Y/%m/%d, %H:%M:%S"))
console = Console()
console.print(table)
return response['items']

def submit_workflow(self, workflow_id: str, parameters: Dict[str, Any]):
response = self.omics_client.submit_workflow(
id=workflow_id,
parameterOverrides=parameters,
)
return response

0 comments on commit 0cd297b

Please sign in to comment.