comparison orthologs/ucsb_hamster/unbuild.py @ 0:5b9a38ec4a39 draft default tip

First commit of old repositories
author osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
date Tue, 11 Mar 2014 12:19:13 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:5b9a38ec4a39
1 #!/usr/bin/env python
2 '''
3 Usage: unbuild.py outputDirectoryName hmmFileWithTabs
4 This script takes a tab sperated, newline escaped HMM models file then splits the models up and makes a file list.
5 The output files are put into the directory outputDirectoryName.
6 '''
7 from sys import argv, exit
8 import os
9
10
11 def parse(line):
12 line = line.partition('\t')
13 name = line[0] + ".hmm"
14 data = line[2].replace("\\n", "\n")
15 return name, data
16
17
18 def writeFile(location, data):
19 try:
20 with open(location, 'w') as f:
21 f.write(data)
22 except:
23 pass
24
25
26 def createDir(dir):
27 if not os.path.exists(dir):
28 os.makedirs(dir)
29
30
31 if __name__ == "__main__":
32 if len(argv) != 3:
33 print "Usage: unbuild.py outputDirectoryName hmmFileWithTabs"
34 exit()
35 dir = argv[1]
36 createDir(dir)
37
38 name_list = [] # Stores new file names
39
40 # Read data and seperate into files.
41 with open(argv[2], 'r') as f:
42 for line in f:
43 name, data = parse(line)
44 if data.strip() == "": # no data? skip it.
45 continue
46 name_list.append(name)
47 name = dir + os.sep + name
48 writeFile(name, data)
49
50 # Write new file names to a file.
51 name_list_location = dir + os.sep + "hmmlist.txt"
52 with open(name_list_location, 'w') as f:
53 for name in name_list:
54 f.write(name + "\n")