import fileinput, re, cgi
def escape(lineiterator=fileinput.input,
cgi_escape=True, tag_with_pre=True, tag_with_br=False):
output = []
if tag_with_pre: output.append('<pre>\n')
for line in lineiterator:
if cgi_escape: line = cgi.escape(line)
line = re.sub(r'^(\s*)\s',
lambda m: ' '*m.end(),
line.rstrip())
output.append(line)
if tag_with_br:
output.append('<br>\n')
else:
output.append('\n')
if tag_with_pre: output.append('</pre>\n')
return ''.join(output)
Saturday, March 28, 2009
How to publish python code in blogger
Thanks to Paddy.
Access PFAM domains from UniProt accessions using python
import xml.dom.minidom as minidom
def getPFamAnnotationByAcc(acc):
res_list = []
slurpp = pycurl.Curl()
slurpp.setopt(pycurl.URL, "http://pfam.sbc.su.se:43210/protein/%s"%acc)
slurpp.setopt(pycurl.POSTFIELDS, "output=xml")
file = open("tmp.xml", "w")
slurpp.setopt(pycurl.FILE, file)
slurpp.perform()
file.close()
#parse the PFam xml file searching for matches
dom = minidom.parse('tmp.xml')
for m in dom.getElementsByTagName('match'):
atts = m.attributes.items()
for l in m.getElementsByTagName('location'):
for t in l.attributes.items():
atts.append(t)
res_list.append(atts)
return res_list
Subscribe to:
Posts (Atom)