This project is aimed at validating RT-QuIC and Nano-QuIC for post- and ante-mortem testing of white-tail deer. This is a longitudinal study, with sampling efforts every 3 months.
- Oral swabs
- Nasal swabs
- Rectoanalmucosa-associated lymph tissue (RAMALT)
- Whole blood
- Plasma
- Serum
- Ear punches
- Feces
- Obex
- RAMALT
- RPLN
Before running anything, make sure the following are installed on your machine:
- R (4.6.1) — download here.
- An R IDE — either:
- Positron — Recommended download here, or -
- RStudio — download here
- Python (3.13.13) — download here.
- On Windows, check "Add Python to PATH" during install.
- Git — download here.
- An Airtable API key with read/write access to the project base (
app7KsgYl2jhOnYg7). Ask the MNPRO Airtable maintainer if you don't have one.
Open a terminal (PowerShell on Windows, Terminal on macOS/Linux) and run:
git clone https://github.com/gage1145/usda-validation.git
cd usda-validationThis project uses two virtual environments — one for R (renv) and one for Python (venv). Set both up once, up front, before running any pipeline steps.
Imporant: Never EVER commit .Renviron or .env to version control! These contain sensitive keys that would give unwanted users access to our data.
This project uses renv to lock R package versions. Always work inside the renv environment so everyone gets the same results. It depends on the development version 4.0.0 of quicR; renv should pull the right version automatically.
-
Open the project:
- RStudio: open
usda-validation.Rproj. - Positron: open the
usda-validationfolder.
In both cases
renvshould activate automatically when an R session starts in the project. - RStudio: open
-
In the R console, restore the locked packages:
# If renv didn't auto-activate, activate it manually. renv::activate() # Restore all locked packages. Run this the first time you set up the project. renv::restore() # quicR, airtabler, and vip sometimes fail to install through restore. # If you see errors about them, install manually: renv::install("gage1145/quicR")
Set up a Python virtual environment and install dependencies.
Windows (PowerShell):
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txtmacOS / Linux:
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtYou should see (.venv) at the start of your prompt once it's activated. You'll need to re-activate it every time you open a new terminal.
Never commit directly to main. All work should happen on your own branch and be merged into main through a pull request (PR) on GitHub. This keeps main stable and gives someone else a chance to review changes before they land.
Before starting new work, pull the latest main so your branch starts from the most up-to-date code:
git checkout main
git pull origin main
git config user.name "Your Name"
git config user.email "youremail@example.com"Use a short, descriptive name. A common convention is yourname/short-description or feature/short-description:
git checkout -b gage/update-readmeThis both creates the branch and switches you to it. Confirm with:
git branchThe branch with the * next to it is the one you're on.
Stage and commit changes in small, logical chunks. Write a clear message describing why the change was made, not just what:
git add path/to/file1 path/to/file2
git commit -m "Add troubleshooting table to README"Avoid
git add .orgit add -A— they can sweep in files you didn't mean to commit (like.env, large data files, or local notes).
The first time you push a new branch, use -u to link it to the remote:
git push -u origin gage/update-readmeAfter that, git push is enough.
- Go to the repository on GitHub.
- GitHub usually shows a yellow banner offering to "Compare & pull request" for your recently pushed branch — click it. Otherwise, go to the Pull requests tab and click New pull request.
- Set the base branch to
mainand the compare branch to your branch. - Give the PR a clear title and a short description: what changed, why, and anything a reviewer should look at carefully.
- Click Create pull request.
- Request a review from a teammate. Address any feedback by pushing more commits to the same branch — the PR updates automatically.
- Once the PR is approved, click Merge pull request on GitHub.
After your PR is merged, delete the branch and pull the updated main:
git checkout main
git pull origin main
git branch -d gage/update-readme # delete local branch
git push origin --delete gage/update-readme # delete remote branch (optional)Don't push. Move the commit to a new branch and reset main:
git branch gage/my-fix # save your work on a new branch
git reset --hard origin/main # reset local main to match GitHub
git checkout gage/my-fix # continue work on the new branchIf you're not sure what state you're in, stop and ask before running reset --hard — it discards uncommitted changes.
This project uses two clients to talk to Airtable:
- Python: pyAirtable
- R: airtabler
You need to store your Airtable API key.
In the project root, create a file named .env:
# Windows (PowerShell)
New-Item .env
# macOS / Linux
touch .envOpen .env in a text editor and add:
KEY=your_airtable_api_key_here
Important: Never EVER commit .env to version control! This contains sensitive keys that would give unwanted users access to our data.
You are now ready to work in the pipeline.
The pipeline has 6 steps:
- Add raw Excel files into the appropriate sub-directory of
raw/.
- Most files will go in /raw/processedSamples/ unless specified otherwise.
- Extract the raw data into tidy-data formats (R).
- Calculate kinetic metrics from the raw data (R).
- Save results as compressed parquet files in
data/(R). - Push results to Airtable and dump to parquet files (Python).
- Analyze results from data-dumped parquet files (R).
Important: Step 5 can only be done by a user with write access to the Airtable base.
Steps 2–4 are all handled by
curate.R.
Step 5 is handled by
airtable/update_results.py. Runpython airtable/update_results.py -hfor more information.
Step 6 is done entirely in R and typically uses scripts in
scripts/.
MARS-exported Excel files should be placed inside raw/. Choose the sub-folder based on the sample type:
| Sample type | Sub-folder |
|---|---|
| Whole blood R&D | raw/blood/ |
| Serum / plasma R&D | raw/serum-plasma/ |
| Anything with a MNPRO process ID | raw/processedSamples/ |
If you're unsure where a file belongs, check what's already in each folder for a similar sample type.
With the R environment set up (see Environment Setup), run the curation script from the R console:
# This does steps 2, 3, and 4.
source("curate.R")When curate.R finishes, you'll see new .parquet files in data/. These are not committed to the repo (they can be regenerated anytime).
With the Python environment activated (see Environment Setup), push the parquet results to Airtable:
python airtable/update_results.py --update-airtableIf you see an authentication error, double-check that
.envexists in the project root and containsKEY=....
All analysis is done in R. Make sure the renv environment is.
The R analysis requires that there is a foder named data-dump.parquet in the data/ folder. This file is generated by running the airtable/data_dump.py script.
If you are authorized to do so, you can unblind the data by adding
--unblinded.
The scripts/ folder contains one analysis/figures script per sample type.
To run one:
source("scripts/oral-swab_figures.R")Figures are written to figures/.
The best way to get data to analyze from airtable is using the data dump python script.
python airtable/data_dump.py --update-airtableThe data dump can be found at data/data_dump.parquet.
If you are authorized to do so, you can unblind the data by adding
--unblinded.
Important: This can be time consuming. It is recommended that you just use the data dump.
If you want to query Airtable using R, you will need to install the
airtablerpackage.
renv::install("bergant/airtabler")
library(airtabler)
# Base ID for this project.
APP <- "app7KsgYl2jhOnYg7"
# Helper for building Airtable filterByFormula strings.
get_formula <- function(id, values, operator = "OR") {
make_string <- function(value) sprintf("%s({%s} = %s", operator, id, value)
sapply(values, make_string) |>
paste(collapse = ",") |>
paste0(strrep(")", length(values)), collapse = "")
}
# Pull the animals and results tables, filtering results to oral-swab samples.
tables <- airtable(APP, c("animals", "results"))
animals <- tables$animals$select_all()
results <- tables$results$select_all(
filterByFormula = get_formula(
"sample_type", c("'MNPRO oral swab'", "'NADC oral swab'")
)
)| Problem | Fix |
|---|---|
renv::restore() fails on quicR |
Run renv::install("gage1145/quicR@v4.0.0", lock=TRUE) manually. |
| Python can't find the Airtable key | Make sure .env lives in the project root and contains KEY=.... |
python command not found (Windows) |
Reinstall Python and tick "Add Python to PATH". |
python command not found (MacOS) |
You may need to use python3 instead of python before the virtual environment is activated. |
pip install -r requirements.txt fails |
Make sure you have the correct version of Python installed, listed in requirements.txt. |
.venv\Scripts\activate blocked on Windows |
Run Set-ExecutionPolicy -Scope CurrentUser RemoteSigned in PowerShell, then retry. |