|
| 1 | +name: Imputation Correlation Workflow |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + paths: |
| 7 | + - '06_imputation/correlation_workflow.qmd' |
| 8 | + pull_request: |
| 9 | + branches: [main] |
| 10 | + paths: |
| 11 | + - '06_imputation/correlation_workflow.qmd' |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +jobs: |
| 15 | + r-imputation: |
| 16 | + runs-on: ubuntu-22.04 |
| 17 | + |
| 18 | + env: |
| 19 | + RENV_PATHS_ROOT: ~/.local/share/renv # persistent cache location |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout code |
| 23 | + uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: Install pandoc |
| 26 | + run: sudo apt-get update && sudo apt-get install -y pandoc |
| 27 | + |
| 28 | + - name: Set up R |
| 29 | + uses: r-lib/actions/setup-r@v2 |
| 30 | + |
| 31 | + - name: Install system dependencies for R packages |
| 32 | + run: | |
| 33 | + sudo apt-get update |
| 34 | + sudo apt-get install -y build-essential libcurl4-openssl-dev libssl-dev libxml2-dev libgit2-dev libmagick++-dev libharfbuzz-dev libfribidi-dev libglpk-dev |
| 35 | + shell: bash |
| 36 | + |
| 37 | + - name: Set up Python with conda |
| 38 | + uses: conda-incubator/setup-miniconda@v3 |
| 39 | + with: |
| 40 | + python-version: 3.9 |
| 41 | + auto-update-conda: true |
| 42 | + |
| 43 | + - name: Create and activate conda environment |
| 44 | + run: | |
| 45 | + conda env remove -n magic_env -y 2>/dev/null || true |
| 46 | + conda create -n magic_env python=3.9 -y |
| 47 | + source "$(conda info --base)/etc/profile.d/conda.sh" |
| 48 | + conda activate magic_env |
| 49 | + |
| 50 | + # Install compatible packages from conda-forge |
| 51 | + conda install -y -c conda-forge numpy=1.24.3 pandas=2.0.3 scipy matplotlib libstdcxx-ng |
| 52 | + |
| 53 | + # Install MAGIC dependencies |
| 54 | + pip install scprep future tasklogger graphtools |
| 55 | + |
| 56 | + # Clone MAGIC repository |
| 57 | + cd 06_imputation |
| 58 | + git clone https://github.com/KrishnaswamyLab/MAGIC.git |
| 59 | + |
| 60 | + # Install MAGIC package |
| 61 | + cd MAGIC/python |
| 62 | + pip install . |
| 63 | + |
| 64 | + |
| 65 | + # Test MAGIC installation |
| 66 | + python -c "import magic; print('MAGIC version:', magic.__version__)" |
| 67 | +
|
| 68 | + cd ../.. |
| 69 | + shell: bash |
| 70 | + |
| 71 | + - name: Cache R packages (renv) |
| 72 | + uses: actions/cache@v4 |
| 73 | + with: |
| 74 | + path: ${{ env.RENV_PATHS_ROOT }} |
| 75 | + key: ${{ runner.os }}-renv-${{ hashFiles('06_imputation/renv.lock') }} |
| 76 | + restore-keys: | |
| 77 | + ${{ runner.os }}-renv- |
| 78 | +
|
| 79 | + - name: Set repositories |
| 80 | + run: Rscript ubuntu.R |
| 81 | + |
| 82 | + - name: Restore environment from renv.lock |
| 83 | + run: | |
| 84 | + install.packages("renv", repos = "https://cloud.r-project.org") |
| 85 | + renv::restore(prompt = FALSE, lockfile = "06_imputation/renv.lock") |
| 86 | + shell: Rscript {0} |
| 87 | + |
| 88 | + - name: Install R MAGIC package |
| 89 | + run: | |
| 90 | + source "$(conda info --base)/etc/profile.d/conda.sh" |
| 91 | + conda activate magic_env |
| 92 | + cd 06_imputation/MAGIC/Rmagic |
| 93 | + R CMD INSTALL . |
| 94 | + R --slave << 'EOF' |
| 95 | + library(Rmagic) |
| 96 | + cat("✓ R MAGIC installed and loaded\n") |
| 97 | + renv::snapshot() |
| 98 | + EOF |
| 99 | + shell: bash |
| 100 | + |
| 101 | + - name: Set up Quarto |
| 102 | + uses: quarto-dev/quarto-actions/setup@v2 |
| 103 | + |
| 104 | + - name: Run imputation correlation workflow |
| 105 | + id: render_qmd |
| 106 | + run: | |
| 107 | + source "$(conda info --base)/etc/profile.d/conda.sh" |
| 108 | + conda activate magic_env |
| 109 | + cd 06_imputation |
| 110 | + quarto render correlation_workflow.qmd |
| 111 | + shell: bash |
| 112 | + |
| 113 | + - name: Deploy HTML to gh-pages |
| 114 | + if: success() |
| 115 | + run: | |
| 116 | + git config --global user.name "github-actions[bot]" |
| 117 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 118 | + OUTPUT_FILE="06_imputation/correlation_workflow.html" |
| 119 | +
|
| 120 | + # Fetch gh-pages (if exists) and create worktree |
| 121 | + git fetch origin gh-pages || true |
| 122 | + git worktree add /tmp/gh-pages gh-pages 2>/dev/null || git worktree add /tmp/gh-pages -b gh-pages |
| 123 | +
|
| 124 | + # Copy the file into the worktree |
| 125 | + mkdir -p "/tmp/gh-pages/$(dirname "$OUTPUT_FILE")" |
| 126 | + cp "$OUTPUT_FILE" "/tmp/gh-pages/$(dirname "$OUTPUT_FILE")/" |
| 127 | +
|
| 128 | + cd /tmp/gh-pages |
| 129 | +
|
| 130 | + # Commit and push if there are changes |
| 131 | + git add "$(dirname "$OUTPUT_FILE")/$(basename "$OUTPUT_FILE")" |
| 132 | + git commit -m "Deploy $(basename "$OUTPUT_FILE") [skip ci]" |
| 133 | + git push --force origin gh-pages |
| 134 | + shell: bash |
0 commit comments