{"data":{"slug":"github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-tf-target-gene-regulatory-network-c3177f8823eb","title":"Transcription Factor (TF) Regulatory Network Analysis","summary":"Identify upstream transcription factors from a list of human or mouse genes using the Dorothea database and generate a TF-target network visualization. The output includes a publication-ready PDF network plot and a TF-target network table.","url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-tf-target-gene-regulatory-network-c3177f8823eb","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-tf-target-gene-regulatory-network-c3177f8823eb","markdown_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-tf-target-gene-regulatory-network-c3177f8823eb.md","download_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-tf-target-gene-regulatory-network-c3177f8823eb\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"Either `--gene` or `--gene_file` must be provided. Input genes must be normalized HGNC symbols for human or first-letter-uppercase symbols for mouse. Local Dorothea `.rds` database files are recommended for faster analysis and offline use.","instructions":"---\nname: tf-target-gene-regulatory-network\ndescription: \"Use when analyzing transcription factor (TF) regulatory networks using Dorothea database. Input gene list, identify regulating transcription factors, generate TF-Target network visualization. For: transcription factor enrichment analysis, gene regulatory network research.\"\nlicense: MIT\nskill-author: AIPOCH\n---\n\n# Transcription Factor (TF) Regulatory Network Analysis\n\n## When to Use\n\n- Use this skill when you have a human or mouse gene list and want to identify upstream TFs from the Dorothea database.\n- Use it when you need a ready-to-export TF-target network table plus a publication-ready PDF network plot.\n- Use it for reproducible CLI execution with saved session information and optional local Dorothea `.rds` databases.\n\n## When Not to Use\n\n- Do not use this skill for differential expression, pathway enrichment, cell type annotation, or survival analysis.\n- Do not use it to infer causal direction beyond curated Dorothea TF-target relationships.\n- Do not use it when your input genes are aliases or mixed-species symbols that have not been normalized first.\n\n## Input Validation\n\nThis skill accepts: a human or mouse gene list (HGNC symbols for human, first-letter-uppercase for mouse) for TF regulatory network analysis using Dorothea.\n\nIf the user's request does not involve identifying upstream transcription factors from a gene list \u2014 for example, asking to run differential expression, pathway enrichment, cell type annotation, or multi-omics integration \u2014 do not proceed with the workflow. Instead respond:\n> \"tf-target-gene-regulatory-network is designed to identify upstream transcription factors from a gene list using the Dorothea database and generate a TF-target network visualization. Your request appears to be outside this scope. Please provide a gene list for TF regulatory analysis, or use a more appropriate tool for your task.\"\n\n## Entry Point\n\n- Primary CLI entry point: `scripts\/main.R`\n- Canonical visualization values: English tokens `fr`, `curve`, `diamond`, `triangle`, `square`\n\n## When to Read External Files\n\n| Situation | File to Read | Purpose |\n|-----------|--------------|---------|\n| **Need algorithm details** | `references\/algorithm.md` | Statistical methods, Dorothea database, network analysis algorithms |\n| **Need to run analysis** | `scripts\/main.R` | Execute: `Rscript scripts\/main.R --gene ... --species ...` |\n| **Encounter errors** | `references\/troubleshooting.md` | Common errors and solutions |\n| **Need CLI examples** | `references\/cli-guide.md` | Detailed CLI usage examples |\n| **Need test data** | `tests\/data\/` | Sample gene lists for testing |\n\n---\n\n## Installation\n\n### R Package Dependencies\n\n```r\n# CRAN packages\ninstall.packages(c(\"optparse\", \"dplyr\", \"openxlsx\", \"tidyverse\", \"tidygraph\", \"ggraph\", \"showtext\"))\n\n# Bioconductor packages (optional if using local database files)\nif (!require(\"BiocManager\", quietly = TRUE))\n    install.packages(\"BiocManager\")\nBiocManager::install(\"dorothea\")\n```\n\n### Local Database Files (Recommended)\n\nFor faster analysis and offline use, generate local database files:\n\n```bash\nRscript database\/database-get.R\n```\n\nThis creates `database\/dorothea_hs.rds` (human) and `database\/dorothea_mm.rds` (mouse) in the skill root directory.\n\n### Verification\n\n```bash\nRscript scripts\/main.R --help\n```\n\n## Usage\n\n```bash\nRscript scripts\/main.R \\\n  --gene \"TP53,MYC,EGFR\" \\\n  --species human \\\n  --output_dir .\/TF_Result \\\n  --seed 42\n```\n\n---\n\n## Arguments\n\n**Note**: Either `--gene` or `--gene_file` must be provided (at least one is required).\n\n| Short | Long | Type | Default | Description |\n|-------|------|------|---------|-------------|\n| `-g` | `--gene` | character | NULL | Comma-separated gene list (e.g., `\"TP53,MYC,EGFR\"`) \u2014 **required if `--gene_file` not provided** |\n| `-f` | `--gene_file` | character | NULL | File with gene names (txt or csv, one per line or comma-separated) \u2014 **required if `--gene` not provided** |\n| `-s` | `--species` | character | `human` | Species: `human` or `mouse` |\n| `-o` | `--output_dir` | character | `TF_Result` | Output directory name |\n|  | `--db_path` | character | NULL | Local `.rds` database file path. If not specified, auto-searches default paths |\n| `-d` | `--dir` | character | NULL | Working root directory (advanced) |\n|  | `--seed` | integer | `42` | Random seed for reproducibility |\n|  | `--title` | character | `\"\"` | Main plot title |\n\n**Visualization Parameters**: For complete list (plot dimensions, colors, labels, layout, edge styles), see [`references\/visualization-parameters.md`](references\/visualization-parameters.md). Canonical values are English tokens: `fr` (force-directed layout), `curve` (curved edges), `diamond` \/ `triangle` \/ `square` (node shapes).\n\n---\n\n## Input Format\n\n### Gene List Input\n\nTwo ways to provide input genes:\n\n1. **Command line**: `--gene \"TP53,MYC,EGFR\"` (comma-separated)\n2. **File input**: `--gene_file genes.txt` (one gene per line or comma-separated)\n\n### Gene Naming Convention\n\n- **Human genes**: All uppercase symbols (e.g., TP53, MYC, EGFR)\n- **Mouse genes**: First letter uppercase only (e.g., Tp53, Myc, Egfr)\n- Use official gene symbols, not aliases\n- Case-sensitive for species matching\n\n### Species Support\n\n- `human`: Human genes (Homo sapiens)\n- `mouse`: Mouse genes (Mus musculus)\n\n### Performance Guidance\n\nFor large gene lists (> 500 genes), Dorothea database queries may take several minutes. Use a local `.rds` database (`--db_path`) for substantially faster lookups. There is currently no `--timeout_seconds` parameter; monitor progress with verbose logging if available.\n\n---\n\n## Output Files\n\n| File | Description |\n|------|-------------|\n| `TF_Network_Plot.pdf` | TF-target network visualization |\n| `tf_network.xlsx` | Network data (edges and nodes worksheets) |\n| `TF_Target_Filtered_Core_<species>.xlsx` | Complete TF-target relationships table |\n| `session_info.txt` | R session and package version info |\n| `tf.Rdata` | R environment data |\n\nOutputs are organized under `TF_Result\/` in `data\/`, `plot\/`, and `table\/` subdirectories.\n\n---\n\n## Workflow\n\n### Step 1: Load Database\n- Priority search for local database files (.rds format) in: `--db_path`, `getwd()\/database\/`, `script_dir\/database\/`, `dirname(script_dir)\/database\/`\n- If no local file found, load from Dorothea R package\n- Filter for high-confidence interactions (confidence levels A, B, C)\n\n### Step 2: Identify Regulating TFs\n- Match input genes against target genes in Dorothea database\n- Extract transcription factors regulating these targets\n- Compute TF frequency (number of targets regulated)\n\n### Step 3: Generate Network Data\n- Create edge list (TF \u2192 Target relationships)\n- Create node list with types (TF or Target)\n- Save to Excel format for downstream analysis\n\n### Step 4: Visualize Network\n- Generate network graph using tidygraph and ggraph\n- Apply visual customization (layout, colors, shapes)\n- Save as PDF publication-ready figure\n\n---\n\n## Methods\n\n### Dorothea Database\n- Curated database of TF-target interactions\n- Confidence levels: A (high), B (medium), C (low)\n- Includes human and mouse data\n- Source: https:\/\/github.com\/saezlab\/dorothea\n\n### Network Analysis\n- **Graph construction**: TF-target relationships as directed edges\n- **Layout algorithms**: Multiple options including `fr` (force-directed), `circle`, `grid`, `sphere`\n- **Visual customization**: Full control over colors, shapes, sizes\n\n### Local Database Feature\n- Option to use pre-saved `.rds` files for faster analysis and offline use\n- Priority search paths for local database files (see Step 1 above)\n- Fallback to Dorothea R package if no local file found\n\n---\n\n## Examples\n\n### Basic Usage (Human Genes)\n```bash\nRscript scripts\/main.R \\\n  -g \"TP53,MYC,EGFR\" \\\n  -s human \\\n  -o .\/TF_Result\n```\n\n### File Input\n```bash\nRscript scripts\/main.R \\\n  -f gene_list.txt \\\n  -s human \\\n  -o .\/TF_Result\n```\n\n### Mouse Genes\n```bash\nRscript scripts\/main.R \\\n  -g \"Tp53,Myc,Egfr\" \\\n  -s mouse \\\n  -o .\/Mouse_TF_Result\n```\n\n### Custom Styling\n```bash\nRscript scripts\/main.R \\\n  -g \"PTPRC,FOXP3,CD4\" \\\n  -s human \\\n  --style_layout \"fr\" \\\n  --style_line \"curve\" \\\n  --point_shape \"diamond,triangle\" \\\n  --line_color \"#E64B35\" \\\n  --title \"Immune TF Network\" \\\n  -o .\/Custom_Plot\n```\n\n### Using Local Database\n```bash\nRscript scripts\/main.R \\\n  -g \"TP53,MYC,EGFR\" \\\n  -s human \\\n  --db_path database\/dorothea_hs.rds \\\n  -o .\/LocalDB_Result\n```\n\n---\n\n## Error Handling\n\n### Common Errors\n\n| Error Code | Cause | Solution |\n|------------|-------|----------|\n| `SKILL_FILE_NOT_FOUND` | Input gene file does not exist | Check file path and permissions |\n| `SKILL_NO_INPUT_GENES` | Empty gene list or file | Provide genes using `--gene` or `--gene_file` |\n| `SKILL_INVALID_SPECIES` | Species not `human` or `mouse` | Use `human` or `mouse` only |\n| `SKILL_INVALID_PARAMETER` | Invalid layout, shape, line, or legend value | Use supported values shown by `Rscript scripts\/main.R --help` |\n| `SKILL_EMPTY_RESULTS` | No TF-target relationships found for input genes | Check gene symbols and species; try broadening confidence levels |\n| `SKILL_DEPENDENCY_MISSING` | Missing dplyr, dorothea, tidygraph, etc. | Install missing packages (see Installation section) |\n\n### Exit Status Codes\n\n| Code | Meaning |\n|------|---------|\n| `0` | Success |\n| `1` | Execution error (see error code for details) |\n| `2` | `SKILL_EMPTY_RESULTS` \u2014 no TF-target matches found for the input genes |\n\n**IF error persists**, READ: `references\/troubleshooting.md`\n\n---\n\n## Testing\n\n### Test with Sample Data\n\n```bash\n# Check help\nRscript scripts\/main.R --help\n\n# Run with sample human genes\nRscript scripts\/main.R \\\n  -g \"TP53,MYC,EGFR\" \\\n  -s human \\\n  -o tests\/output_human\/\n\n# Run with sample mouse genes\nRscript scripts\/main.R \\\n  -g \"Tp53,Myc,Egfr\" \\\n  -s mouse \\\n  -o tests\/output_mouse\/\n```\n\nAfter running, verify `tests\/output_human\/plot\/TF_Network_Plot.pdf` and `tests\/output_human\/table\/tf_network.xlsx` exist and are non-empty.\n\n## Reference Files\n\n| File | Purpose |\n|---|---|\n| `references\/algorithm.md` | Statistical methods and Dorothea database details |\n| `references\/troubleshooting.md` | Common errors and solutions |\n| `references\/cli-guide.md` | CLI usage examples |\n| `references\/visualization-parameters.md` | Complete visualization parameter list |\n","use_cases":["Identify upstream transcription factors for a list of human genes","Generate publication-ready TF-target network visualizations","Perform reproducible CLI-based TF regulatory network analysis"],"limitations":[],"compatibility":[],"setup_tip":"### R Package Dependencies\n\n```r\n# CRAN packages\ninstall.packages(c(\"optparse\", \"dplyr\", \"openxlsx\", \"tidyverse\", \"tidygraph\", \"ggraph\", \"showtext\"))\n\n# Bioconductor packages (optional if using local database files)\nif (!require(\"BiocManager\", quietly = TRUE))\n    install.packages(\"BiocManager\")\nBiocManager::install(\"dorothea\")\n```\n\n### Local Database Files (Recommended)\n\nFor faster analysis and offline use, generate local database files:\n\n```bash\nRscript database\/database-get.R\n```\n\nThis creates `database\/dorothea_hs.rds` (human) and `database\/dorothea_mm.rds` (mouse) in the skill root directory.\n\n### Verification\n\n```bash\nRscript scripts\/main.R --help\n```","sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/aipoch\/medical-research-skills\/blob\/686e09dfdb45d9fa1a08664f06bb93769b3c9d91\/awesome-med-research-skills\/Data%20Analysis\/tf-target-gene-regulatory-network\/SKILL.md","source_commit":"686e09dfdb45d9fa1a08664f06bb93769b3c9d91","license":"MIT","version":null,"listing_approved_at":"2026-11-24","created_at":"2026-11-23T07:35:02.000000Z","updated_at":"2026-11-24T07:13:22.000000Z","seo_title":"Transcription Factor Regulatory Network Analysis Tool","seo_description":"Analyze gene regulatory networks using the Dorothea database. Identify upstream transcription factors and generate network visualizations for human or mouse genes.","seo_keywords":["TF regulatory network analysis","Dorothea database gene analysis","Transcription factor upstream identification","Gene regulatory network visualization","Human gene network analysis"]}}