0
|
1
|
|
2 def fasta_from_SAR_dict(sar_dict,fa_file):
|
|
3 """ makes a multi fasta with candidates from SAR dictionary """
|
|
4 with fa_file as f:
|
|
5 for data in sar_dict.values():
|
|
6 f.writelines(">{}\n".format(data["description"]))
|
|
7 f.writelines("{}\n".format(data["sequence"]))
|
|
8
|
|
9 def gff3_from_SAR_dict(sar_dict,gff3_file):
|
|
10 """ make a multi gff3 with candidates from SAR dictionary """
|
|
11 gff3_cols = ["Seqid","Source","Type","Start","End","Score","Strand","Phase","Attributes"]
|
|
12 with gff3_file as f:
|
|
13 f.writelines(f"{gff3_cols[0]}\t{gff3_cols[1]}\t{gff3_cols[2]}\t{gff3_cols[3]}\t{gff3_cols[4]}\t{gff3_cols[5]}\t{gff3_cols[6]}\t{gff3_cols[7]}\t{gff3_cols[8]}\n")
|
|
14 if sar_dict:
|
|
15 #print(sar_dict)
|
|
16 for name, data in sar_dict.items():
|
|
17 min_idx = 0
|
|
18 f.writelines("##gff-version 3\n")
|
|
19 f.writelines(f"##sequence-region {name}\n")
|
|
20 n_start, n_end = split_seq_string(data["TMD_"+str(data["biggest_sar"])][min_idx][4])
|
|
21 sar_start, sar_end = split_seq_string(data["TMD_"+str(data["biggest_sar"])][min_idx][5])
|
|
22 c_start, c_end = split_seq_string(data["TMD_"+str(data["biggest_sar"])][min_idx][6])
|
|
23 f.writelines(f'{name}\tSAR_finder\tTopological domain\t{n_start}\t{n_end}\t.\t.\t.\tNote=N-terminal net charge is {data["TMD_"+str(data["biggest_sar"])][min_idx][2]}\n')
|
|
24 f.writelines(f'{name}\tSAR_finder\tSAR domain\t{sar_start}\t{sar_end}\t.\t.\t.\tNote=residue % in SAR {[perc for perc in data["TMD_"+str(data["biggest_sar"])][min_idx][3]]},Total % is {round(sum(j for i,j in data["TMD_"+str(data["biggest_sar"])][min_idx][3]),2)}\n')
|
|
25 f.writelines(f'{name}\tSAR_finder\tTopological domain\t{c_start}\t{c_end}\t.\t.\t.\tNote=C-terminus\n')
|
|
26 else:
|
|
27 f.writelines("##gff-version 3\n")
|
|
28 f.writelines(f"##sequence-region\n")
|
|
29
|
|
30
|
|
31 def tab_from_SAR_dict(sar_dict,stat_file,hydrophillic_res, sar_min, sar_max):
|
|
32 """ convert SAR dict to a dataframe """
|
|
33 columns = ["Name","Protein Sequence","Protein Length","SAR Length","SAR Start","Putative SAR Sequence","SAR End",[f"{res}%" for res in hydrophillic_res],"% Total","N-term Sequence","N-term net Charge"] # using different residues for percent calc: [f"{res}%" for res in hydrophillic_res]
|
|
34 with stat_file as f:
|
|
35 f.writelines(f"{columns[0]}\t{columns[1]}\t{columns[2]}\t{columns[3]}\t{columns[4]}\t{columns[5]}\t{columns[6]}\t{columns[7]}\t{columns[8]}\t{columns[9]}\t{columns[10]}\n")
|
|
36 if sar_dict:
|
|
37 #print(sar_dict)
|
|
38 for name, data in sar_dict.items():
|
|
39 for tmd_size in range(sar_max, sar_min-1, -1):
|
|
40 if "TMD_"+str(tmd_size) in data:
|
|
41 for each_match in data["TMD_"+str(tmd_size)]:
|
|
42 if each_match != [""]:
|
|
43 #print(f"{name} - {data}")
|
|
44 #print(each_match)
|
|
45 #for perc in each_match[3]:
|
|
46 # print(perc)
|
|
47 try:
|
|
48 f.writelines(f'{name}\t{data["sequence"]}\t{data["size"]}\t{tmd_size}\t{int(each_match[7])+1}\t{each_match[0]}\t{int(each_match[8])+1}\t{[perc for perc in each_match[3]]}\t{round(sum(j for i,j in each_match[3]),2)}\t{each_match[1]}\t{each_match[2]}\n')
|
|
49 except IndexError:
|
|
50 f.writelines(f'ERROR\tERROR\tERROR\tERROR\tERROR\tERROR\tERROR\tERROR\tERROR\tERROR\tERROR\n')
|
|
51 else:
|
|
52 continue
|
|
53
|
|
54 def stat_file_from_SAR_dict(sar_dict, stat_file, sar_min, sar_max):
|
|
55 """ summary statistics from SAR finder function """
|
|
56 with stat_file as f:
|
|
57 f.writelines("..........:::::: Candidate SAR Proteins ::::::..........\n\n")
|
|
58 if sar_dict:
|
|
59 for data in sar_dict.values():
|
|
60 f.writelines("Protein Description and Name: {}\n".format(data["description"]))
|
|
61 f.writelines("Protein Sequence: {}\n".format(data["sequence"]))
|
|
62 f.writelines("Protein Length: {}\n".format(data["size"]))
|
|
63 f.writelines("SAR Criteria matching region(s)\n")
|
|
64 for tmd_size in range(sar_max, sar_min-1, -1):
|
|
65 if "TMD_"+str(tmd_size) in data:
|
|
66 f.writelines("\nSAR length of {}:\n".format(tmd_size))
|
|
67 for each_match in data["TMD_"+str(tmd_size)]:
|
|
68 if each_match != ['']:
|
|
69 f.writelines("\nPotential SAR domain sequence: {}\n".format(each_match[0]))
|
|
70 f.writelines("N-term sequence: {}\n".format(each_match[1]))
|
|
71 f.writelines("N-term net charge: {}\n".format(each_match[2]))
|
|
72 for each_perc_calc in each_match[3]:
|
|
73 f.writelines("Percent {} content: {}%\n".format(each_perc_calc[0],each_perc_calc[1]))
|
|
74 f.writelines("N-term coords: {}\n".format(each_match[4]))
|
|
75 f.writelines("SAR coords: {}\n".format(each_match[5]))
|
|
76 f.writelines("C-term coords: {}\n".format(each_match[6]))
|
|
77 f.writelines("SAR start: {}\n".format(each_match[7]))
|
|
78 else:
|
|
79 continue
|
|
80 f.writelines("========================================================\n\n")
|
|
81 else:
|
|
82 f.writelines("No candidate SAR Proteins found")
|
|
83
|
|
84 def split_seq_string(input_range, python_indexing=True):
|
|
85 """ splits a #..# sequence into the two respective starts and ends, if python indexing, adds 1, otherwise keeps """
|
|
86 if python_indexing:
|
|
87 values = input_range.split("..")
|
|
88 start =int(values[0]) + 1
|
|
89 end = int(values[1]) + 1
|
|
90 else:
|
|
91 values = input_range.split("..")
|
|
92 start = values[0]
|
|
93 end = values[1]
|
|
94
|
|
95 return start, end
|
|
96
|
|
97 if __name__ == "__main__":
|
|
98 pass |