-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGenerateMappingFiles.py
More file actions
executable file
·29 lines (27 loc) · 947 Bytes
/
GenerateMappingFiles.py
File metadata and controls
executable file
·29 lines (27 loc) · 947 Bytes
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
#!/usr/bin/env python
import glob
import re
import os
import sys
"""
Maps UniprotKB/Swissprot IDs from the cafa target files to the CAFA IDs
Files to be mapped should have the format <somestring>.taxid.(fasta|tfa)
"""
def make_mapping_files(targetdir="TargetFiles",mapdir="MappingFiles"):
filepat = re.compile(r'%s\/[^\.]+\.([0-9]+)\.(tfa|fasta)' % targetdir)
if not os.path.exists(mapdir):
os.makedirs(mapdir)
for infilename in glob.glob(targetdir+"/*"):
mid = re.match(filepat, infilename)
if not mid:
continue
outfilename = "%s/mapping.%s.map" % (mapdir,str(mid.group(1)))
fh1 = open(infilename, "r")
fh2 = open(outfilename, "w")
for line in fh1:
if line[0] == ">":
fh2.write(str("\t".join(line[1:].split()))+"\n")
fh2.close()
fh1.close()
if __name__ == "__main__":
make_mapping_files(sys.argv[1], sys.argv[2])