Untitled conversation
- Usercode
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
import pandas as pd
import numpy as np
import math
# Read the CSV file with no headers and appropriate delimiter
df = pd.read_csv('3548.csv', delimiter=';', header=None)
# Convert the first column (sequences) to lowercase
df['promoter_sequence'] = df[0].str.lower()
# Get the length of the first sequence (assuming all are the same length)
seq_length = len(df['promoter_sequence'].iloc[0])
# Initialize count matrix for A, C, G, T
counts = {
'a': np.zeros(seq_length),
'c': np.zeros(seq_length),
'g': np.zeros(seq_length),
't': np.zeros(seq_length)
}
# Count nucleotides at each position
for seq in df['promoter_sequence']:
for i, nucleotide in enumerate(seq):
counts[nucleotide][i] += 1
# Convert counts to probabilities
total_sequences = len(df)
ppm = {base: counts[base] / total_sequences for base in 'acgt'}
# Save PWM to file
with open('sigma70-PWM.txt', 'w') as f:
f.write('pos\tA\tC\tG\tT\n')
for i in range(seq_length):
a_val = ppm['a'][i]
c_val = ppm['c'][i]
g_val = ppm['g'][i]
t_val = ppm['t'][i]
# Apply log2 transformation with background frequencies
a_log = math.log2(a_val / 0.246)
c_log = math.log2(c_val / 0.254)
g_log = math.log2(g_val / 0.254)
t_log = math.log2(t_val / 0.246)
# Write to file (no rounding, exact values)
f.write(f"{i+1}\t{a_log}\t{c_log}\t{g_log}\t{t_log}\n")
Convert this code into PPM calculator instead of PWM calculator.
Here's the modified code to calculate a Position Probability Matrix (PPM) instead of a PWM:
import pandas as pd
import numpy as np
# Read the CSV file with no headers and appropriate delimiter
df = pd.read_csv('3548.csv', delimiter=';', header=None)
# Convert the first column (sequences) to lowercase
df['promoter_sequence'] = df[0].str.lower()
# Get the length of the first sequence (assuming all are the same length)
seq_length = len(df['promoter_sequence'].iloc[0])
# Initialize count matrix for A, C, G, T
counts = {
'a': np.zeros(seq_length),
'c': np.zeros(seq_length),
'g': np.zeros(seq_length),
't': np.zeros(seq_length)
}
# Count nucleotides at each position
for seq in df['promoter_sequence']:
for i, nucleotide in enumerate(seq):
counts[nucleotide][i] += 1
# Convert counts to probabilities (PPM)
total_sequences = len(df)
ppm = {base: counts[base] / total_sequences for base in 'acgt'}
# Save PPM to file
with open('sigma70-PPM.txt', 'w') as f:
f.write('pos\tA\tC\tG\tT\n')
for i in range(seq_length):
a_val = ppm['a'][i]
c_val = ppm['c'][i]
g_val = ppm['g'][i]
t_val = ppm['t'][i]
# Write probabilities directly without log transformation
f.write(f"{i+1}\t{a_val}\t{c_val}\t{g_val}\t{t_val}\n")
Key changes made from the original PWM code:
The resulting PPM file will contain the raw probabilities of each nucleotide at each position, which is the standard definition of a Position Probability Matrix.