-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathep2 ProfileMatrix.py
More file actions
51 lines (41 loc) · 1.41 KB
/
Copy pathep2 ProfileMatrix.py
File metadata and controls
51 lines (41 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def Count(motif):
"""
Counts the frequency of each nucleotide (A, C, G, T) at each position in the motif.
Args:
motif (list): A list of DNA sequences of the same length.
Returns:
dict: A dictionary where keys are nucleotides and values are lists of frequencies.
"""
count = {nt: [0] * len(motif[0]) for nt in "ACGT"}
for sequence in motif:
for i, nucleotide in enumerate(sequence):
count[nucleotide][i] += 1
return count
def Profile(motif):
"""
Calculates the profile matrix for a given motif by converting nucleotide counts to probabilities.
Args:
motif (list): A list of DNA sequences of the same length.
Returns:
dict: A dictionary where keys are nucleotides and values are lists of probabilities.
"""
t = len(motif) # Total number of sequences
k = len(motif[0]) # Length of each sequence
profile = {} # Initialize profile matrix
# Get nucleotide counts using the Count function
count_matrix = Count(motif)
# Convert counts to probabilities
for nt in "ACGT":
profile[nt] = [count / t for count in count_matrix[nt]]
return profile
# Example motif input
motif = [
'AACGTA',
'CCCGTT',
'CACCTT',
'GGATTA',
'TTCCGG'
]
# Calculate and display the profile matrix
profile_matrix = Profile(motif)
print("Profile Matrix:\n", profile_matrix)