-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseq_alignment.py
More file actions
41 lines (31 loc) · 1.36 KB
/
seq_alignment.py
File metadata and controls
41 lines (31 loc) · 1.36 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
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 23 09:20:24 2024
@author: Marina Moro López
"""
from tkinter.filedialog import askopenfile
def read_sequence_from_file(prompt):
print(prompt)
file = askopenfile(mode='r')
sequence = file.readlines()[1:]
sequence = ''.join(sequence).replace('\n', '')
return sequence
def align_sequences(gene_seq, patient_seq):
alignment = [gene_seq[position] == patient_seq[position] for position in range(len(gene_seq))]
return alignment
def get_mutation_positions(alignment):
mutation_positions = [position for position, match in enumerate(alignment) if not match]
return mutation_positions
def report_mutations(mutation_positions, gene_seq, patient_seq):
for mutation in mutation_positions:
print(f"Mutation position: {mutation + 1}")
print(f"Original base: {gene_seq[mutation]}")
print(f"Mutated base: {patient_seq[mutation]}")
def main():
gene_seq = read_sequence_from_file('Please select the file with the gene of reference')
patient_seq = read_sequence_from_file('Please select the file with the patient sequence')
alignment = align_sequences(gene_seq, patient_seq)
mutation_positions = get_mutation_positions(alignment)
report_mutations(mutation_positions, gene_seq, patient_seq)
if __name__ == "__main__":
main()