2 # Copyright (C) 2003 Rune Linding - EMBL
4 # GlobPlot is licensed under the Academic Free license
10 from os import system,popen3
12 relpath = re.sub("/GlobPipe.py$","",argv[0])
13 cwd = re.sub("/$","", os.getcwd())
14 print '!' +os.getcwd()
16 newpath =cwd+"/"+relpath+"/biopython-1.50"
17 sys.path.append(newpath)
27 RL = {'N':0.229885057471264,'P':0.552316012226663,'Q':-0.187676577424997,'A':-0.261538461538462,'R':-0.176592654077609, \
28 'S':0.142883029808825,'C':-0.0151515151515152,'T':0.00887797506611258,'D':0.227629796839729,'E':-0.204684629516228, \
29 'V':-0.386174834235195,'F':-0.225572305974316,'W':-0.243375458622095,'G':0.433225711769886,'H':-0.00121743364986608, \
30 'Y':-0.20750516775322,'I':-0.422234699606962,'K':-0.100092289621613,'L':-0.337933495925287,'M':-0.225903614457831}
32 def Sum(seq,par_dict):
40 parameter = par_dict[residue]
46 sum = sum + parameter#*math.log10(p)
47 ssum = float(fpformat.fix(sum,10))
52 def getSlices(dydx_data, DOM_join_frame, DOM_peak_frame, DIS_join_frame, DIS_peak_frame):
61 for i in range( len(dydx_data) ):
63 if in_DOMslice and dydx_data[i] > 0:
64 DOMslices.append([beginDOMslice, endDOMslice])
67 elif in_DISslice and dydx_data[i] < 0:
68 DISslices.append([beginDISslice, endDISslice])
70 # elseif inSlice expandslice
75 # if not in slice and dydx !== 0 start slice
76 if dydx_data[i] > 0 and not in_DISslice:
80 elif dydx_data[i] < 0 and not in_DOMslice:
86 DOMslices.append([beginDOMslice, endDOMslice])
88 DISslices.append([beginDISslice,endDISslice])
91 while k < len(DOMslices):
92 if k+1 < len(DOMslices) and DOMslices[k+1][0]-DOMslices[k][1] < DOM_join_frame:
93 DOMslices[k] = [ DOMslices[k][0], DOMslices[k+1][1] ]
95 elif DOMslices[k][1]-DOMslices[k][0]+1 < DOM_peak_frame:
99 while l < len(DISslices):
100 if l+1 < len(DISslices) and DISslices[l+1][0]-DISslices[l][1] < DIS_join_frame:
101 DISslices[l] = [ DISslices[l][0], DISslices[l+1][1] ]
103 elif DISslices[l][1]-DISslices[l][0]+1 < DIS_peak_frame:
107 return DOMslices, DISslices
110 def SavitzkyGolay(window,derivative,datalist):
111 SG_bin = '/homes/pvtroshin/soft/GlobPipe-2.3/sav_gol -V0 '
112 stdin, stdout, stderr = popen3(SG_bin + '-D' + str(derivative) + ' -n' + str(window)+','+str(window))
113 for data in datalist:
114 stdin.write(`data`+'\n')
118 print stderr.readlines()
119 results = stdout.readlines()
122 for result in results:
123 SG_results.append(float(fpformat.fix(result,6)))
127 def reportSlicesTXT(slices, sequence, maskFlag):
128 if maskFlag == 'DOM':
129 coordstr = '|GlobDoms:'
130 elif maskFlag == 'DIS':
131 coordstr = '|Disorder:'
135 #by default the sequence is in uppercase which is our search space
138 # insert seq before first slide
140 s = sequence[0:slices[0][0]]
143 for i in range(len(slices)):
146 coordstr = coordstr + ', '
147 coordstr = coordstr + str(slices[i][0]+1) + '-' + str(slices[i][1]+1)
148 #insert the actual slice
149 if maskFlag == 'DOM':
150 s = s + lower(sequence[slices[i][0]:(slices[i][1]+1)])
151 if i < len(slices)-1:
152 s = s + upper(sequence[(slices[i][1]+1):(slices[i+1][0])])
154 elif slices[i][1] < len(sequence)-1:
155 s = s + lower(sequence[(slices[i][1]+1):(len(sequence))])
156 elif maskFlag == 'DIS':
157 s = s + upper(sequence[slices[i][0]:(slices[i][1]+1)])
158 #insert untouched seq between disorder segments, 2-run labelling
159 if i < len(slices)-1:
160 s = s + sequence[(slices[i][1]+1):(slices[i+1][0])]
162 elif slices[i][1] < len(sequence)-1:
163 s = s + sequence[(slices[i][1]+1):(len(sequence))]
169 smoothFrame = int(sys.argv[1])
170 DOM_joinFrame = int(sys.argv[2])
171 DOM_peakFrame = int(sys.argv[3])
172 DIS_joinFrame = int(sys.argv[4])
173 DIS_peakFrame = int(sys.argv[5])
174 file = str(sys.argv[6])
178 print ' ./GlobPipe.py SmoothFrame DOMjoinFrame DOMpeakFrame DISjoinFrame DISpeakFrame FASTAfile'
179 print ' Optimised for ELM: ./GlobPlot.py 10 8 75 8 8 sequence_file'
180 print ' Webserver settings: ./GlobPlot.py 10 15 74 4 5 sequence_file'
182 parser = Fasta.RecordParser()
183 iterator = Fasta.Iterator(db,parser)
186 cur_record = iterator.next()
187 #uppercase is searchspace
188 seq = upper(cur_record.sequence)
190 sum_vector = Sum(seq,RL)
192 smooth = SavitzkyGolay(`smoothFrame`,0, sum_vector)
193 dydx_vector = SavitzkyGolay(`smoothFrame`,1, sum_vector)
195 sumHEAD = sum_vector[:smoothFrame]
196 sumTAIL = sum_vector[len(sum_vector)-smoothFrame:]
199 for i in range(len(sumHEAD)):
201 dHEAD = (sumHEAD[i+1]-sumHEAD[i])/2
203 dHEAD = (sumHEAD[i]-sumHEAD[i-1])/2
205 dTAIL = (sumTAIL[i+1]-sumTAIL[i])/2
207 dTAIL = (sumTAIL[i]-sumTAIL[i-1])/2
208 newHEAD.append(dHEAD)
209 newTAIL.append(dTAIL)
210 dydx_vector[:smoothFrame] = newHEAD
211 dydx_vector[len(dydx_vector)-smoothFrame:] = newTAIL
212 globdoms, globdis = getSlices(dydx_vector, DOM_joinFrame, DOM_peakFrame, DIS_joinFrame, DIS_peakFrame)
213 s_domMask, coordstrDOM = reportSlicesTXT(globdoms, seq, 'DOM')
214 s_final, coordstrDIS = reportSlicesTXT(globdis, s_domMask, 'DIS')
215 sys.stdout.write('>'+cur_record.title+coordstrDOM+coordstrDIS+'\n')
218 except AttributeError: