-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHuGO.py
More file actions
117 lines (98 loc) · 3.73 KB
/
Copy pathHuGO.py
File metadata and controls
117 lines (98 loc) · 3.73 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# Mac OS needs ssl certificates specified
def sslContext():
import certifi
import ssl
return ssl.create_default_context(cafile=certifi.where())
# The key separating accession code from the rest of the fasta id
def source_key(source):
if source == 'interpro':
f_key = '|'
elif source == 'panther':
f_key = '|'
elif source == 'pfam':
f_key = '/'
elif source == 'pfam2':
f_key = '_'
return(f_key)
# Generate fasta files from a meta data file
def curate_fasta(curatedData,f_curated_fasta,f_curated_fasta_full,source,full=True):
curated_fasta = []
sequenceColumn = 1
if source == 'pfam':
accessionColumn = 0
else:
accessionColumn = 2
for i,n in enumerate(curatedData):
if i > 0:
curated_fasta.append('>' + str(n[accessionColumn]))
curated_fasta.append(str(n[sequenceColumn]))
with open(f_curated_fasta, 'w+') as o:
for item in curated_fasta:
o.write(str(item) + '\n')
if not full:
curated_fasta = {}
accessionColumn = 2
sequenceColumn = 20
for i,n in enumerate(curatedData):
if i > 0:
curated_fasta[n[accessionColumn]] = n[sequenceColumn]
with open(f_curated_fasta_full, 'w+') as o:
for key in curated_fasta:
o.write('>{}\n{}\n'.format(key,curated_fasta[key]))
print('\tWrote curated fasta to: {}'.format(f_curated_fasta_full))
def HuGOvars(filename='IPR032358.fasta',project='DUF4867',fastaformat='interpro',maxthreads='14',percent_identity='99red',full=True):
import os
HuGO = {}
source = fastaformat
threads = maxthreads
pid = percent_identity
p_project = 'HuGO/' + project.replace(' ','_') + '/'
if not os.path.exists(p_project[0:-1]):
try:
os.makedirs(p_project[0:-1])
except:
raise 'Invalid characters in project name'
workdirs = ['metadata','fasta','blastp','cdhit','cytoscape','clustalo','interproscan','itol']
paths = {'project': p_project}
for d in workdirs:
paths[d] = paths['project'] + d + '/'
if not os.path.exists(p_project + d):
try:
os.makedirs(paths['project']+d)
except:
print('\tCould not create directory {}'.format(paths['project']+d))
files = {
'input_fasta': p_project + filename,
'meta_data': paths['metadata'] + 'meta_data.tsv',
'meta_data_curated': paths['metadata'] + 'meta_data_curated.tsv',
'curated_fasta': paths['fasta'] + project + '_curated.fasta',
'curated_fasta_full': paths['fasta'] + project + '_curated_full.fasta',
'itoldomains': paths['itol'] + project + 'iToldomains.txt'
}
files['curated_fasta_clustered'] = os.path.splitext(files['curated_fasta'])[0] + '_clustered_' + pid + '.fasta'
files['curated_fasta_full_clustered'] = os.path.splitext(files['curated_fasta_full'])[0] + '_clustered_' + pid + '.fasta'
HuGO['source'] = source
HuGO['threads'] = threads
HuGO['pid'] = pid
HuGO['files'] = files
HuGO['paths'] = paths
HuGO['full'] = full
HuGO['project'] = str(project)
return HuGO
def main():
import HuGO_getFamily
# HuGO_getFamily.main()
import HuGO_uniprot
# HuGO_uniprot.main()
import HuGO_cluster
# HuGO_cluster.main()
import HuGO_blast
HuGO_blast.main()
import HuGO_interproscan
# HuGO_interproscan.main(HuGO = HuGOvars(full=True))
import HuGO_itoldomains
# HuGO_itoldomains.main(HuGO = HuGOvars(full=True))
import HuGO_tree
# HuGO_tree.main()
if __name__ == "__main__":
main()