Skip to content

Commit

Permalink
Refactor interface (#88)
Browse files Browse the repository at this point in the history
* Update setup.cfg for new structure

* Update name

* Update tests for new structure

* Setup pipeval main module

* Update validate module

* Update validate module with new structure

* Update checksum module

* Remove old structure

* Update Dockerfile

* Update command name

* Update CHANGELOG

* Update commands in README

* Remove version from subcommands
  • Loading branch information
yashpatel6 authored Nov 30, 2023
1 parent 2ed7792 commit ee3dbe1
Show file tree
Hide file tree
Showing 22 changed files with 166 additions and 140 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

---

## [5.0.0-rc.1] - 2023-11-22
### Changed
- Restructured CLI to have common main command `pipeval`

---

## [4.0.0] - 2023-11-22
### Added
- Parallelize validation

---

## [4.0.0-rc.2] - 2023-04-24
### Changed
- Resolve potential symlinks before validation
Expand Down
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,15 @@ pip install .
```

## Usage
### `validate`
### `pipeval validate`
```
usage: validate [-h] [-v] [-r CRAM_REFERENCE] path [path ...]
usage: pipeval validate [-h] [-v] [-r CRAM_REFERENCE] path [path ...]
positional arguments:
path one or more paths of files to validate
options:
-h, --help show this help message and exit
-v, --version show program's version number and exit
-r CRAM_REFERENCE, --cram-reference CRAM_REFERENCE
Path to reference file for CRAM
-p PROCESSES, --processes PROCESSES
Expand Down Expand Up @@ -111,9 +110,9 @@ Input: path/to/input is valid <file-type>
Error: path/to/input <error message>
```

### `generate-checksum`
### `pipeval generate-checksum`
```
usage: generate-checksum [-h] [-t {md5,sha512}] [-v] path [path ...]
usage: pipeval generate-checksum [-h] [-t {md5,sha512}] [-v] path [path ...]
positional arguments:
path one or more paths of files to validate
Expand All @@ -122,7 +121,6 @@ options:
-h, --help show this help message and exit
-t {md5,sha512}, --type {md5,sha512}
Checksum type
-v, --version show program's version number and exit
```

## Development
Expand Down
7 changes: 3 additions & 4 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ RUN mkdir -p /tool/validate/
COPY setup.py /tool
COPY setup.cfg /tool
COPY pyproject.toml /tool
COPY /generate_checksum /tool/generate_checksum
COPY /validate/ /tool/validate/
COPY /pipeval /tool/pipeval
WORKDIR /tool
RUN pip install build && \
pip install .
Expand All @@ -48,5 +47,5 @@ RUN groupadd -g 500001 bldocker && \
# Change the default user to bldocker from root
USER bldocker

LABEL maintainer="Arpi Beshlikyan <abeshlikyan@mednet.ucla.edu>" \
org.opencontainers.image.source=https://github.com/uclahs-cds/public-tool-PipeVal
LABEL maintainer="Yash Patel <yashpatel@mednet.ucla.edu>" \
org.opencontainers.image.source=https://github.com/uclahs-cds/package-PipeVal
25 changes: 0 additions & 25 deletions generate_checksum/__main__.py

This file was deleted.

3 changes: 3 additions & 0 deletions pipeval/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'''Inits pipeval module'''

__version__ = '5.0.0-rc.1'
32 changes: 32 additions & 0 deletions pipeval/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
''' Console script main entrance '''
import argparse
from pipeval import __version__

from pipeval.validate.__main__ import add_subparser_validate
from pipeval.generate_checksum.__main__ import add_subparser_generate_checksum

def _parse_args():
""" Parse arguments """
parser = argparse.ArgumentParser(
prog = 'pipeval'
)

parser.add_argument(
'-v', '--version',
action='version',
version=f'%(prog)s {__version__}'
)

subparsers = parser.add_subparsers(dest = 'command')
add_subparser_validate(subparsers)
add_subparser_generate_checksum(subparsers)

return parser.parse_args()

def main():
''' Main entrance '''
args = _parse_args()
args.func(args)

if __name__=='__main__':
main()
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
'''Inits checksum module'''

__version__ = '3.0.0'
18 changes: 18 additions & 0 deletions pipeval/generate_checksum/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
''' Console script main entrance '''
import argparse
from pipeval.generate_checksum.checksum import generate_checksum

def add_subparser_generate_checksum(subparsers:argparse._SubParsersAction):
""" Parse arguments """
parser = subparsers.add_parser(
name = 'generate-checksum',
help = 'Generate checksums for one or more file(s)',
description = 'Generate checksums for one or more file(s)',
formatter_class = argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument('path', help='one or more paths of files to validate', type=str, nargs='+')
parser.add_argument('-t', '--type', help='Checksum type',
choices=['md5', 'sha512'],
default='sha512')

parser.set_defaults(func=generate_checksum)
File renamed without changes.
2 changes: 0 additions & 2 deletions validate/__init__.py → pipeval/validate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
'''Inits validate module'''

__version__ = '4.0.0'
26 changes: 10 additions & 16 deletions validate/__main__.py → pipeval/validate/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
''' Console script main entrance '''
import argparse
from validate import __version__
from validate.validate import run_validate
from pipeval.validate.validate import run_validate

def positive_integer(arg):
""" Type and value check for positive integers """
Expand All @@ -15,24 +14,19 @@ def positive_integer(arg):

return i

def _parse_args():
def add_subparser_validate(subparsers:argparse._SubParsersAction):
""" Parse arguments """
parser = argparse.ArgumentParser()
parser.add_argument('path', help='one or more paths of files to validate', type=str, nargs='+')
parser.add_argument('-v', '--version', action='version', version=f'%(prog)s {__version__}')
parser = subparsers.add_parser(
name = 'validate',
help = 'Validate one or more file(s)',
description = 'Validate one or more file(s)',
formatter_class = argparse.ArgumentDefaultsHelpFormatter
)

parser.add_argument('path', help='One or more paths of files to validate', type=str, nargs='+')
parser.add_argument('-r', '--cram-reference', default=None, \
help='Path to reference file for CRAM')
parser.add_argument('-p', '--processes', type=positive_integer, default=1, \
help='Number of processes to run in parallel when validating multiple files')

parser.set_defaults(func=run_validate)

return parser.parse_args()

def main():
''' Main entrance '''
args = _parse_args()
args.func(args)

if __name__=='__main__':
main()
File renamed without changes.
14 changes: 7 additions & 7 deletions validate/validate.py → pipeval/validate/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
import multiprocessing
from itertools import repeat

from validate.validators.bam import _check_bam
from validate.validators.sam import _check_sam
from validate.validators.cram import _check_cram
from validate.validators.vcf import _check_vcf
from validate.files import (
from pipeval.validate.validators.bam import _check_bam
from pipeval.validate.validators.sam import _check_sam
from pipeval.validate.validators.cram import _check_cram
from pipeval.validate.validators.vcf import _check_vcf
from pipeval.validate.files import (
_check_compressed,
_path_exists
)
from validate.validate_types import ValidateArgs
from generate_checksum.checksum import _validate_checksums
from pipeval.validate.validate_types import ValidateArgs
from pipeval.generate_checksum.checksum import _validate_checksums

# Currently supported data types
FILE_TYPES_DICT = {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pysam

from validate.validate_types import ValidateArgs
from pipeval.validate.validate_types import ValidateArgs

def _validate_bam_file(path:Path):
'''Validates bam file'''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pysam

from validate.validate_types import ValidateArgs
from pipeval.validate.validate_types import ValidateArgs

def _validate_cram_file(path:Path, reference:str=None):
'''Validates cram file'''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pysam

from validate.validate_types import ValidateArgs
from pipeval.validate.validate_types import ValidateArgs

def _validate_sam_file(path:Path):
'''Validates sam file'''
Expand Down
File renamed without changes.
7 changes: 3 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = validate
version = attr: validate.__version__
name = pipeval
version = attr: pipeval.__version__
author = 'Yash Patel'
author_email = 'YashPatel@mednet.ucla.edu'
description = 'Python CLI tool to validate different file types and their contents in Nextflow scripts/pipelines'
Expand Down Expand Up @@ -31,5 +31,4 @@ where = .

[options.entry_points]
console_scripts =
validate = validate.__main__:main
generate-checksum = generate_checksum.__main__:main
pipeval = pipeval.__main__:main
Loading

0 comments on commit ee3dbe1

Please sign in to comment.