Skip to content

Commit

Permalink
Improve the implement of the spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
yjcyxky committed May 30, 2023
1 parent 7aff8fa commit 7022ee9
Show file tree
Hide file tree
Showing 11 changed files with 1,654 additions and 124 deletions.
49 changes: 44 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,20 @@ python setup.py install
### Usage

```bash
Usage: metadata_validator [OPTIONS]
Usage: metav [OPTIONS] COMMAND [ARGS]...

Console script for metadata_validator.
Options:
--help Show this message and exit.

Commands:
generate-template Generate metadata template as a xlsx file.
validate Metadata Validator
```

```bash
Usage: metav validate [OPTIONS]

Metadata Validator

Options:
-i, --input FILE Input file path, only support xlsx file.
Expand All @@ -37,22 +48,50 @@ Options:
--help Show this message and exit.
```
```bash
Usage: metav generate-template [OPTIONS]
Generate metadata template as a xlsx file.
Options:
-o, --output TEXT Output metadata template as a file.
[required]
-t, --template-type [DNAseq|RNAseq|Proteomics|Metabolomics]
It support the following metadata tables:
'DNAseq', 'RNAseq', 'Proteomics,
'Metabolomics' [required]
--help Show this message and exit.
```

### Example

Validate your metadata file of DNAseq template with the following command:
#### Generate metadata template

```bash
metadata_validator -i your_metadata_file.xlsx -o output.log -t DNAseq
metav generate-template -t Metabolomics -o metabolomics_metadata.xlsx
```

![metabolomics_metadata](./assets/metabolomics-metadata-table.png)

#### Validate metadata

Validate your metadata file of Metabolomics template with the following command:

```bash
metav validate -i your_metadata_file.xlsx -o output.log -t Metabolomics
```

### Metada

* Free software: MIT license
* Documentation: https://metadata-validator.readthedocs.io.

### Features

- Generate metadata template as a xlsx file.

- Validate metadata file.

### TODO

### Credits
Expand Down
Binary file added assets/metabolomics-metadata-table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 61 additions & 14 deletions metadata_validator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,42 @@
import os
import sys
import click

from metadata_validator.validator import DNAseqMetadataValidator
from metadata_validator.specs import spec_dict

validator_dict = {
"DNAseq": DNAseqMetadataValidator,
"RNAseq": None,
"Proteomics": None,
"Metabolomics": None
"Metabolomics": None,
}

@click.command("Metadata Validator")
@click.option("--input", "-i", required=True, type=click.Path(exists=True, file_okay=True, dir_okay=False),
help="Input file path, only support xlsx file.")
@click.option("--output", "-o", required=True, help="Output error and warning messages as a file.")
@click.option("--template-type", "-t", required=True, help="It support the following metadata tables: 'DNAseq', 'RNAseq', 'Proteomics, 'Metabolomics'", type=click.Choice(['DNAseq', 'RNAseq', 'Proteomics', 'Metabolomics']))
def main(input, output, template_type):

@click.group()
def cli():
pass


@cli.command(help="Metadata Validator")
@click.option(
"--input",
"-i",
required=True,
type=click.Path(exists=True, file_okay=True, dir_okay=False),
help="Input file path, only support xlsx file.",
)
@click.option(
"--output", "-o", required=True, help="Output error and warning messages as a file."
)
@click.option(
"--template-type",
"-t",
required=True,
help="It support the following metadata tables: 'DNAseq', 'RNAseq', 'Proteomics, 'Metabolomics'",
type=click.Choice(["DNAseq", "RNAseq", "Proteomics", "Metabolomics"]),
)
def validate(input, output, template_type):
"""Console script for metadata_validator."""
if template_type in validator_dict.keys():
validator = validator_dict[template_type](input)
Expand All @@ -25,18 +46,44 @@ def main(input, output, template_type):
error_msg = validator.errors
warning_msg = validator.warnings

if os.path.exists(output):
raise FileExistsError("The output file already exists.")
if output:
if os.path.exists(output):
raise FileExistsError("The output file already exists.")
else:
with open(output, "w") as f:
f.write(error_msg)
f.write("\n")
f.write(warning_msg)
else:
with open(output, "w") as f:
f.write(error_msg)
f.write("\n")
f.write(warning_msg)
print(error_msg)
print("\n")
print(warning_msg)
else:
click.echo("The template type is not supported.")

return 0


@cli.command(help="Generate metadata template as a xlsx file.")
@click.option(
"--output", "-o", required=True, help="Output metadata template as a file."
)
@click.option(
"--template-type",
"-t",
required=True,
help="It support the following metadata tables: 'DNAseq', 'RNAseq', 'Proteomics, 'Metabolomics'",
type=click.Choice(["DNAseq", "RNAseq", "Proteomics", "Metabolomics"]),
)
def generate_template(output, template_type):
if template_type in spec_dict.keys():
template = spec_dict[template_type]()
template.generate_template(output)
else:
click.echo("The template type is not supported.")

return 0


if __name__ == "__main__":
sys.exit(main()) # pragma: no cover
sys.exit(cli()) # pragma: no cover
20 changes: 20 additions & 0 deletions metadata_validator/specs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from .dnaseq_spec import DNAseqSpec
from .rnaseq_spec import RNAseqSpec
from .metabolomics_spec import MetabolomicsSpec

from .spec import ExpectedColumnItem

spec_dict = {
"DNAseq": DNAseqSpec,
"RNAseq": RNAseqSpec,
"Metabolomics": MetabolomicsSpec,
}


__all__ = [
"DNAseqSpec",
"RNAseqSpec",
"MetabolomicsSpec",
"ExpectedColumnItem",
"spec_dict",
]
Loading

0 comments on commit 7022ee9

Please sign in to comment.