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 combine_pmos

Handling multiple PMOs pmotools-python

  • Show All Code
  • Hide All Code

  • View Source

pmotools-python combine_pmos

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 combine_pmos --help
usage: pmotools-python combine_pmos [-h] --pmo_files PMO_FILES --output OUTPUT
                                    [--overwrite]

options:
  -h, --help            show this help message and exit
  --pmo_files PMO_FILES
                        a list of PMO files to combine into 1 PMO file, must
                        be from same amplicon panel
  --output OUTPUT       Output new combined PMO file
  --overwrite           If output file exists, overwrite it

The list of PMO files can be given comma separated to their relative paths from where you run the script or in a file where each line is a different file to combine

Code
cd example 

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


pmotools-python combine_pmos --pmo_files moz2018_PMO.json.gz,PathWeaverHeome1_PMO.json.gz --output combined_Heome1_PMO.json.gz --overwrite

The python code for combine_pmos script is below

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


from pmotools.pmo_engine.pmo_writer import PMOWriter
from pmotools.utils.small_utils import Utils
from pmotools.pmo_engine.pmo_reader import PMOReader


def parse_args_combine_pmos():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--pmo_files",
        type=str,
        required=True,
        help="a list of PMO files to combine into 1 PMO file, must be from same amplicon panel",
    )
    parser.add_argument(
        "--output", type=str, required=True, help="Output new combined PMO file"
    )
    parser.add_argument(
        "--overwrite", action="store_true", help="If output file exists, overwrite it"
    )

    return parser.parse_args()


def combine_pmos():
    args = parse_args_combine_pmos()

    # set up output
    args.output = PMOWriter.add_pmo_extension_as_needed(
        args.output, args.output.endswith(".gz")
    )
    Utils.outputfile_check(args.output, args.overwrite)

    # check if at least 2 PMO files supplied
    pmo_files_list = Utils.parse_delimited_input_or_file(args.pmo_files, ",")
    if len(pmo_files_list) < 2:
        raise Exception(
            "Only supplied "
            + str(len(pmo_files_list))
            + " but multiple PMO files were expected"
        )

    # read in the PMOs
    pmos = PMOReader.read_in_pmos(pmo_files_list)

    # combine PMOs
    pmo_out = PMOReader.combine_multiple_pmos(pmos)

    # write
    PMOWriter.write_out_pmo(pmo_out, args.output, args.overwrite)


if __name__ == "__main__":
    combine_pmos()
Source Code
---
title: Handling multiple PMOs pmotools-python
---

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


# pmotools-python combine_pmos

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 combine_pmos --help
```


The list of PMO files can be given comma separated to their relative paths from where you run the script or in a file where each line is a different file to combine

```{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/PathWeaverHeome1_PMO.json.gz


pmotools-python combine_pmos --pmo_files moz2018_PMO.json.gz,PathWeaverHeome1_PMO.json.gz --output combined_Heome1_PMO.json.gz --overwrite
```


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

pmotools-python combine_pmos --pmo_files ../../format/moz2018_PMO.json.gz,../../format/PathWeaverHeome1_PMO.json.gz --output combined_Heome1_PMO.json.gz --overwrite
```

The python code for `combine_pmos` script is below

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