Genomics and Machine Learning
DNA Sequence Analysis
One-Hot Encoding
import numpy as np
def one_hot_encode(sequence, seq_length=1000):
nucleotides = {'A': 0, 'C': 1, 'G': 2, 'T': 3}
encoding = np.zeros((seq_length, 4), dtype=np.float32)
for i, base in enumerate(sequence[:seq_length]):
if base in nucleotides:
encoding[i, nucleotides[base]] = 1.0
return encoding
Sequence Alignment with ML
Pairwise Alignment Score
Learned Scoring
class NeuralAligner(nn.Module):
def __init__(self, embed_dim=32):
super().__init__()
self.nuc_embed = nn.Embedding(4, embed_dim)
self.score_matrix = nn.Linear(embed_dim * 2, 1)
def score_pair(self, nuc1, nuc2):
e1, e2 = self.nuc_embed(nuc1), self.nuc_embed(nuc2)
return self.score_matrix(torch.cat([e1, e2], dim=-1))
Variant Calling
Gene Expression Prediction
class ExpressionPredictor(nn.Module):
def __init__(self, seq_length=10000):
super().__init__()
self.conv1 = nn.Conv1d(4, 64, kernel_size=15, padding=7)
self.conv2 = nn.Conv1d(64, 128, kernel_size=15, padding=7)
self.pool = nn.AdaptiveAvgPool1d(1)
self.fc = nn.Sequential(nn.Linear(128, 64), nn.ReLU(),
nn.Dropout(0.3), nn.Linear(64, 1))
def forward(self, x):
x = torch.relu(self.conv1(x))
x = torch.relu(self.conv2(x))
return self.fc(self.pool(x).squeeze(-1))
Multi-Modal Genomic Models
Evaluation
- Pearson correlation for expression prediction
- AUC-ROC for variant pathogenicity
- Cohen's kappa: