annotate umelt_service.py @ 6:f201e8c6e004 draft default tip

Uploaded
author ben-warren
date Mon, 07 Jul 2014 19:28:17 -0400
parents b321e0517be3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
1 #!/usr/bin/env python
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
2
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
3 ##interrogate umelt service at Univ of Utah
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
4 import sys
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
5 import urllib
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
6 import urllib2
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
7 import xml.etree.ElementTree as ET
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
8 import numpy as np
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
9 import scipy as sp
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
10 from scipy import interpolate
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
11 from scipy.interpolate import interp1d
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
12
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
13
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
14 url='https://www.dna.utah.edu/db/services/cgi-bin/udesign.cgi'
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
15 timeout_sec=500 ## default for timeout
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
16
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
17 # Query UW melt prediction service for a single sequence, returning default array for helicity, assuming within temperature range of 65-95
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
18 def getmelt(input_seq):
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
19 values = {'seq' : input_seq, 'rs':0, 'dmso':0,'cation': 20 ,'mg': 2} # Note the buffer conditions
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
20 data = urllib.urlencode(values)
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
21 req = urllib2.Request(url, data)
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
22 try:
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
23 response = urllib2.urlopen(req,timeout=timeout_sec)
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
24 except urllib2.HTTPError, e:
6
f201e8c6e004 Uploaded
ben-warren
parents: 5
diff changeset
25 print >> sys.stderr, 'The server couldn\'t fulfill the request.'
f201e8c6e004 Uploaded
ben-warren
parents: 5
diff changeset
26 print >> sys.stderr, 'Error code: ', e.code
5
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
27 except urllib2.URLError, e:
6
f201e8c6e004 Uploaded
ben-warren
parents: 5
diff changeset
28 print >> sys.stderr, 'We failed to reach a server.'
f201e8c6e004 Uploaded
ben-warren
parents: 5
diff changeset
29 print >> sys.stderr, 'Reason: ', e.reason
5
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
30 else:
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
31 melt_data = response.read()
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
32 tree = ET.fromstring(melt_data)
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
33 helicity = [amp.find('helicity').text.split() for amp in tree.findall('amplicon')]
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
34 hels = np.array(helicity[0], dtype=np.float32).transpose()
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
35 return hels
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
36
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
37 # helicity[0] used because the default retreived data is a list of 3 lists (for WT, mu and hets). The 3 lists are identical for our data (no IUPAC) so only [0] is used.
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
38
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
39 def getTm(hel_array):
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
40 temps=np.arange(65,100.5,0.5) # Temperature range of 65-100.5. Step of 0.5 NEEDS TO BE CHECKED..REcent change?
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
41 tck = interpolate.splrep(temps,hel_array,s=0)
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
42 xnew =np.arange(65,95.5,0.05)
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
43 yder = interpolate.splev(xnew,tck,der=1) # der=1, first derivative
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
44 return xnew[yder.argmin()] # Returns the x value corresponding to the minimum (peak) y value -> Tm