# MethScope-MRMP

## Generate an MRMP reference

MethScope includes pre-defined MRMP references, and you can also build your own from a methylation atlas.

### Prerequisites

1. Install YAME for `.cg` processing: https://zhou-lab.github.io/YAME/
2. Prepare a reference methylation `.cg` file (for example, an atlas or merged reference panel)
3. Install and load `MethScope`

    library(MethScope)

### Step 1: Binarize the reference `.cg` file

Convert methylation proportions into binary strings. The default threshold is 0.5; adjust with `-b` if needed.

    yame rowop example.cg -o binstring > example_binstring

### Step 2: Build MRMP pattern definitions

Use `GenerateReference()` to identify recurrent patterns.
`min_CG` controls the minimum CpGs per MRMP (default: `50`).

    GenerateReference(binary_file = "example_binstring", min_CG = 50)

This step generates a `patterns.txt` file.

### Step 3: Pack patterns into a `.cm` reference

Pack `patterns.txt` into a `.cm` file that can be passed as `reference_pattern` in `GenerateInput()`.

    yame pack -f s patterns.txt patterns.cm

## Build MRMP references from cell-type pseudobulks

If cell-type labels are available, pseudobulked profiles can produce robust cell-type-informed MRMP references.

### Step 1: Create pseudobulk profiles per cell type

Prepare a text file (`samples.txt`) containing sample IDs for one cell type, then aggregate with `musum`.

    yame subset -l samples.txt example.cg | yame rowop -o musum - example_pseudobulk.cg

### Step 2: Repeat per cell type and build MRMPs

Run the same workflow above (`binstring -> GenerateReference -> yame pack`) on each pseudobulk or combined pseudobulk panel.

For running a full parallelized multi-cell-type script, please refer to: https://github.com/zhou-lab/MethScope/blob/main/analysis/GenerateReference.sh

After generating `patterns.cm`, use it as the custom MRMP reference in downstream MethScope analyses.