@brainpilot/skills 0.0.10 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (392) hide show
  1. package/package.json +1 -1
  2. package/skills/01_Meta-Skills/workflow-skill-creator/SKILL.md +288 -0
  3. package/skills/01_Meta-Skills/workflow-skill-creator/references/cli_script_template.py +217 -0
  4. package/skills/06_fMRI_Neuroimaging/netneurotools-guide/SKILL.md +212 -0
  5. package/skills/06_fMRI_Neuroimaging/netneurotools-guide/references/datasets.md +252 -0
  6. package/skills/06_fMRI_Neuroimaging/netneurotools-guide/references/interface-plotting.md +238 -0
  7. package/skills/06_fMRI_Neuroimaging/netneurotools-guide/references/metrics.md +236 -0
  8. package/skills/06_fMRI_Neuroimaging/netneurotools-guide/references/networks.md +273 -0
  9. package/skills/06_fMRI_Neuroimaging/netneurotools-guide/references/spatial-modularity.md +291 -0
  10. package/skills/06_fMRI_Neuroimaging/netneurotools-guide/references/stats.md +290 -0
  11. package/skills/09_Cellular_Molecular_Neuroscience/alphafold-database-fetch-and-analyze/SKILL.md +116 -0
  12. package/skills/09_Cellular_Molecular_Neuroscience/alphafold-database-fetch-and-analyze/references/citation.bib +58 -0
  13. package/skills/09_Cellular_Molecular_Neuroscience/alphafold-database-fetch-and-analyze/scripts/analyze_pae.py +212 -0
  14. package/skills/09_Cellular_Molecular_Neuroscience/alphafold-database-fetch-and-analyze/scripts/analyze_plddt.py +125 -0
  15. package/skills/09_Cellular_Molecular_Neuroscience/alphafold-database-fetch-and-analyze/scripts/fetch_structure.py +168 -0
  16. package/skills/09_Cellular_Molecular_Neuroscience/gtex-database/SKILL.md +176 -0
  17. package/skills/09_Cellular_Molecular_Neuroscience/gtex-database/references/citation.bib +14 -0
  18. package/skills/09_Cellular_Molecular_Neuroscience/gtex-database/scripts/gtex_cli.py +281 -0
  19. package/skills/09_Cellular_Molecular_Neuroscience/human-protein-atlas-database/SKILL.md +181 -0
  20. package/skills/09_Cellular_Molecular_Neuroscience/human-protein-atlas-database/references/citation.bib +14 -0
  21. package/skills/09_Cellular_Molecular_Neuroscience/human-protein-atlas-database/references/search-api.md +137 -0
  22. package/skills/09_Cellular_Molecular_Neuroscience/human-protein-atlas-database/scripts/hpa_cli.py +263 -0
  23. package/skills/09_Cellular_Molecular_Neuroscience/pdb-database/SKILL.md +169 -0
  24. package/skills/09_Cellular_Molecular_Neuroscience/pdb-database/references/citation.bib +15 -0
  25. package/skills/09_Cellular_Molecular_Neuroscience/pdb-database/scripts/download_coordinate_files.py +113 -0
  26. package/skills/09_Cellular_Molecular_Neuroscience/pdb-database/scripts/fetch_pdb_metadata.py +70 -0
  27. package/skills/09_Cellular_Molecular_Neuroscience/pdb-database/scripts/fetch_schema.py +251 -0
  28. package/skills/09_Cellular_Molecular_Neuroscience/pdb-database/scripts/search_pdb.py +187 -0
  29. package/skills/09_Cellular_Molecular_Neuroscience/pymol/SKILL.md +146 -0
  30. package/skills/09_Cellular_Molecular_Neuroscience/pymol/references/PYMOL_REFERENCE.md +160 -0
  31. package/skills/09_Cellular_Molecular_Neuroscience/pymol/references/RECIPES.md +348 -0
  32. package/skills/09_Cellular_Molecular_Neuroscience/pymol/references/citation.bib +6 -0
  33. package/skills/17_Literature_Databases/literature-search-arxiv/SKILL.md +120 -0
  34. package/skills/17_Literature_Databases/literature-search-arxiv/references/citation.bib +18 -0
  35. package/skills/17_Literature_Databases/literature-search-arxiv/references/query_syntax.md +34 -0
  36. package/skills/17_Literature_Databases/literature-search-arxiv/scripts/download_paper.py +116 -0
  37. package/skills/17_Literature_Databases/literature-search-arxiv/scripts/download_paper_source.py +98 -0
  38. package/skills/17_Literature_Databases/literature-search-arxiv/scripts/search_arxiv.py +174 -0
  39. package/skills/17_Literature_Databases/literature-search-biorxiv/SKILL.md +169 -0
  40. package/skills/17_Literature_Databases/literature-search-biorxiv/references/citation.bib +12 -0
  41. package/skills/17_Literature_Databases/literature-search-biorxiv/scripts/search_by_dates.py +297 -0
  42. package/skills/17_Literature_Databases/literature-search-biorxiv/scripts/search_by_doi.py +72 -0
  43. package/skills/17_Literature_Databases/literature-search-europepmc/SKILL.md +229 -0
  44. package/skills/17_Literature_Databases/literature-search-europepmc/references/citation.bib +15 -0
  45. package/skills/17_Literature_Databases/literature-search-europepmc/scripts/europepmc_api.py +345 -0
  46. package/skills/17_Literature_Databases/literature-search-openalex/SKILL.md +169 -0
  47. package/skills/17_Literature_Databases/literature-search-openalex/references/authors.md +78 -0
  48. package/skills/17_Literature_Databases/literature-search-openalex/references/citation.bib +8 -0
  49. package/skills/17_Literature_Databases/literature-search-openalex/references/geo_and_language.md +37 -0
  50. package/skills/17_Literature_Databases/literature-search-openalex/references/institutions.md +64 -0
  51. package/skills/17_Literature_Databases/literature-search-openalex/references/publishers_funders.md +42 -0
  52. package/skills/17_Literature_Databases/literature-search-openalex/references/sources.md +79 -0
  53. package/skills/17_Literature_Databases/literature-search-openalex/references/taxonomy.md +52 -0
  54. package/skills/17_Literature_Databases/literature-search-openalex/references/topics.md +29 -0
  55. package/skills/17_Literature_Databases/literature-search-openalex/references/type_values.md +65 -0
  56. package/skills/17_Literature_Databases/literature-search-openalex/references/works.md +304 -0
  57. package/skills/17_Literature_Databases/literature-search-openalex/scripts/openalex_cli.py +633 -0
  58. package/skills/17_Literature_Databases/pubmed-database/SKILL.md +185 -0
  59. package/skills/17_Literature_Databases/pubmed-database/references/advanced-linking.md +128 -0
  60. package/skills/17_Literature_Databases/pubmed-database/references/advanced-search.md +98 -0
  61. package/skills/17_Literature_Databases/pubmed-database/references/bulk-workflows.md +88 -0
  62. package/skills/17_Literature_Databases/pubmed-database/references/citation-matching.md +155 -0
  63. package/skills/17_Literature_Databases/pubmed-database/references/citation.bib +15 -0
  64. package/skills/17_Literature_Databases/pubmed-database/references/cross-database-linking.md +93 -0
  65. package/skills/17_Literature_Databases/pubmed-database/references/fetch-and-resolve.md +125 -0
  66. package/skills/17_Literature_Databases/pubmed-database/references/search-and-discovery.md +106 -0
  67. package/skills/17_Literature_Databases/pubmed-database/references/utilities.md +42 -0
  68. package/skills/17_Literature_Databases/pubmed-database/scripts/pubmed_api.py +715 -0
  69. package/skills/18_Genetics_Genomics/alphagenome-single-variant-analysis/SKILL.md +251 -0
  70. package/skills/18_Genetics_Genomics/alphagenome-single-variant-analysis/pyproject.toml +15 -0
  71. package/skills/18_Genetics_Genomics/alphagenome-single-variant-analysis/references/citation.bib +12 -0
  72. package/skills/18_Genetics_Genomics/alphagenome-single-variant-analysis/scripts/analyze_ism.py +334 -0
  73. package/skills/18_Genetics_Genomics/alphagenome-single-variant-analysis/scripts/generate_ontology_mapping.py +170 -0
  74. package/skills/18_Genetics_Genomics/alphagenome-single-variant-analysis/scripts/interpret_splicing.py +305 -0
  75. package/skills/18_Genetics_Genomics/alphagenome-single-variant-analysis/scripts/lookup_gene_info.py +337 -0
  76. package/skills/18_Genetics_Genomics/alphagenome-single-variant-analysis/scripts/resolve_ontology_terms.py +155 -0
  77. package/skills/18_Genetics_Genomics/alphagenome-single-variant-analysis/scripts/visualize_genome_tracks.py +402 -0
  78. package/skills/18_Genetics_Genomics/alphagenome-single-variant-analysis/scripts/visualize_variant_effects.py +1198 -0
  79. package/skills/18_Genetics_Genomics/clinvar-database/SKILL.md +370 -0
  80. package/skills/18_Genetics_Genomics/clinvar-database/references/citation.bib +23 -0
  81. package/skills/18_Genetics_Genomics/clinvar-database/scripts/clinvar_api.py +711 -0
  82. package/skills/18_Genetics_Genomics/dbsnp-database/SKILL.md +350 -0
  83. package/skills/18_Genetics_Genomics/dbsnp-database/references/api-notes.md +88 -0
  84. package/skills/18_Genetics_Genomics/dbsnp-database/references/citation.bib +12 -0
  85. package/skills/18_Genetics_Genomics/dbsnp-database/scripts/dbsnp_cli.py +625 -0
  86. package/skills/18_Genetics_Genomics/gnomad-database/SKILL.md +73 -0
  87. package/skills/18_Genetics_Genomics/gnomad-database/references/citation.bib +14 -0
  88. package/skills/18_Genetics_Genomics/gnomad-database/scripts/get_gene_constraint.py +90 -0
  89. package/skills/18_Genetics_Genomics/gnomad-database/scripts/get_variant_frequency.py +181 -0
  90. package/skills/18_Genetics_Genomics/gnomad-database/scripts/search_variants.py +207 -0
  91. package/skills/19_Pharmacology/chembl-database/SKILL.md +283 -0
  92. package/skills/19_Pharmacology/chembl-database/references/api_endpoints.md +97 -0
  93. package/skills/19_Pharmacology/chembl-database/references/citation.bib +30 -0
  94. package/skills/19_Pharmacology/chembl-database/scripts/chembl_api.py +657 -0
  95. package/skills/19_Pharmacology/clinical-trials-database/SKILL.md +378 -0
  96. package/skills/19_Pharmacology/clinical-trials-database/references/citation.bib +11 -0
  97. package/skills/19_Pharmacology/clinical-trials-database/references/clinical_trials_api.md +187 -0
  98. package/skills/19_Pharmacology/clinical-trials-database/references/studies_schema.md +143 -0
  99. package/skills/19_Pharmacology/clinical-trials-database/scripts/clinical_trials_api.py +373 -0
  100. package/skills/19_Pharmacology/openfda-database/SKILL.md +225 -0
  101. package/skills/19_Pharmacology/openfda-database/references/api_endpoints.md +207 -0
  102. package/skills/19_Pharmacology/openfda-database/references/citation.bib +15 -0
  103. package/skills/19_Pharmacology/openfda-database/references/recipes.md +150 -0
  104. package/skills/19_Pharmacology/openfda-database/scripts/openfda_query.py +505 -0
  105. package/skills/19_Pharmacology/opentargets-database/SKILL.md +198 -0
  106. package/skills/19_Pharmacology/opentargets-database/references/OpenTargets_GraphQL_Guide.md +216 -0
  107. package/skills/19_Pharmacology/opentargets-database/references/citation.bib +15 -0
  108. package/skills/19_Pharmacology/opentargets-database/scripts/query_opentargets.py +533 -0
  109. package/skills/19_Pharmacology/pubchem-database/SKILL.md +164 -0
  110. package/skills/19_Pharmacology/pubchem-database/references/citation.bib +15 -0
  111. package/skills/19_Pharmacology/pubchem-database/references/endpoints.md +71 -0
  112. package/skills/19_Pharmacology/pubchem-database/references/workflows.md +32 -0
  113. package/skills/19_Pharmacology/pubchem-database/scripts/pubchem_api.py +327 -0
  114. package/skills/20_Infrastructure/uv/SKILL.md +30 -0
  115. package/skills/01_Meta-Skills/academic-research-hub/SKILL.md +0 -108
  116. package/skills/01_Meta-Skills/academic-research-hub/scripts/requirements.txt +0 -17
  117. package/skills/01_Meta-Skills/academic-research-hub/scripts/research.py +0 -781
  118. package/skills/01_Meta-Skills/beautiful-log/SKILL.md +0 -64
  119. package/skills/01_Meta-Skills/beautiful-log/scripts/beautiful_log.py +0 -274
  120. package/skills/01_Meta-Skills/ethoclaw-daily-paper/SKILL.md +0 -130
  121. package/skills/01_Meta-Skills/ethoclaw-daily-paper/assets/config.template.yaml +0 -54
  122. package/skills/01_Meta-Skills/ethoclaw-daily-paper/assets/top5_digest_template.md +0 -5
  123. package/skills/01_Meta-Skills/ethoclaw-daily-paper/scripts/build_top5_digest.py +0 -300
  124. package/skills/01_Meta-Skills/ethoclaw-daily-paper/scripts/common.py +0 -137
  125. package/skills/01_Meta-Skills/ethoclaw-daily-paper/scripts/merge_results.py +0 -106
  126. package/skills/01_Meta-Skills/ethoclaw-daily-paper/scripts/run_pipeline.py +0 -177
  127. package/skills/01_Meta-Skills/ethoclaw-daily-paper/scripts/search_arxiv.py +0 -162
  128. package/skills/01_Meta-Skills/ethoclaw-daily-paper/scripts/search_pubmed.py +0 -202
  129. package/skills/01_Meta-Skills/ethoclaw-normalize-tabular/SKILL.md +0 -173
  130. package/skills/01_Meta-Skills/ethoclaw-normalize-tabular/scripts/normalize_data.py +0 -874
  131. package/skills/01_Meta-Skills/ethoclaw-pdf-research/SKILL.md +0 -134
  132. package/skills/01_Meta-Skills/ethoclaw-pdf-research/references/confirmation-prompts.md +0 -31
  133. package/skills/01_Meta-Skills/ethoclaw-pdf-research/references/output-patterns.md +0 -45
  134. package/skills/01_Meta-Skills/ethoclaw-pdf-research/scripts/build_markdown_deliverables.py +0 -41
  135. package/skills/01_Meta-Skills/ethoclaw-pdf-research/scripts/build_research_log.py +0 -84
  136. package/skills/01_Meta-Skills/ethoclaw-pdf-research/scripts/build_summary_md.py +0 -63
  137. package/skills/01_Meta-Skills/ethoclaw-pdf-research/scripts/extract_pdf_bundle.py +0 -140
  138. package/skills/01_Meta-Skills/experiment-controller/SKILL.md +0 -140
  139. package/skills/01_Meta-Skills/knowledge-graph-builder/SKILL.md +0 -366
  140. package/skills/01_Meta-Skills/knowledge-graph-builder/scripts/entity_resolution.py +0 -120
  141. package/skills/01_Meta-Skills/knowledge-graph-builder/scripts/extraction_prompt_template.txt +0 -19
  142. package/skills/01_Meta-Skills/knowledge-graph-builder/scripts/graph_query.py +0 -106
  143. package/skills/01_Meta-Skills/knowledge-graph-builder/scripts/hypothesis_cli_reference.py +0 -42
  144. package/skills/01_Meta-Skills/knowledge-graph-builder/scripts/new_data_source_template.py +0 -116
  145. package/skills/01_Meta-Skills/knowledge-graph-builder/scripts/requirements.txt +0 -15
  146. package/skills/01_Meta-Skills/method-design/SKILL.md +0 -61
  147. package/skills/01_Meta-Skills/multi-search-engine/SKILL.md +0 -119
  148. package/skills/01_Meta-Skills/research-idea/SKILL.md +0 -65
  149. package/skills/05_EEG_ERP/eeg-skill/SKILL.md +0 -197
  150. package/skills/05_EEG_ERP/meg-skill/SKILL.md +0 -188
  151. package/skills/05_EEG_ERP/meg-skill/scripts/time_frequency.py +0 -223
  152. package/skills/05_EEG_ERP/mne-eeg-tool/SKILL.md +0 -165
  153. package/skills/05_EEG_ERP/mne-eeg-tool/scripts/eeg_pipeline_reference.py +0 -231
  154. package/skills/05_EEG_ERP/seed-iv-skill/SKILL.md +0 -184
  155. package/skills/05_EEG_ERP/seed-iv-skill/scripts/classify_seed_iv.py +0 -154
  156. package/skills/05_EEG_ERP/seed-iv-skill/scripts/extract_seed_iv_features.py +0 -190
  157. package/skills/05_EEG_ERP/seed-iv-skill/scripts/validate_seed_iv.py +0 -102
  158. package/skills/05_EEG_ERP/seed-vig-skill/SKILL.md +0 -182
  159. package/skills/05_EEG_ERP/seed-vig-skill/scripts/classify_seed_vig.py +0 -165
  160. package/skills/05_EEG_ERP/seed-vig-skill/scripts/extract_seed_vig_features.py +0 -185
  161. package/skills/05_EEG_ERP/seed-vig-skill/scripts/validate_seed_vig.py +0 -88
  162. package/skills/06_fMRI_Neuroimaging/abcd-skill/SKILL.md +0 -308
  163. package/skills/06_fMRI_Neuroimaging/abcd-skill/scripts/abcd_qc_summary.py +0 -449
  164. package/skills/06_fMRI_Neuroimaging/abcd-skill/scripts/extract_abcd_phenotype.py +0 -292
  165. package/skills/06_fMRI_Neuroimaging/abcd-skill/scripts/reorganize_abcd.py +0 -387
  166. package/skills/06_fMRI_Neuroimaging/abide-skill/SKILL.md +0 -302
  167. package/skills/06_fMRI_Neuroimaging/abide-skill/scripts/abide_qc_summary.py +0 -317
  168. package/skills/06_fMRI_Neuroimaging/abide-skill/scripts/extract_abide_phenotype.py +0 -267
  169. package/skills/06_fMRI_Neuroimaging/abide-skill/scripts/reorganize_abide.py +0 -387
  170. package/skills/06_fMRI_Neuroimaging/adhd200-skill/SKILL.md +0 -244
  171. package/skills/06_fMRI_Neuroimaging/adhd200-skill/scripts/adhd200_qc_summary.py +0 -98
  172. package/skills/06_fMRI_Neuroimaging/adhd200-skill/scripts/extract_adhd200_phenotype.py +0 -134
  173. package/skills/06_fMRI_Neuroimaging/adhd200-skill/scripts/reorganize_adhd200.py +0 -206
  174. package/skills/06_fMRI_Neuroimaging/adni-skill/SKILL.md +0 -358
  175. package/skills/06_fMRI_Neuroimaging/adni-skill/scripts/generate_adni_task_files.py +0 -1305
  176. package/skills/06_fMRI_Neuroimaging/adni-skill/scripts/generate_vqa_from_tasks.py +0 -766
  177. package/skills/06_fMRI_Neuroimaging/adni-skill/scripts/reorganize_adni.py +0 -491
  178. package/skills/06_fMRI_Neuroimaging/aibl-skill/SKILL.md +0 -295
  179. package/skills/06_fMRI_Neuroimaging/aibl-skill/scripts/aibl_qc_summary.py +0 -260
  180. package/skills/06_fMRI_Neuroimaging/aibl-skill/scripts/extract_aibl_phenotype.py +0 -365
  181. package/skills/06_fMRI_Neuroimaging/aibl-skill/scripts/reorganize_aibl.py +0 -394
  182. package/skills/06_fMRI_Neuroimaging/aomic-skill/SKILL.md +0 -292
  183. package/skills/06_fMRI_Neuroimaging/aomic-skill/scripts/aomic_qc_summary.py +0 -258
  184. package/skills/06_fMRI_Neuroimaging/aomic-skill/scripts/extract_aomic_phenotype.py +0 -284
  185. package/skills/06_fMRI_Neuroimaging/aomic-skill/scripts/reorganize_aomic.py +0 -322
  186. package/skills/06_fMRI_Neuroimaging/asl-skill/SKILL.md +0 -168
  187. package/skills/06_fMRI_Neuroimaging/asl-skill/scripts/compute_cbf.py +0 -224
  188. package/skills/06_fMRI_Neuroimaging/bids-organizer/SKILL.md +0 -241
  189. package/skills/06_fMRI_Neuroimaging/bold5000-skill/SKILL.md +0 -186
  190. package/skills/06_fMRI_Neuroimaging/bold5000-skill/scripts/bold5000_qc_summary.py +0 -96
  191. package/skills/06_fMRI_Neuroimaging/bold5000-skill/scripts/extract_bold5000_stimulus.py +0 -125
  192. package/skills/06_fMRI_Neuroimaging/bold5000-skill/scripts/reorganize_bold5000.py +0 -102
  193. package/skills/06_fMRI_Neuroimaging/camcan-skill/SKILL.md +0 -213
  194. package/skills/06_fMRI_Neuroimaging/camcan-skill/scripts/camcan_qc_summary.py +0 -131
  195. package/skills/06_fMRI_Neuroimaging/camcan-skill/scripts/extract_camcan_phenotype.py +0 -145
  196. package/skills/06_fMRI_Neuroimaging/camcan-skill/scripts/validate_camcan.py +0 -141
  197. package/skills/06_fMRI_Neuroimaging/cobre-skill/SKILL.md +0 -201
  198. package/skills/06_fMRI_Neuroimaging/cobre-skill/scripts/cobre_qc_summary.py +0 -95
  199. package/skills/06_fMRI_Neuroimaging/cobre-skill/scripts/extract_cobre_phenotype.py +0 -104
  200. package/skills/06_fMRI_Neuroimaging/cobre-skill/scripts/reorganize_cobre.py +0 -140
  201. package/skills/06_fMRI_Neuroimaging/conn-tool/SKILL.md +0 -180
  202. package/skills/06_fMRI_Neuroimaging/dcm2nii/SKILL.md +0 -189
  203. package/skills/06_fMRI_Neuroimaging/dmt-har-med-skill/SKILL.md +0 -183
  204. package/skills/06_fMRI_Neuroimaging/dmt-har-med-skill/scripts/dmt_har_med_qc_summary.py +0 -96
  205. package/skills/06_fMRI_Neuroimaging/dmt-har-med-skill/scripts/extract_dmt_har_med_phenotype.py +0 -121
  206. package/skills/06_fMRI_Neuroimaging/dmt-har-med-skill/scripts/reorganize_dmt_har_med.py +0 -125
  207. package/skills/06_fMRI_Neuroimaging/dwi-skill/SKILL.md +0 -359
  208. package/skills/06_fMRI_Neuroimaging/fmri-skill/SKILL.md +0 -371
  209. package/skills/06_fMRI_Neuroimaging/fmriprep-tool/SKILL.md +0 -228
  210. package/skills/06_fMRI_Neuroimaging/freesurfer-tool/SKILL.md +0 -286
  211. package/skills/06_fMRI_Neuroimaging/freesurfer-tool/scripts/freesurfer_processor.py +0 -145
  212. package/skills/06_fMRI_Neuroimaging/fsl-tool/SKILL.md +0 -208
  213. package/skills/06_fMRI_Neuroimaging/hbn-skill/SKILL.md +0 -271
  214. package/skills/06_fMRI_Neuroimaging/hbn-skill/scripts/extract_hbn_phenotype.py +0 -107
  215. package/skills/06_fMRI_Neuroimaging/hbn-skill/scripts/hbn_qc_summary.py +0 -96
  216. package/skills/06_fMRI_Neuroimaging/hbn-skill/scripts/reorganize_hbn.py +0 -150
  217. package/skills/06_fMRI_Neuroimaging/hcpa-skill/SKILL.md +0 -210
  218. package/skills/06_fMRI_Neuroimaging/hcpa-skill/scripts/extract_hcpa_phenotype.py +0 -146
  219. package/skills/06_fMRI_Neuroimaging/hcpa-skill/scripts/hcpa_qc_summary.py +0 -120
  220. package/skills/06_fMRI_Neuroimaging/hcpa-skill/scripts/reorganize_hcpa.py +0 -155
  221. package/skills/06_fMRI_Neuroimaging/hcpd-skill/SKILL.md +0 -210
  222. package/skills/06_fMRI_Neuroimaging/hcpd-skill/scripts/extract_hcpd_phenotype.py +0 -148
  223. package/skills/06_fMRI_Neuroimaging/hcpd-skill/scripts/hcpd_qc_summary.py +0 -125
  224. package/skills/06_fMRI_Neuroimaging/hcpd-skill/scripts/reorganize_hcpd.py +0 -146
  225. package/skills/06_fMRI_Neuroimaging/hcpep-skill/SKILL.md +0 -215
  226. package/skills/06_fMRI_Neuroimaging/hcpep-skill/scripts/extract_hcpep_phenotype.py +0 -157
  227. package/skills/06_fMRI_Neuroimaging/hcpep-skill/scripts/hcpep_qc_summary.py +0 -143
  228. package/skills/06_fMRI_Neuroimaging/hcpep-skill/scripts/reorganize_hcpep.py +0 -146
  229. package/skills/06_fMRI_Neuroimaging/hcppipeline-tool/SKILL.md +0 -217
  230. package/skills/06_fMRI_Neuroimaging/hcpya-skill/SKILL.md +0 -214
  231. package/skills/06_fMRI_Neuroimaging/hcpya-skill/scripts/extract_hcpya_phenotype.py +0 -190
  232. package/skills/06_fMRI_Neuroimaging/hcpya-skill/scripts/hcpya_qc_summary.py +0 -152
  233. package/skills/06_fMRI_Neuroimaging/hcpya-skill/scripts/reorganize_hcpya.py +0 -203
  234. package/skills/06_fMRI_Neuroimaging/ixi-skill/SKILL.md +0 -198
  235. package/skills/06_fMRI_Neuroimaging/ixi-skill/scripts/ixi_qc_summary.py +0 -137
  236. package/skills/06_fMRI_Neuroimaging/ixi-skill/scripts/reorganize_ixi.py +0 -190
  237. package/skills/06_fMRI_Neuroimaging/mnd-skill/SKILL.md +0 -191
  238. package/skills/06_fMRI_Neuroimaging/mnd-skill/scripts/extract_mnd_phenotype.py +0 -143
  239. package/skills/06_fMRI_Neuroimaging/mnd-skill/scripts/mnd_qc_summary.py +0 -120
  240. package/skills/06_fMRI_Neuroimaging/mnd-skill/scripts/validate_mnd.py +0 -107
  241. package/skills/06_fMRI_Neuroimaging/mschallenge-skill/SKILL.md +0 -203
  242. package/skills/06_fMRI_Neuroimaging/mschallenge-skill/scripts/analyze_lesions.py +0 -119
  243. package/skills/06_fMRI_Neuroimaging/mschallenge-skill/scripts/longitudinal_lesion.py +0 -148
  244. package/skills/06_fMRI_Neuroimaging/mschallenge-skill/scripts/mschallenge_qc_summary.py +0 -132
  245. package/skills/06_fMRI_Neuroimaging/mschallenge-skill/scripts/validate_mschallenge.py +0 -116
  246. package/skills/06_fMRI_Neuroimaging/nibabel-skill/SKILL.md +0 -184
  247. package/skills/06_fMRI_Neuroimaging/nibabel-skill/scripts/atlas_coordinate_reference.py +0 -61
  248. package/skills/06_fMRI_Neuroimaging/nibabel-skill/scripts/freesurfer_io_reference.py +0 -34
  249. package/skills/06_fMRI_Neuroimaging/nibabel-skill/scripts/nifti_inspection_reference.py +0 -35
  250. package/skills/06_fMRI_Neuroimaging/nifd-skill/SKILL.md +0 -205
  251. package/skills/06_fMRI_Neuroimaging/nifd-skill/scripts/extract_nifd_phenotype.py +0 -132
  252. package/skills/06_fMRI_Neuroimaging/nifd-skill/scripts/nifd_qc_summary.py +0 -111
  253. package/skills/06_fMRI_Neuroimaging/nifd-skill/scripts/validate_nifd.py +0 -111
  254. package/skills/06_fMRI_Neuroimaging/nii2dcm/SKILL.md +0 -143
  255. package/skills/06_fMRI_Neuroimaging/nilearn-tool/SKILL.md +0 -266
  256. package/skills/06_fMRI_Neuroimaging/nilearn-tool/scripts/connectome_reference.py +0 -65
  257. package/skills/06_fMRI_Neuroimaging/nilearn-tool/scripts/denoise_timeseries_reference.py +0 -58
  258. package/skills/06_fMRI_Neuroimaging/nilearn-tool/scripts/hierarchical_parcellation_reference.py +0 -53
  259. package/skills/06_fMRI_Neuroimaging/nilearn-tool/scripts/kmeans_parcellation_reference.py +0 -53
  260. package/skills/06_fMRI_Neuroimaging/nilearn-tool/scripts/preprocess_bold_reference.py +0 -76
  261. package/skills/06_fMRI_Neuroimaging/nilearn-tool/scripts/rest_dictlearning_reference.py +0 -56
  262. package/skills/06_fMRI_Neuroimaging/nilearn-tool/scripts/rest_ica_reference.py +0 -59
  263. package/skills/06_fMRI_Neuroimaging/nilearn-tool/scripts/second_level_glm_reference.py +0 -58
  264. package/skills/06_fMRI_Neuroimaging/nilearn-tool/scripts/spacenet_classifier_reference.py +0 -59
  265. package/skills/06_fMRI_Neuroimaging/nilearn-tool/scripts/svm_classifier_reference.py +0 -60
  266. package/skills/06_fMRI_Neuroimaging/nilearn-tool/scripts/task_glm_reference.py +0 -63
  267. package/skills/06_fMRI_Neuroimaging/nilearn-tool/scripts/zalff_summary_reference.py +0 -109
  268. package/skills/06_fMRI_Neuroimaging/nsd-skill/SKILL.md +0 -210
  269. package/skills/06_fMRI_Neuroimaging/nsd-skill/scripts/extract_nsd_stimulus.py +0 -171
  270. package/skills/06_fMRI_Neuroimaging/nsd-skill/scripts/nsd_qc_summary.py +0 -142
  271. package/skills/06_fMRI_Neuroimaging/nsd-skill/scripts/validate_nsd.py +0 -142
  272. package/skills/06_fMRI_Neuroimaging/oasis-skill/SKILL.md +0 -205
  273. package/skills/06_fMRI_Neuroimaging/oasis-skill/scripts/extract_oasis_phenotype.py +0 -126
  274. package/skills/06_fMRI_Neuroimaging/oasis-skill/scripts/oasis_qc_summary.py +0 -115
  275. package/skills/06_fMRI_Neuroimaging/oasis-skill/scripts/validate_oasis.py +0 -119
  276. package/skills/06_fMRI_Neuroimaging/pet-skill/SKILL.md +0 -173
  277. package/skills/06_fMRI_Neuroimaging/pet-skill/scripts/compute_suvr.py +0 -202
  278. package/skills/06_fMRI_Neuroimaging/pnc-skill/SKILL.md +0 -206
  279. package/skills/06_fMRI_Neuroimaging/pnc-skill/scripts/extract_pnc_phenotype.py +0 -136
  280. package/skills/06_fMRI_Neuroimaging/pnc-skill/scripts/pnc_qc_summary.py +0 -116
  281. package/skills/06_fMRI_Neuroimaging/pnc-skill/scripts/validate_pnc.py +0 -120
  282. package/skills/06_fMRI_Neuroimaging/ppmi-skill/SKILL.md +0 -209
  283. package/skills/06_fMRI_Neuroimaging/ppmi-skill/scripts/extract_ppmi_phenotype.py +0 -138
  284. package/skills/06_fMRI_Neuroimaging/ppmi-skill/scripts/ppmi_qc_summary.py +0 -111
  285. package/skills/06_fMRI_Neuroimaging/ppmi-skill/scripts/validate_ppmi.py +0 -117
  286. package/skills/06_fMRI_Neuroimaging/qsiprep-tool/SKILL.md +0 -320
  287. package/skills/06_fMRI_Neuroimaging/rest-mneta-mdd-skill/SKILL.md +0 -215
  288. package/skills/06_fMRI_Neuroimaging/rest-mneta-mdd-skill/scripts/extract_rest_mdd_phenotype.py +0 -132
  289. package/skills/06_fMRI_Neuroimaging/rest-mneta-mdd-skill/scripts/harmonize_sites.py +0 -152
  290. package/skills/06_fMRI_Neuroimaging/rest-mneta-mdd-skill/scripts/rest_mdd_qc_summary.py +0 -124
  291. package/skills/06_fMRI_Neuroimaging/rest-mneta-mdd-skill/scripts/validate_rest_mdd.py +0 -103
  292. package/skills/06_fMRI_Neuroimaging/smri-skill/SKILL.md +0 -302
  293. package/skills/06_fMRI_Neuroimaging/tcp-skill/SKILL.md +0 -204
  294. package/skills/06_fMRI_Neuroimaging/tcp-skill/scripts/extract_tcp_phenotype.py +0 -139
  295. package/skills/06_fMRI_Neuroimaging/tcp-skill/scripts/tcp_qc_summary.py +0 -111
  296. package/skills/06_fMRI_Neuroimaging/tcp-skill/scripts/validate_tcp.py +0 -99
  297. package/skills/06_fMRI_Neuroimaging/ucla-cnp-skill/SKILL.md +0 -217
  298. package/skills/06_fMRI_Neuroimaging/ucla-cnp-skill/scripts/extract_ucla_cnp_phenotype.py +0 -145
  299. package/skills/06_fMRI_Neuroimaging/ucla-cnp-skill/scripts/ucla_cnp_qc_summary.py +0 -111
  300. package/skills/06_fMRI_Neuroimaging/ucla-cnp-skill/scripts/validate_ucla_cnp.py +0 -113
  301. package/skills/06_fMRI_Neuroimaging/ukb-skill/SKILL.md +0 -310
  302. package/skills/06_fMRI_Neuroimaging/ukb-skill/scripts/build_ukb_survival.py +0 -210
  303. package/skills/06_fMRI_Neuroimaging/ukb-skill/scripts/extract_ukb_cases.py +0 -308
  304. package/skills/06_fMRI_Neuroimaging/ukb-skill/scripts/extract_ukb_phenotype.py +0 -232
  305. package/skills/06_fMRI_Neuroimaging/ukb-skill/scripts/ukb_qc_summary.py +0 -158
  306. package/skills/06_fMRI_Neuroimaging/wmh-segmentation/SKILL.md +0 -133
  307. package/skills/07_Computational_Modeling/detrending/SKILL.md +0 -118
  308. package/skills/07_Computational_Modeling/dictlearning/SKILL.md +0 -122
  309. package/skills/07_Computational_Modeling/filtering/SKILL.md +0 -121
  310. package/skills/07_Computational_Modeling/glm/SKILL.md +0 -153
  311. package/skills/07_Computational_Modeling/hierarchical/SKILL.md +0 -121
  312. package/skills/07_Computational_Modeling/ica/SKILL.md +0 -122
  313. package/skills/07_Computational_Modeling/kmeans/SKILL.md +0 -119
  314. package/skills/07_Computational_Modeling/run_models/SKILL.md +0 -427
  315. package/skills/07_Computational_Modeling/spacenet/SKILL.md +0 -122
  316. package/skills/07_Computational_Modeling/svm/SKILL.md +0 -120
  317. package/skills/08_Computational_Neuroscience/brain_gnn/SKILL.md +0 -183
  318. package/skills/08_Computational_Neuroscience/dipy-tool/SKILL.md +0 -239
  319. package/skills/08_Computational_Neuroscience/dipy-tool/scripts/dti_metrics_reference.py +0 -70
  320. package/skills/08_Computational_Neuroscience/dipy-tool/scripts/load_and_mask_reference.py +0 -76
  321. package/skills/08_Computational_Neuroscience/dipy-tool/scripts/roi_stats_reference.py +0 -59
  322. package/skills/08_Computational_Neuroscience/fm_app/SKILL.md +0 -195
  323. package/skills/08_Computational_Neuroscience/neurostorm/SKILL.md +0 -151
  324. package/skills/13_Visualization/brain-visualization/SKILL.md +0 -191
  325. package/skills/13_Visualization/brain-visualization/scripts/connectome_reference.py +0 -108
  326. package/skills/13_Visualization/brain-visualization/scripts/freesurfer_ply_reference.py +0 -54
  327. package/skills/13_Visualization/brain-visualization/scripts/zalff_summary_reference.py +0 -116
  328. package/skills/13_Visualization/ethoclaw-paper-figure-layout/SKILL.md +0 -78
  329. package/skills/13_Visualization/ethoclaw-paper-figure-layout/assets/naturecomm_figures.tex +0 -74
  330. package/skills/13_Visualization/ethoclaw-paper-figure-layout/scripts/layout_results_foldered.py +0 -579
  331. package/skills/14_Writing/overleaf-skill/SKILL.md +0 -184
  332. package/skills/14_Writing/overleaf-skill/scripts/install.sh +0 -30
  333. package/skills/14_Writing/paper-writing/SKILL.md +0 -146
  334. package/skills/14_Writing/paper-writing/scripts/data_statement_templates.py +0 -164
  335. package/skills/14_Writing/paper-writing/scripts/figure_templates.py +0 -315
  336. package/skills/14_Writing/paper-writing/scripts/nature_figure_style.py +0 -214
  337. package/skills/14_Writing/paper-writing/scripts/section_phrasebank.py +0 -246
  338. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/SKILL.md +0 -274
  339. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/assets/report_template_en.html +0 -112
  340. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/assets/report_template_en.md +0 -21
  341. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/assets/section_templates/cluster-section.md +0 -5
  342. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/assets/section_templates/heatmap-section.md +0 -5
  343. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/assets/section_templates/integrated-interpretation.md +0 -3
  344. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/assets/section_templates/overview.md +0 -3
  345. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/assets/section_templates/project-summary.md +0 -3
  346. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/assets/section_templates/radar-section.md +0 -5
  347. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/assets/section_templates/raw-trajectory.md +0 -3
  348. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/assets/section_templates/sample-check.md +0 -3
  349. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/assets/section_templates/single-subject-section.md +0 -3
  350. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/assets/section_templates/stats-section.md +0 -5
  351. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/references/experiment-types/epm.md +0 -52
  352. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/references/experiment-types/fst.md +0 -37
  353. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/references/experiment-types/nor.md +0 -39
  354. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/references/experiment-types/oft.md +0 -43
  355. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/references/experiment-types/tcst.md +0 -45
  356. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/references/experiment-types/tst.md +0 -36
  357. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/references/input-types.md +0 -59
  358. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/references/interpretation-guardrails.md +0 -45
  359. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/references/metadata-schema.md +0 -57
  360. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/references/report-sections.md +0 -86
  361. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/references/section-selection-rules.md +0 -169
  362. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/scripts/build_report_manifest.py +0 -27
  363. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/scripts/render_report.py +0 -34
  364. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/scripts/report_utils.py +0 -1121
  365. package/skills/16_Animal_Behavior/ethoclaw-animal-grounding/SKILL.md +0 -390
  366. package/skills/16_Animal_Behavior/ethoclaw-animal-grounding/reference_code.py +0 -98
  367. package/skills/16_Animal_Behavior/ethoclaw-animal-pose-estimation/SKILL.md +0 -336
  368. package/skills/16_Animal_Behavior/ethoclaw-kinematic-parameter-generator/README.md +0 -21
  369. package/skills/16_Animal_Behavior/ethoclaw-kinematic-parameter-generator/SKILL.md +0 -41
  370. package/skills/16_Animal_Behavior/ethoclaw-kinematic-parameter-generator/batch_kinematic_generator.py +0 -663
  371. package/skills/16_Animal_Behavior/ethoclaw-kinematic-parameter-generator/config.json +0 -19
  372. package/skills/16_Animal_Behavior/ethoclaw-kinematic-parameter-generator/generate_kinematic_parameter.py +0 -401
  373. package/skills/16_Animal_Behavior/ethoclaw-kinematic-parameter-generator/kinematic_generator.py +0 -265
  374. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-clustermap-generate/SKILL.md +0 -72
  375. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-clustermap-generate/references/config.example.toml +0 -56
  376. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-clustermap-generate/scripts/cluster_all_params.py +0 -232
  377. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-clustermap-generate/scripts/cluster_all_params_from_config.py +0 -236
  378. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-radar-generate/SKILL.md +0 -68
  379. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-radar-generate/references/notes.md +0 -5
  380. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-radar-generate/scripts/plot_h5_radar.py +0 -513
  381. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-violin-stats-generate/SKILL.md +0 -52
  382. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-violin-stats-generate/config.toml +0 -81
  383. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-violin-stats-generate/references/stats-rule.md +0 -18
  384. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-violin-stats-generate/scripts/h5_inspect.py +0 -79
  385. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-violin-stats-generate/scripts/h5_violin_batch.py +0 -624
  386. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-violin-stats-generate/scripts/h5_violin_stats.py +0 -438
  387. package/skills/16_Animal_Behavior/ethoclaw-trajectory-velocity-heatmap-generate/SKILL.md +0 -280
  388. package/skills/16_Animal_Behavior/ethoclaw-trajectory-velocity-heatmap-generate/core_scripts/heatmap_trajectory.py +0 -790
  389. package/skills/16_Animal_Behavior/ethoclaw-trajectory-velocity-heatmap-generate/core_scripts/heatmap_velocity.py +0 -855
  390. package/skills/16_Animal_Behavior/ethoclaw-trajectory-velocity-heatmap-generate/reference_data/reference_2d.csv +0 -101
  391. package/skills/16_Animal_Behavior/ethoclaw-trajectory-velocity-heatmap-generate/reference_data/reference_2d.h5 +0 -0
  392. package/skills/16_Animal_Behavior/ethoclaw-trajectory-velocity-heatmap-generate/reference_data/reference_data_readme.md +0 -126
@@ -0,0 +1,1198 @@
1
+ # Copyright 2026 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ r"""Visualize variant effects using AlphaGenome predictions.
16
+
17
+ Compares REF and ALT alleles, overlays them for clarity, and handles custom
18
+ coloring for Sashimi plots.
19
+
20
+ Design Note:
21
+ This tool produces variant-effect visualizations for analysis reports.
22
+ It handles complex track filtering to ensure Ref/Alt pairing and applies
23
+ preferences (e.g., Total RNA over PolyA RNA) to reduce noise.
24
+
25
+ Usage:
26
+ uv run visualize_variant_effects.py --chrom=chr21 --pos=46126238 --ref=G \
27
+ --alt=C --gene=COL6A2 --tissue=muscle --ontology=UBERON:0001134 \
28
+ --output_dir=./plots --tracks=splicing
29
+
30
+ Examples:
31
+ uv run visualize_variant_effects.py --chrom=chr21 --pos=46126238 --ref=G \
32
+ --alt=C --gene=COL6A2 --tissue=muscle --ontology=UBERON:0001134 \
33
+ --output_dir=./plots --tracks=splicing
34
+ uv run visualize_variant_effects.py --chrom=chr7 --pos=5529776 --ref=C \
35
+ --alt=T --gene=ACTB --tissue=HepG2 --ontology=EFO:0001187 \
36
+ --output_dir=./plots --view=whole_gene
37
+ """
38
+
39
+ # /// script
40
+ # requires-python = ">=3.10"
41
+ # dependencies = [
42
+ # "alphagenome",
43
+ # "matplotlib",
44
+ # "numpy",
45
+ # "pandas",
46
+ # "pyarrow", # Required by pandas to read .feather files
47
+ # "python-dotenv",
48
+ # ]
49
+ # ///
50
+
51
+ from __future__ import annotations
52
+
53
+ import argparse
54
+ import os
55
+ from typing import Any
56
+
57
+ from alphagenome.data import gene_annotation
58
+ from alphagenome.data import genome
59
+ from alphagenome.data import junction_data
60
+ from alphagenome.data import transcript as transcript_utils
61
+ from alphagenome.models import dna_client
62
+ from alphagenome.visualization import plot_components
63
+ import dotenv
64
+ import matplotlib as mpl
65
+ import matplotlib.pyplot as plt
66
+ import numpy as np
67
+ import pandas as pd
68
+
69
+ GTF_URL = (
70
+ 'https://storage.googleapis.com/alphagenome/reference/gencode/'
71
+ 'hg38/gencode.v46.annotation.gtf.gz.feather'
72
+ )
73
+ API_ADDRESS = 'dns:///gdmscience.googleapis.com:443'
74
+
75
+ COLOR_REF = '#22AAE1'
76
+ COLOR_ALT = 'red'
77
+
78
+
79
+ def colored_sashimi_plot(
80
+ junctions: Any,
81
+ ax: Any,
82
+ interval: Any = None,
83
+ filter_threshold: float = 0.01,
84
+ annotate_counts: bool = True,
85
+ rng: Any = None,
86
+ color: str | None = None,
87
+ ) -> None:
88
+ """Modified sashimi_plot that accepts a color argument.
89
+
90
+ Args:
91
+ junctions: List of junctions to plot.
92
+ ax: Matplotlib axis.
93
+ interval: Genomic interval.
94
+ filter_threshold: Threshold for filtering junctions.
95
+ annotate_counts: Whether to annotate junction counts.
96
+ rng: Random number generator.
97
+ color: Color of the sashimi plot.
98
+ """
99
+ rng = rng or np.random.default_rng()
100
+ total = np.sum([junction.k for junction in junctions])
101
+ # Random jitter position to avoid overlap.
102
+ jitters = rng.uniform(low=0.05, high=0.15, size=len(junctions))
103
+
104
+ for junction, jt in zip(junctions, jitters):
105
+ if junction.k < filter_threshold:
106
+ continue
107
+ k = junction.k / total
108
+ verts = [
109
+ (junction.start, 0.0),
110
+ (junction.start, jt),
111
+ (junction.end, jt),
112
+ (junction.end, 0.0),
113
+ ]
114
+
115
+ path = mpl.path.Path(
116
+ verts,
117
+ [
118
+ mpl.path.Path.MOVETO,
119
+ mpl.path.Path.CURVE4,
120
+ mpl.path.Path.CURVE4,
121
+ mpl.path.Path.CURVE4,
122
+ ],
123
+ )
124
+ # Use provided color or default
125
+ edgecolor = color if color else 'black'
126
+ # Scale width by relative abundance, but enforce min width for visibility
127
+ min_lw = 0.5
128
+ calc_lw = min(k * 30, 5)
129
+ lw = max(calc_lw, min_lw)
130
+ patch = mpl.patches.PathPatch(
131
+ path, facecolor='none', lw=lw, edgecolor=edgecolor
132
+ )
133
+ ax.add_patch(patch)
134
+
135
+ if annotate_counts:
136
+ text_pos = junction.center()
137
+ if interval is not None:
138
+ if text_pos < interval.start or text_pos > interval.end:
139
+ continue
140
+ text_format = '{:.1f}' if total < 10 else '{:.0f}'
141
+ ax.text(
142
+ text_pos,
143
+ 0.8 * jt,
144
+ text_format.format(junction.k),
145
+ horizontalalignment='center',
146
+ color=edgecolor,
147
+ )
148
+ ax.set_ylim(0, 0.15)
149
+
150
+
151
+ class ColoredSashimi(plot_components.Sashimi):
152
+ """Sashimi component with color and forced strand options."""
153
+
154
+ def __init__(
155
+ self,
156
+ *args: Any,
157
+ color: str | None = None,
158
+ forced_strand: str | None = None,
159
+ **kwargs: Any,
160
+ ) -> None:
161
+ super().__init__(*args, **kwargs)
162
+ self._color = color
163
+ self._forced_strand = forced_strand
164
+
165
+ @property
166
+ def num_axes(self) -> int:
167
+ if self._forced_strand:
168
+ return self._junction_track.num_tracks
169
+ return super().num_axes
170
+
171
+ def _get_strand_and_metadata_index(self, axis_index: int) -> tuple[str, int]:
172
+ if self._forced_strand:
173
+ return self._forced_strand, axis_index
174
+ return super()._get_strand_and_metadata_index(axis_index)
175
+
176
+ def get_junctions(self, interval: Any) -> Any:
177
+ """Returns the list of junctions that would be plotted in given interval."""
178
+ # Mimic plot_ax logic to ensure consistency
179
+ # We need a dummy axis index, usually 0 is fine if we have 1 track
180
+ strand, metadata_index = self._get_strand_and_metadata_index(0)
181
+ track_name = self._junction_track.metadata.iloc[metadata_index]['name']
182
+ junction_track = self._junction_track.intersect_with_interval(interval)
183
+
184
+ junctions = junction_data.get_junctions_to_plot(
185
+ predictions=junction_track,
186
+ strand=strand,
187
+ name=track_name,
188
+ k_threshold=self._filter_threshold,
189
+ )
190
+ return junctions
191
+
192
+ def plot_ax(self, ax: Any, axis_index: int, interval: Any) -> None:
193
+ # We override plot_ax to call our colored_sashimi_plot
194
+ strand, metadata_index = self._get_strand_and_metadata_index(axis_index)
195
+ track_name = self._junction_track.metadata.iloc[metadata_index]['name']
196
+
197
+ junction_track = self._junction_track.intersect_with_interval(interval)
198
+
199
+ junctions = junction_data.get_junctions_to_plot(
200
+ predictions=junction_track,
201
+ strand=strand,
202
+ name=track_name,
203
+ k_threshold=self._filter_threshold,
204
+ )
205
+
206
+ if self._interval_contained:
207
+ junctions = [j for j in junctions if interval.contains(j)]
208
+ else:
209
+ junctions = [j for j in junctions if j.overlaps(interval)]
210
+
211
+ colored_sashimi_plot(
212
+ junctions,
213
+ ax=ax,
214
+ interval=interval,
215
+ filter_threshold=0, # Filtering done above
216
+ annotate_counts=self._annotate_counts,
217
+ rng=self._rng,
218
+ color=self._color,
219
+ )
220
+ ax.set_yticklabels([])
221
+ ax.set_yticks([])
222
+ ax.spines['left'].set_visible(False)
223
+
224
+ # Manually set ylabel since we might have overridden strand logic
225
+ if self._ylabel_template:
226
+ row = self._junction_track.metadata.iloc[metadata_index].to_dict()
227
+ row['strand'] = strand
228
+ ylabel = self._ylabel_template.format(**row)
229
+
230
+ if self._ylabel_horizontal:
231
+ ax.set_ylabel(
232
+ ylabel,
233
+ rotation=0,
234
+ multialignment='center',
235
+ va='center',
236
+ ha='right',
237
+ labelpad=5,
238
+ )
239
+ else:
240
+ ax.set_ylabel(ylabel)
241
+
242
+
243
+ def dynamic_label(track: Any, label_suffix: str = '') -> str:
244
+ """Constructs a label based on available metadata columns."""
245
+ if track is None or track.metadata.empty:
246
+ return f'Track {label_suffix}'
247
+
248
+ cols = track.metadata.columns
249
+ parts = []
250
+
251
+ # Get first row for labeling
252
+ row = track.metadata.iloc[0]
253
+
254
+ # Assay / Output Type
255
+ if 'Assay title' in cols:
256
+ title = str(row['Assay title'])
257
+ # Clean up long titles for display
258
+ if 'total RNA-seq' in title:
259
+ title = 'Total RNA'
260
+ elif 'polyA plus RNA-seq' in title:
261
+ title = 'PolyA RNA'
262
+ parts.append(title)
263
+
264
+ # Target / Antibody (Critically important for ChIP)
265
+ # Check common column names for TF/Histone targets
266
+ target_cols = [
267
+ 'target',
268
+ 'antibody',
269
+ 'bio_target',
270
+ 'experiment_target',
271
+ 'target_label',
272
+ ]
273
+ for c in target_cols:
274
+ if c in cols:
275
+ val = str(row[c]).strip()
276
+ if val and val.lower() != 'nan' and val.lower() != 'none':
277
+ parts.append(val)
278
+ break # Use the first valid target column found
279
+
280
+ # Clean up name if it contains weird characters like $
281
+ # (User reported "$aorta" in labels)
282
+ name = row.get('name', '')
283
+ if isinstance(name, str):
284
+ name = name.lstrip('$') # Remove leading $
285
+ if name and name.lower() != 'nan':
286
+ # Only add name if it provides new info (not just a duplicate of target)
287
+ if name not in parts:
288
+ parts.append(name)
289
+
290
+ parts.append(label_suffix)
291
+ return ' '.join(parts).strip()
292
+
293
+
294
+ def filter_preference(track: Any) -> Any:
295
+ """Prefers 'total RNA-seq' over 'polyA plus RNA-seq' if both exist.
296
+
297
+ Also aggressively dedups if 'Assay title' is not present but 'biosample_type'
298
+ or implicit duplicates exist.
299
+
300
+ Args:
301
+ track: The track to filter.
302
+
303
+ Returns:
304
+ The filtered track.
305
+ """
306
+ if track is None or len(track.metadata) < 2:
307
+ return track
308
+
309
+ cols = track.metadata.columns
310
+ # Check for 'Assay title' or 'Assay Title'
311
+ title_col = None
312
+ if 'Assay title' in cols:
313
+ title_col = 'Assay title'
314
+ elif 'Assay Title' in cols:
315
+ title_col = 'Assay Title'
316
+
317
+ if title_col:
318
+ titles = track.metadata[title_col].unique()
319
+ # Case insensitive check
320
+ titles_lower = [t.lower() for t in titles if isinstance(t, str)]
321
+
322
+ has_total = any('total rna-seq' in t for t in titles_lower)
323
+ has_polya = any('polya plus rna-seq' in t for t in titles_lower)
324
+
325
+ if has_total and has_polya:
326
+ # Filter to total RNA-seq only
327
+ mask = track.metadata[title_col].str.contains(
328
+ 'total RNA-seq', case=False, na=False
329
+ )
330
+ return track.filter_tracks(np.flatnonzero(mask.values))
331
+
332
+ return track
333
+
334
+
335
+ def get_deduplicated_indices(
336
+ track: Any, label_suffix: str = '', max_tracks: int = 5
337
+ ) -> list[int]:
338
+ """Returns indices of tracks with unique labels.
339
+
340
+ When multiple tracks produce the same label (via `dynamic_label`), only the
341
+ index of the first track with that label is kept.
342
+
343
+ Args:
344
+ track: The track to deduplicate.
345
+ label_suffix: Suffix to append to the label.
346
+ max_tracks: Maximum number of tracks to keep.
347
+
348
+ Returns:
349
+ List of integer indices to keep.
350
+ """
351
+ if track is None or track.metadata.empty:
352
+ return []
353
+
354
+ keep_indices = []
355
+ seen_labels = set()
356
+
357
+ for i in range(len(track.metadata)):
358
+ sub_track = track.filter_tracks([i])
359
+ label = dynamic_label(sub_track, label_suffix)
360
+
361
+ if label not in seen_labels:
362
+ seen_labels.add(label)
363
+ keep_indices.append(i)
364
+
365
+ if len(keep_indices) > max_tracks:
366
+ print(
367
+ f'Warning: Limiting {len(keep_indices)} tracks to top {max_tracks}'
368
+ ' for clarity.'
369
+ )
370
+ keep_indices = keep_indices[:max_tracks]
371
+
372
+ return keep_indices
373
+
374
+
375
+ def deduplicate_tracks(
376
+ track: Any, label_suffix: str = '', max_tracks: int = 5
377
+ ) -> Any:
378
+ """Deduplicates tracks based on their generated label."""
379
+ keep_indices = get_deduplicated_indices(track, label_suffix, max_tracks)
380
+ return track.filter_tracks(keep_indices)
381
+
382
+
383
+ def filter_and_create_overlay(
384
+ ref_track: Any,
385
+ alt_track: Any,
386
+ ontology_curie: str,
387
+ strand: str | None = None,
388
+ label_suffix: str = '',
389
+ color_ref: str = COLOR_REF,
390
+ color_alt: str = COLOR_ALT,
391
+ target_tf: str | None = None,
392
+ ) -> list[Any] | None:
393
+ """Filters tracks by ontology and strand and returns OverlaidTracks."""
394
+ if ref_track is None or ref_track.metadata.empty:
395
+ return []
396
+
397
+ # Start with all True
398
+ valid_mask = np.ones(len(ref_track.metadata), dtype=bool)
399
+
400
+ # Filter by Ontology if column exists
401
+ if 'ontology_curie' in ref_track.metadata.columns:
402
+ # Robust comparison: cast to string and strip
403
+ vals = ref_track.metadata['ontology_curie'].astype(str).str.strip().values
404
+ target = str(ontology_curie).strip()
405
+ valid_mask = valid_mask & (vals == target)
406
+
407
+ # Filter by TF if provided
408
+ if target_tf:
409
+ target_cols = [
410
+ 'target',
411
+ 'antibody',
412
+ 'bio_target',
413
+ 'experiment_target',
414
+ 'target_label',
415
+ ]
416
+ tf_cols = [c for c in target_cols if c in ref_track.metadata.columns]
417
+ if tf_cols:
418
+ target = str(target_tf).strip().lower()
419
+ # Succinct pandas-based row-wise check across TF columns
420
+ tf_mask = (
421
+ ref_track.metadata[tf_cols]
422
+ .astype(str)
423
+ .apply(lambda s: s.str.contains(target, case=False, na=False))
424
+ .any(axis=1)
425
+ .values
426
+ )
427
+ valid_mask = valid_mask & tf_mask
428
+
429
+ # Filter by Strand if provided and column exists
430
+ if strand and 'strand' in ref_track.metadata.columns:
431
+ strand_mask = (ref_track.metadata['strand'] == strand).values
432
+ # Fallback: if strand filtering removes all tracks, ignore it
433
+ if np.sum(valid_mask & strand_mask) > 0:
434
+ valid_mask = valid_mask & strand_mask
435
+
436
+ if np.sum(valid_mask) == 0:
437
+ return []
438
+
439
+ ref_filt = ref_track.filter_tracks(valid_mask)
440
+ alt_filt = alt_track.filter_tracks(valid_mask)
441
+
442
+ # Apply Preference Filter (Total > PolyA)
443
+ ref_filt = filter_preference(ref_filt)
444
+ alt_filt = filter_preference(alt_filt)
445
+
446
+ # Deduplicate by label. We skip deduplicate_tracks() here and inline the
447
+ # logic so we can filter BOTH ref and alt by the same indices, preserving
448
+ # Ref/Alt pairing required by OverlaidTracks.
449
+ if ref_filt is None or ref_filt.metadata.empty:
450
+ return []
451
+
452
+ keep_indices = get_deduplicated_indices(ref_filt, label_suffix)
453
+
454
+ ref_filt = ref_filt.filter_tracks(keep_indices)
455
+ alt_filt = alt_filt.filter_tracks(keep_indices)
456
+
457
+ if ref_filt.metadata.empty:
458
+ return []
459
+
460
+ components = []
461
+ # Create individual component for each unique track to ensure correct labeling
462
+ for i in range(len(ref_filt.metadata)):
463
+ # Extract single track (row)
464
+ r_track = ref_filt.filter_tracks([i])
465
+ a_track = alt_filt.filter_tracks([i])
466
+
467
+ # Generate specific label for this track
468
+ label = dynamic_label(r_track, label_suffix)
469
+
470
+ try:
471
+ comp = plot_components.OverlaidTracks(
472
+ tdata={'REF': r_track, 'ALT': a_track},
473
+ colors={'REF': color_ref, 'ALT': color_alt},
474
+ ylabel_template=label,
475
+ )
476
+ components.append(comp)
477
+ except (ValueError, RuntimeError) as e:
478
+ print(f'Warning: OverlaidTracks init failed for {label}: {e}')
479
+
480
+ return components
481
+
482
+
483
+ def compute_splicing_zoom(
484
+ chrom: str,
485
+ variant_start: int,
486
+ ref_allele: str,
487
+ gene_gtf: pd.DataFrame,
488
+ ref_sashimi: Any,
489
+ alt_sashimi: Any,
490
+ clamp_interval: Any,
491
+ ) -> genome.Interval | None:
492
+ """Computes a zoom interval that includes flanking exons and junctions.
493
+
494
+ Expands the view to show the nearest upstream and downstream exons relative
495
+ to the variant, plus any significant splice junctions overlapping the region.
496
+
497
+ Args:
498
+ chrom: Chromosome string.
499
+ variant_start: Variant start position.
500
+ ref_allele: Reference allele string (used to compute variant end).
501
+ gene_gtf: GTF DataFrame filtered to the target gene.
502
+ ref_sashimi: Reference ColoredSashimi component.
503
+ alt_sashimi: Alternate ColoredSashimi component.
504
+ clamp_interval: Outer interval to clamp results within.
505
+
506
+ Returns:
507
+ A genome.Interval for the zoom view, or None if exons are unavailable.
508
+ """
509
+ feature_col = 'Feature' if 'Feature' in gene_gtf.columns else 'feature'
510
+ if feature_col not in gene_gtf.columns:
511
+ return None
512
+
513
+ exons = gene_gtf[gene_gtf[feature_col] == 'exon'].copy()
514
+ if exons.empty:
515
+ return None
516
+
517
+ exons = exons.sort_values('Start')
518
+ v_start = variant_start
519
+ v_end = variant_start + len(ref_allele)
520
+
521
+ # Start with a small window around the variant.
522
+ new_start = v_start - 200
523
+ new_end = v_end + 200
524
+
525
+ # Extend to the nearest flanking exons.
526
+ upstream_exons = exons[exons['End'] < v_start]
527
+ if not upstream_exons.empty:
528
+ new_start = min(new_start, upstream_exons.iloc[-1]['Start'] - 100)
529
+
530
+ downstream_exons = exons[exons['Start'] > v_end]
531
+ if not downstream_exons.empty:
532
+ new_end = max(new_end, downstream_exons.iloc[0]['End'] + 100)
533
+
534
+ # Include any exons overlapping the variant itself.
535
+ overlapping = exons[(exons['Start'] <= v_end) & (exons['End'] >= v_start)]
536
+ if not overlapping.empty:
537
+ new_start = min(new_start, overlapping['Start'].min() - 100)
538
+ new_end = max(new_end, overlapping['End'].max() + 100)
539
+
540
+ # Expand to include significant splice junctions.
541
+ all_juncs = []
542
+ try:
543
+ all_juncs.extend(ref_sashimi.get_junctions(clamp_interval))
544
+ all_juncs.extend(alt_sashimi.get_junctions(clamp_interval))
545
+ except (ValueError, IndexError, AttributeError) as e:
546
+ print(f'Warning: Failed to fetch junctions for zoom: {e}')
547
+
548
+ if all_juncs:
549
+ max_score = max(j.k for j in all_juncs)
550
+ base_interval_obj = genome.Interval(chrom, new_start, new_end)
551
+ significant_juncs = [
552
+ j
553
+ for j in all_juncs
554
+ if (j.k >= 5 or (max_score > 0 and j.k / max_score > 0.1))
555
+ and genome.Interval(chrom, j.start, j.end).overlaps(base_interval_obj)
556
+ ]
557
+
558
+ if significant_juncs:
559
+ j_min = min(j.start for j in significant_juncs)
560
+ j_max = max(j.end for j in significant_juncs)
561
+ new_start = min(new_start, j_min)
562
+ new_end = max(new_end, j_max)
563
+
564
+ # Snap to exon boundaries near junction anchors.
565
+ up_anchor = exons[
566
+ (exons['End'] >= j_min - 100) & (exons['End'] <= j_min + 100)
567
+ ]
568
+ if not up_anchor.empty:
569
+ new_start = min(new_start, up_anchor['Start'].min() - 100)
570
+
571
+ down_anchor = exons[
572
+ (exons['Start'] >= j_max - 100) & (exons['Start'] <= j_max + 100)
573
+ ]
574
+ if not down_anchor.empty:
575
+ new_end = max(new_end, down_anchor['End'].max() + 100)
576
+
577
+ # Clamp to the prediction interval to prevent out-of-bounds errors.
578
+ new_start = max(new_start, clamp_interval.start)
579
+ new_end = min(new_end, clamp_interval.end)
580
+
581
+ return genome.Interval(chrom, new_start, new_end)
582
+
583
+
584
+ def resolve_tracks_argument(tracks_arg: str | None) -> dict[str, Any]:
585
+ """Resolves --tracks argument to list of OutputTypes and flags."""
586
+ if not tracks_arg:
587
+ # Default: RNA_SEQ and DNASE if nothing specified
588
+ return {
589
+ 'outputs': [dna_client.OutputType.RNA_SEQ, dna_client.OutputType.DNASE],
590
+ 'show_splicing': False,
591
+ 'show_regulatory': True,
592
+ }
593
+
594
+ arg_list = [t.strip().lower() for t in tracks_arg.split(',')]
595
+ outputs = set()
596
+ show_splicing = False
597
+ show_regulatory = False
598
+
599
+ # Macros
600
+ if 'all' in arg_list:
601
+ arg_list = ['splicing', 'regulatory']
602
+
603
+ if 'splicing' in arg_list:
604
+ outputs.update([
605
+ dna_client.OutputType.RNA_SEQ,
606
+ dna_client.OutputType.SPLICE_JUNCTIONS,
607
+ dna_client.OutputType.SPLICE_SITE_USAGE,
608
+ dna_client.OutputType.SPLICE_SITES,
609
+ ])
610
+ show_splicing = True
611
+
612
+ if 'regulatory' in arg_list:
613
+ outputs.update([
614
+ dna_client.OutputType.DNASE,
615
+ dna_client.OutputType.CHIP_TF,
616
+ dna_client.OutputType.CHIP_HISTONE,
617
+ ])
618
+ show_regulatory = True
619
+
620
+ # Individual output type overrides (e.g. --tracks=dnase,chip_tf)
621
+ if 'rna_seq' in arg_list or 'expression' in arg_list:
622
+ outputs.add(dna_client.OutputType.RNA_SEQ)
623
+ if 'dnase' in arg_list:
624
+ outputs.add(dna_client.OutputType.DNASE)
625
+ show_regulatory = True
626
+ if 'chip' in arg_list or 'chip_tf' in arg_list:
627
+ outputs.add(dna_client.OutputType.CHIP_TF)
628
+ show_regulatory = True
629
+ if 'chip_histone' in arg_list:
630
+ outputs.add(dna_client.OutputType.CHIP_HISTONE)
631
+ show_regulatory = True
632
+
633
+ return {
634
+ 'outputs': list(outputs),
635
+ 'show_splicing': show_splicing,
636
+ 'show_regulatory': show_regulatory,
637
+ }
638
+
639
+
640
+ def load_target_gene_info(
641
+ gtf: pd.DataFrame, gene_name: str, interval_1mb: genome.Interval
642
+ ) -> tuple[genome.Interval, str | None, list[Any], pd.DataFrame]:
643
+ """Loads gene info from GTF and returns interval, strand, transcripts, and filtered GTF."""
644
+ gene_gtf = gtf[gtf['gene_name'] == gene_name]
645
+ if gene_gtf.empty:
646
+ print(f'Gene {gene_name} not found.')
647
+ gene_interval = interval_1mb
648
+ strand = None
649
+ transcripts = []
650
+ else:
651
+ gene_interval = gene_annotation.get_gene_interval(
652
+ gene_gtf, gene_symbol=gene_name
653
+ )
654
+ strand = gene_gtf['Strand'].iloc[0]
655
+ print(f'Target Gene: {gene_name} ({strand})')
656
+
657
+ # Extract transcripts
658
+ print('Filtering to longest transcripts...')
659
+ longest_gene_gtf = gene_annotation.filter_to_longest_transcript(gene_gtf)
660
+ transcript_extractor = transcript_utils.TranscriptExtractor(
661
+ longest_gene_gtf
662
+ )
663
+ transcripts = transcript_extractor.extract(
664
+ gene_interval.resize(gene_interval.width + 10000)
665
+ )
666
+ # Filter transcripts to gene strand
667
+ transcripts = [t for t in transcripts if t.strand == strand]
668
+
669
+ if not transcripts:
670
+ print(
671
+ 'WARNING: No transcripts found for gene on the expected strand.'
672
+ ' Transcript track will be missing.'
673
+ )
674
+
675
+ return gene_interval, strand, transcripts, gene_gtf
676
+
677
+
678
+ def get_rna_seq_components(
679
+ prediction: Any,
680
+ requested_outputs: list[dna_client.OutputType],
681
+ ontology: str,
682
+ strand: str | None,
683
+ pretty_id: str,
684
+ ) -> list[Any]:
685
+ """Returns RNA-seq overlay components."""
686
+ if dna_client.OutputType.RNA_SEQ not in requested_outputs:
687
+ return []
688
+ rna_comps = filter_and_create_overlay(
689
+ prediction.reference.rna_seq,
690
+ prediction.alternate.rna_seq,
691
+ ontology,
692
+ strand=strand,
693
+ label_suffix=f'\n{pretty_id}\nRNA',
694
+ )
695
+ return rna_comps or []
696
+
697
+
698
+ def add_splicing_components(
699
+ prediction: Any,
700
+ requested_outputs: list[dna_client.OutputType],
701
+ show_splicing: bool,
702
+ variant: genome.Variant,
703
+ variant_args: Any,
704
+ gene_gtf: pd.DataFrame,
705
+ interval_1mb: genome.Interval,
706
+ strand: str | None,
707
+ pretty_id: str,
708
+ components: list[Any],
709
+ zoom_interval: genome.Interval,
710
+ ) -> genome.Interval:
711
+ """Adds splicing components and updates zoom interval."""
712
+ if not show_splicing:
713
+ return zoom_interval
714
+
715
+ # WHOLE GENE ZOOM
716
+ if variant_args.view == 'whole_gene':
717
+ if not gene_gtf.empty:
718
+ gene_interval = gene_annotation.get_gene_interval(
719
+ gene_gtf, gene_symbol=variant_args.gene
720
+ )
721
+ padding = max(1000, int(gene_interval.width * 0.05))
722
+ zoom_interval = gene_interval.resize(gene_interval.width + padding * 2)
723
+ print(f'Zooming to Whole Gene: {zoom_interval}')
724
+ else:
725
+ print(
726
+ 'WARNING: --view whole_gene requested but gene not found in GTF.'
727
+ ' Falling back to default zoom.'
728
+ )
729
+
730
+ # Pre-calculate Sashimi for Zoom
731
+ try:
732
+ if (
733
+ 'ontology_curie'
734
+ in prediction.reference.splice_junctions.metadata.columns
735
+ ):
736
+ ref_junc = prediction.reference.splice_junctions.filter_by_ontology(
737
+ variant_args.ontology
738
+ )
739
+ alt_junc = prediction.alternate.splice_junctions.filter_by_ontology(
740
+ variant_args.ontology
741
+ )
742
+ else:
743
+ print(
744
+ 'WARNING: Splicing tracks missing "ontology_curie" metadata.'
745
+ ' Skipping ontology filtering.'
746
+ )
747
+ ref_junc = prediction.reference.splice_junctions
748
+ alt_junc = prediction.alternate.splice_junctions
749
+ except (KeyError, ValueError, AttributeError) as e:
750
+ print(
751
+ f'WARNING: Splicing ontology filtering failed: {e}. Using all'
752
+ ' returned junctions.'
753
+ )
754
+ ref_junc = prediction.reference.splice_junctions
755
+ alt_junc = prediction.alternate.splice_junctions
756
+
757
+ ref_junc = filter_preference(ref_junc)
758
+ alt_junc = filter_preference(alt_junc)
759
+
760
+ ref_sashimi = ColoredSashimi(
761
+ ref_junc,
762
+ ylabel_template=f"Ref Junc\n{pretty_id}\n({strand if strand else ''})",
763
+ color=COLOR_REF,
764
+ normalize_values=False,
765
+ forced_strand=strand,
766
+ )
767
+ alt_sashimi = ColoredSashimi(
768
+ alt_junc,
769
+ ylabel_template=f"Alt Junc\n{pretty_id}\n({strand if strand else ''})",
770
+ color=COLOR_ALT,
771
+ normalize_values=False,
772
+ forced_strand=strand,
773
+ )
774
+
775
+ # Dynamic zoom: expand the zoom interval to include flanking exons
776
+ # and significant splice junctions around the variant.
777
+ if not gene_gtf.empty:
778
+ computed_zoom = compute_splicing_zoom(
779
+ chrom=variant_args.chrom,
780
+ variant_start=variant.start,
781
+ ref_allele=variant_args.ref,
782
+ gene_gtf=gene_gtf,
783
+ ref_sashimi=ref_sashimi,
784
+ alt_sashimi=alt_sashimi,
785
+ clamp_interval=interval_1mb,
786
+ )
787
+ if computed_zoom is not None:
788
+ zoom_interval = computed_zoom
789
+
790
+ # Splice Usage
791
+ if dna_client.OutputType.SPLICE_SITE_USAGE in requested_outputs:
792
+ usage_comps = filter_and_create_overlay(
793
+ prediction.reference.splice_site_usage,
794
+ prediction.alternate.splice_site_usage,
795
+ variant_args.ontology,
796
+ strand=strand,
797
+ label_suffix=f'\n{pretty_id}\nUsage',
798
+ )
799
+ if usage_comps:
800
+ components.extend(usage_comps)
801
+
802
+ # Splice Sites
803
+ if dna_client.OutputType.SPLICE_SITES in requested_outputs:
804
+ ref_sites = filter_preference(prediction.reference.splice_sites)
805
+ alt_sites = filter_preference(prediction.alternate.splice_sites)
806
+
807
+ def split_sites(track: Any, pattern: str) -> Any:
808
+ if track is None or track.metadata.empty:
809
+ return None
810
+ mask = np.zeros(len(track.metadata), dtype=bool)
811
+ if 'name' in track.metadata.columns:
812
+ mask |= track.metadata['name'].str.contains(
813
+ pattern, case=False, na=False
814
+ )
815
+ if 'Assay title' in track.metadata.columns:
816
+ mask |= track.metadata['Assay title'].str.contains(
817
+ pattern, case=False, na=False
818
+ )
819
+ return (
820
+ track.filter_tracks(np.flatnonzero(mask.values))
821
+ if np.any(mask)
822
+ else None
823
+ )
824
+
825
+ ref_donor = split_sites(ref_sites, 'Donor')
826
+ alt_donor = split_sites(alt_sites, 'Donor')
827
+ if ref_donor:
828
+ donor_comps = filter_and_create_overlay(
829
+ ref_donor,
830
+ alt_donor,
831
+ variant_args.ontology,
832
+ strand=strand,
833
+ label_suffix=f'\n{pretty_id}\nSites (Donor, {strand})',
834
+ )
835
+ if donor_comps:
836
+ components.extend(donor_comps)
837
+
838
+ ref_acceptor = split_sites(ref_sites, 'Acceptor')
839
+ alt_acceptor = split_sites(alt_sites, 'Acceptor')
840
+ if ref_acceptor:
841
+ acc_comps = filter_and_create_overlay(
842
+ ref_acceptor,
843
+ alt_acceptor,
844
+ variant_args.ontology,
845
+ strand=strand,
846
+ label_suffix=f'\n{pretty_id}\nSites (Acceptor, {strand})',
847
+ )
848
+ if acc_comps:
849
+ components.extend(acc_comps)
850
+
851
+ components.append(ref_sashimi)
852
+ components.append(alt_sashimi)
853
+
854
+ return zoom_interval
855
+
856
+
857
+ def get_regulatory_components(
858
+ prediction: Any,
859
+ requested_outputs: list[dna_client.OutputType],
860
+ show_regulatory: bool,
861
+ variant_args: Any,
862
+ pretty_id: str,
863
+ ) -> list[Any]:
864
+ """Returns regulatory overlay components (DNase, ChIP-TF)."""
865
+ if not show_regulatory:
866
+ return []
867
+
868
+ components = []
869
+ if dna_client.OutputType.DNASE in requested_outputs:
870
+ dnase_comp = filter_and_create_overlay(
871
+ prediction.reference.dnase,
872
+ prediction.alternate.dnase,
873
+ variant_args.ontology,
874
+ strand=None,
875
+ label_suffix=f'\n{pretty_id}\nDNASE',
876
+ )
877
+ if dnase_comp:
878
+ components.extend(dnase_comp)
879
+
880
+ if dna_client.OutputType.CHIP_TF in requested_outputs:
881
+ chip_tf_comps = filter_and_create_overlay(
882
+ prediction.reference.chip_tf,
883
+ prediction.alternate.chip_tf,
884
+ variant_args.ontology,
885
+ strand=None,
886
+ label_suffix=f'\n{pretty_id}\nCHIP_TF',
887
+ target_tf=variant_args.tf,
888
+ )
889
+ if chip_tf_comps:
890
+ components.extend(chip_tf_comps)
891
+
892
+ return components
893
+
894
+
895
+ def render_plots(
896
+ variant_args: Any,
897
+ prediction: Any,
898
+ components: list[Any],
899
+ zoom_interval: genome.Interval,
900
+ variant: genome.Variant,
901
+ requested_outputs: list[dna_client.OutputType],
902
+ gene_gtf: pd.DataFrame,
903
+ gene_interval: genome.Interval,
904
+ ) -> None:
905
+ """Renders default, detail, and whole-gene plots."""
906
+ print('Generating plot...')
907
+ plot_path = os.path.join(
908
+ variant_args.output_dir,
909
+ f"plot_{variant_args.tissue.replace(' ', '_')}"
910
+ f'_{variant_args.gene}_effects.png',
911
+ )
912
+
913
+ max_diff = 0.0
914
+ if (
915
+ prediction.reference.rna_seq is not None
916
+ and not prediction.reference.rna_seq.metadata.empty
917
+ and prediction.alternate.rna_seq is not None
918
+ and not prediction.alternate.rna_seq.metadata.empty
919
+ ):
920
+ try:
921
+ diff = np.max(
922
+ np.abs(
923
+ prediction.alternate.rna_seq.values
924
+ - prediction.reference.rna_seq.values
925
+ )
926
+ )
927
+ max_diff = max(max_diff, diff)
928
+ except (ValueError, TypeError) as e:
929
+ print(f'Warning: Could not compute RNA diff summary: {e}')
930
+
931
+ summary_text = (
932
+ variant_args.description
933
+ if variant_args.description
934
+ else f'Max DNASE/RNA Diff: {max_diff:.2f}'
935
+ )
936
+
937
+ try:
938
+ plot_components.plot(
939
+ components=components,
940
+ interval=zoom_interval, # Tighter zoom or dynamic zoom
941
+ annotations=[plot_components.VariantAnnotation([variant], alpha=0.8)],
942
+ )
943
+ plt.suptitle(
944
+ f'{variant_args.gene} {variant_args.tissue}'
945
+ f' {variant_args.chrom}:{variant_args.pos}'
946
+ f':{variant_args.ref}>{variant_args.alt}'
947
+ f'\n{summary_text}\nZoom:'
948
+ f' {zoom_interval}'
949
+ )
950
+ plt.savefig(plot_path, dpi=150, bbox_inches='tight')
951
+ plt.close()
952
+ print(f'Saved plot to {plot_path}')
953
+ except (ValueError, RuntimeError, OSError) as e:
954
+ print(f'Failed to plot: {e}')
955
+
956
+ print('Generating Detail View (+/- 50bp)...')
957
+ detail_path = os.path.join(
958
+ variant_args.output_dir,
959
+ f"plot_{variant_args.tissue.replace(' ', '_')}"
960
+ f'_{variant_args.gene}_detail.png',
961
+ )
962
+
963
+ detail_interval = genome.Interval(
964
+ variant_args.chrom, variant_args.pos - 50, variant_args.pos + 50
965
+ )
966
+
967
+ try:
968
+ plot_components.plot(
969
+ components=components,
970
+ interval=detail_interval,
971
+ annotations=[plot_components.VariantAnnotation([variant], alpha=0.8)],
972
+ )
973
+ plt.suptitle(
974
+ f'{variant_args.gene} {variant_args.tissue}'
975
+ f' {variant_args.chrom}:{variant_args.pos} Detail View (+/- 50bp)'
976
+ )
977
+ plt.savefig(detail_path, dpi=150, bbox_inches='tight')
978
+ plt.close()
979
+ print(f'Saved detail plot to {detail_path}')
980
+ except (ValueError, RuntimeError, OSError) as e:
981
+ print(f'Failed to plot detail view: {e}')
982
+
983
+ if dna_client.OutputType.RNA_SEQ in requested_outputs and not gene_gtf.empty:
984
+ print('Generating Whole-Gene View (RNA-seq requested)...')
985
+ filename = (
986
+ f"plot_{variant_args.tissue.replace(' ', '_')}"
987
+ f'_{variant_args.gene}_wholegene.png'
988
+ )
989
+ wholegene_path = os.path.join(variant_args.output_dir, filename)
990
+
991
+ pad = int(gene_interval.width * 0.1)
992
+ wholegene_interval = gene_interval.resize(gene_interval.width + pad)
993
+
994
+ try:
995
+ plot_components.plot(
996
+ components=components,
997
+ interval=wholegene_interval,
998
+ annotations=[plot_components.VariantAnnotation([variant], alpha=0.8)],
999
+ )
1000
+ plt.suptitle(
1001
+ f'{variant_args.gene} {variant_args.tissue} Whole Gene'
1002
+ f' View\n{summary_text}'
1003
+ )
1004
+ plt.savefig(wholegene_path, dpi=150, bbox_inches='tight')
1005
+ plt.close()
1006
+ print(f'Saved whole-gene plot to {wholegene_path}')
1007
+ except (ValueError, RuntimeError, OSError) as e:
1008
+ print(f'Failed to plot whole-gene view: {e}')
1009
+
1010
+
1011
+ def visualize_variant_effects(variant_args: Any) -> None:
1012
+ """Main function to visualize variant effects."""
1013
+ # Setup Output
1014
+ os.makedirs(variant_args.output_dir, exist_ok=True)
1015
+
1016
+ # Initialize Client
1017
+ api_key = os.environ.get('ALPHAGENOME_API_KEY')
1018
+ if not api_key:
1019
+ raise ValueError('ALPHAGENOME_API_KEY environment variable not set.')
1020
+
1021
+ dna_model = dna_client.create(
1022
+ api_key=api_key,
1023
+ address=API_ADDRESS,
1024
+ )
1025
+
1026
+ # Variant Setup
1027
+ variant = genome.Variant(
1028
+ variant_args.chrom, variant_args.pos, variant_args.ref, variant_args.alt
1029
+ )
1030
+
1031
+ # Context Interval (1Mb)
1032
+ seq_length = 2**20
1033
+ interval_1mb = genome.Interval(
1034
+ variant_args.chrom,
1035
+ variant_args.pos - seq_length // 2,
1036
+ variant_args.pos + seq_length // 2,
1037
+ )
1038
+
1039
+ # Determine requested tracks
1040
+ track_config = resolve_tracks_argument(variant_args.tracks)
1041
+ requested_outputs = track_config['outputs']
1042
+ show_splicing = track_config['show_splicing']
1043
+ show_regulatory = track_config['show_regulatory']
1044
+
1045
+ print(
1046
+ f'Predicting variant effects for {variant_args.tissue}'
1047
+ f' ({variant_args.ontology})...'
1048
+ )
1049
+ print(f'Requested Outputs: {[o.name for o in requested_outputs]}')
1050
+
1051
+ # Load GTF for Gene Info
1052
+ print('Loading GTF...')
1053
+ gtf = pd.read_feather(GTF_URL)
1054
+
1055
+ gene_interval, strand, transcripts, gene_gtf = load_target_gene_info(
1056
+ gtf, variant_args.gene, interval_1mb
1057
+ )
1058
+
1059
+ # Predict
1060
+ prediction = dna_model.predict_variant(
1061
+ interval=interval_1mb,
1062
+ variant=variant,
1063
+ requested_outputs=requested_outputs,
1064
+ ontology_terms=[variant_args.ontology],
1065
+ )
1066
+
1067
+ # --- Plotting ---
1068
+ components = []
1069
+
1070
+ # 1. Transcripts (Verified: User wants these AT THE TOP)
1071
+ if transcripts:
1072
+ components.append(
1073
+ plot_components.TranscriptAnnotation(
1074
+ transcripts, label_name='gene_name'
1075
+ )
1076
+ )
1077
+
1078
+ # Formatted Label for User Readability
1079
+ pretty_id = f'{variant_args.tissue}\n({variant_args.ontology})'
1080
+
1081
+ # 2. RNA-seq (Stranded)
1082
+ components.extend(
1083
+ get_rna_seq_components(
1084
+ prediction,
1085
+ requested_outputs,
1086
+ variant_args.ontology,
1087
+ strand,
1088
+ pretty_id,
1089
+ )
1090
+ )
1091
+
1092
+ # Default Zoom: +/- 1000bp around variant (total 2000bp window).
1093
+ zoom_interval = variant.reference_interval.resize(2000)
1094
+
1095
+ # 3. Splicing Tracks (Conditional)
1096
+ zoom_interval = add_splicing_components(
1097
+ prediction,
1098
+ requested_outputs,
1099
+ show_splicing,
1100
+ variant,
1101
+ variant_args,
1102
+ gene_gtf,
1103
+ interval_1mb,
1104
+ strand,
1105
+ pretty_id,
1106
+ components,
1107
+ zoom_interval,
1108
+ )
1109
+ # 4. Regulatory Tracks (DNASE, CHIP_TF, CHIP_HISTONE)
1110
+ components.extend(
1111
+ get_regulatory_components(
1112
+ prediction,
1113
+ requested_outputs,
1114
+ show_regulatory,
1115
+ variant_args,
1116
+ pretty_id,
1117
+ )
1118
+ )
1119
+
1120
+ render_plots(
1121
+ variant_args,
1122
+ prediction,
1123
+ components,
1124
+ zoom_interval,
1125
+ variant,
1126
+ requested_outputs,
1127
+ gene_gtf,
1128
+ gene_interval,
1129
+ )
1130
+
1131
+
1132
+ def main(argv: list[str] | None = None) -> None:
1133
+ """Main entry point for the variant effects visualization CLI tool."""
1134
+ dotenv.load_dotenv(os.path.expanduser('~/.env'))
1135
+ parser = argparse.ArgumentParser(
1136
+ description='Visualize variant effects using AlphaGenome predictions.'
1137
+ )
1138
+ parser.add_argument(
1139
+ '--chrom',
1140
+ required=True,
1141
+ help='Chromosome (e.g., chr17).',
1142
+ )
1143
+ parser.add_argument(
1144
+ '--pos',
1145
+ type=int,
1146
+ required=True,
1147
+ help='Position (1-based).',
1148
+ )
1149
+ parser.add_argument(
1150
+ '--ref',
1151
+ required=True,
1152
+ help='Reference allele.',
1153
+ )
1154
+ parser.add_argument(
1155
+ '--alt',
1156
+ required=True,
1157
+ help='Alternate allele.',
1158
+ )
1159
+ parser.add_argument(
1160
+ '--gene',
1161
+ required=True,
1162
+ help='Gene symbol.',
1163
+ )
1164
+ parser.add_argument(
1165
+ '--tissue',
1166
+ required=True,
1167
+ help='Tissue name for labeling.',
1168
+ )
1169
+ parser.add_argument(
1170
+ '--ontology', required=True, help='Ontology CURIE (e.g., UBERON:0002107).'
1171
+ )
1172
+ parser.add_argument('--output_dir', required=True, help='Output directory.')
1173
+ parser.add_argument(
1174
+ '--tracks',
1175
+ default='regulatory',
1176
+ help='Comma-separated track types: splicing, regulatory, all.',
1177
+ )
1178
+ parser.add_argument(
1179
+ '--tf', default=None, help='TF name to filter CHIP_TF tracks.'
1180
+ )
1181
+ parser.add_argument(
1182
+ '--view',
1183
+ choices=['default', 'whole_gene'],
1184
+ default='default',
1185
+ help="Zoom level. 'whole_gene' plots the entire gene interval.",
1186
+ )
1187
+ parser.add_argument(
1188
+ '--description',
1189
+ default=None,
1190
+ help='Natural language summary of the variant effect.',
1191
+ )
1192
+ args = parser.parse_args(argv)
1193
+
1194
+ visualize_variant_effects(args)
1195
+
1196
+
1197
+ if __name__ == '__main__':
1198
+ main()