import numpy as np import pandas as pd --- Load PWM --- pwmfile = 'sigma70-PWM.txt'…
- User
import numpy as np import pandas as pd
--- Load PWM ---
pwm_file = 'sigma70-PWM.txt' pwm_df = pd.read_csv(pwm_file, sep='\t')
seq_length = len(pwm_df)
--- Load FASTA sequence ---
def read_fasta(filename): seq = [] with open(filename) as f: for line in f: if line.startswith('>'): continue seq.append(line.strip()) return ''.join(seq).lower()
fasta_file = 'sega007.fasta' # Change to your file path if needed sequence = read_fasta(fasta_file)
--- Slide window and calculate PWM scores ---
scores = [] for i in range(len(sequence) - seq_length + 1): window = sequence[i:i+seq_length] score = 0.0 for j, nt in enumerate(window): # Optionally, you can handle invalid characters as needed (e.g., skip window or assign a penalty). score += pwm_df.loc[j, nt.upper()] scores.append(score)
Pad scores with zeros to match the length of the FASTA sequence
padded_scores = np.zeros(len(sequence)) padded_scores[:len(scores)] = scores
--- Save array to file ---
np.save('sliding_scores-full-pos.npy', padded_scores) print(f"Saved {len(padded_scores)} scores to sliding_scores.npy")
Modify this file to store the scores at the position of +length pwm-20
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.