@brainpilot/skills 0.0.11 → 0.0.13

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 (405) 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/fmriprep/SKILL.md +256 -0
  5. package/skills/06_fMRI_Neuroimaging/fmriprep/references/bids-filter.md +287 -0
  6. package/skills/06_fMRI_Neuroimaging/fmriprep/references/citation.md +284 -0
  7. package/skills/06_fMRI_Neuroimaging/fmriprep/references/cli-reference.md +260 -0
  8. package/skills/06_fMRI_Neuroimaging/fmriprep/references/confounds.md +344 -0
  9. package/skills/06_fMRI_Neuroimaging/fmriprep/references/installation.md +346 -0
  10. package/skills/06_fMRI_Neuroimaging/fmriprep/references/outputs.md +369 -0
  11. package/skills/06_fMRI_Neuroimaging/fmriprep/references/sdc-fieldmaps.md +306 -0
  12. package/skills/06_fMRI_Neuroimaging/fmriprep/references/spaces.md +334 -0
  13. package/skills/06_fMRI_Neuroimaging/fmriprep/references/troubleshooting-faq.md +419 -0
  14. package/skills/06_fMRI_Neuroimaging/fmriprep/references/usage-examples.md +465 -0
  15. package/skills/06_fMRI_Neuroimaging/fmriprep/references/versions-dependencies.md +228 -0
  16. package/skills/06_fMRI_Neuroimaging/fmriprep/references/workflows.md +392 -0
  17. package/skills/06_fMRI_Neuroimaging/netneurotools-guide/SKILL.md +212 -0
  18. package/skills/06_fMRI_Neuroimaging/netneurotools-guide/references/datasets.md +252 -0
  19. package/skills/06_fMRI_Neuroimaging/netneurotools-guide/references/interface-plotting.md +238 -0
  20. package/skills/06_fMRI_Neuroimaging/netneurotools-guide/references/metrics.md +236 -0
  21. package/skills/06_fMRI_Neuroimaging/netneurotools-guide/references/networks.md +273 -0
  22. package/skills/06_fMRI_Neuroimaging/netneurotools-guide/references/spatial-modularity.md +291 -0
  23. package/skills/06_fMRI_Neuroimaging/netneurotools-guide/references/stats.md +290 -0
  24. package/skills/09_Cellular_Molecular_Neuroscience/alphafold-database-fetch-and-analyze/SKILL.md +116 -0
  25. package/skills/09_Cellular_Molecular_Neuroscience/alphafold-database-fetch-and-analyze/references/citation.bib +58 -0
  26. package/skills/09_Cellular_Molecular_Neuroscience/alphafold-database-fetch-and-analyze/scripts/analyze_pae.py +212 -0
  27. package/skills/09_Cellular_Molecular_Neuroscience/alphafold-database-fetch-and-analyze/scripts/analyze_plddt.py +125 -0
  28. package/skills/09_Cellular_Molecular_Neuroscience/alphafold-database-fetch-and-analyze/scripts/fetch_structure.py +168 -0
  29. package/skills/09_Cellular_Molecular_Neuroscience/gtex-database/SKILL.md +176 -0
  30. package/skills/09_Cellular_Molecular_Neuroscience/gtex-database/references/citation.bib +14 -0
  31. package/skills/09_Cellular_Molecular_Neuroscience/gtex-database/scripts/gtex_cli.py +281 -0
  32. package/skills/09_Cellular_Molecular_Neuroscience/human-protein-atlas-database/SKILL.md +181 -0
  33. package/skills/09_Cellular_Molecular_Neuroscience/human-protein-atlas-database/references/citation.bib +14 -0
  34. package/skills/09_Cellular_Molecular_Neuroscience/human-protein-atlas-database/references/search-api.md +137 -0
  35. package/skills/09_Cellular_Molecular_Neuroscience/human-protein-atlas-database/scripts/hpa_cli.py +263 -0
  36. package/skills/09_Cellular_Molecular_Neuroscience/pdb-database/SKILL.md +169 -0
  37. package/skills/09_Cellular_Molecular_Neuroscience/pdb-database/references/citation.bib +15 -0
  38. package/skills/09_Cellular_Molecular_Neuroscience/pdb-database/scripts/download_coordinate_files.py +113 -0
  39. package/skills/09_Cellular_Molecular_Neuroscience/pdb-database/scripts/fetch_pdb_metadata.py +70 -0
  40. package/skills/09_Cellular_Molecular_Neuroscience/pdb-database/scripts/fetch_schema.py +251 -0
  41. package/skills/09_Cellular_Molecular_Neuroscience/pdb-database/scripts/search_pdb.py +187 -0
  42. package/skills/09_Cellular_Molecular_Neuroscience/pymol/SKILL.md +146 -0
  43. package/skills/09_Cellular_Molecular_Neuroscience/pymol/references/PYMOL_REFERENCE.md +160 -0
  44. package/skills/09_Cellular_Molecular_Neuroscience/pymol/references/RECIPES.md +348 -0
  45. package/skills/09_Cellular_Molecular_Neuroscience/pymol/references/citation.bib +6 -0
  46. package/skills/17_Literature_Databases/literature-search-arxiv/SKILL.md +120 -0
  47. package/skills/17_Literature_Databases/literature-search-arxiv/references/citation.bib +18 -0
  48. package/skills/17_Literature_Databases/literature-search-arxiv/references/query_syntax.md +34 -0
  49. package/skills/17_Literature_Databases/literature-search-arxiv/scripts/download_paper.py +116 -0
  50. package/skills/17_Literature_Databases/literature-search-arxiv/scripts/download_paper_source.py +98 -0
  51. package/skills/17_Literature_Databases/literature-search-arxiv/scripts/search_arxiv.py +174 -0
  52. package/skills/17_Literature_Databases/literature-search-biorxiv/SKILL.md +169 -0
  53. package/skills/17_Literature_Databases/literature-search-biorxiv/references/citation.bib +12 -0
  54. package/skills/17_Literature_Databases/literature-search-biorxiv/scripts/search_by_dates.py +297 -0
  55. package/skills/17_Literature_Databases/literature-search-biorxiv/scripts/search_by_doi.py +72 -0
  56. package/skills/17_Literature_Databases/literature-search-europepmc/SKILL.md +229 -0
  57. package/skills/17_Literature_Databases/literature-search-europepmc/references/citation.bib +15 -0
  58. package/skills/17_Literature_Databases/literature-search-europepmc/scripts/europepmc_api.py +345 -0
  59. package/skills/17_Literature_Databases/literature-search-openalex/SKILL.md +169 -0
  60. package/skills/17_Literature_Databases/literature-search-openalex/references/authors.md +78 -0
  61. package/skills/17_Literature_Databases/literature-search-openalex/references/citation.bib +8 -0
  62. package/skills/17_Literature_Databases/literature-search-openalex/references/geo_and_language.md +37 -0
  63. package/skills/17_Literature_Databases/literature-search-openalex/references/institutions.md +64 -0
  64. package/skills/17_Literature_Databases/literature-search-openalex/references/publishers_funders.md +42 -0
  65. package/skills/17_Literature_Databases/literature-search-openalex/references/sources.md +79 -0
  66. package/skills/17_Literature_Databases/literature-search-openalex/references/taxonomy.md +52 -0
  67. package/skills/17_Literature_Databases/literature-search-openalex/references/topics.md +29 -0
  68. package/skills/17_Literature_Databases/literature-search-openalex/references/type_values.md +65 -0
  69. package/skills/17_Literature_Databases/literature-search-openalex/references/works.md +304 -0
  70. package/skills/17_Literature_Databases/literature-search-openalex/scripts/openalex_cli.py +633 -0
  71. package/skills/17_Literature_Databases/pubmed-database/SKILL.md +185 -0
  72. package/skills/17_Literature_Databases/pubmed-database/references/advanced-linking.md +128 -0
  73. package/skills/17_Literature_Databases/pubmed-database/references/advanced-search.md +98 -0
  74. package/skills/17_Literature_Databases/pubmed-database/references/bulk-workflows.md +88 -0
  75. package/skills/17_Literature_Databases/pubmed-database/references/citation-matching.md +155 -0
  76. package/skills/17_Literature_Databases/pubmed-database/references/citation.bib +15 -0
  77. package/skills/17_Literature_Databases/pubmed-database/references/cross-database-linking.md +93 -0
  78. package/skills/17_Literature_Databases/pubmed-database/references/fetch-and-resolve.md +125 -0
  79. package/skills/17_Literature_Databases/pubmed-database/references/search-and-discovery.md +106 -0
  80. package/skills/17_Literature_Databases/pubmed-database/references/utilities.md +42 -0
  81. package/skills/17_Literature_Databases/pubmed-database/scripts/pubmed_api.py +715 -0
  82. package/skills/18_Genetics_Genomics/alphagenome-single-variant-analysis/SKILL.md +251 -0
  83. package/skills/18_Genetics_Genomics/alphagenome-single-variant-analysis/pyproject.toml +15 -0
  84. package/skills/18_Genetics_Genomics/alphagenome-single-variant-analysis/references/citation.bib +12 -0
  85. package/skills/18_Genetics_Genomics/alphagenome-single-variant-analysis/scripts/analyze_ism.py +334 -0
  86. package/skills/18_Genetics_Genomics/alphagenome-single-variant-analysis/scripts/generate_ontology_mapping.py +170 -0
  87. package/skills/18_Genetics_Genomics/alphagenome-single-variant-analysis/scripts/interpret_splicing.py +305 -0
  88. package/skills/18_Genetics_Genomics/alphagenome-single-variant-analysis/scripts/lookup_gene_info.py +337 -0
  89. package/skills/18_Genetics_Genomics/alphagenome-single-variant-analysis/scripts/resolve_ontology_terms.py +155 -0
  90. package/skills/18_Genetics_Genomics/alphagenome-single-variant-analysis/scripts/visualize_genome_tracks.py +402 -0
  91. package/skills/18_Genetics_Genomics/alphagenome-single-variant-analysis/scripts/visualize_variant_effects.py +1198 -0
  92. package/skills/18_Genetics_Genomics/clinvar-database/SKILL.md +370 -0
  93. package/skills/18_Genetics_Genomics/clinvar-database/references/citation.bib +23 -0
  94. package/skills/18_Genetics_Genomics/clinvar-database/scripts/clinvar_api.py +711 -0
  95. package/skills/18_Genetics_Genomics/dbsnp-database/SKILL.md +350 -0
  96. package/skills/18_Genetics_Genomics/dbsnp-database/references/api-notes.md +88 -0
  97. package/skills/18_Genetics_Genomics/dbsnp-database/references/citation.bib +12 -0
  98. package/skills/18_Genetics_Genomics/dbsnp-database/scripts/dbsnp_cli.py +625 -0
  99. package/skills/18_Genetics_Genomics/gnomad-database/SKILL.md +73 -0
  100. package/skills/18_Genetics_Genomics/gnomad-database/references/citation.bib +14 -0
  101. package/skills/18_Genetics_Genomics/gnomad-database/scripts/get_gene_constraint.py +90 -0
  102. package/skills/18_Genetics_Genomics/gnomad-database/scripts/get_variant_frequency.py +181 -0
  103. package/skills/18_Genetics_Genomics/gnomad-database/scripts/search_variants.py +207 -0
  104. package/skills/19_Pharmacology/chembl-database/SKILL.md +283 -0
  105. package/skills/19_Pharmacology/chembl-database/references/api_endpoints.md +97 -0
  106. package/skills/19_Pharmacology/chembl-database/references/citation.bib +30 -0
  107. package/skills/19_Pharmacology/chembl-database/scripts/chembl_api.py +657 -0
  108. package/skills/19_Pharmacology/clinical-trials-database/SKILL.md +378 -0
  109. package/skills/19_Pharmacology/clinical-trials-database/references/citation.bib +11 -0
  110. package/skills/19_Pharmacology/clinical-trials-database/references/clinical_trials_api.md +187 -0
  111. package/skills/19_Pharmacology/clinical-trials-database/references/studies_schema.md +143 -0
  112. package/skills/19_Pharmacology/clinical-trials-database/scripts/clinical_trials_api.py +373 -0
  113. package/skills/19_Pharmacology/openfda-database/SKILL.md +225 -0
  114. package/skills/19_Pharmacology/openfda-database/references/api_endpoints.md +207 -0
  115. package/skills/19_Pharmacology/openfda-database/references/citation.bib +15 -0
  116. package/skills/19_Pharmacology/openfda-database/references/recipes.md +150 -0
  117. package/skills/19_Pharmacology/openfda-database/scripts/openfda_query.py +505 -0
  118. package/skills/19_Pharmacology/opentargets-database/SKILL.md +198 -0
  119. package/skills/19_Pharmacology/opentargets-database/references/OpenTargets_GraphQL_Guide.md +216 -0
  120. package/skills/19_Pharmacology/opentargets-database/references/citation.bib +15 -0
  121. package/skills/19_Pharmacology/opentargets-database/scripts/query_opentargets.py +533 -0
  122. package/skills/19_Pharmacology/pubchem-database/SKILL.md +164 -0
  123. package/skills/19_Pharmacology/pubchem-database/references/citation.bib +15 -0
  124. package/skills/19_Pharmacology/pubchem-database/references/endpoints.md +71 -0
  125. package/skills/19_Pharmacology/pubchem-database/references/workflows.md +32 -0
  126. package/skills/19_Pharmacology/pubchem-database/scripts/pubchem_api.py +327 -0
  127. package/skills/20_Infrastructure/uv/SKILL.md +30 -0
  128. package/skills/01_Meta-Skills/academic-research-hub/SKILL.md +0 -108
  129. package/skills/01_Meta-Skills/academic-research-hub/scripts/requirements.txt +0 -17
  130. package/skills/01_Meta-Skills/academic-research-hub/scripts/research.py +0 -781
  131. package/skills/01_Meta-Skills/beautiful-log/SKILL.md +0 -64
  132. package/skills/01_Meta-Skills/beautiful-log/scripts/beautiful_log.py +0 -274
  133. package/skills/01_Meta-Skills/ethoclaw-daily-paper/SKILL.md +0 -130
  134. package/skills/01_Meta-Skills/ethoclaw-daily-paper/assets/config.template.yaml +0 -54
  135. package/skills/01_Meta-Skills/ethoclaw-daily-paper/assets/top5_digest_template.md +0 -5
  136. package/skills/01_Meta-Skills/ethoclaw-daily-paper/scripts/build_top5_digest.py +0 -300
  137. package/skills/01_Meta-Skills/ethoclaw-daily-paper/scripts/common.py +0 -137
  138. package/skills/01_Meta-Skills/ethoclaw-daily-paper/scripts/merge_results.py +0 -106
  139. package/skills/01_Meta-Skills/ethoclaw-daily-paper/scripts/run_pipeline.py +0 -177
  140. package/skills/01_Meta-Skills/ethoclaw-daily-paper/scripts/search_arxiv.py +0 -162
  141. package/skills/01_Meta-Skills/ethoclaw-daily-paper/scripts/search_pubmed.py +0 -202
  142. package/skills/01_Meta-Skills/ethoclaw-normalize-tabular/SKILL.md +0 -173
  143. package/skills/01_Meta-Skills/ethoclaw-normalize-tabular/scripts/normalize_data.py +0 -874
  144. package/skills/01_Meta-Skills/ethoclaw-pdf-research/SKILL.md +0 -134
  145. package/skills/01_Meta-Skills/ethoclaw-pdf-research/references/confirmation-prompts.md +0 -31
  146. package/skills/01_Meta-Skills/ethoclaw-pdf-research/references/output-patterns.md +0 -45
  147. package/skills/01_Meta-Skills/ethoclaw-pdf-research/scripts/build_markdown_deliverables.py +0 -41
  148. package/skills/01_Meta-Skills/ethoclaw-pdf-research/scripts/build_research_log.py +0 -84
  149. package/skills/01_Meta-Skills/ethoclaw-pdf-research/scripts/build_summary_md.py +0 -63
  150. package/skills/01_Meta-Skills/ethoclaw-pdf-research/scripts/extract_pdf_bundle.py +0 -140
  151. package/skills/01_Meta-Skills/experiment-controller/SKILL.md +0 -140
  152. package/skills/01_Meta-Skills/knowledge-graph-builder/SKILL.md +0 -366
  153. package/skills/01_Meta-Skills/knowledge-graph-builder/scripts/entity_resolution.py +0 -120
  154. package/skills/01_Meta-Skills/knowledge-graph-builder/scripts/extraction_prompt_template.txt +0 -19
  155. package/skills/01_Meta-Skills/knowledge-graph-builder/scripts/graph_query.py +0 -106
  156. package/skills/01_Meta-Skills/knowledge-graph-builder/scripts/hypothesis_cli_reference.py +0 -42
  157. package/skills/01_Meta-Skills/knowledge-graph-builder/scripts/new_data_source_template.py +0 -116
  158. package/skills/01_Meta-Skills/knowledge-graph-builder/scripts/requirements.txt +0 -15
  159. package/skills/01_Meta-Skills/method-design/SKILL.md +0 -61
  160. package/skills/01_Meta-Skills/multi-search-engine/SKILL.md +0 -119
  161. package/skills/01_Meta-Skills/research-idea/SKILL.md +0 -65
  162. package/skills/05_EEG_ERP/eeg-skill/SKILL.md +0 -197
  163. package/skills/05_EEG_ERP/meg-skill/SKILL.md +0 -188
  164. package/skills/05_EEG_ERP/meg-skill/scripts/time_frequency.py +0 -223
  165. package/skills/05_EEG_ERP/mne-eeg-tool/SKILL.md +0 -165
  166. package/skills/05_EEG_ERP/mne-eeg-tool/scripts/eeg_pipeline_reference.py +0 -231
  167. package/skills/05_EEG_ERP/seed-iv-skill/SKILL.md +0 -184
  168. package/skills/05_EEG_ERP/seed-iv-skill/scripts/classify_seed_iv.py +0 -154
  169. package/skills/05_EEG_ERP/seed-iv-skill/scripts/extract_seed_iv_features.py +0 -190
  170. package/skills/05_EEG_ERP/seed-iv-skill/scripts/validate_seed_iv.py +0 -102
  171. package/skills/05_EEG_ERP/seed-vig-skill/SKILL.md +0 -182
  172. package/skills/05_EEG_ERP/seed-vig-skill/scripts/classify_seed_vig.py +0 -165
  173. package/skills/05_EEG_ERP/seed-vig-skill/scripts/extract_seed_vig_features.py +0 -185
  174. package/skills/05_EEG_ERP/seed-vig-skill/scripts/validate_seed_vig.py +0 -88
  175. package/skills/06_fMRI_Neuroimaging/abcd-skill/SKILL.md +0 -308
  176. package/skills/06_fMRI_Neuroimaging/abcd-skill/scripts/abcd_qc_summary.py +0 -449
  177. package/skills/06_fMRI_Neuroimaging/abcd-skill/scripts/extract_abcd_phenotype.py +0 -292
  178. package/skills/06_fMRI_Neuroimaging/abcd-skill/scripts/reorganize_abcd.py +0 -387
  179. package/skills/06_fMRI_Neuroimaging/abide-skill/SKILL.md +0 -302
  180. package/skills/06_fMRI_Neuroimaging/abide-skill/scripts/abide_qc_summary.py +0 -317
  181. package/skills/06_fMRI_Neuroimaging/abide-skill/scripts/extract_abide_phenotype.py +0 -267
  182. package/skills/06_fMRI_Neuroimaging/abide-skill/scripts/reorganize_abide.py +0 -387
  183. package/skills/06_fMRI_Neuroimaging/adhd200-skill/SKILL.md +0 -244
  184. package/skills/06_fMRI_Neuroimaging/adhd200-skill/scripts/adhd200_qc_summary.py +0 -98
  185. package/skills/06_fMRI_Neuroimaging/adhd200-skill/scripts/extract_adhd200_phenotype.py +0 -134
  186. package/skills/06_fMRI_Neuroimaging/adhd200-skill/scripts/reorganize_adhd200.py +0 -206
  187. package/skills/06_fMRI_Neuroimaging/adni-skill/SKILL.md +0 -358
  188. package/skills/06_fMRI_Neuroimaging/adni-skill/scripts/generate_adni_task_files.py +0 -1305
  189. package/skills/06_fMRI_Neuroimaging/adni-skill/scripts/generate_vqa_from_tasks.py +0 -766
  190. package/skills/06_fMRI_Neuroimaging/adni-skill/scripts/reorganize_adni.py +0 -491
  191. package/skills/06_fMRI_Neuroimaging/aibl-skill/SKILL.md +0 -295
  192. package/skills/06_fMRI_Neuroimaging/aibl-skill/scripts/aibl_qc_summary.py +0 -260
  193. package/skills/06_fMRI_Neuroimaging/aibl-skill/scripts/extract_aibl_phenotype.py +0 -365
  194. package/skills/06_fMRI_Neuroimaging/aibl-skill/scripts/reorganize_aibl.py +0 -394
  195. package/skills/06_fMRI_Neuroimaging/aomic-skill/SKILL.md +0 -292
  196. package/skills/06_fMRI_Neuroimaging/aomic-skill/scripts/aomic_qc_summary.py +0 -258
  197. package/skills/06_fMRI_Neuroimaging/aomic-skill/scripts/extract_aomic_phenotype.py +0 -284
  198. package/skills/06_fMRI_Neuroimaging/aomic-skill/scripts/reorganize_aomic.py +0 -322
  199. package/skills/06_fMRI_Neuroimaging/asl-skill/SKILL.md +0 -168
  200. package/skills/06_fMRI_Neuroimaging/asl-skill/scripts/compute_cbf.py +0 -224
  201. package/skills/06_fMRI_Neuroimaging/bids-organizer/SKILL.md +0 -241
  202. package/skills/06_fMRI_Neuroimaging/bold5000-skill/SKILL.md +0 -186
  203. package/skills/06_fMRI_Neuroimaging/bold5000-skill/scripts/bold5000_qc_summary.py +0 -96
  204. package/skills/06_fMRI_Neuroimaging/bold5000-skill/scripts/extract_bold5000_stimulus.py +0 -125
  205. package/skills/06_fMRI_Neuroimaging/bold5000-skill/scripts/reorganize_bold5000.py +0 -102
  206. package/skills/06_fMRI_Neuroimaging/camcan-skill/SKILL.md +0 -213
  207. package/skills/06_fMRI_Neuroimaging/camcan-skill/scripts/camcan_qc_summary.py +0 -131
  208. package/skills/06_fMRI_Neuroimaging/camcan-skill/scripts/extract_camcan_phenotype.py +0 -145
  209. package/skills/06_fMRI_Neuroimaging/camcan-skill/scripts/validate_camcan.py +0 -141
  210. package/skills/06_fMRI_Neuroimaging/cobre-skill/SKILL.md +0 -201
  211. package/skills/06_fMRI_Neuroimaging/cobre-skill/scripts/cobre_qc_summary.py +0 -95
  212. package/skills/06_fMRI_Neuroimaging/cobre-skill/scripts/extract_cobre_phenotype.py +0 -104
  213. package/skills/06_fMRI_Neuroimaging/cobre-skill/scripts/reorganize_cobre.py +0 -140
  214. package/skills/06_fMRI_Neuroimaging/conn-tool/SKILL.md +0 -180
  215. package/skills/06_fMRI_Neuroimaging/dcm2nii/SKILL.md +0 -189
  216. package/skills/06_fMRI_Neuroimaging/dmt-har-med-skill/SKILL.md +0 -183
  217. package/skills/06_fMRI_Neuroimaging/dmt-har-med-skill/scripts/dmt_har_med_qc_summary.py +0 -96
  218. package/skills/06_fMRI_Neuroimaging/dmt-har-med-skill/scripts/extract_dmt_har_med_phenotype.py +0 -121
  219. package/skills/06_fMRI_Neuroimaging/dmt-har-med-skill/scripts/reorganize_dmt_har_med.py +0 -125
  220. package/skills/06_fMRI_Neuroimaging/dwi-skill/SKILL.md +0 -359
  221. package/skills/06_fMRI_Neuroimaging/fmri-skill/SKILL.md +0 -371
  222. package/skills/06_fMRI_Neuroimaging/fmriprep-tool/SKILL.md +0 -228
  223. package/skills/06_fMRI_Neuroimaging/freesurfer-tool/SKILL.md +0 -286
  224. package/skills/06_fMRI_Neuroimaging/freesurfer-tool/scripts/freesurfer_processor.py +0 -145
  225. package/skills/06_fMRI_Neuroimaging/fsl-tool/SKILL.md +0 -208
  226. package/skills/06_fMRI_Neuroimaging/hbn-skill/SKILL.md +0 -271
  227. package/skills/06_fMRI_Neuroimaging/hbn-skill/scripts/extract_hbn_phenotype.py +0 -107
  228. package/skills/06_fMRI_Neuroimaging/hbn-skill/scripts/hbn_qc_summary.py +0 -96
  229. package/skills/06_fMRI_Neuroimaging/hbn-skill/scripts/reorganize_hbn.py +0 -150
  230. package/skills/06_fMRI_Neuroimaging/hcpa-skill/SKILL.md +0 -210
  231. package/skills/06_fMRI_Neuroimaging/hcpa-skill/scripts/extract_hcpa_phenotype.py +0 -146
  232. package/skills/06_fMRI_Neuroimaging/hcpa-skill/scripts/hcpa_qc_summary.py +0 -120
  233. package/skills/06_fMRI_Neuroimaging/hcpa-skill/scripts/reorganize_hcpa.py +0 -155
  234. package/skills/06_fMRI_Neuroimaging/hcpd-skill/SKILL.md +0 -210
  235. package/skills/06_fMRI_Neuroimaging/hcpd-skill/scripts/extract_hcpd_phenotype.py +0 -148
  236. package/skills/06_fMRI_Neuroimaging/hcpd-skill/scripts/hcpd_qc_summary.py +0 -125
  237. package/skills/06_fMRI_Neuroimaging/hcpd-skill/scripts/reorganize_hcpd.py +0 -146
  238. package/skills/06_fMRI_Neuroimaging/hcpep-skill/SKILL.md +0 -215
  239. package/skills/06_fMRI_Neuroimaging/hcpep-skill/scripts/extract_hcpep_phenotype.py +0 -157
  240. package/skills/06_fMRI_Neuroimaging/hcpep-skill/scripts/hcpep_qc_summary.py +0 -143
  241. package/skills/06_fMRI_Neuroimaging/hcpep-skill/scripts/reorganize_hcpep.py +0 -146
  242. package/skills/06_fMRI_Neuroimaging/hcppipeline-tool/SKILL.md +0 -217
  243. package/skills/06_fMRI_Neuroimaging/hcpya-skill/SKILL.md +0 -214
  244. package/skills/06_fMRI_Neuroimaging/hcpya-skill/scripts/extract_hcpya_phenotype.py +0 -190
  245. package/skills/06_fMRI_Neuroimaging/hcpya-skill/scripts/hcpya_qc_summary.py +0 -152
  246. package/skills/06_fMRI_Neuroimaging/hcpya-skill/scripts/reorganize_hcpya.py +0 -203
  247. package/skills/06_fMRI_Neuroimaging/ixi-skill/SKILL.md +0 -198
  248. package/skills/06_fMRI_Neuroimaging/ixi-skill/scripts/ixi_qc_summary.py +0 -137
  249. package/skills/06_fMRI_Neuroimaging/ixi-skill/scripts/reorganize_ixi.py +0 -190
  250. package/skills/06_fMRI_Neuroimaging/mnd-skill/SKILL.md +0 -191
  251. package/skills/06_fMRI_Neuroimaging/mnd-skill/scripts/extract_mnd_phenotype.py +0 -143
  252. package/skills/06_fMRI_Neuroimaging/mnd-skill/scripts/mnd_qc_summary.py +0 -120
  253. package/skills/06_fMRI_Neuroimaging/mnd-skill/scripts/validate_mnd.py +0 -107
  254. package/skills/06_fMRI_Neuroimaging/mschallenge-skill/SKILL.md +0 -203
  255. package/skills/06_fMRI_Neuroimaging/mschallenge-skill/scripts/analyze_lesions.py +0 -119
  256. package/skills/06_fMRI_Neuroimaging/mschallenge-skill/scripts/longitudinal_lesion.py +0 -148
  257. package/skills/06_fMRI_Neuroimaging/mschallenge-skill/scripts/mschallenge_qc_summary.py +0 -132
  258. package/skills/06_fMRI_Neuroimaging/mschallenge-skill/scripts/validate_mschallenge.py +0 -116
  259. package/skills/06_fMRI_Neuroimaging/nibabel-skill/SKILL.md +0 -184
  260. package/skills/06_fMRI_Neuroimaging/nibabel-skill/scripts/atlas_coordinate_reference.py +0 -61
  261. package/skills/06_fMRI_Neuroimaging/nibabel-skill/scripts/freesurfer_io_reference.py +0 -34
  262. package/skills/06_fMRI_Neuroimaging/nibabel-skill/scripts/nifti_inspection_reference.py +0 -35
  263. package/skills/06_fMRI_Neuroimaging/nifd-skill/SKILL.md +0 -205
  264. package/skills/06_fMRI_Neuroimaging/nifd-skill/scripts/extract_nifd_phenotype.py +0 -132
  265. package/skills/06_fMRI_Neuroimaging/nifd-skill/scripts/nifd_qc_summary.py +0 -111
  266. package/skills/06_fMRI_Neuroimaging/nifd-skill/scripts/validate_nifd.py +0 -111
  267. package/skills/06_fMRI_Neuroimaging/nii2dcm/SKILL.md +0 -143
  268. package/skills/06_fMRI_Neuroimaging/nilearn-tool/SKILL.md +0 -266
  269. package/skills/06_fMRI_Neuroimaging/nilearn-tool/scripts/connectome_reference.py +0 -65
  270. package/skills/06_fMRI_Neuroimaging/nilearn-tool/scripts/denoise_timeseries_reference.py +0 -58
  271. package/skills/06_fMRI_Neuroimaging/nilearn-tool/scripts/hierarchical_parcellation_reference.py +0 -53
  272. package/skills/06_fMRI_Neuroimaging/nilearn-tool/scripts/kmeans_parcellation_reference.py +0 -53
  273. package/skills/06_fMRI_Neuroimaging/nilearn-tool/scripts/preprocess_bold_reference.py +0 -76
  274. package/skills/06_fMRI_Neuroimaging/nilearn-tool/scripts/rest_dictlearning_reference.py +0 -56
  275. package/skills/06_fMRI_Neuroimaging/nilearn-tool/scripts/rest_ica_reference.py +0 -59
  276. package/skills/06_fMRI_Neuroimaging/nilearn-tool/scripts/second_level_glm_reference.py +0 -58
  277. package/skills/06_fMRI_Neuroimaging/nilearn-tool/scripts/spacenet_classifier_reference.py +0 -59
  278. package/skills/06_fMRI_Neuroimaging/nilearn-tool/scripts/svm_classifier_reference.py +0 -60
  279. package/skills/06_fMRI_Neuroimaging/nilearn-tool/scripts/task_glm_reference.py +0 -63
  280. package/skills/06_fMRI_Neuroimaging/nilearn-tool/scripts/zalff_summary_reference.py +0 -109
  281. package/skills/06_fMRI_Neuroimaging/nsd-skill/SKILL.md +0 -210
  282. package/skills/06_fMRI_Neuroimaging/nsd-skill/scripts/extract_nsd_stimulus.py +0 -171
  283. package/skills/06_fMRI_Neuroimaging/nsd-skill/scripts/nsd_qc_summary.py +0 -142
  284. package/skills/06_fMRI_Neuroimaging/nsd-skill/scripts/validate_nsd.py +0 -142
  285. package/skills/06_fMRI_Neuroimaging/oasis-skill/SKILL.md +0 -205
  286. package/skills/06_fMRI_Neuroimaging/oasis-skill/scripts/extract_oasis_phenotype.py +0 -126
  287. package/skills/06_fMRI_Neuroimaging/oasis-skill/scripts/oasis_qc_summary.py +0 -115
  288. package/skills/06_fMRI_Neuroimaging/oasis-skill/scripts/validate_oasis.py +0 -119
  289. package/skills/06_fMRI_Neuroimaging/pet-skill/SKILL.md +0 -173
  290. package/skills/06_fMRI_Neuroimaging/pet-skill/scripts/compute_suvr.py +0 -202
  291. package/skills/06_fMRI_Neuroimaging/pnc-skill/SKILL.md +0 -206
  292. package/skills/06_fMRI_Neuroimaging/pnc-skill/scripts/extract_pnc_phenotype.py +0 -136
  293. package/skills/06_fMRI_Neuroimaging/pnc-skill/scripts/pnc_qc_summary.py +0 -116
  294. package/skills/06_fMRI_Neuroimaging/pnc-skill/scripts/validate_pnc.py +0 -120
  295. package/skills/06_fMRI_Neuroimaging/ppmi-skill/SKILL.md +0 -209
  296. package/skills/06_fMRI_Neuroimaging/ppmi-skill/scripts/extract_ppmi_phenotype.py +0 -138
  297. package/skills/06_fMRI_Neuroimaging/ppmi-skill/scripts/ppmi_qc_summary.py +0 -111
  298. package/skills/06_fMRI_Neuroimaging/ppmi-skill/scripts/validate_ppmi.py +0 -117
  299. package/skills/06_fMRI_Neuroimaging/qsiprep-tool/SKILL.md +0 -320
  300. package/skills/06_fMRI_Neuroimaging/rest-mneta-mdd-skill/SKILL.md +0 -215
  301. package/skills/06_fMRI_Neuroimaging/rest-mneta-mdd-skill/scripts/extract_rest_mdd_phenotype.py +0 -132
  302. package/skills/06_fMRI_Neuroimaging/rest-mneta-mdd-skill/scripts/harmonize_sites.py +0 -152
  303. package/skills/06_fMRI_Neuroimaging/rest-mneta-mdd-skill/scripts/rest_mdd_qc_summary.py +0 -124
  304. package/skills/06_fMRI_Neuroimaging/rest-mneta-mdd-skill/scripts/validate_rest_mdd.py +0 -103
  305. package/skills/06_fMRI_Neuroimaging/smri-skill/SKILL.md +0 -302
  306. package/skills/06_fMRI_Neuroimaging/tcp-skill/SKILL.md +0 -204
  307. package/skills/06_fMRI_Neuroimaging/tcp-skill/scripts/extract_tcp_phenotype.py +0 -139
  308. package/skills/06_fMRI_Neuroimaging/tcp-skill/scripts/tcp_qc_summary.py +0 -111
  309. package/skills/06_fMRI_Neuroimaging/tcp-skill/scripts/validate_tcp.py +0 -99
  310. package/skills/06_fMRI_Neuroimaging/ucla-cnp-skill/SKILL.md +0 -217
  311. package/skills/06_fMRI_Neuroimaging/ucla-cnp-skill/scripts/extract_ucla_cnp_phenotype.py +0 -145
  312. package/skills/06_fMRI_Neuroimaging/ucla-cnp-skill/scripts/ucla_cnp_qc_summary.py +0 -111
  313. package/skills/06_fMRI_Neuroimaging/ucla-cnp-skill/scripts/validate_ucla_cnp.py +0 -113
  314. package/skills/06_fMRI_Neuroimaging/ukb-skill/SKILL.md +0 -310
  315. package/skills/06_fMRI_Neuroimaging/ukb-skill/scripts/build_ukb_survival.py +0 -210
  316. package/skills/06_fMRI_Neuroimaging/ukb-skill/scripts/extract_ukb_cases.py +0 -308
  317. package/skills/06_fMRI_Neuroimaging/ukb-skill/scripts/extract_ukb_phenotype.py +0 -232
  318. package/skills/06_fMRI_Neuroimaging/ukb-skill/scripts/ukb_qc_summary.py +0 -158
  319. package/skills/06_fMRI_Neuroimaging/wmh-segmentation/SKILL.md +0 -133
  320. package/skills/07_Computational_Modeling/detrending/SKILL.md +0 -118
  321. package/skills/07_Computational_Modeling/dictlearning/SKILL.md +0 -122
  322. package/skills/07_Computational_Modeling/filtering/SKILL.md +0 -121
  323. package/skills/07_Computational_Modeling/glm/SKILL.md +0 -153
  324. package/skills/07_Computational_Modeling/hierarchical/SKILL.md +0 -121
  325. package/skills/07_Computational_Modeling/ica/SKILL.md +0 -122
  326. package/skills/07_Computational_Modeling/kmeans/SKILL.md +0 -119
  327. package/skills/07_Computational_Modeling/run_models/SKILL.md +0 -427
  328. package/skills/07_Computational_Modeling/spacenet/SKILL.md +0 -122
  329. package/skills/07_Computational_Modeling/svm/SKILL.md +0 -120
  330. package/skills/08_Computational_Neuroscience/brain_gnn/SKILL.md +0 -183
  331. package/skills/08_Computational_Neuroscience/dipy-tool/SKILL.md +0 -239
  332. package/skills/08_Computational_Neuroscience/dipy-tool/scripts/dti_metrics_reference.py +0 -70
  333. package/skills/08_Computational_Neuroscience/dipy-tool/scripts/load_and_mask_reference.py +0 -76
  334. package/skills/08_Computational_Neuroscience/dipy-tool/scripts/roi_stats_reference.py +0 -59
  335. package/skills/08_Computational_Neuroscience/fm_app/SKILL.md +0 -195
  336. package/skills/08_Computational_Neuroscience/neurostorm/SKILL.md +0 -151
  337. package/skills/13_Visualization/brain-visualization/SKILL.md +0 -191
  338. package/skills/13_Visualization/brain-visualization/scripts/connectome_reference.py +0 -108
  339. package/skills/13_Visualization/brain-visualization/scripts/freesurfer_ply_reference.py +0 -54
  340. package/skills/13_Visualization/brain-visualization/scripts/zalff_summary_reference.py +0 -116
  341. package/skills/13_Visualization/ethoclaw-paper-figure-layout/SKILL.md +0 -78
  342. package/skills/13_Visualization/ethoclaw-paper-figure-layout/assets/naturecomm_figures.tex +0 -74
  343. package/skills/13_Visualization/ethoclaw-paper-figure-layout/scripts/layout_results_foldered.py +0 -579
  344. package/skills/14_Writing/overleaf-skill/SKILL.md +0 -184
  345. package/skills/14_Writing/overleaf-skill/scripts/install.sh +0 -30
  346. package/skills/14_Writing/paper-writing/SKILL.md +0 -146
  347. package/skills/14_Writing/paper-writing/scripts/data_statement_templates.py +0 -164
  348. package/skills/14_Writing/paper-writing/scripts/figure_templates.py +0 -315
  349. package/skills/14_Writing/paper-writing/scripts/nature_figure_style.py +0 -214
  350. package/skills/14_Writing/paper-writing/scripts/section_phrasebank.py +0 -246
  351. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/SKILL.md +0 -274
  352. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/assets/report_template_en.html +0 -112
  353. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/assets/report_template_en.md +0 -21
  354. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/assets/section_templates/cluster-section.md +0 -5
  355. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/assets/section_templates/heatmap-section.md +0 -5
  356. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/assets/section_templates/integrated-interpretation.md +0 -3
  357. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/assets/section_templates/overview.md +0 -3
  358. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/assets/section_templates/project-summary.md +0 -3
  359. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/assets/section_templates/radar-section.md +0 -5
  360. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/assets/section_templates/raw-trajectory.md +0 -3
  361. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/assets/section_templates/sample-check.md +0 -3
  362. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/assets/section_templates/single-subject-section.md +0 -3
  363. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/assets/section_templates/stats-section.md +0 -5
  364. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/references/experiment-types/epm.md +0 -52
  365. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/references/experiment-types/fst.md +0 -37
  366. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/references/experiment-types/nor.md +0 -39
  367. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/references/experiment-types/oft.md +0 -43
  368. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/references/experiment-types/tcst.md +0 -45
  369. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/references/experiment-types/tst.md +0 -36
  370. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/references/input-types.md +0 -59
  371. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/references/interpretation-guardrails.md +0 -45
  372. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/references/metadata-schema.md +0 -57
  373. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/references/report-sections.md +0 -86
  374. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/references/section-selection-rules.md +0 -169
  375. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/scripts/build_report_manifest.py +0 -27
  376. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/scripts/render_report.py +0 -34
  377. package/skills/16_Animal_Behavior/ethoclaw-analysis-report/scripts/report_utils.py +0 -1121
  378. package/skills/16_Animal_Behavior/ethoclaw-animal-grounding/SKILL.md +0 -390
  379. package/skills/16_Animal_Behavior/ethoclaw-animal-grounding/reference_code.py +0 -98
  380. package/skills/16_Animal_Behavior/ethoclaw-animal-pose-estimation/SKILL.md +0 -336
  381. package/skills/16_Animal_Behavior/ethoclaw-kinematic-parameter-generator/README.md +0 -21
  382. package/skills/16_Animal_Behavior/ethoclaw-kinematic-parameter-generator/SKILL.md +0 -41
  383. package/skills/16_Animal_Behavior/ethoclaw-kinematic-parameter-generator/batch_kinematic_generator.py +0 -663
  384. package/skills/16_Animal_Behavior/ethoclaw-kinematic-parameter-generator/config.json +0 -19
  385. package/skills/16_Animal_Behavior/ethoclaw-kinematic-parameter-generator/generate_kinematic_parameter.py +0 -401
  386. package/skills/16_Animal_Behavior/ethoclaw-kinematic-parameter-generator/kinematic_generator.py +0 -265
  387. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-clustermap-generate/SKILL.md +0 -72
  388. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-clustermap-generate/references/config.example.toml +0 -56
  389. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-clustermap-generate/scripts/cluster_all_params.py +0 -232
  390. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-clustermap-generate/scripts/cluster_all_params_from_config.py +0 -236
  391. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-radar-generate/SKILL.md +0 -68
  392. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-radar-generate/references/notes.md +0 -5
  393. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-radar-generate/scripts/plot_h5_radar.py +0 -513
  394. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-violin-stats-generate/SKILL.md +0 -52
  395. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-violin-stats-generate/config.toml +0 -81
  396. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-violin-stats-generate/references/stats-rule.md +0 -18
  397. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-violin-stats-generate/scripts/h5_inspect.py +0 -79
  398. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-violin-stats-generate/scripts/h5_violin_batch.py +0 -624
  399. package/skills/16_Animal_Behavior/ethoclaw-multiparameter-violin-stats-generate/scripts/h5_violin_stats.py +0 -438
  400. package/skills/16_Animal_Behavior/ethoclaw-trajectory-velocity-heatmap-generate/SKILL.md +0 -280
  401. package/skills/16_Animal_Behavior/ethoclaw-trajectory-velocity-heatmap-generate/core_scripts/heatmap_trajectory.py +0 -790
  402. package/skills/16_Animal_Behavior/ethoclaw-trajectory-velocity-heatmap-generate/core_scripts/heatmap_velocity.py +0 -855
  403. package/skills/16_Animal_Behavior/ethoclaw-trajectory-velocity-heatmap-generate/reference_data/reference_2d.csv +0 -101
  404. package/skills/16_Animal_Behavior/ethoclaw-trajectory-velocity-heatmap-generate/reference_data/reference_2d.h5 +0 -0
  405. package/skills/16_Animal_Behavior/ethoclaw-trajectory-velocity-heatmap-generate/reference_data/reference_data_readme.md +0 -126
@@ -0,0 +1,633 @@
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
+ """CLI tool for querying the OpenAlex API.
16
+
17
+ This script provides robust access to the OpenAlex REST API with automatic
18
+ pagination handling, rate limit backoffs, and error checking.
19
+ """
20
+
21
+ # /// script
22
+ # requires-python = ">=3.10"
23
+ # dependencies = [
24
+ # "polite-http",
25
+ # "python-dotenv",
26
+ # ]
27
+ # ///
28
+
29
+ from __future__ import annotations
30
+
31
+ import argparse
32
+ import json
33
+ import logging
34
+ import os
35
+ import re
36
+ import sys
37
+ from typing import Any, Sequence
38
+ import urllib.parse
39
+
40
+ import dotenv
41
+ from polite_http import http_client
42
+
43
+ logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
44
+
45
+ BASE_URL = "https://api.openalex.org"
46
+ PDF_BASE_URL = "https://content.openalex.org"
47
+
48
+ _API_CLIENT = http_client.HttpClient(
49
+ BASE_URL,
50
+ qps=10.0,
51
+ referer="https://github.com/google-deepmind/science-skills/tree/main/literature-search-openalex",
52
+ )
53
+ _PDF_CLIENT = http_client.HttpClient(
54
+ PDF_BASE_URL,
55
+ qps=1.0,
56
+ referer="https://github.com/google-deepmind/science-skills/tree/main/literature-search-openalex",
57
+ )
58
+
59
+
60
+ DEFAULT_PER_PAGE = 25
61
+ MAX_PER_PAGE = 100
62
+ RESOLVE_PER_PAGE = 5
63
+ DEFAULT_TIMEOUT_SECS = 30
64
+ PDF_TIMEOUT_SECS = 60
65
+ MAX_RETRIES = 5
66
+ TRUNCATE_LINE_LIMIT = 500
67
+
68
+ ENTITY_TYPES = [
69
+ "works",
70
+ "authors",
71
+ "sources",
72
+ "institutions",
73
+ "topics",
74
+ "domains",
75
+ "fields",
76
+ "subfields",
77
+ "sdgs",
78
+ "countries",
79
+ "continents",
80
+ "languages",
81
+ "keywords",
82
+ "publishers",
83
+ "funders",
84
+ "awards",
85
+ "work-types",
86
+ "source-types",
87
+ "institution-types",
88
+ "licenses",
89
+ ]
90
+
91
+
92
+ def _build_url_with_api_key(url: str, api_key: str | None) -> str:
93
+ """Appends the ``api_key`` query parameter to *url* if a key is provided.
94
+
95
+ Callers should keep the original *url* for logging so the key does not
96
+ leak into log messages.
97
+
98
+ Args:
99
+ url: The base URL, which may already contain query parameters.
100
+ api_key: Optional API key string.
101
+
102
+ Returns:
103
+ The URL with ``api_key`` appended, or the original URL unchanged
104
+ if *api_key* is ``None``.
105
+ """
106
+ if not api_key:
107
+ return url
108
+ separator = "&" if "?" in url else "?"
109
+ return f"{url}{separator}{urllib.parse.urlencode({'api_key': api_key})}"
110
+
111
+
112
+ def fetch_with_retry(
113
+ url: str,
114
+ params: dict[str, Any],
115
+ api_key: str | None = None,
116
+ max_retries: int = MAX_RETRIES,
117
+ exit_on_error: bool = True,
118
+ return_headers: bool = False,
119
+ ) -> dict[str, Any] | None:
120
+ """Fetches data from the OpenAlex API with exponential backoff.
121
+
122
+ Args:
123
+ url: The base URL to fetch.
124
+ params: URL query parameters.
125
+ api_key: Optional API key for authentication.
126
+ max_retries: Maximum number of retry attempts.
127
+ exit_on_error: If True, exit the process on non-retriable errors.
128
+ return_headers: If True, include response headers under a
129
+ "_response_headers" key in the returned dict.
130
+
131
+ Returns:
132
+ The JSON-parsed response as a dictionary.
133
+ """
134
+ # Build the URL from params, then append the API key separately via the
135
+ # shared helper. This keeps the key out of the params dict so it cannot
136
+ # be accidentally logged or returned to the caller.
137
+ query_string = urllib.parse.urlencode(params, doseq=True)
138
+ full_url = f"{url}?{query_string}" if query_string else url
139
+ full_url = _build_url_with_api_key(full_url, api_key)
140
+
141
+ try:
142
+ if url.startswith(PDF_BASE_URL):
143
+ resp = _PDF_CLIENT.fetch(full_url, max_retries=max_retries)
144
+ elif url.startswith(BASE_URL):
145
+ resp = _API_CLIENT.fetch(full_url, max_retries=max_retries)
146
+ else:
147
+ raise ValueError(f"Unsupported URL base: {url}")
148
+ data = resp.json()
149
+ if return_headers:
150
+ data["_response_headers"] = resp.headers
151
+ return data
152
+ except http_client.HttpError as e:
153
+ if e.status_code == 429 and not api_key:
154
+ logging.warning(
155
+ "Rate limit hit (429 Too Many Requests). You are currently running "
156
+ "without an API key, which limits API usage. Please provide an API "
157
+ "key via --api-key to increase your limit."
158
+ )
159
+ if e.status_code == 404:
160
+ logging.error(
161
+ "HTTP Error 404: Entity not found at %s. Hint: verify the ID is"
162
+ " correct, or use the 'resolve' command to look it up by name.",
163
+ url,
164
+ )
165
+ else:
166
+ logging.error(
167
+ "HTTP Error %s while fetching %s: %s", e.status_code, url, e
168
+ )
169
+ if exit_on_error:
170
+ sys.exit(1)
171
+ return None
172
+
173
+
174
+ def print_json(data: Any) -> None:
175
+ """Prints JSON data.
176
+
177
+ Truncates output if it exceeds TRUNCATE_LINE_LIMIT lines to protect context
178
+ when printing to a terminal. If output is redirected to a file, the full data
179
+ is printed.
180
+
181
+ Args:
182
+ data: The JSON-serializable Python object to print.
183
+ """
184
+ output = json.dumps(data, indent=2)
185
+
186
+ if not sys.stdout.isatty():
187
+ print(output)
188
+ return
189
+
190
+ lines = output.splitlines()
191
+ if len(lines) > TRUNCATE_LINE_LIMIT:
192
+ remaining = len(lines) - TRUNCATE_LINE_LIMIT
193
+ print("\n".join(lines[:TRUNCATE_LINE_LIMIT]))
194
+ logging.warning(
195
+ "Output truncated. %d additional lines not shown. Redirect"
196
+ " output to a file if you need the full data.",
197
+ remaining,
198
+ )
199
+ else:
200
+ print(output)
201
+
202
+
203
+ # --- Command Handlers ---
204
+
205
+
206
+ def handle_resolve(args: argparse.Namespace) -> None:
207
+ """Searches for an entity by name and returns candidate IDs.
208
+
209
+ Args:
210
+ args: Parsed command-line arguments containing `entity_type`, `query`,
211
+ `per_page`, and optional `api_key`.
212
+ """
213
+ # Construct search URL (e.g., https://api.openalex.org/works)
214
+ url = f"{BASE_URL}/{args.entity_type}"
215
+ params = {
216
+ "search": args.query,
217
+ "per_page": max(1, min(args.per_page, MAX_PER_PAGE)),
218
+ }
219
+ data = fetch_with_retry(url, params, api_key=args.api_key)
220
+ if data is None:
221
+ logging.error("No response received from the API.")
222
+ sys.exit(1)
223
+
224
+ # Extract minimal fields to make disambiguation easier for the user/agent.
225
+ results = []
226
+ for item in data.get("results", []):
227
+ entry = {
228
+ "id": item.get("id"),
229
+ "display_name": item.get("display_name"),
230
+ "hint": item.get("hint") or item.get("works_count"),
231
+ }
232
+ results.append(entry)
233
+ print_json(results)
234
+
235
+
236
+ # Matches standard OpenAlex short IDs like W2741809807, A5023888391, etc.
237
+ _OPENALEX_SHORT_ID_RE = re.compile(r"^[A-Za-z]\d+$")
238
+
239
+
240
+ def _is_valid_entity_id(entity_id: str) -> bool:
241
+ """Returns True if *entity_id* looks like a valid OpenAlex entity reference.
242
+
243
+ Accepted formats:
244
+ - Short IDs: W2741809807, A5023888391
245
+ - Full OpenAlex URLs: https://openalex.org/W2741809807
246
+ - DOIs: https://doi.org/10.xxx
247
+ """
248
+ return bool(
249
+ _OPENALEX_SHORT_ID_RE.match(entity_id)
250
+ or entity_id.startswith("https://openalex.org/")
251
+ or entity_id.startswith("https://doi.org/")
252
+ )
253
+
254
+
255
+ def handle_get(args: argparse.Namespace) -> None:
256
+ """Retrieves complete details for a single entity by its ID.
257
+
258
+ Args:
259
+ args: Parsed command-line arguments containing `entity_type`, `id`,
260
+ optional `select` (fields to return), and optional `api_key`.
261
+ """
262
+ if not _is_valid_entity_id(args.id):
263
+ logging.error(
264
+ "Invalid entity ID %r. Expected a short ID (e.g. W2741809807),"
265
+ " a full OpenAlex URL, or a DOI URL.",
266
+ args.id,
267
+ )
268
+ sys.exit(1)
269
+
270
+ # Construct entity-specific URL (e.g., https://api.openalex.org/works/W123)
271
+ url = f"{BASE_URL}/{args.entity_type}/{args.id}"
272
+ params = {}
273
+
274
+ # Add optional 'select' parameter to return only requested fields.
275
+ if args.select is not None:
276
+ params["select"] = args.select
277
+
278
+ data = fetch_with_retry(url, params, api_key=args.api_key)
279
+ print_json(data)
280
+
281
+
282
+ def _is_valid_pdf(data: bytes) -> bool:
283
+ """Checks whether raw bytes represent a valid PDF by inspecting the header.
284
+
285
+ PDF files must start with the magic bytes '%PDF-'. This catches common
286
+ failure modes where a server returns an HTML error page, paywall redirect,
287
+ or other non-PDF content with a 200 status code.
288
+
289
+ Args:
290
+ data: The raw bytes to validate.
291
+
292
+ Returns:
293
+ True if the data starts with the PDF magic bytes, False otherwise.
294
+ """
295
+ return data[:5] == b"%PDF-"
296
+
297
+
298
+ def _try_download_url(url: str, output_path: str) -> bool:
299
+ """Attempts to download a PDF from a URL.
300
+
301
+ Downloads the content and validates that it is actually a PDF by checking
302
+ for the %PDF- magic bytes before writing to disk.
303
+
304
+ Args:
305
+ url: The URL to download from.
306
+ output_path: The local file path to save to.
307
+
308
+ Returns:
309
+ True if a valid PDF was downloaded, False otherwise.
310
+ """
311
+ try:
312
+ # Extract the base URL (scheme + netloc) for the HttpClient.
313
+ parsed = urllib.parse.urlparse(url)
314
+ base = f"{parsed.scheme}://{parsed.netloc}"
315
+ client = http_client.HttpClient(base, qps=1.0)
316
+ data = client.fetch_bytes(url, timeout=PDF_TIMEOUT_SECS)
317
+ if not _is_valid_pdf(data):
318
+ logging.warning(
319
+ "Downloaded content from %s is not a valid PDF (missing %%PDF-"
320
+ " header). Skipping.",
321
+ url,
322
+ )
323
+ return False
324
+ with open(output_path, "wb") as f:
325
+ f.write(data)
326
+ return True
327
+ except http_client.HttpError as e:
328
+ logging.warning("Failed to download from %s: %s", url, e)
329
+ return False
330
+
331
+
332
+ def _try_fallback_locations(
333
+ work_id: str, output_path: str, api_key: str | None
334
+ ) -> bool:
335
+ """Tries to download a PDF from alternative locations in work metadata.
336
+
337
+ Queries the OpenAlex API for the work's metadata and attempts each location
338
+ that has a pdf_url. If no PDF can be downloaded, logs any available landing
339
+ pages as manual alternatives.
340
+
341
+ Args:
342
+ work_id: The OpenAlex work ID.
343
+ output_path: The local file path to save the PDF to.
344
+ api_key: Optional API key for authentication.
345
+
346
+ Returns:
347
+ True if a PDF was successfully downloaded, False otherwise.
348
+ """
349
+ logging.info("Checking alternative locations in work metadata...")
350
+ work_url = f"{BASE_URL}/works/{work_id}"
351
+ work_data = fetch_with_retry(
352
+ work_url, {}, api_key=api_key, exit_on_error=False
353
+ )
354
+ if work_data is None:
355
+ logging.error("Failed to fetch work metadata for %s.", work_id)
356
+ return False
357
+
358
+ locations = work_data.get("locations", [])
359
+ if not locations and "best_oa_location" in work_data:
360
+ locations = [work_data["best_oa_location"]]
361
+
362
+ for loc in locations:
363
+ if loc and loc.get("pdf_url"):
364
+ logging.info("Attempting fallback download from: %s", loc["pdf_url"])
365
+ if _try_download_url(loc["pdf_url"], output_path):
366
+ logging.info("Successfully downloaded PDF from fallback location.")
367
+ return True
368
+
369
+ logging.error("No direct PDF download link found in locations.")
370
+ landing_pages = [
371
+ loc.get("landing_page_url")
372
+ for loc in locations
373
+ if loc and loc.get("landing_page_url")
374
+ ]
375
+ if landing_pages:
376
+ logging.info("Alternative Landing Pages to check manually:")
377
+ for page_url in landing_pages:
378
+ logging.info(" - %s", page_url)
379
+ return False
380
+
381
+
382
+ def handle_download_pdf(args: argparse.Namespace) -> None:
383
+ """Fetches and saves the open-access PDF for a specific work.
384
+
385
+ Tries the OpenAlex premium content server first (requires API key), then
386
+ falls back to PDF URLs listed in the work's metadata.
387
+
388
+ Args:
389
+ args: Parsed command-line arguments containing `id` (the OpenAlex work
390
+ ID), `output` (destination file path), and optional `api_key`.
391
+ """
392
+ # OpenAlex serves PDFs via a separate base URL (content.openalex.org)
393
+ url = f"{PDF_BASE_URL}/works/{args.id}.pdf"
394
+
395
+ # Build the authenticated URL in a separate variable so the API key
396
+ # does not leak into log messages that reference ``url``.
397
+ fetch_url = _build_url_with_api_key(url, args.api_key)
398
+
399
+ logging.info("Downloading PDF for %s to %s", args.id, args.output)
400
+ try:
401
+ data = _PDF_CLIENT.fetch_bytes(fetch_url, timeout=PDF_TIMEOUT_SECS)
402
+ if not _is_valid_pdf(data):
403
+ logging.warning(
404
+ "Content server returned non-PDF content (missing %%PDF- header)."
405
+ )
406
+ else:
407
+ with open(args.output, "wb") as f:
408
+ f.write(data)
409
+ logging.info("Successfully downloaded PDF to %s", args.output)
410
+ return
411
+ except http_client.HttpError as e:
412
+ if e.status_code == 401:
413
+ logging.warning(
414
+ "Premium content server requires an API key (HTTP 401)."
415
+ " Trying fallback locations from work metadata..."
416
+ )
417
+ elif e.status_code == 404:
418
+ logging.warning("PDF not found on OpenAlex content server (404).")
419
+ else:
420
+ logging.warning("Failed to download PDF from primary server: %s", e)
421
+ except OSError as e:
422
+ logging.warning("Network error downloading PDF: %s", e)
423
+
424
+ # Try fallback: download from PDF URLs in the work's metadata.
425
+ if _try_fallback_locations(args.id, args.output, args.api_key):
426
+ return
427
+
428
+ logging.error(
429
+ "Could not download PDF for %s. If the work requires premium access,"
430
+ " provide an API key via --api-key or OPENALEX_API_KEY.",
431
+ args.id,
432
+ )
433
+ sys.exit(1)
434
+
435
+
436
+ def handle_filter(args: argparse.Namespace) -> None:
437
+ """Searches and filters entities based on various criteria.
438
+
439
+ Args:
440
+ args: Parsed arguments defining filters (`search`, `filter`, `sort`,
441
+ `group_by`, pagination vars, random `sample`, `seed`, `select`), and
442
+ `api_key`.
443
+ """
444
+ # Warn about incompatible flag combinations before making the request.
445
+ if args.sample is not None and args.sort is not None:
446
+ logging.warning(
447
+ "--sort is ignored when --sample is used. OpenAlex returns random"
448
+ " results regardless of sort order."
449
+ )
450
+
451
+ url = f"{BASE_URL}/{args.entity_type}"
452
+
453
+ # Populate provided query parameters. Exclude --sort when sampling since
454
+ # the API ignores it and including it would be misleading.
455
+ optional_params = [
456
+ "search",
457
+ "filter",
458
+ "group_by",
459
+ "sample",
460
+ "seed",
461
+ "select",
462
+ ]
463
+ params = {
464
+ k: getattr(args, k)
465
+ for k in optional_params
466
+ if getattr(args, k) is not None
467
+ }
468
+ # Only include sort when NOT sampling.
469
+ if args.sort is not None and args.sample is None:
470
+ params["sort"] = args.sort
471
+
472
+ # Pagination parameters are only valid if we are NOT grouping or sampling.
473
+ # OpenAlex does not allow paging when 'group_by' or 'sample' is requested.
474
+ if args.group_by is None and args.sample is None:
475
+ params["per_page"] = max(1, min(args.per_page, MAX_PER_PAGE))
476
+ params["page"] = args.page
477
+
478
+ data = fetch_with_retry(url, params, api_key=args.api_key)
479
+ print_json(data)
480
+
481
+
482
+ def handle_rate_limit(args: argparse.Namespace) -> None:
483
+ """Checks the current rate limit status.
484
+
485
+ Args:
486
+ args: Parsed command-line arguments containing optional `api_key`.
487
+ """
488
+ url = f"{BASE_URL}/works"
489
+
490
+ # Fetch a single result just to obtain the rate limit HTTP headers.
491
+ data = fetch_with_retry(
492
+ url, {"per_page": 1}, api_key=args.api_key, return_headers=True
493
+ )
494
+ if data is None:
495
+ logging.error("Could not fetch rate limit information from the API.")
496
+ sys.exit(1)
497
+
498
+ # Read rate limits from standard headers injected by OpenAlex.
499
+ headers = {k.lower(): v for k, v in data.pop("_response_headers", {}).items()}
500
+ limit_val = headers.get("x-ratelimit-limit")
501
+ remaining_val = headers.get("x-ratelimit-remaining")
502
+ reset_val = headers.get("x-ratelimit-reset")
503
+
504
+ limits = {
505
+ "x-ratelimit-limit": limit_val,
506
+ "x-ratelimit-remaining": remaining_val,
507
+ "x-ratelimit-reset": reset_val,
508
+ }
509
+
510
+ if limit_val is None and remaining_val is None:
511
+ logging.warning(
512
+ "Rate limit headers were not returned by the API. This can happen"
513
+ " when using an unauthenticated (polite pool) request. Provide an"
514
+ " API key via --api-key or OPENALEX_API_KEY for detailed limits."
515
+ )
516
+
517
+ # Output the captured limits to the user.
518
+ print_json({"rate_limits": limits})
519
+
520
+
521
+ def main(argv: Sequence[str]) -> None:
522
+ """Main entry point for the OpenAlex CLI.
523
+
524
+ Args:
525
+ argv: Command line arguments, including the executable name.
526
+ """
527
+ dotenv.load_dotenv(os.path.expanduser("~/.env"))
528
+ parser = argparse.ArgumentParser(description="OpenAlex API CLI Utility")
529
+
530
+ # Global arguments applying to all subcommands.
531
+ parser.add_argument(
532
+ "--api-key",
533
+ type=str,
534
+ default=os.environ.get("OPENALEX_API_KEY"),
535
+ help=(
536
+ "Optional API key for higher rate limits. Without it, usage is "
537
+ "strictly limited. If you hit rate limits frequently, please provide "
538
+ "an API key. Defaults to the OPENALEX_API_KEY environment variable "
539
+ "if set. An explicit --api-key flag overrides the environment "
540
+ "variable."
541
+ ),
542
+ )
543
+
544
+ # Organize commands using subparsers for clarity and isolated configurations.
545
+ subparsers = parser.add_subparsers(dest="command", required=True)
546
+
547
+ # Resolve Command
548
+ parser_resolve = subparsers.add_parser(
549
+ "resolve", help="Resolve an entity name to its OpenAlex ID"
550
+ )
551
+ parser_resolve.add_argument("entity_type", choices=ENTITY_TYPES)
552
+ parser_resolve.add_argument(
553
+ "query", help="Name or part of the name to search for"
554
+ )
555
+ parser_resolve.add_argument(
556
+ "--per-page",
557
+ type=int,
558
+ default=RESOLVE_PER_PAGE,
559
+ help=f"Number of candidates to return (default: {RESOLVE_PER_PAGE})",
560
+ )
561
+ parser_resolve.set_defaults(func=handle_resolve)
562
+
563
+ # Get Entity Command
564
+ parser_get = subparsers.add_parser(
565
+ "get", help="Get a single entity by its ID"
566
+ )
567
+ parser_get.add_argument("entity_type", choices=ENTITY_TYPES)
568
+ parser_get.add_argument("id", help="The OpenAlex ID (e.g., W2741809807)")
569
+ parser_get.add_argument(
570
+ "--select", type=str, help="Limit returned fields (e.g., id,title)"
571
+ )
572
+ parser_get.set_defaults(func=handle_get)
573
+
574
+ # Download PDF Command
575
+ parser_pdf = subparsers.add_parser(
576
+ "download-pdf", help="Download PDF for a work (costs $0.01 per request)"
577
+ )
578
+ parser_pdf.add_argument("id", help="The OpenAlex Work ID (e.g., W2741809807)")
579
+ parser_pdf.add_argument("output", help="Output file path (e.g., paper.pdf)")
580
+ parser_pdf.set_defaults(func=handle_download_pdf)
581
+
582
+ # Filter Command
583
+ parser_filter = subparsers.add_parser(
584
+ "filter", help="Filter and search entities"
585
+ )
586
+ parser_filter.add_argument("entity_type", choices=ENTITY_TYPES)
587
+ parser_filter.add_argument(
588
+ "--search", type=str, help="Full-text search query"
589
+ )
590
+ parser_filter.add_argument(
591
+ "--filter", type=str, help="Filter string (e.g. is_oa:true)"
592
+ )
593
+ parser_filter.add_argument(
594
+ "--sort", type=str, help="Sort string (e.g. cited_by_count:desc)"
595
+ )
596
+ parser_filter.add_argument(
597
+ "--group-by", type=str, help="Group results by a field"
598
+ )
599
+ parser_filter.add_argument(
600
+ "--per-page",
601
+ type=int,
602
+ default=DEFAULT_PER_PAGE,
603
+ help=(
604
+ f"Results per page (max {MAX_PER_PAGE}, default: {DEFAULT_PER_PAGE})"
605
+ ),
606
+ )
607
+ parser_filter.add_argument("--page", type=int, default=1, help="Page number")
608
+ parser_filter.add_argument(
609
+ "--sample", type=int, help="Number of random samples to return"
610
+ )
611
+ parser_filter.add_argument(
612
+ "--seed", type=int, help="Seed for random sampling"
613
+ )
614
+ parser_filter.add_argument(
615
+ "--select", type=str, help="Limit returned fields (e.g., id,title)"
616
+ )
617
+ parser_filter.set_defaults(func=handle_filter)
618
+
619
+ # Rate Limit Command
620
+ parser_rate_limit = subparsers.add_parser(
621
+ "rate-limit",
622
+ help="Check current rate limit status",
623
+ )
624
+ parser_rate_limit.set_defaults(func=handle_rate_limit)
625
+
626
+ # Parse the arguments and dispatch execution to the appropriate handle_*
627
+ # function set as the default via .set_defaults(func=...) above.
628
+ args = parser.parse_args(argv[1:])
629
+ args.func(args)
630
+
631
+
632
+ if __name__ == "__main__":
633
+ main(sys.argv)