Homework 1 - Computational Tools for Bioengineers 2026

Due: Submit your work via Canvas by the end of the day (midnight) on Monday, November 16th, 2026.

Important

This homework has two questions. Question 1 uses the shell scripting skills from the first half of the course to analyze two bacterial genomes. Question 2 uses the R and Python scripting skills from recent weeks to analyze a bioengineering dataset that we provide. Complete both questions.

Question 1: Bacterial Genome Analysis with Shell Scripts

Learning Objectives

  • Download genomic data from NCBI using command-line tools
  • Work with compressed genomic files efficiently
  • Apply GREP and regular expressions to analyze biological sequences
  • Use Unix pipes to create analysis workflows
  • Write shell scripts to automate genome analysis
  • Run the shell scripts and create output files

Background

Note
  • In this exercise, you’ll download and analyze two bacterial genomes with very different characteristics:

    1. Escherichia coli K-12 MG1655: A well-studied model organism with a typical-sized bacterial genome (~4.6 Mb)
    2. Mycoplasma genitalium G37: One of the smallest known genomes of any free-living organism (~0.58 Mb)
  • Your goal is to write all of the commands below and include them into executable shell scripts. Note that you’ll probably have several scripts, one for each exercise or task.

  • In this exercise I’ve given you a lot of hints, but you’ll have to modify most commands just a little bit to make sure that they work on your computer.

  • The goal is for you to think about and understand what is happening with each step of the script.


Part 1: Setup and Data Download

Task 1.1: Create your workspace

  • Create a working directory structure using mkdir
  • Organize your directories into those named something like: input, results and scripts
  • Remember that throughout the rest of the exercise you’ll either need to be in the appropriate directory, or use paths to point to the appropriate directory
  • In the examples below I use names for directories in paths but of course they won’t be the same as yours
  • You’ll need to make sure that you use your directory names in your paths

Task 1.2: Download the E. coli and M. genitalium genomes

  • Navigate into the ‘input’ directory
  • Download the E. coli and M. genitalium genomes and CDS files
  • hint - you may want to make more subdirectories for each genome

# Download E. coli K-12 MG1655 genome using curl

curl -o ecoli_genome.fna.gz \
  https://ftp.ncbi.nlm.nih.gov/genomes/all/GCF/000/005/845/GCF_000005845.2_ASM584v2/GCF_000005845.2_ASM584v2_genomic.fna.gz

# Download the CDS (coding sequences) file

curl -o ecoli_cds.fna.gz \
  https://ftp.ncbi.nlm.nih.gov/genomes/all/GCF/000/005/845/GCF_000005845.2_ASM584v2/GCF_000005845.2_ASM584v2_cds_from_genomic.fna.gz


# Download M. genitalium G37 genome using curl

curl -o mycoplasma_genome.fna.gz \
  https://ftp.ncbi.nlm.nih.gov/genomes/all/GCF/000/027/325/GCF_000027325.1_ASM2732v1/GCF_000027325.1_ASM2732v1_genomic.fna.gz

# Download the CDS file

curl -o mycoplasma_cds.fna.gz \
  https://ftp.ncbi.nlm.nih.gov/genomes/all/GCF/000/027/325/GCF_000027325.1_ASM2732v1/GCF_000027325.1_ASM2732v1_cds_from_genomic.fna.gz

# Verify downloads

ls -lh *.gz
Note
  • Remind yourself of how curl works and the structure of the command
  • Also, you can write this into your first executable script (maybe download_genomes.sh or something like that)
  • Once you do run this command: chmod +x download_genomes.sh
  • You’ll want to do this for each of the scripts that you write
  • Remind yourself what chmod does

Task 1.3: Initial exploration of compressed files

  • use the command ls -lh */*.gz to compare the size of each file

  • Preview each genome without decompressing


echo "=== E. coli genome preview ==="
zcat ecoli/ecoli_genome.fna.gz | head -10

echo -e "\n=== Mycoplasma genome preview ==="
zcat mycoplasma/mycoplasma_genome.fna.gz | head -10

# Count sequence records in each compressed file

echo -e "\nE. coli sequences: $(zgrep -c '^>' ecoli/ecoli_genome.fna.gz)"
echo "Mycoplasma sequences: $(zgrep -c '^>' mycoplasma/mycoplasma_genome.fna.gz)"
Note
  • I briefly touched on this in calss, but a number of the standard Unix commands work the same way on compressed files if you use the ‘z’ version of them (e.g. zcat and zgrep)
  • You can always unzip first and then use cat and grep, but sometimes it helps to save disk space to just work with the zipped files
  • You can run these commands in the command line to begin, but then write a script with the appending redirects >> to write the output to the file
  • This will be your first script from this exercise

Part 2: Basic Genome Statistics

Task 2.1: Decompress and prepare files

# Decompress all files (keeping originals using the option `-k`)

# E. coli files

gunzip -k ecoli/*.gz

# Mycoplasma files

gunzip -k mycoplasma/*.gz

# Check uncompressed sizes

ls -lh */*.fna
Note
  • Remind yourself what the * wild card is doing
  • Also, I forgot about this -k option in class - that would have saved time!

Task 2.2: Count genes in each organism


# Count genes in CDS files

echo "E. coli genes: $(grep -c '^>' ecoli/ecoli_cds.fna)"
echo "Mycoplasma genes: $(grep -c '^>' mycoplasma/mycoplasma_cds.fna)"
Note
  • Note that in the cds files, each gene entry starts with the character >
  • Just one more reminder - the paths I wrote above won’t be the same as yours if you use different directory names
  • Also, take the time to remind yourself what grep does and the structure

Part 3: Nucleotide Composition Analysis

Task 3.1: Create a nucleotide composition analyzer


#!/bin/bash
# Analyze nucleotide composition of a genome

if [ $# -ne 2 ]; then
    echo "Usage: $0 <fasta_file> <organism_name>"
    exit 1
fi

FASTA=$1
NAME=$2

echo "=== Nucleotide Composition for $NAME ==="

# Count each nucleotide

echo "Nucleotide counts:"
grep -v "^>" "$FASTA" | tr -d '\n' | fold -w1 | \
  tr '[:lower:]' '[:upper:]' | sort | uniq -c

# Calculate total

TOTAL=$(grep -v "^>" "$FASTA" | tr -d '\n' | wc -c)
echo -e "\nTotal nucleotides: $TOTAL"

# Calculate GC content

GC_COUNT=$(grep -v "^>" "$FASTA" | tr -d '\n' | grep -o "[GCgc]" | wc -l)
GC_PERCENT=$(echo "scale=2; $GC_COUNT * 100 / $TOTAL" | bc)
echo "GC content: $GC_PERCENT%"

# Calculate AT content

AT_COUNT=$(grep -v "^>" "$FASTA" | tr -d '\n' | grep -o "[ATat]" | wc -l)
AT_PERCENT=$(echo "scale=2; $AT_COUNT * 100 / $TOTAL" | bc)
echo "AT content: $AT_PERCENT%"
Note
  • This script is allowing you to point it to a file
  • The script also allows you to input a name of the organism
  • The file is then input and analyzed (which is what you’ll do in the next section)

Task 3.2: Compare nucleotide composition


# Analyze E. coli

../scripts/nucleotide_stats.sh ecoli/ecoli_genome.fna "E. coli" \
  > ../results/ecoli_nucleotides.txt

# Analyze Mycoplasma

../scripts/nucleotide_stats.sh mycoplasma/mycoplasma_genome.fna "Mycoplasma" \
  > ../results/mycoplasma_nucleotides.txt

# Display results

cat ../results/ecoli_nucleotides.txt
echo ""
cat ../results/mycoplasma_nucleotides.txt
echo ""
Note
  • In this case you’re running your scripts and redirecting the results into a new file
  • OK, one last time - the names of your files and directories will be different!

Part 4: Biological Feature Analysis

Task 4.1: Search for restriction enzyme sites


#!/bin/bash
# Count common restriction enzyme sites

if [ $# -ne 2 ]; then
    echo "Usage: $0 <fasta_file> <organism_name>"
    exit 1
fi

FASTA=$1
NAME=$2

echo "=== Restriction Sites in $NAME ==="
echo "Enzyme  | Site    | Count"
echo "--------|---------|-------"

# Common 6-cutters
echo -n "EcoRI   | GAATTC  | "
grep -v "^>" "$FASTA" | tr -d '\n' | grep -o "GAATTC" | wc -l

echo -n "BamHI   | GGATCC  | "
grep -v "^>" "$FASTA" | tr -d '\n' | grep -o "GGATCC" | wc -l

echo -n "HindIII | AAGCTT  | "
grep -v "^>" "$FASTA" | tr -d '\n' | grep -o "AAGCTT" | wc -l

echo -n "PstI    | CTGCAG  | "
grep -v "^>" "$FASTA" | tr -d '\n' | grep -o "CTGCAG" | wc -l

echo -n "SalI    | GTCGAC  | "
grep -v "^>" "$FASTA" | tr -d '\n' | grep -o "GTCGAC" | wc -l

echo -n "XbaI    | TCTAGA  | "
grep -v "^>" "$FASTA" | tr -d '\n' | grep -o "TCTAGA" | wc -l

Reminder to make this script executable:

chmod +x 

Task 4.2 Compare restriction sites

../scripts/restriction_sites.sh ecoli/ecoli_genome.fna "E. coli" \
  > ../results/ecoli_restriction.txt

../scripts/restriction_sites.sh mycoplasma/mycoplasma_genome.fna "Mycoplasma" \
  > ../results/mycoplasma_restriction.txt

cat ../results/ecoli_restriction.txt
echo ""
cat ../results/mycoplasma_restriction.txt
echo ""
Note

Just like above, this shows you how to execute your script and redirect the results to output files

Task 4.3: Search for promoter elements

# Search for bacterial promoter elements
echo "=== Promoter Elements ==="

# -10 box (Pribnow box) TATAAT
echo "Pribnow box (TATAAT) counts:"
echo -n "E. coli: "
grep -v "^>" ecoli/ecoli_genome.fna | tr -d '\n' | grep -o "TATAAT" | wc -l

echo -n "Mycoplasma: "
grep -v "^>" mycoplasma/mycoplasma_genome.fna | tr -d '\n' | grep -o "TATAAT" | wc -l

# Shine-Dalgarno sequence (AGGAGG)
echo -e "Shine-Dalgarno (AGGAGG) counts:"
echo -n "E. coli: "
grep -v "^>" ecoli/ecoli_genome.fna | tr -d '\n' | grep -o "AGGAGG" | wc -l

echo -n "Mycoplasma: "
grep -v "^>" mycoplasma/mycoplasma_genome.fna | tr -d '\n' | grep -o "AGGAGG" | wc -l

Task 4.4 Compare promoter elements

  • On your own execute the scripts and redirect the output of the analyses to files
  • This is the same structure as you’ve used on the previous tasks (e.g. look at Task 4.2)
  • Don’t forget to make your scripts executable!

Question 2: Analyzing BMP-2 Release from Hydrogels with R or Python

Learning Objectives

  • Read a tidy dataset from a .csv file into R or Python
  • Compute grouped summary statistics and write them to an output file
  • Build a plot that layers jittered data points over violin plots, with the median identified
  • Save a publication-quality figure to a .svg file from code
  • Write an executable analysis script that runs top-to-bottom using relative paths

Background

Note
  • Hydrogels are water-swollen polymer networks widely used in tissue engineering as delivery vehicles for growth factors. A classic application is loading a gel with bone morphogenetic protein 2 (BMP-2) and letting it diffuse out to induce bone formation.

  • The polymer concentration of the gel controls the mesh size of the network, and therefore how quickly a loaded ligand can diffuse out.

  • We fabricated two GelMA (gelatin methacryloyl) hydrogel formulations — 5% (w/v) and 10% (w/v) — and loaded each gel with 10 µg of BMP-2. For each formulation we made 20 replicate gels (40 gels total). Each gel was placed in buffer and the cumulative BMP-2 released was measured by ELISA at days 1, 2, and 3.

  • The diffusion rate for each gel is the cumulative 3-day release divided by 3 (µg/day). This is the main response variable you will summarize and plot.

  • Your job is to write one script, in either R or Python (your choice — or both if you’re feeling ambitious), that performs the whole analysis from reading the data to saving the figure.

The dataset

Download the data file here: Hydrogel_BMP2_release.csv

The file has one row per gel (40 rows plus a header) with these columns:

Column Description
gel_id Unique ID for each gel (e.g. G05_01)
formulation GelMA_5pct or GelMA_10pct
replicate Replicate number within formulation (1–20)
bmp2_loaded_ug BMP-2 loaded into the gel (µg) — 10 µg for every gel
release_day1_ug Cumulative BMP-2 released by day 1 (µg)
release_day2_ug Cumulative BMP-2 released by day 2 (µg)
release_day3_ug Cumulative BMP-2 released by day 3 (µg)
diffusion_rate_ug_per_day 3-day release ÷ 3 days (µg/day) — your response variable

Part 5: Setup and Data Download

Task 5.1: Create your project

  • Just like Question 1, make a project directory with data, scripts, and results subdirectories
  • Put the .csv file in data — you can click the link above, or practice your Question 1 skills:
curl -o data/Hydrogel_BMP2_release.csv \
  https://wcresko.github.io/BioE_Comp_Tools_Fa2026/Data_Folder/Hydrogel_BMP2_release.csv
  • Take a first look at the file from the shell (head, wc -l, maybe cut -d',' -f2 | sort | uniq -c) before you write a single line of R or Python — always know what your data looks like!

Part 6: Write Your Analysis Script

Write one script — scripts/analyze_hydrogels.R or scripts/analyze_hydrogels.py — that does all of the following when run from your project’s top directory.

Task 6.1: Read in the data

  • Read data/Hydrogel_BMP2_release.csv into a data frame
  • Hints: read_csv() from readr (tidyverse) in R; pd.read_csv() from pandas in Python
  • Make formulation a factor (R) or categorical (Python) so the groups plot in the order you want

Task 6.2: Create a summary table

  • For each of the two formulations, compute at least: the number of gels (n), mean, standard deviation, and median of diffusion_rate_ug_per_day
  • Write the summary table to results/diffusion_summary.csv (a .txt is fine too)
  • Hints: group_by() + summarize() in R; groupby() + agg() in Python
  • Sanity check: the two formulations should not look the same — if they do, something has gone wrong

Task 6.3: Create a simple distribution figure

Make a single plot with:

  • formulation on the x-axis (the two categories)
  • diffusion_rate_ug_per_day on the y-axis
  • A violin plot for each formulation showing the shape of the distribution
  • The individual data points jittered horizontally on top of the violins (all 20 points per group should be visible)
  • The median clearly identified for each group (a horizontal line, a large point, or a crossbar — your choice, as long as a reader can find it)
  • Real axis labels with units (e.g. “BMP-2 diffusion rate (µg/day)”), not raw column names
Note
  • In R: ggplot2 with geom_violin() + geom_jitter() is the natural combination; stat_summary(fun = median, ...) is one clean way to mark the median. Keep the jitter width small (e.g. width = 0.1) so points stay over their violin.
  • In Python: seaborn’s violinplot() + stripplot() on the same axes works well (set inner="quartile" or draw the median yourself); or build it from matplotlib’s violinplot(..., showmedians=True) plus a jittered scatter().

Task 6.4: Write the figure to a .svg file

  • Save the figure as results/diffusion_rates.svg from inside the script — not by exporting from a viewer window
  • Hints: ggsave("results/diffusion_rates.svg", ...) in R (you may need the svglite package: install.packages("svglite")); fig.savefig("results/diffusion_rates.svg") in Python
  • SVG is a vector format — open it in your browser and zoom in to admire your infinitely sharp plot

Part 7: Make It Executable and Reproducible

Task 7.1: Make the script executable

  • Add the appropriate shebang as the first line of the script:
    • R: #!/usr/bin/env Rscript
    • Python: #!/usr/bin/env python3
  • Then chmod +x scripts/analyze_hydrogels.R (or .py), just like your Question 1 shell scripts
  • Run it from the top of your project: ./scripts/analyze_hydrogels.R — it should run top-to-bottom with no errors and (re)create both files in results

Task 7.2: Use relative paths

Important
  • Your script must use relative paths only (data/Hydrogel_BMP2_release.csv, results/diffusion_rates.svg) — no absolute paths like /Users/yourname/..., and no setwd() or os.chdir() to a hard-coded location
  • The test: I should be able to download your project folder and just run your script, from the top of the project, and have it work on my computer the first time
  • Before you submit, try it yourself: copy your project folder somewhere else on your computer (or delete results and recreate it) and run the script again

What to Submit (both questions)

  • Question 1: your shell scripts, and the output files in results they produced
  • Question 2: your R or Python script, results/diffusion_summary.csv, and results/diffusion_rates.svg

Tips for Success

  • Always verify file downloads completed successfully
  • Test scripts on small test files before running on full genomes
  • Use meaningful variable names in your scripts
  • Add error checking to scripts (verify files exist, etc.)
  • Comment your code to explain what each section does
  • Save intermediate results in case you need to re-run analyses
  • If a command is taking too long, you might be able to optimize it
  • For Question 2, build the script up interactively (in Positron, or the R/Python console), then assemble the working pieces into the final script and run it clean from the top