Tuesday, May 19, 2026
Cohort 3 | Project CloudIgnite Topics: Python for Bioinformatics (Labs 118, 120, 122), File Handling, String Operations, Dictionaries, Loops, Functions Duration: ~3 hours
⚠️ CLF-C02 Relevance Notice
This session is primarily Python programming focused and does not directly cover AWS Certified Cloud Practitioner (CLF-C02) exam content. However, brief incidental mentions of AWS services (Cloud9, EC2) appear. These are noted at the bottom of this document.
Key Takeaways
- Lab 118: Read insulin sequence from NCBI; cleaned text files; split sequences with string slicing
- Lab 120: Counted amino acid occurrences (
.count()); built dictionaries; calculated molecular weight - Lab 122: Calculated net charge using PKa values and Henderson-Hasselbalch formula; while loop over pH range
- Variable scope: declare variables outside
withblock to access in global scope - Dictionary comprehension:
{x: seq.count(x) for x in keys}— one-liner equivalent of multi-line loop - String methods:
.upper(),.count(x), slicingseq[0:24], concatenation with+ - f-string formatting:
{value:.2f}for 2 decimal places
Table of Contents
- Lab 118 — Analyzing Insulin with Python (String Handling)
- Lab 120 — String Sequences and Numeric Weight
- Lab 122 — Calculating Net Charge of Insulin
- Lab 124 — Caesar Cipher (Reference)
- Key Python Concepts Covered
- AWS CLF-C02 Relevant Content
- Upcoming Topics
Lab 118 — Analyzing Insulin with Python (String Handling) {#lab-118}
Objective
Read biological sequence data from files, clean it, and verify character counts using Python.
Steps Covered
1. Fetching the Insulin Sequence
- Go to NCBI → Protein database
- Search:
Human Insulin Homo sapiens - Target protein: 110 amino acid (AAA) sequence
- Example accession ID:
AAA59172.1 - Copy the sequence from the "Origin" section (ends with
//)
2. Cleaning the Sequence File (clean.txt)
Manual steps to produce a clean sequence:
- Remove the
ORIGINheader line - Remove all line numbers
- Remove the
//double slash at the end - Remove all spaces and newline characters
- Result: a single line of 110 characters
Tip: Select the text in your editor — the status bar shows byte count. Since each amino acid character = 1 byte, 110 bytes = 110 characters.
3. Splitting into Protein Sub-sequences (Python — prepare_files.py)
The 110-character pre-proinsulin sequence is split into functional sub-sequences:
| File | Segment | Index (0-based) | Length |
|---|---|---|---|
signal.txt (S) | Signal peptide | [0:24] | 24 chars |
b_insulin.txt (B) | B chain | [24:54] | 30 chars |
c_insulin.txt (C) | C peptide | [54:89] | 35 chars |
a_insulin.txt (A) | A chain | [89:] | 21 chars |
4. Key Python Concepts Used
# Reading a file safely
sequence = ""
try:
with open("preinsulin_sequence_clean.txt", "r") as file:
sequence = file.read()
except Exception as e:
print(e)
# Writing a slice to a new file
with open("signal.txt", "w") as file1:
file1.write(sequence[0:24])
Important: Declare variables (e.g., sequence = "") outside the with block so they are accessible in the global scope. Variables declared inside a with block are scoped to that block.
5. Lesson: Automate vs. Manual
"A programmer will decide to write code for 30 minutes to save a 10-minute task. We have to balance."
- Automation is not always faster or better
- Choose automation when: the task repeats, is error-prone, or scales
- Do it manually when: it's a one-time task and coding takes longer
Lab 120 — String Sequences and Numeric Weight {#lab-120}
Objective
Count amino acid occurrences in the insulin sequence and calculate the molecular weight of insulin.
Key Concepts
Variable Initialization & Multiline Strings
# Backslash continues a string on the next line (same logical line)
pre_pro_insulin = "MALWMRLLPLLALLALWGPDPAAAFVNQHLCGSHLVEALYLVCGERGFFYTPKT" \
"RREAEDLQVGQVELGGGPGAGSLQPLALEGSLQKRGIVEQCCTSICSLYQLENYCN"
Counting Characters in a String
# .count() method — case sensitive!
insulin = b_insulin + a_insulin # string concatenation with +
print(insulin.upper().count("A")) # convert to uppercase before counting
Building a Count Dictionary (Two Equivalent Approaches)
Multi-line (beginner-friendly):
key_list = ["A", "C", "D", "E", "F", "G", "H", "I", "K", "L",
"M", "N", "P", "Q", "R", "S", "T", "V", "W", "Y"]
aa_count_insulin = {}
for x in key_list:
aa_count_insulin[x] = float(insulin.upper().count(x))
One-liner (advanced):
aa_count_insulin = {x: float(insulin.upper().count(x)) for x in key_list}
Instructor Note: "I'm not satisfied with this lab — they shouldn't give beginners this kind of one-liner syntax. Always prefer the multi-line approach when learning."
Calculating Molecular Weight
Each amino acid has a known weight (e.g., A = 89.09, C = 121.16). Multiply count × weight and sum all:
aa_weight = {"A": 89.09, "C": 121.16, "D": 115.09, ...} # full dictionary
# Build weight dictionary
molecular_weight_insulin = {}
for x in key_list:
molecular_weight_insulin[x] = aa_count_insulin[x] * aa_weight[x]
# Sum all values
total_weight = sum(molecular_weight_insulin.values())
Calculating Error Percentage
actual_weight = 5807.65 # known value
weight_diff = total_weight - actual_weight
error_percentage = (weight_diff / actual_weight) * 100
print(f"Error Percentage: {error_percentage:.2f}%")
# Output: ~15%
Importing Between Files
# In lab122.py — import variables from lab120.py
import lab120 # This executes lab120.py; all its print statements will run too
Note: Importing a module executes it. If the imported file has
if __name__ == "__main__":to prevent this. For now, just copy-paste shared variables.
Lab 122 — Calculating Net Charge of Insulin {#lab-122}
Objective
Use PKa values and a while loop to calculate the net charge of insulin across pH 0–14.
Key Concepts
PKa Dictionary
pkr = {"Y": 10.07, "C": 8.18, "K": 10.53, "R": 12.48, "H": 6.00,
"D": 3.65, "E": 4.25}
Counting Sequence Amino Acids
acids = ["Y", "C", "K", "R", "H", "D", "E"]
sequence_count = {}
for x in acids:
sequence_count[x] = float(insulin.count(x)) # insulin already uppercase here
Net Charge Formula
The net charge is the sum of positive charges minus negative charges, where each term uses the Henderson-Hasselbalch-style formula:
- Positive charge (basic residues: Y, C, K, R, H):
count × (10^PKa) / (10^PKa + 10^pH) - Negative charge (acidic residues: D, E):
count × (10^pH) / (10^PKa + 10^pH)
Using a Function to Avoid Code Repetition
def calculate_positive_charge(acids_list):
pos_charge = 0
for x in acids_list:
numerator = sequence_count[x] * (10 ** pkr[x])
denominator = (10 ** pkr[x]) + (10 ** pH)
pos_charge += numerator / denominator
return pos_charge
def calculate_negative_charge(acids_list):
neg_charge = 0
for x in acids_list:
numerator = sequence_count[x] * (10 ** pH)
denominator = (10 ** pkr[x]) + (10 ** pH)
neg_charge += numerator / denominator
return neg_charge
While Loop Over pH Range
pH = 0
net_charge = 0
while pH < 14:
pos = calculate_positive_charge(["Y", "C", "K", "R", "H"])
neg = calculate_negative_charge(["D", "E"])
net_charge = pos - neg
print(f"{pH:.2f} {net_charge:.2f}")
pH += 1
Note: The instructor's output differed from the expected lab output (~13.97 vs expected). The main takeaway is understanding Python syntax, not getting the exact biochemical result correct.
Lab 124 — Caesar Cipher (Reference / Self-Study) {#lab-124}
This lab was covered in a previous session. Code was shared for self-study.
Concept
- Encrypting a message: shift each letter by a fixed number (the key)
- Decrypting: shift in the reverse direction
- Uses string indexing, loops, and modulo arithmetic (
%)
Review the shared
lab124.pyfile. Ask the instructor if you have questions.
Key Python Concepts Covered {#key-python-concepts}
Variable Scope
sequence = "" # global variable — accessible everywhere
with open("file.txt", "r") as f:
sequence = f.read() # reuses global variable, does NOT create a new one
# sequence is still accessible here ✅
String Methods
| Method | Example | Result |
|---|---|---|
.upper() | "acgt".upper() | "ACGT" |
.count(x) | "ACGTA".count("A") | 2 |
| Slicing | seq[0:24] | first 24 chars |
| Concatenation | "AB" + "CD" | "ABCD" |
f-Strings (Formatted Strings)
value = 3.14159
print(f"Value: {value:.2f}") # 2 decimal places → "Value: 3.14"
Dictionaries
d = {} # empty dictionary
d["key"] = "value" # add item
d.values() # all values
sum(d.values()) # sum numeric values
List Comprehension / Dict Comprehension
# List
squares = [x**2 for x in range(10)]
# Dictionary
counts = {x: seq.count(x) for x in amino_acids}
Try / Except (Error Handling)
try:
with open("file.txt", "r") as f:
data = f.read()
except Exception as e:
print(e) # prints actual error message (e.g., "No such file or directory")
While Loop
i = 0
while i < 14:
# do something
i += 1 # equivalent to i = i + 1
Functions
def my_function(param1, param2):
result = param1 + param2
return result
Good Coding Practices Mentioned
- Add a comment block at the top of every script explaining its purpose
- Use descriptive variable names
- Use
try/exceptwithException as eso errors are informative, not silent - Prefer multi-line, readable code over one-liners when learning
- Know when to automate vs. do manually
AWS CLF-C02 Relevant Content {#aws-clf-c02-relevant-content}
This session was not exam-focused, but two AWS services were mentioned in passing:
AWS Cloud9
- A cloud-based IDE (Integrated Development Environment) accessible via browser
- Runs inside an EC2 instance (so the environment resets/stops after ~1 hour on the free tier)
- Used in this lab to write and run Python code
- CLF-C02 context: Cloud9 falls under AWS Developer Tools. For the exam, know that it is a browser-based IDE integrated with AWS services.
Amazon EC2 (Elastic Compute Cloud)
- Cloud9 environments run on EC2 instances
- The lab environment stopped after ~1 hour (a free-tier/lab time limit behavior)
- CLF-C02 context: EC2 is a core IaaS (Infrastructure as a Service) compute service. Key exam points:
- EC2 provides resizable virtual servers in the cloud
- Instance lifecycle: start, stop, terminate
- Part of the AWS Compute service category
📌 For CLF-C02 study, this session alone is not sufficient. Focus on the official AWS Cloud Practitioner Essentials course and the exam guide for complete coverage of all domains.
Upcoming Topics {#upcoming-topics}
As mentioned by the instructor for the next session(s):
- File Handling — Reading JSON files in Python
- System Administration with Python — Using the
subprocessmodule (Linux commands from Python) - Debugging — Using a Python debugger; debugging a buggy Caesar Cipher program
- Goal: Complete all remaining labs by Thursday/Friday
Notes compiled from lecture — May 19, 2026
AWS re/Start Program — Cohort 3, Project CloudIgnite