-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpos_switch.py
60 lines (48 loc) · 2.31 KB
/
pos_switch.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import pandas as pd
from ms2pip.single_prediction import SinglePrediction
import spectrum_utils.spectrum as sus
import math
from itertools import permutations
from copy import deepcopy
def switch_pos_center(seq,pos_switch="middle",rev_length=2):
if pos_switch == "middle":
sel_pos = int(len(seq)/2)
if pos_switch == "left":
sel_pos = int(int(len(seq)/2)/2)
if pos_switch == "right":
sel_pos = int(len(seq)/2)+int(int(len(seq)/2)/2)
new_seq = seq[:sel_pos-math.ceil(rev_length/2)+1]+seq[sel_pos-math.ceil(rev_length/2)+1:sel_pos+int(rev_length/2)+1][::-1]+seq[sel_pos+int(rev_length/2)+1:]
return pd.Series({"seq":new_seq,"aa_sw1":seq[sel_pos-math.ceil(rev_length/2)+1:sel_pos+int(rev_length/2)+1],"aa_sw2":seq[sel_pos-math.ceil(rev_length/2)+1:sel_pos+int(rev_length/2)+1][::-1]})
def get_all_combs(seq,rev_length=2,pos_switch="middle"):
if pos_switch == "middle":
sel_pos = int(len(seq)/2)
if pos_switch == "left":
sel_pos = int(int(len(seq)/2)/2)
if pos_switch == "right":
sel_pos = int(len(seq)/2)+int(int(len(seq)/2)/2)
sel_seq = seq[sel_pos-math.ceil(rev_length/2)+1:sel_pos+int(rev_length/2)+1][::-1]
all_combs = ["".join(v) for v in permutations(sel_seq)]
ret_dict = {}
for idx,v in enumerate(all_combs):
new_seq = seq[:sel_pos-math.ceil(rev_length/2)+1]+v+seq[sel_pos+int(rev_length/2)+1:]
if v == sel_seq:
continue
ret_dict[idx] = {"seq":new_seq,"aa_sw1":sel_seq,"aa_sw2":v}
return pd.DataFrame(ret_dict)
def mutate_aa(seq,mutate_to):
sel_pos = int(len(seq)/2)
orig_aa = str(seq[sel_pos])
new_seq = list(seq)
new_seq[sel_pos] = mutate_to
new_seq = "".join(new_seq)
return pd.Series({"seq":new_seq,"sel_pos":sel_pos,"aa_sw1":orig_aa,"aa_sw2":new_seq[sel_pos]})
#def switch_two_pos_center(seq,pos_switch="middle"):
# sel_pos = int(len(seq)/2)
# return pd.Series({"seq":seq[:sel_pos]+seq[sel_pos:sel_pos+4][::-1]+seq[sel_pos+4:],"aa_sw1":}
def get_predicted_spectrum(peptide, modifications, charge, model="HCD2021", ms2pip_instance=None):
if not ms2pip_instance:
ms2pip = SinglePrediction()
else:
ms2pip = ms2pip_instance
mz, intensity, annotation = ms2pip.predict(peptide, modifications, charge, model=model)
return (mz, intensity)