Portable Microhaplotype Object (PMO)
  • Home
  • Format Info
    • Development of Format
    • PMO fields overview
    • PMO Examples
    • Format Overview For Developers
  • Tools Installation
    • pmotools-python installation
  • pmotools-python usages
    • Command line interface

    • pmotools-python
    • Command line interface to pmotools-python with pmotools-python
    • Extracting out of PMO
    • Extracting allele tables using pmotools-python
    • Subset PMO
    • Subsetting from a PMO using pmotools-python
    • Getting sub info from PMO
    • Getting basic info out of PMO using pmotools-python
    • Getting panel info out of PMO using pmotools-python
    • Handling Multiple PMOs
    • Handling multiple PMOs pmotools-python
    • Validating PMO files
    • Validating PMOs pmotools-python

    • Python interface
    • Getting basic info out of a PMO
    • Creating a PMO File
  • Resources
    • References
    • Documentation
    • Documentation Source Code
    • Comment or Report an issue for Documentation

    • pmotools-python
    • pmotools-python Source Code
    • Comment or Report an issue for pmotools-python

Contents

  • pmotools-python validate_pmo

Validating PMOs pmotools-python

  • Show All Code
  • Hide All Code

  • View Source

pmotools-python validate_pmo

Can download multiple PMOs here

https://plasmogenepi.github.io/PMO_Docs/format/moz2018_PMO.json.gz

https://plasmogenepi.github.io/PMO_Docs/format/PathWeaverHeome1_PMO.json.gz

Code
pmotools-python validate_pmo --help
usage: pmotools-python validate_pmo [-h] --pmo PMO
                                    [--jsonschema_file JSONSCHEMA_FILE]

options:
  -h, --help            show this help message and exit
  --pmo PMO             a pmo file to validate
  --jsonschema_file JSONSCHEMA_FILE
                        jsonschema to validate against

Use this validate a PMO file that follows the standard format, by default will use the schema that is within the pmotools-python directory

Code
cd example 

wget https://plasmogenepi.github.io/PMO_Docs/format/moz2018_PMO.json.gz


pmotools-python validate_pmo --pmo moz2018_PMO.json.gz

Can also use specific jsonschema file

Code
cd example 

wget https://plasmogenepi.github.io/PMO_Docs/format/moz2018_PMO.json.gz
wget https://plasmogenepi.github.io/PMO_Docs/format/portable_microhaplotype_object.schema.json


pmotools-python validate_pmo --pmo moz2018_PMO.json.gz --jsonschema_file portable_microhaplotype_object.schema.json

The python code for validate_pmo script is below

Code
pmotools-python/src/pmotools/scripts/pmo_utils/validate_pmo.py
#!/usr/bin/env python3
import os
import argparse
import json


from pmotools.pmo_engine.pmo_reader import PMOReader
from pmotools.pmo_engine.pmo_checker import PMOChecker
from pmotools.utils.small_utils import Utils
from pmotools import __version__ as __pmotools_version__


def parse_args_validate_pmo():
    parser = argparse.ArgumentParser()
    parser.add_argument("--pmo", type=str, required=True, help="a pmo file to validate")
    parser.add_argument(
        "--jsonschema_file",
        default=os.path.join(
            os.path.dirname(
                os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
            ),
            "schemas/",
            f"portable_microhaplotype_object_v{__pmotools_version__}.schema.json",
        ),
        type=str,
        required=False,
        help="jsonschema to validate against",
    )

    return parser.parse_args()


def validate_pmo():
    args = parse_args_validate_pmo()

    # read in the PMO
    pmo = PMOReader.read_in_pmo(args.pmo)

    # create checker
    with Utils.smart_open_read_by_ext(args.jsonschema_file) as f:
        checker = PMOChecker(json.load(f))
        # validate
        checker.validate_pmo_json(pmo)


if __name__ == "__main__":
    validate_pmo()
Source Code
---
title: Validating PMOs pmotools-python
---

```{r setup, echo=F}
source("../common.R")
```


# pmotools-python validate_pmo

Can download multiple PMOs here 

<https://plasmogenepi.github.io/PMO_Docs/format/moz2018_PMO.json.gz> 

<https://plasmogenepi.github.io/PMO_Docs/format/PathWeaverHeome1_PMO.json.gz> 



```{bash}
pmotools-python validate_pmo --help
```

Use this validate a PMO file that follows the standard format, by default will use the schema that is within the pmotools-python directory 

```{bash, eval = F}
cd example 

wget https://plasmogenepi.github.io/PMO_Docs/format/moz2018_PMO.json.gz


pmotools-python validate_pmo --pmo moz2018_PMO.json.gz
```


```{bash, echo = F, eval = T}
cd example 

pmotools-python validate_pmo --pmo ../../format/moz2018_PMO.json.gz
```

Can also use specific jsonschema file 

```{bash, eval = F}
cd example 

wget https://plasmogenepi.github.io/PMO_Docs/format/moz2018_PMO.json.gz
wget https://plasmogenepi.github.io/PMO_Docs/format/portable_microhaplotype_object.schema.json


pmotools-python validate_pmo --pmo moz2018_PMO.json.gz --jsonschema_file portable_microhaplotype_object.schema.json
```


```{bash, echo = F, eval = T}
cd example 

pmotools-python validate_pmo --pmo ../../format/moz2018_PMO.json.gz --jsonschema_file ../../format/portable_microhaplotype_object.schema.json
```

The python code for `validate_pmo` script is below

```{python}
#| echo: true
#| eval: false
#| code-fold: true
#| code-line-numbers: true
#| filename: pmotools-python/src/pmotools/scripts/pmo_utils/validate_pmo.py
#| file: ../pmotools-python/src/pmotools/scripts/pmo_utils/validate_pmo.py
```