-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeep_mutational_scanning.py
More file actions
59 lines (47 loc) · 2.09 KB
/
Deep_mutational_scanning.py
File metadata and controls
59 lines (47 loc) · 2.09 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
52
53
54
55
56
57
58
59
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import re
np.random.seed(19680801)
def AA_mutagenesis(name_query, sequence_query):
'''Generate a single-point mutation with defined amino acids upon a given sequence. Here the function AA_mutagenesis()
should take name_query and sequence_query of the fasta entry'''
# Create two lists for new mutants ids and sequences, include sequence candidate (name_0, seq_0)
name_0 = name_query
seq_0 = sequence_query
ids =[name_0,]
seqs =[seq_0,]
list_aa = ['A','C','D','E','F','G','H','I','K','L','M','N','P','Q','R','S','T','V','W','Y']
def AA_mutation(sequence, position, mutation):
# Generate a single-point mutation upon a given sequence
mutation = str(mutation)
for char in sequence:
if char == position.upper() or char == position.lower():
sequence = sequence.replace(char, mutation)
return sequence
# AA mutagenesis applied to seq_0, new ids with name_0
for aa in list_aa:
for i in range(len(seq_0)):
mutant = AA_mutation(seq_0, seq_0[i], aa)
new_name = '[' + seq_0[i] + str(i+1) + aa + ']' + name_0
ids.append(new_name)
seqs.append(mutant)
#return ids, seqs
#print(new_name, mutant)
# Convert that labelled list into a dataframe
mutagenesis_df = pd.DataFrame(seqs, columns=['SEQUENCE'], index=ids)
link = "./Data/" + name_0 + '_mutagenesis.csv'
mutagenesis_df.to_csv(link)
def fasta_converter(database):
# Convert that labelled list into a dataframe
'''Use the indices of the database and the column 'SEQUENCE' to create a fasta file'''
link2 = "./Data/" + name_0 + '_mutagenesis.fasta'
ofile = open(link2, "w")
for i in range(len(database.SEQUENCE)):
ofile.write(">" + database.index[i] + "\n" +database.SEQUENCE[i] + "\n")
ofile.close()
# Convert that dataframe into fasta file
fasta_converter(mutagenesis_df)
if __name__ == "__main__":
AA_mutagenesis()