Atharva Bhagwat

Stage 12: Organising a project

0Plan
Stage 12Level up
★★

Give your work a tidy home: folders, a download you can repeat, a check that the file is intact, and a place for code you reuse.

In Part 1 your files lived in a temporary Colab session. Real projects live in folders on your disk. Analyses that last are organised in a way anyone can understand. Not fancy, just predictable.

pybio-project/
├── README.md              what this is and how to run it
├── environment.yml        the recipe for the conda environment
├── data/
│   ├── raw/               downloaded files, never edited
│   └── derived/           tables your code creates
├── notebooks/             your notebooks, numbered in order
│   └── helpers.py         functions you reuse
└── results/
    └── figures/           plots saved by code

1. Make the folders

In your terminal, choose where the project should live (with cd), then:

macOS / Linux terminal
mkdir pybio-project
cd pybio-project
mkdir -p data/raw data/derived notebooks results/figures
ls
Windows (PowerShell)
mkdir pybio-project
cd pybio-project
mkdir data/raw, data/derived, notebooks, results/figures
ls

2. Download the data

Downloading with commands is a record of where each file came from, which clicking links is not. Three files power the rest of this guide: the toy table, the real PTEN table, and the table of regions. Run these from inside the project folder:

macOS / Linux terminal
curl -L -o data/raw/toy_vampseq_bin_counts.csv https://atharvabhagwat.dev/assets/data/toy_vampseq_bin_counts.csv
curl -L -o data/raw/pten-variant-abundance.csv https://atharvabhagwat.dev/assets/data/pten-variant-abundance.csv
curl -L -o data/raw/pten-region-annotations.csv https://atharvabhagwat.dev/assets/data/pten-region-annotations.csv
Windows (PowerShell)
Invoke-WebRequest -Uri https://atharvabhagwat.dev/assets/data/toy_vampseq_bin_counts.csv -OutFile data/raw/toy_vampseq_bin_counts.csv
Invoke-WebRequest -Uri https://atharvabhagwat.dev/assets/data/pten-variant-abundance.csv -OutFile data/raw/pten-variant-abundance.csv
Invoke-WebRequest -Uri https://atharvabhagwat.dev/assets/data/pten-region-annotations.csv -OutFile data/raw/pten-region-annotations.csv

Check they arrived:

terminal
ls data/raw

3. Check the file is the real file

A partial or edited download can look fine and quietly ruin your results. A checksum is a fingerprint of a file: change one character and the fingerprint changes completely. Compute yours:

macOS / Linux terminal
shasum -a 256 data/raw/pten-variant-abundance.csv
Windows (PowerShell)
Get-FileHash data/raw/pten-variant-abundance.csv

4. Write a README

A README is a short note that explains the project. Make a file called README.md in the project folder with something like:

README.md
# PTEN abundance analysis

Explores a published table of protein variant abundance scores.

## How to run
1. conda env create -f environment.yml
2. conda activate pybio
3. open the notebooks in order

## Decisions
- Score = weighted average of four bins.
- Variants with fewer than 50 reads are left out.

Save the environment next to it, as in Stage 11:

terminal
conda env export --from-history > environment.yml

5. A file for code you reuse

In Stage 5 you wrote add_scores. Instead of pasting it into every notebook, put it in a file next to your notebooks. Create notebooks/helpers.py containing:

notebooks/helpers.py
def add_scores(df, min_reads=0):
    """Add total_reads and score columns. Rows with fewer than min_reads reads get no score."""
    df = df.copy()
    df["total_reads"] = df["bin1_count"] + df["bin2_count"] + df["bin3_count"] + df["bin4_count"]
    df["score"] = (df["bin1_count"] * 1 + df["bin2_count"] * 2 + df["bin3_count"] * 3 + df["bin4_count"] * 4) / df["total_reads"]
    df.loc[df["total_reads"] < min_reads, "score"] = None
    return df

Any notebook in that folder can now use it with one line:

in a notebook cell
from helpers import add_scores

Exercises

These are also in the notebook. Try each one yourself before you open the solution.

Build the project folders

Create the folders from the layout above, then run ls to check them. Paste the output into the puzzle below when you are done.
Show a solution (try it first)
one solution
mkdir -p data/raw data/derived notebooks results/figures
ls

Check your understanding

First star

Compute the checksum of data/raw/pten-variant-abundance.csv and paste the line it printed. The checker compares it with the fingerprint of the original file. If it does not match, download the file again.

Stuck? Get a nudge

A mismatch usually means a partial download (the file should be about a megabyte), or the file was opened and re-saved in a spreadsheet program. Delete it and download it again.

Special thanks to Nilay!