Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "toolchest-client"
version = "0.7.40"
version = "0.7.43"
description = "Python client for Toolchest"
authors = [
"Bryce Cai <bcai@trytoolchest.com>",
Expand Down
2 changes: 1 addition & 1 deletion toolchest_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
from toolchest_client.api.auth import get_key, set_key
from toolchest_client.api.exceptions import ToolchestException, DataLimitError, ToolchestJobError
from toolchest_client.api.query import Query
from .tools.api import bowtie2, cellranger_mkfastq, kraken2, shi7, shogun_align, shogun_filter, STAR, test, unicycler
from .tools.api import bowtie2, cellranger_mkfastq, kraken2, megahit, shi7, shogun_align, shogun_filter, STAR, test, unicycler
1 change: 1 addition & 0 deletions toolchest_client/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .bowtie2 import Bowtie2
from .cellranger import CellRangerMkfastq
from .kraken2 import Kraken2
from .megahit import Megahit
from .shi7 import Shi7
from .shogun import ShogunAlign, ShogunFilter
from .star import STARInstance
Expand Down
63 changes: 59 additions & 4 deletions toolchest_client/tools/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
This module contains the API for using Toolchest tools.
"""
from toolchest_client.files import assert_exists
from toolchest_client.tools import Kraken2, CellRangerMkfastq, Bowtie2, Shi7, ShogunAlign, ShogunFilter, STARInstance, Test, Unicycler
from toolchest_client.tools import Kraken2, CellRangerMkfastq, Bowtie2, Megahit, Shi7, ShogunAlign, ShogunFilter, STARInstance, Test, Unicycler


def bowtie2(inputs, output_path, database_name="GRCh38_noalt_as", database_version="1", tool_args=""):
Expand Down Expand Up @@ -102,7 +102,7 @@ def kraken2(output_path, inputs=[], database_name="standard", database_version="
>>> toolchest.kraken2(
... tool_args="",
... inputs="./path/to/input.fastq",
... output_path="./path/to/output.txt",
... output_path="./path/to/output",
... )

"""
Expand Down Expand Up @@ -135,6 +135,61 @@ def kraken2(output_path, inputs=[], database_name="standard", database_version="
instance.run()


def megahit(output_path, tool_args="", read_one=None, read_two=None, interleaved=None,
single_end=None):
"""Runs Megahit via Toolchest.

:param output_path: Path (client-side) where the output will be downloaded.
:param tool_args: (optional) Additional arguments to be passed to Megahit.
:param read_one: (optional) `-1` inputs. Path or list of paths for read 1 of paired-read input files.
:param read_two: (optional) `-2` inputs. Path or list of paths for read 2 of paired-read input files.
:param interleaved: (optional) `--12` inputs. Path or list of paths for interleaved paired-end files.
:param single_end: (optional) `-r` inputs. Path or list of paths for single-end inputs.

.. note:: Each read in `read_one` should match with a read in `read_two`, and vice
versa. In other words, the nth read in `read_one` should be paired with the nth read
in `read_two`.

Usage::

>>> import toolchest_client as toolchest
>>> toolchest.megahit(
... tool_args="",
... read_one=["./pair_1/r1.fa", "./pair_2/r1.fa"],
... read_two=["./pair_1/r2.fa", "./pair_2/r2.fa"],
... output_path="./path/to/output",
... )

"""

# If input parameters are lists, parse these for input_prefix_mapping.
tag_to_param_map = {
"-1": read_one,
"-2": read_two,
"--12": interleaved,
"-r": single_end,
}
input_list = [] # list of all inputs
input_prefix_mapping = {} # map of each input to its respective tag
for tag, param in tag_to_param_map.items():
if isinstance(param, list):
for input_file in param:
input_list.append(input_file)
input_prefix_mapping[input_file] = tag
elif isinstance(param, str):
input_list.append(param)
input_prefix_mapping[param] = tag

instance = Megahit(
tool_args=tool_args,
output_name='output.tar.gz',
input_prefix_mapping=input_prefix_mapping,
inputs=input_list,
output_path=output_path,
)
instance.run()


def shi7(inputs, output_path, tool_args=""):
"""Runs shi7 via Toolchest.

Expand Down Expand Up @@ -189,7 +244,7 @@ def shogun_align(inputs, output_path, database_name="shogun_standard", database_
inputs=inputs,
output_path=output_path,
database_name=database_name,
database_version=database_version
database_version=database_version,
)
instance.run()

Expand Down Expand Up @@ -222,7 +277,7 @@ def shogun_filter(inputs, output_path, database_name="shogun_standard", database
inputs=inputs,
output_path=output_path,
database_name=database_name,
database_version=database_version
database_version=database_version,
)
instance.run()

Expand Down
38 changes: 38 additions & 0 deletions toolchest_client/tools/megahit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
toolchest_client.tools.megahit
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is the megahit implementation of the Tool class.
"""
from toolchest_client.files import OutputType

from . import Tool


class Megahit(Tool):
"""
The megahit implementation of the Tool class.
"""
def __init__(self, tool_args, output_name, inputs, input_prefix_mapping,
output_path):
super().__init__(
tool_name="megahit",
tool_version="1.2.9", # todo: allow version to be set by the user
tool_args=tool_args,
output_name=output_name,
output_path=output_path,
inputs=inputs,
input_prefix_mapping=input_prefix_mapping,
min_inputs=1,
max_inputs=10, # todo: make this unlimited?
parallel_enabled=False,
output_type=OutputType.GZ_TAR,
output_is_directory=True,
output_names=[
"checkpoints.txt",
"done",
"final.contigs.fa",
"log",
"options.json",
],
)
26 changes: 26 additions & 0 deletions toolchest_client/tools/tool_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,32 @@
"--paired": 0,
},
},
"megahit": {
"blacklist": [
"--continue",
"-o",
],
"whitelist": {
"--min-count": 1,
"--k-list": 1,
"--k-min": 1,
"--k-max": 1,
"--k-step": 1,
"--no-mercy": 0,
"--bubble-level": 1,
"--merge-level": 1,
"--prune-level": 1,
"--prune-depth": 1,
"--disconnect-ratio": 1,
"--low-local-ratio": 1,
"--max-tip-len": 1,
"--cleaning-rounds": 1,
"--no-local": 0,
"--kmin-1pass": 1,
"--presets": 1,
"--min-contig-len": 1,
},
},
"shi7": {
"whitelist": {
"--debug": 0,
Expand Down