1
Instructor:
Welcome to BME 603/606�
Computational Methods for�Biological Modeling & Simulation
Assistant Professor of Biomedical Engineering�Affiliate, Data Science Institute�Affiliate, Biophysics Graduate Program�Affiliate, Center for Genomic Science Innovation�Affiliate, Wisconsin Institute for Translational Neuroengineering �University of Wisconsin-Madison
DHANANJAY ‘Jay’ BHASKAR
Course Website: https://bio-modeling-uw-madison-f26.github.io/
2
BME 603/606: Computational Methods for Biological Modeling & Simulation
Survey: my office hours
Takeaway: I will hold office hours on Fri (10-11 am) and Thr (4 - 5 pm). Place TBD.
3
BME 603/606: Computational Methods for Biological Modeling & Simulation
Survey Results – TA office hours
Takeaway: Colin will hold office hours on Mon (1-2 pm) and Tue (2-3 pm). Place TBD.
4
BME 603/606: Computational Methods for Biological Modeling & Simulation
Survey: Programming experience varies
Takeaway: Graded components at beginner level, advanced exercises for bonus credit
5
BME 603/606: Computational Methods for Biological Modeling & Simulation
Survey: Most of you are comfortable with Python
Takeaway: Most of you know Python or a closely related language (R/MATLAB/Julia)
6
BME 603/606: Computational Methods for Biological Modeling & Simulation
Survey: You’re in the right class!
Takeaway: We’ll teach you fundamentals of scientific computing, modeling and simulation ☺
7
BME 603/606: Computational Methods for Biological Modeling & Simulation
Survey: Majority prefer VS Code
Takeaway: We will continue to use VS Code as the default IDE for this class.
8
BME 603/606: Computational Methods for Biological Modeling & Simulation
Survey: Experience with Git varies
9
BME 603/606: Computational Methods for Biological Modeling & Simulation
Survey: Most of you asked for help with Git
Takeaway: Colin will give a Git/GitHub tutorial in-class on Mon, Sept 14.
10
BME 603/606: Computational Methods for Biological Modeling & Simulation
Survey: you’re here because you want to learn
11
BME 603/606: Computational Methods for Biological Modeling & Simulation
Survey: you’re here because you want to learn
“develop a stronger foundation in computational biology methods, particularly how genomic and molecular data”
“translate biological mechanisms into computational models”
“in-class exercises (based on effort) are going to greatly help me in this class.”
“develop my programming skill”
“know more about the computational biology research field and possible future career path”
“better understand the code, packages to use, the coding logic, and apply these skills into my research”
“become comfortable using models and visuals in order to represent quantitative biological or biomedical data”
12
BME 603/606: Computational Methods for Biological Modeling & Simulation
Survey: topics you want me to cover
“make inferences about biological interactions for potential medical device/human interactions”
“algorithmic methods for analyzing protein sequences and DNA”
“learn about the main bottlenecks and limitations in modeling each system we discuss”
“I don't have any thing specific in mind”
“Spatial and Multicellular Modeling”
“want to learn about cell modeling and how a degree of randomness can be added, with things like cancer developing over time/with certain stimuli”
“predictive drug/protein design and drug discovery”
“Machine Learning and Signal Processing in biomedical engineering”
“neuronal signaling and gene regulation”
13
BME 603/606: Computational Methods for Biological Modeling & Simulation
Survey: how can we help you succeed?
“I look forward to this class, meeting new people, and learning a ton of interesting and applicable information”
“This is my final semester before graduation […] I’d really appreciate patience and understanding as I learn, make mistakes, ask questions, […]”
“Quick piazza and email responses”
“Given that it's a new course, I'm a little worried about the quizzes as I don't really know what to expect, so maybe practice material.”
14
BME 603/606: Computational Methods for Biological Modeling & Simulation
Python fundamentals: String Manipulation
# DNA sequence stored as a Python string
sequence = 'ATGCGTACGATCG'
# Indexing (zero-based)
first_base = sequence[0] # 'A'
last_base = sequence[-1] # 'G'
# Slicing [start : stop]
codon = sequence[0:3] # 'ATG'
exon = sequence[3:9] # 'CGTACG'
suffix = sequence[9:] # 'ATCG'
print(f'Codon : {codon}')
# Codon : ATG
print(f'Length : {len(sequence)}')
# Length : 13
15
BME 603/606: Computational Methods for Biological Modeling & Simulation
Python fundamentals: String Methods
sequence = 'ATGCGTACGATCGATCG'
# Count occurrences of a motif
atg_count = sequence.count('ATG') # 2
gc_count = sequence.count('G') + sequence.count('C')
# Find first match position
pos = sequence.find('CGA') # 5
# RNA transcription: replace T with U
rna = sequence.replace('T', 'U')
# 'AUGCGUACGAUCGAUCG'
print(f'ATG count : {atg_count}')
# ATG count : 2
print(f'GC bases : {gc_count}')
# GC bases : 10
16
BME 603/606: Computational Methods for Biological Modeling & Simulation
sequence = 'ATGCGTACGCGT'
# Initialise counter dictionary
counts = {'A': 0, 'T': 0, 'G': 0, 'C': 0}
for base in sequence:
counts[base] += 1
print(counts) # {'A': 2, 'T': 2, 'G': 4, 'C': 4}
# Compute GC content
gc = (counts['G'] + counts['C']) / len(sequence)
print(f'GC content: {gc:.1%}') # GC content: 66.7%
Python fundamentals: For Loops
17
BME 603/606: Computational Methods for Biological Modeling & Simulation
Python fundamentals: Conditionals (if/elif/else)
sequence = 'ATGCGTACGATCGATCG'
# Count occurrences of a motif
atg_count = sequence.count('ATG') # 2
gc_count = sequence.count('G') + sequence.count('C')
# Find first match position
pos = sequence.find('CGA') # 5
# RNA transcription: replace T with U
rna = sequence.replace('T', 'U')
# 'AUGCGUACGAUCGAUCG'
print(f'ATG count : {atg_count}')
# ATG count : 2
print(f'GC bases : {gc_count}')
# GC bases : 10
def classify_gc(sequence):
gc = (sequence.count('G') + sequence.count('C')) / len(sequence)
if gc < 0.4:
return 'AT-rich region'
elif gc < 0.6:
return 'Balanced GC content'
else:
return 'GC-rich region'
print(classify_gc('ATAATATATA')) # AT-rich region
print(classify_gc('ATGCATGCGC')) # Balanced GC content
print(classify_gc('GCGCGCGCGC')) # GC-rich region
18
BME 603/606: Computational Methods for Biological Modeling & Simulation
STOP_CODONS = {'TAA', 'TAG', 'TGA'}
def classify_codon(codon):
codon = codon.upper()
if len(codon) != 3:
return 'Invalid'
elif codon == 'ATG':
return 'Start codon'
elif codon in STOP_CODONS:
return 'Stop codon'
else:
return 'Coding codon'
print(classify_codon('ATG')) # Start codon
print(classify_codon('TAA')) # Stop codon
print(classify_codon('GCT')) # Coding codon
Python fundamentals: Conditionals (if/elif/else)
19
BME 603/606: Computational Methods for Biological Modeling & Simulation
sequence = 'ATGCGTACG'
# Find every position of dinucleotide 'CG'
positions = []
for i, base in enumerate(sequence):
if sequence[i:i+2] == 'CG':
positions.append(i)
print(positions) # [3, 7]
# Walk codons (step = 3)
for i in range(0, len(sequence) - 2, 3):
print(f'pos {i}: {sequence[i:i+3]}')
# pos 0: ATG
# pos 3: CGT
# pos 6: ACG
Python fundamentals: Enumerate/Range
20
BME 603/606: Computational Methods for Biological Modeling & Simulation
# log2 fold-change values per gene
expression = {'TP53': 3.2, 'MDM2': -1.4, 'BRCA1': 2.8,
'MYC': 4.1, 'PTEN': -2.3, 'EGFR': 1.1}
# Upregulated genes (log2FC > 2)
up = [g for g, v in expression.items() if v > 2]
# ['TP53', 'BRCA1', 'MYC']
# Downregulated genes (log2FC < -1)
dn = [g for g, v in expression.items() if v < -1]
# ['MDM2', 'PTEN']
# Absolute fold-change dictionary
abs_fc = {g: abs(v) for g, v in expression.items()}
Python fundamentals: List Comprehension
21
BME 603/606: Computational Methods for Biological Modeling & Simulation
population = 100 # initial cell count
doubling_time = 20 # minutes
max_time = 120 # minutes
time = 0
while time <= max_time:
print(f't={time:3d} min cells={population:,}')
time += doubling_time
population *= 2
# t= 0 min cells=100
# t= 20 min cells=200
# t= 40 min cells=400
# t= 60 min cells=800
# t= 80 min cells=1,600
# t=100 min cells=3,200
# t=120 min cells=6,400
Python fundamentals: While Loop
22
BME 603/606: Computational Methods for Biological Modeling & Simulation
def gc_content(seq):
seq = seq.upper()
return (seq.count('G') + seq.count('C')) / len(seq)
def melting_temp(seq):
# Wallace rule: 2(A+T) + 4(G+C) [short oligos]
seq = seq.upper()
at = seq.count('A') + seq.count('T')
gc = seq.count('G') + seq.count('C')
return 2 * at + 4 * gc
primer = 'ATGCGTACGATCG'
print(f'GC : {gc_content(primer):.1%}') # GC : 53.8%
print(f'Tm : {melting_temp(primer)} C') # Tm : 42 C
Python fundamentals: Functions
23
BME 603/606: Computational Methods for Biological Modeling & Simulation
def find_motif(sequence, motif, overlap=False):
# Return start positions of motif in sequence
positions, i = [], 0
step = 1 if overlap else len(motif)
while i <= len(sequence) - len(motif):
if sequence[i : i+len(motif)] == motif:
positions.append(i)
i += 1 if overlap else len(motif)
else:
i += 1
return positions
seq = 'ATATAT'
find_motif(seq, 'AT') # [0, 2, 4]
find_motif(seq, 'AT', overlap=True) # [0, 2, 4]
find_motif(seq, 'ATA') # [0, 2]
Python fundamentals: Default Arguments
24
BME 603/606: Computational Methods for Biological Modeling & Simulation
class Gene:
def __init__(self, name, sequence, chromosome):
self.name = name
self.sequence = sequence.upper()
self.chromosome = chromosome
def length(self):
return len(self.sequence)
def gc_content(self):
gc = self.sequence.count('G') + self.sequence.count('C')
return gc / len(self.sequence)
brca1 = Gene('BRCA1', 'ATGCGTACGATCG', 'chr17')
print(brca1.length()) # 13
print(brca1.gc_content()) # 0.538
Python fundamentals: Classes
25
BME 603/606: Computational Methods for Biological Modeling & Simulation
class GeneRegulatoryNetwork:
def __init__(self, name):
self.name = name
self.genes = {} # gene -> expression level
self.edges = [] # (regulator, target, type)
def add_gene(self, name, expression=0.0):
self.genes[name] = expression
def add_edge(self, regulator, target, kind='activates'):
self.edges.append((regulator, target, kind))
def regulators_of(self, target):
return [(r, k) for r, t, k in self.edges if t == target]
grn = GeneRegulatoryNetwork('p53 pathway')
for gene, expr in [('TP53', 2.4), ('MDM2', 0.8), ('CDKN1A', 1.6)]:
grn.add_gene(gene, expr)
grn.add_edge('TP53', 'MDM2', 'activates')
grn.add_edge('TP53', 'CDKN1A', 'activates')
grn.add_edge('MDM2', 'TP53', 'represses')
print(grn.regulators_of('TP53')) # [('MDM2', 'represses')]
Python fundamentals: Classes
26
BME 603/606: Computational Methods for Biological Modeling & Simulation
Conway’s Game of Life
27
BME 603/606: Computational Methods for Biological Modeling & Simulation
Conway’s Game of Life
28
BME 603/606: Computational Methods for Biological Modeling & Simulation
Course Website:� https://bio-modeling-uw-madison-f26.github.io/
In-class exercises
Please ask Colin to mark you for completion before end of class.
29
BME 603/606: Computational Methods for Biological Modeling & Simulation
Homework/Reminders