Source: https://github.com/aipoch/medical-research-skills
ceRNA Analysis
When to Use
Use this skill when you need to construct a ceRNA regulatory network from a known key-gene list using the bundled miRNA-mRNA and miRNA-lncRNA reference tables.
Use it for:
- Building a ceRNA network from one gene list and exporting flat CSV plus PDF outputs
- Comparing supported miRNA source modes such as
combined, starbase, or pairwise overlaps
- Re-running the same local workflow with different lncRNA strictness, layout, or plotting parameters
Do not use it for:
- Differential expression, single-cell, enrichment, or survival analysis
- Workflows that do not start from a key gene list
- Cases where you want a miRNA-mRNA-only graph without a retained lncRNA ceRNA layer
When to Read External Files
| Situation |
File to Read |
Purpose |
| Need algorithm details |
references/algorithm.md |
ceRNA construction logic, dataset combinations, filtering rules |
| Need to run analysis |
scripts/main.R |
Execute: Rscript scripts/main.R --key_genes ... --output_dir ... |
| Encounter errors |
references/troubleshooting.md |
Common errors and solutions |
| Need CLI examples |
references/cli-guide.md |
Detailed local run examples with measured outputs |
| Need test data |
tests/data/ |
Sample key-gene input for testing |
Usage
Rscript scripts/main.R \
--key_genes tests/data/gene.txt \
--output_dir ./output/ \
--mirna_dataset combined \
--lncrna_strictness High \
--lncrna_freq_thresh 0 \
--timeout_seconds 600 \
--seed 42
Arguments
Main Analysis: scripts/main.R
| Short |
Long |
Type |
Default |
Description |
-i |
--key_genes |
character |
required |
Key gene file path or comma-separated gene names |
-o |
--output_dir |
character |
./output/ |
Output directory |
-m |
--mirna_dataset |
character |
combined |
Dataset: combined, starbase, mirdb, mirtarbase, starbase+mirdb, starbase+mirtarbase, mirdb+mirtarbase |
-l |
--lncrna_strictness |
character |
High |
lncRNA interaction strictness: Low, Median, High |
-f |
--lncrna_freq_thresh |
integer |
0 |
Minimum retained lncRNA frequency |
-r |
--reference_dir |
character |
file.path(script_dir, "..", "references", "database") |
Database directory |
|
--plot_width |
double |
12 |
PDF width in inches |
|
--plot_height |
double |
8 |
PDF height in inches |
|
--layout_type |
character |
kk |
Layout: kk, fr, nicely, circle, grid, randomly |
|
--mrna_color |
character |
#D16BA5 |
mRNA node color |
|
--lncrna_color |
character |
#008dcd |
lncRNA node color |
|
--mirna_color |
character |
#00c9a7 |
miRNA node color |
|
--node_size_base |
double |
15 |
Base node size |
|
--label_size |
double |
0.8 |
Node label size |
|
--show_legend |
logical |
TRUE |
Show legend in the PDF |
-t |
--timeout_seconds |
integer |
3600 |
Elapsed timeout limit |
-s |
--seed |
integer |
42 |
Random seed for reproducibility |
Input Format
Key Genes (key_genes)
Plain-text input with one gene symbol per line, or a comma-separated string passed directly on the CLI.
TP53
BRCA1
MYC
Rules:
- Blank lines are ignored
- Lines starting with
# are ignored
- Duplicate genes are removed
- At least one valid gene is required
Database Directory (reference_dir)
The bundled database directory is references/database/. Required files depend on the selected mirna_dataset plus the selected lncRNA strictness file.
combined: miRNA_mRNA.csv
starbase: starbase_miRNA_mRNA.csv
mirdb: miRDB_miRNA_mRNA.csv
mirtarbase: miRTarbase_miRNA_mRNA.csv
starbase+mirdb: starbase_miRNA_mRNA.csv and miRDB_miRNA_mRNA.csv
starbase+mirtarbase: starbase_miRNA_mRNA.csv and miRTarbase_miRNA_mRNA.csv
mirdb+mirtarbase: miRDB_miRNA_mRNA.csv and miRTarbase_miRNA_mRNA.csv
- lncRNA file: one of
starbase_miRNA_lncRNA_High.csv, starbase_miRNA_lncRNA_Median.csv, or starbase_miRNA_lncRNA_Low.csv
Output Files
| File |
Description |
ceRNA_network_edges.csv |
Edge table with node1,node2 columns |
ceRNA_network_nodes.csv |
Node table with node,type,degree columns |
ceRNA_network.pdf |
ceRNA network visualization |
session_info.txt |
R session details and loaded package versions |
Workflow
Step 1: Validate Input
- Check key-gene input existence or parse comma-separated genes
- Validate parameter choices, numeric limits, timeout, and colors
- Verify the database directory and required files
Step 2: Load Interaction Data
- Load the selected miRNA-mRNA dataset
- Load the selected miRNA-lncRNA dataset by strictness level
- Recompute pairwise intersections when requested
Step 3: Filter the Network
- Retain miRNA-mRNA pairs linked to the provided key genes
- Retain miRNA-lncRNA pairs connected to the retained miRNAs
- Apply the lncRNA frequency threshold
- Stop with
SKILL_INVALID_DATA if no lncRNA interactions remain after filtering, because the ceRNA layer has collapsed
Step 4: Build Outputs
- Construct edge and node tables
- Save CSV, PDF, and session information in the output directory root
Methods
combined
Uses the bundled precomputed overlap across three miRNA-mRNA resources for higher-confidence interactions.
Pairwise Intersections
starbase+mirdb, starbase+mirtarbase, and mirdb+mirtarbase recompute the overlap between two bundled databases.
lncRNA Strictness
High, Median, and Low select different bundled starBase evidence levels for miRNA-lncRNA interactions.
Examples
Basic Combined Analysis
Rscript scripts/main.R \
-i ./key_genes.txt \
-o ./output \
-m combined
Single Database Analysis
Rscript scripts/main.R \
-i ./key_genes.txt \
-o ./output_starbase \
-m starbase \
-l Median \
-f 1
Error Handling
Common Errors
| Error |
Cause |
Solution |
SKILL_FILE_NOT_FOUND |
Input file or database file is missing |
Check the file path or bundled database directory |
SKILL_EMPTY_FILE |
A required file exists but has no content |
Replace or regenerate the file |
SKILL_EMPTY_DATA |
A required reference table has no usable rows |
Verify the input content and regenerate the file if needed |
SKILL_MISSING_COLUMNS |
An input table lacks required columns |
Verify the expected schema |
SKILL_INVALID_PARAMETER |
An invalid CLI value was provided |
Use one of the documented parameter values |
SKILL_INVALID_DATA |
The input data cannot build a valid ceRNA network, or lncRNA filtering removes the ceRNA layer entirely |
Verify the key genes and database files, then lower --lncrna_freq_thresh or choose a different dataset / strictness |
SKILL_DEPENDENCY_MISSING |
A required package is not installed |
Install the missing package |
SKILL_TIMEOUT |
The run exceeded the timeout limit |
Increase --timeout_seconds |
SKILL_RUNTIME_ERROR |
An unexpected runtime failure occurred |
Re-run after checking the console error message |
IF error persists, READ: references/troubleshooting.md
Testing
Test with Sample Data
# Check help
Rscript scripts/main.R --help
# Run with sample data
Rscript scripts/main.R \
-i tests/data/gene.txt \
-o tests/output/
Validation Commands
# Inspect edge output
wc -l tests/output/ceRNA_network_edges.csv
# Check plot exists
ls -la tests/output/ceRNA_network.pdf
Implementation Checklist
Last updated: 2026-04-17 | Version: 1.0.0
1---2name: cerna-analysis3description: > **Source**: [https://github.com/aipoch/medical-research-skills](https://github.com/aipoch/medical-research-skills)4---5> **Source**: [https://github.com/aipoch/medical-research-skills](https://github.com/aipoch/medical-research-skills)67# ceRNA Analysis89## When to Use1011Use this skill when you need to construct a ceRNA regulatory network from a known key-gene list using the bundled miRNA-mRNA and miRNA-lncRNA reference tables.1213Use it for:1415- Building a ceRNA network from one gene list and exporting flat CSV plus PDF outputs16- Comparing supported miRNA source modes such as `combined`, `starbase`, or pairwise overlaps17- Re-running the same local workflow with different lncRNA strictness, layout, or plotting parameters1819Do not use it for:2021- Differential expression, single-cell, enrichment, or survival analysis22- Workflows that do not start from a key gene list23- Cases where you want a miRNA-mRNA-only graph without a retained lncRNA ceRNA layer2425## When to Read External Files2627| Situation | File to Read | Purpose |28|-----------|--------------|---------|29| **Need algorithm details** | `references/algorithm.md` | ceRNA construction logic, dataset combinations, filtering rules |30| **Need to run analysis** | `scripts/main.R` | Execute: `Rscript scripts/main.R --key_genes ... --output_dir ...` |31| **Encounter errors** | `references/troubleshooting.md` | Common errors and solutions |32| **Need CLI examples** | `references/cli-guide.md` | Detailed local run examples with measured outputs |33| **Need test data** | `tests/data/` | Sample key-gene input for testing |3435---3637## Usage3839```bash40Rscript scripts/main.R \41 --key_genes tests/data/gene.txt \42 --output_dir ./output/ \43 --mirna_dataset combined \44 --lncrna_strictness High \45 --lncrna_freq_thresh 0 \46 --timeout_seconds 600 \47 --seed 4248```4950---5152## Arguments5354### Main Analysis: `scripts/main.R`5556| Short | Long | Type | Default | Description |57|-------|------|------|---------|-------------|58| `-i` | `--key_genes` | character | **required** | Key gene file path or comma-separated gene names |59| `-o` | `--output_dir` | character | `./output/` | Output directory |60| `-m` | `--mirna_dataset` | character | `combined` | Dataset: `combined`, `starbase`, `mirdb`, `mirtarbase`, `starbase+mirdb`, `starbase+mirtarbase`, `mirdb+mirtarbase` |61| `-l` | `--lncrna_strictness` | character | `High` | lncRNA interaction strictness: `Low`, `Median`, `High` |62| `-f` | `--lncrna_freq_thresh` | integer | `0` | Minimum retained lncRNA frequency |63| `-r` | `--reference_dir` | character | `file.path(script_dir, "..", "references", "database")` | Database directory |64| | `--plot_width` | double | `12` | PDF width in inches |65| | `--plot_height` | double | `8` | PDF height in inches |66| | `--layout_type` | character | `kk` | Layout: `kk`, `fr`, `nicely`, `circle`, `grid`, `randomly` |67| | `--mrna_color` | character | `#D16BA5` | mRNA node color |68| | `--lncrna_color` | character | `#008dcd` | lncRNA node color |69| | `--mirna_color` | character | `#00c9a7` | miRNA node color |70| | `--node_size_base` | double | `15` | Base node size |71| | `--label_size` | double | `0.8` | Node label size |72| | `--show_legend` | logical | `TRUE` | Show legend in the PDF |73| `-t` | `--timeout_seconds` | integer | `3600` | Elapsed timeout limit |74| `-s` | `--seed` | integer | `42` | Random seed for reproducibility |7576## Input Format7778### Key Genes (`key_genes`)7980Plain-text input with one gene symbol per line, or a comma-separated string passed directly on the CLI.8182```text83TP5384BRCA185MYC86```8788Rules:8990- Blank lines are ignored91- Lines starting with `#` are ignored92- Duplicate genes are removed93- At least one valid gene is required9495### Database Directory (`reference_dir`)9697The bundled database directory is `references/database/`. Required files depend on the selected `mirna_dataset` plus the selected lncRNA strictness file.9899- `combined`: `miRNA_mRNA.csv`100- `starbase`: `starbase_miRNA_mRNA.csv`101- `mirdb`: `miRDB_miRNA_mRNA.csv`102- `mirtarbase`: `miRTarbase_miRNA_mRNA.csv`103- `starbase+mirdb`: `starbase_miRNA_mRNA.csv` and `miRDB_miRNA_mRNA.csv`104- `starbase+mirtarbase`: `starbase_miRNA_mRNA.csv` and `miRTarbase_miRNA_mRNA.csv`105- `mirdb+mirtarbase`: `miRDB_miRNA_mRNA.csv` and `miRTarbase_miRNA_mRNA.csv`106- lncRNA file: one of `starbase_miRNA_lncRNA_High.csv`, `starbase_miRNA_lncRNA_Median.csv`, or `starbase_miRNA_lncRNA_Low.csv`107108---109110## Output Files111112| File | Description |113|------|-------------|114| `ceRNA_network_edges.csv` | Edge table with `node1,node2` columns |115| `ceRNA_network_nodes.csv` | Node table with `node,type,degree` columns |116| `ceRNA_network.pdf` | ceRNA network visualization |117| `session_info.txt` | R session details and loaded package versions |118119---120121## Workflow122123### Step 1: Validate Input124- Check key-gene input existence or parse comma-separated genes125- Validate parameter choices, numeric limits, timeout, and colors126- Verify the database directory and required files127128### Step 2: Load Interaction Data129- Load the selected miRNA-mRNA dataset130- Load the selected miRNA-lncRNA dataset by strictness level131- Recompute pairwise intersections when requested132133### Step 3: Filter the Network134- Retain miRNA-mRNA pairs linked to the provided key genes135- Retain miRNA-lncRNA pairs connected to the retained miRNAs136- Apply the lncRNA frequency threshold137- Stop with `SKILL_INVALID_DATA` if no lncRNA interactions remain after filtering, because the ceRNA layer has collapsed138139### Step 4: Build Outputs140- Construct edge and node tables141- Save CSV, PDF, and session information in the output directory root142143---144145## Methods146147### `combined`148Uses the bundled precomputed overlap across three miRNA-mRNA resources for higher-confidence interactions.149150### Pairwise Intersections151`starbase+mirdb`, `starbase+mirtarbase`, and `mirdb+mirtarbase` recompute the overlap between two bundled databases.152153### lncRNA Strictness154`High`, `Median`, and `Low` select different bundled starBase evidence levels for miRNA-lncRNA interactions.155156---157158## Examples159160### Basic Combined Analysis161162```bash163Rscript scripts/main.R \164 -i ./key_genes.txt \165 -o ./output \166 -m combined167```168169### Single Database Analysis170171```bash172Rscript scripts/main.R \173 -i ./key_genes.txt \174 -o ./output_starbase \175 -m starbase \176 -l Median \177 -f 1178```179180## Error Handling181182### Common Errors183184| Error | Cause | Solution |185|-------|-------|----------|186| `SKILL_FILE_NOT_FOUND` | Input file or database file is missing | Check the file path or bundled database directory |187| `SKILL_EMPTY_FILE` | A required file exists but has no content | Replace or regenerate the file |188| `SKILL_EMPTY_DATA` | A required reference table has no usable rows | Verify the input content and regenerate the file if needed |189| `SKILL_MISSING_COLUMNS` | An input table lacks required columns | Verify the expected schema |190| `SKILL_INVALID_PARAMETER` | An invalid CLI value was provided | Use one of the documented parameter values |191| `SKILL_INVALID_DATA` | The input data cannot build a valid ceRNA network, or lncRNA filtering removes the ceRNA layer entirely | Verify the key genes and database files, then lower `--lncrna_freq_thresh` or choose a different dataset / strictness |192| `SKILL_DEPENDENCY_MISSING` | A required package is not installed | Install the missing package |193| `SKILL_TIMEOUT` | The run exceeded the timeout limit | Increase `--timeout_seconds` |194| `SKILL_RUNTIME_ERROR` | An unexpected runtime failure occurred | Re-run after checking the console error message |195196**IF error persists**, READ: `references/troubleshooting.md`197198---199200## Testing201202### Test with Sample Data203204```bash205# Check help206Rscript scripts/main.R --help207208# Run with sample data209Rscript scripts/main.R \210 -i tests/data/gene.txt \211 -o tests/output/212```213214### Validation Commands215216```bash217# Inspect edge output218wc -l tests/output/ceRNA_network_edges.csv219220# Check plot exists221ls -la tests/output/ceRNA_network.pdf222```223224---225226## Implementation Checklist227228- [x] CLI parsing with `optparse`229- [x] `set.seed()` for reproducibility230- [x] `requireNamespace()` dependency checks231- [x] Session info recording232- [x] File reading instructions in `SKILL.md`233- [x] Modular script structure (`scripts/`)234- [x] Test data provided235- [x] Error handling with `SKILL_*` codes236237---238239*Last updated: 2026-04-17 | Version: 1.0.0*