From Spaghetti Code to Reproducible Work
2026-11-01
1. Writing Scripts in VS Code
2. Good Coding Practices
3. Version Control with Git
4. Colab, Micromamba
5. Practice
1. Writing Scripts in VS Code
01_prepare.R, clean.sh, …*.R and *.sh in one place, with syntax help and run buttons?1. Writing Scripts in VS Code
*.R, *.sh, *.md.1. Writing Scripts in VS Code
.deb from https://code.visualstudio.com/Download once, then:bradford.r) for *.R.1. Writing Scripts in VS Code
mdd_RNAseq_pipeline01_core_alignment/, _data/, results/).01_raw_fastqc.sh).mdd_RNAseq_pipeline master prompt).1. Writing Scripts in VS Code
*.R, *.sh, *.py, *.md in one window, with terminals and Jupyter notebooks.1. Writing Scripts in VS Code
1. Writing Scripts in VS Code
# goal: mean TPM per gene, then a bar
counts <- read.table("data/counts/counts.tsv", sep = "\t", header = TRUE)
mat <- as.matrix(counts[-1])
tpm <- mat / rep(colSums(mat), each = nrow(mat)) * 1e6
mean_tpm <- data.frame(gene = counts$GeneID, tpm = rowMeans(tpm))
top <- head(mean_tpm[order(-mean_tpm$tpm), ], 20)
write.csv(top, "results/mean_tpm.csv", row.names = FALSE)
library(ggplot2)
ggsave("results/mean_tpm.png",
ggplot(top, aes(x = reorder(factor(gene), tpm), y = tpm)) +
geom_col() + coord_flip() + theme_minimal(),
width = 5.4, height = 3.4)02_analyse.R, numbered in run order.data/counts/counts.tsv, writes results/ — never edits the raw reads.1. Writing Scripts in VS Code
2. Good Coding Practices
3. Version Control with Git
4. Colab, Micromamba
5. Practice
2. Good Coding Practices
x, temp, data22. Good Coding Practices
raw_counts, filtered_spotscalculate_average(), filter_failed_samples()2. Good Coding Practices
2. Good Coding Practices
2. Good Coding Practices
2. Good Coding Practices
2. Good Coding Practices
2. Good Coding Practices
total gives Inf with no message.2. Good Coding Practices
stop() before divide2. Good Coding Practices
v1, v2, v3… loop becomes one named function.2. Good Coding Practices
2. Good Coding Practices
final in every name. Which one is real?2. Good Coding Practices
demo/
├── 01_raw_fastqc.sh # run first
├── 02_analyse.R # run second
├── data/
│ ├── raw_fastq/ # unpacked, never edit
│ ├── counts/counts.tsv # the real input
│ └── qc_raw/ # generated, not committed
├── results/
│ ├── mean_tpm.csv # generated
│ └── mean_tpm.png # generated
├── environment.yml # the toolbox recipe
├── README.md # how to run it
└── .gitignore # what Git must skipREADME.md + environment.yml + .gitignore tell a colleague how to rebuild it.2. Good Coding Practices
herehere() finds the project root; pass subfolders as parts.2. Good Coding Practices
here() paths1. Writing Scripts in VS Code
2. Good Coding Practices
3. Version Control with Git
4. Colab, Micromamba
5. Practice
3. Version Control with Git
3. Version Control with Git
3. Version Control with Git
git init in your project.3. Version Control with Git
3. Version Control with Git
3. Version Control with Git
Warning
No passwords on GitHub: use a token (PAT) or an SSH key.
3. Version Control with Git
main stays stable.3. Version Control with Git
HEAD moves to the branch. Edits and commits land there.3. Version Control with Git
main.3. Version Control with Git
3. Version Control with Git
<<<<<<<, =======, >>>>>>>, then git add + git commit.3. Version Control with Git
.gitignore: never track dataREADME.md, environment.yml. The QC reports, plots, and the 56 MB archive stay local.1. Writing Scripts in VS Code
2. Good Coding Practices
3. Version Control with Git
4. Colab, Micromamba
5. Practice
4. Colab, Micromamba
4. Colab, Micromamba
Ctrl + Enter) + Markdown cells (notes).+ Code, ▶, upload in Files → read.csv("/content/metadata.csv")Warning
Uploads vanish on idle. Mount Google Drive to keep files.
4. Colab, Micromamba
4. Colab, Micromamba
environment.yml, tiny binary, fast solver. Drop-in replacement.4. Colab, Micromamba
sudo needed: one static binary into ~/bin.Note
Optional: echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc — puts ~/bin on your PATH in every new terminal.
4. Colab, Micromamba
environment.yml: the toolbox recipechannels = where packages come from; dependencies = the exact tools and versions.4. Colab, Micromamba
demo.4. Colab, Micromamba
Note
Optional, once: micromamba run -n demo R -e 'IRkernel::installspec(user = TRUE)' — registers R for your notebook.
4. Colab, Micromamba
--prune removes what is no longer listed.4. Colab, Micromamba
4. Colab, Micromamba
Only run micromamba clean --all if you are out of disk — it deletes the package cache.
1. Writing Scripts in VS Code
2. Good Coding Practices
3. Version Control with Git
4. Colab, Micromamba
5. Practice
5. Practice
No blanks, no answers here. Just choose.
5. Practice
5. Practice
git commitgit status only reports what changed.git commit saves the staged snapshot.Status reports. Commit saves.
5. Practice
5. Practice
data/data/ holds the original inputs.results/ is written by code, so it can change.Never edit inputs.
5. Practice
5. Practice
environment.yml.gitignore only ignores data files in Git.One file rebuilds the toolbox.
5. Practice
5. Practice
my_data_table_.Pick one style and stay with it.
5. Practice
stop() do?5. Practice
print() shows a message and continues; stop() ends it.Check inputs before you compute.
_data, here() paths, stop() before you compute.main. Never track data — .gitignore.environment.yml + Micromamba locally (R and Python).Module III — Single-cell RNA-seq
Counts → QC → statistics → figure — with Git and environments behind it.
Keep the code boring. So the science can be interesting.
Fighting Cancer with Transcriptomics · Lecture 10 · Good Coding Practices, Version Control & Environments