Skip to content

Commit

Permalink
Merge pull request #6 from rabix/feature/publishDir_support
Browse files Browse the repository at this point in the history
Binding takes itemSeparator and shellQuote
  • Loading branch information
pavlemarinkovic authored Jun 28, 2024
2 parents 8fd5e80 + d3720e9 commit a38c3f9
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 18 deletions.
15 changes: 9 additions & 6 deletions wrabbit/parser/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,19 @@ class EXTENSIONS:
}

GENERIC_NF_OUTPUT_DIRECTORY = {
"id": "nf_workdir",
"id": "nf_publishdir",
"type": [
'null',
'Directory'
{
'type': 'array',
'items': 'File'
}
],
"label": "Work Directory",
"label": "Publish Directory",
"doc": "This is a template output. "
"Please change glob to directories specified in "
"publishDir in the workflow.",
"You can modify the glob pattern to make outputs more specific.",
"outputBinding": {
'glob': "work"
'glob': "*"
}
}

Expand Down Expand Up @@ -139,6 +141,7 @@ def sample_sheet(
SB_SCHEMA_DEFAULT_NAME = 'sb_nextflow_schema'
README_DEFAULT_NAME = 'README.md'
MINIMUM_SUPPORTED_NF_VERSION = "21.10.0"
NFCORE_OUTPUT_DIRECTORY_ID = 'outdir'

# Mappings of nextflow input fields to SB input fields
# nextflow_key: cwl_key mapping
Expand Down
32 changes: 26 additions & 6 deletions wrabbit/parser/nextflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
SAMPLE_SHEET_SWITCH,
LOAD_LISTING_REQUIREMENT,
SKIP_NEXTFLOW_TOWER_KEYS,
NFCORE_OUTPUT_DIRECTORY_ID,
)

from wrabbit.specification.node import (
Expand All @@ -60,6 +61,11 @@


class NextflowParser:
nf_config_files: list
nf_schema_path: Optional[str]
readme_path: Optional[str]
sb_samplesheet_schema: Optional[str]

def __init__(
self, workflow_path: str,
sb_doc: Optional[str] = None,
Expand All @@ -72,7 +78,7 @@ def __init__(
self.workflow_path = workflow_path

# Locate nextflow files in the package if possible
self.nf_config_files = get_config_files(self.workflow_path) or []
self.init_config_files()
self.nf_schema_path = get_nf_schema(self.workflow_path)
self.readme_path = get_docs_file(self.workflow_path)
self.sb_samplesheet_schema = get_sample_sheet_schema(
Expand All @@ -85,6 +91,13 @@ def __init__(
self.executor_version = executor_version
self.sb_package_id = sb_package_id

def init_config_files(self):
"""
Config may be initialized multiple times while working with a code
package in case a new config file is generated with nf-core lib.
"""
self.nf_config_files = get_config_files(self.workflow_path) or []

def generate_sb_inputs(self):
"""
Generate SB inputs schema
Expand Down Expand Up @@ -159,6 +172,12 @@ def generate_sb_inputs(self):
required=req,
))

# Remap publishDir to string type
if temp := self.sb_wrapper.get_input(NFCORE_OUTPUT_DIRECTORY_ID):
print(f"Detected publishDir input --{temp.id_}. Remapping to "
f"string type input.")
temp.set_property('type', 'string')

# Add the generic file array input - auxiliary files
self.sb_wrapper.safe_add_input(GENERIC_FILE_ARRAY_INPUT)
self.sb_wrapper.safe_add_input(NF_PARAMS_FILE_INPUT)
Expand Down Expand Up @@ -210,12 +229,13 @@ def generate_app_data(self):
# Stop searching if manifest is found
break

self.executor_version = self.executor_version or \
get_executor_version(self.sb_doc)
if not self.executor_version and self.sb_doc:
self.executor_version = get_executor_version(self.sb_doc)

# Confirm if the executor version is valid.
# If it is below 22.10.1 it is not supported.
self.executor_version.correct_version()
if self.executor_version:
# Confirm if the executor version is valid.
# If it is below 22.10.1 it is not supported.
self.executor_version.correct_version()

# step2: add links

Expand Down
2 changes: 1 addition & 1 deletion wrabbit/parser/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def get_nf_schema(string):
if os.path.exists(path):
return path
else:
raise Exception()
return None


def get_docs_file(path):
Expand Down
6 changes: 4 additions & 2 deletions wrabbit/specification/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ def __init__(
**kwargs
):
self.prefix = prefix
self.item_separator = item_separator
self.shell_quote = shell_quote
self.item_separator = item_separator or \
kwargs.get('itemSeparator', None)
self.shell_quote = shell_quote or \
kwargs.get('shellQuote', None)
self.glob = glob

def serialize(self):
Expand Down
5 changes: 5 additions & 0 deletions wrabbit/specification/listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ def deserialize(listing):
elif isinstance(listing, str):
return Listing(listing)
return Listing(**listing)

def __eq__(self, other):
assert isinstance(other, Listing)

return self.__dict__ == other.__dict__
6 changes: 4 additions & 2 deletions wrabbit/specification/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ def add_listing(self, obj: Union[dict, str, Listing]):
if not self.listing:
self.listing = list()

if obj not in self.listing:
self.listing.append(obj)
for ref_obj in self.listing:
if ref_obj != obj:
self.listing.append(obj)
break

def serialize(self):
temp = {
Expand Down
2 changes: 1 addition & 1 deletion wrabbit/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.3"
__version__ = "0.2.0"
1 change: 1 addition & 0 deletions wrabbit/wrapper/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def add_requirement(self, requirement: [dict, Requirement]):
for req in self.requirements:
if req.class_ == requirement.class_:
req.update(requirement)
break
else:
# add new class
self.requirements.append(requirement)
Expand Down

0 comments on commit a38c3f9

Please sign in to comment.