forked from harismallick/boyer-moore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteln.py
46 lines (34 loc) · 1.08 KB
/
teln.py
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
import pandas as pd
from Bio import SeqIO
def get_parent_seq(handle: str) -> str:
for record in SeqIO.parse(handle, 'fasta'):
if "parent" in record.id:
#print(record)
return record.seq
def get_mutations(handle: str, parent: str):
mut_dict = {}
counter_lim = len(parent)
for record in SeqIO.parse(handle, 'fasta'):
seq = record.seq
id = record.id
for i in range(counter_lim):
if seq[i] != parent[i]:
if id not in mut_dict.keys():
mut_dict[id] = [(i+1, seq[i])]
else:
mut_dict[id].append((i+1, seq[i]))
return mut_dict
def get_dataframe(mut_dict: dict):
df = pd.DataFrame.from_dict(mut_dict, orient='index')
#print(df)
df.to_csv("2023-01-16_teln_mutants.csv")
pass
def main():
#handle: str = 'test_file.txt'
handle: str = 'TL_Rd2_AA.txt'
wt_seq: str = get_parent_seq(handle)
mut_dict: dict = get_mutations(handle, wt_seq)
#print(mut_dict)
get_dataframe(mut_dict)
if __name__ == '__main__':
main()