comparison PDAUG_Sequence_Based_Peptide_Generation/PDAUG_Sequence_Based_Peptide_Generation.py @ 0:7557b48b2872 draft

"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
author jay
date Wed, 28 Oct 2020 02:10:12 +0000
parents
children d7e684975db3
comparison
equal deleted inserted replaced
-1:000000000000 0:7557b48b2872
1 import sys
2 import itertools
3 import pandas as pd
4 import random
5 import os
6 from itertools import permutations
7 from random import shuffle
8 import argparse, sys
9 import pandas as pd
10
11
12 def MutatedPeptides(input_file, index_list, AA, outputFile):
13
14
15 index_list = [int(x) for x in index_list.split(',')]
16 out_put = []
17 AA = AA.split(',')
18 l = len(index_list)
19
20 replacements = [x for x in itertools.permutations(AA,l)]
21
22
23 counter = 0
24 to_modify = [x for x in input_file]
25
26 for replacement in replacements:
27 for i,index in enumerate(index_list):
28 to_modify[index_list[i]-1] = replacement[i]
29
30 counter = counter + 1
31 out_put.append("".join(to_modify).upper())
32
33 w = open(outputFile, 'w')
34
35 for i, f in enumerate(out_put):
36
37
38 w.write(">sequence_"+str(i)+'\n')
39 w.write(f+'\n')
40
41 def RandomPeptides(AAs, pep_length, out_pep_num, outputFile):
42
43
44 if int(pep_length) > 20:
45 print ("Max peptide lenth 20")
46 exit()
47 else:
48 pass
49
50 if int(out_pep_num) > 10000:
51 print ("Max peptide library 10000")
52 exit()
53 else:
54 pass
55
56 out_pep_lib = []
57 raw = AAs.split(',')
58
59 for x in range(int(out_pep_num)):
60 un_seq = []
61 for i in range(int(pep_length)):
62 un_seq.append(random.choice(raw))
63 out_pep_lib.append("".join(un_seq))
64
65
66 w = open(outputFile, 'w')
67
68
69 for i, f in enumerate(out_pep_lib):
70
71 w.write(">sequence_"+str(i)+'\n')
72 w.write(f+'\n')
73
74 def SlidingWindowPeptide(infile, window_size, frag_size, outputFile):
75
76
77 if int(window_size) > 10:
78 print ("Max window_size 10")
79 exit()
80 else:
81 pass
82 if int(frag_size) > 20:
83 print ("Max frag size is 20")
84 exit()
85 else:
86 pass
87
88
89 pep_list = []
90
91 f = open(infile)
92
93 lines = f.readlines()
94
95 flines = []
96
97 for line in lines:
98 if '>' in line:
99 pass
100 else:
101 flines.append(line.strip('\n'))
102 sequence = "".join(flines)
103
104 for i in range(int(frag_size)):
105 if int(frag_size) == len(sequence[i*int(window_size):i*int(window_size)+int(frag_size)]):
106 pep_list.append(sequence[i*int(window_size):i*int(window_size)+int(frag_size)])
107 else:
108 break
109
110 w = open(outputFile, 'w')
111
112
113 for i, f in enumerate(pep_list):
114
115 w.write(">sequence_"+str(i)+'\n')
116 w.write(f+'\n')
117
118 if __name__=='__main__':
119
120 parser = argparse.ArgumentParser(description='Deployment tool')
121 subparsers = parser.add_subparsers()
122
123 Mp = subparsers.add_parser('MutatedPeptides')
124 Mp.add_argument("-s","--sequence")
125 Mp.add_argument("-m","--mutation_site_list")
126 Mp.add_argument("-a","--AA_list")
127 Mp.add_argument("-d", "--outputFile", required=None, default='out.fasta', help="Path to out file")
128
129 Rp = subparsers.add_parser('RandomPeptides')
130 Rp.add_argument("-a","--AA_list")
131 Rp.add_argument("-l","--pep_length")
132 Rp.add_argument("-o","--out_pep_lenght")
133 Rp.add_argument("-d", "--outputFile", required=None, default=os.path.join(os.getcwd(),'report_dirr'), help="Path to out file")
134
135 Sp = subparsers.add_parser('SlidingWindowPeptide')
136 Sp.add_argument("-i","--InFile")
137 Sp.add_argument("-w","--winSize")
138 Sp.add_argument("-s","--FragSize")
139 Sp.add_argument("-d", "--outputFile", required=None, default=os.path.join(os.getcwd(),'report_dirr'), help="Path to out file")
140
141 args = parser.parse_args()
142
143 if sys.argv[1] == 'MutatedPeptides':
144 MutatedPeptides(args.sequence, args.mutation_site_list, args.AA_list, args.outputFile)
145
146 elif sys.argv[1] == 'RandomPeptides':
147 RandomPeptides(args.AA_list, args.pep_length, args.out_pep_lenght, args.outputFile)
148
149 elif sys.argv[1] == 'SlidingWindowPeptide':
150 SlidingWindowPeptide(args.InFile, args.winSize, args.FragSize, args.outputFile)
151
152 else:
153 print("In Correct Option:")
154