-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_pfam_search.py
45 lines (36 loc) · 1.15 KB
/
parse_pfam_search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
'''
Parse transposase Pfam accessions and descriptions from pfam.xfam.org search.
Created: March 6, 2016
Last modified: March 6, 2016
Ian Rambo
'''
import re
import urllib.request
import urllib.parse
#==============================================================================
#GLOBAL VARIABLES
rootDir = '/Users/imrambo/Dropbox/OysterRocksMethylationProject'
print('\n-----BEGIN-----\n')
query = 'transposase'
urlString = 'http://pfam.xfam.org/search/keyword?query=%s&submit=Submit' % query
url = urllib.request.urlopen(urlString)
urlSource = str(url.read())
pfam = re.findall(r'family/PF\d+\">(PF\d+)<', urlSource)
pfamDesc = re.findall(r'<td class\=\"desc\">(.*?)</td>', urlSource)
outfile = open('%s/transposase_pfams.txt' % rootDir, 'w')
if len(pfam) == len(pfamDesc) :
print('length matches')
pfamDict = {}
for p in pfamDesc :
if re.search(r'[Tt]ransposase', p) :
pfamDict[pfam[p]] = pfamDesc[p]
else :
pass
for p in pfam :
if p in pfamDict :
outfile.write(p + '\t' + pfamDict[p] + '\n')
else :
pass
outfile.close()
print('\n-----DONE-----\n')