1 | #!/usr/bin/env python
|
---|
2 | #Dan Blankenberg
|
---|
3 |
|
---|
4 | import sys, os
|
---|
5 |
|
---|
6 | assert sys.version_info[:2] >= ( 2, 4 )
|
---|
7 |
|
---|
8 | def __main__():
|
---|
9 | base_dir = os.path.join( os.getcwd(), "bacteria" )
|
---|
10 | try:
|
---|
11 | base_dir = sys.argv[1]
|
---|
12 | except:
|
---|
13 | pass
|
---|
14 | #print "using default base_dir:", base_dir
|
---|
15 |
|
---|
16 | organisms = {}
|
---|
17 | for result in os.walk(base_dir):
|
---|
18 | this_base_dir,sub_dirs,files = result
|
---|
19 | for file in files:
|
---|
20 | if file[-5:] == ".info":
|
---|
21 | dict = {}
|
---|
22 | info_file = open(os.path.join(this_base_dir,file),'r')
|
---|
23 | info = info_file.readlines()
|
---|
24 | info_file.close()
|
---|
25 | for line in info:
|
---|
26 | fields = line.replace("\n","").split("=")
|
---|
27 | dict[fields[0]]="=".join(fields[1:])
|
---|
28 | if 'genome project id' in dict.keys():
|
---|
29 | name = dict['genome project id']
|
---|
30 | if 'build' in dict.keys():
|
---|
31 | name = dict['build']
|
---|
32 | if name not in organisms.keys():
|
---|
33 | organisms[name] = {'chrs':{},'base_dir':this_base_dir}
|
---|
34 | for key in dict.keys():
|
---|
35 | organisms[name][key]=dict[key]
|
---|
36 | else:
|
---|
37 | if dict['organism'] not in organisms.keys():
|
---|
38 | organisms[dict['organism']] = {'chrs':{},'base_dir':this_base_dir}
|
---|
39 | organisms[dict['organism']]['chrs'][dict['chromosome']]=dict
|
---|
40 | for org in organisms:
|
---|
41 | org = organisms[org]
|
---|
42 | #if no gpi, then must be a ncbi chr which corresponds to a UCSC org, w/o matching UCSC designation
|
---|
43 | try:
|
---|
44 | build = org['genome project id']
|
---|
45 | except: continue
|
---|
46 |
|
---|
47 | if 'build' in org:
|
---|
48 | build = org['build']
|
---|
49 |
|
---|
50 | chrs=[]
|
---|
51 | for chrom in org['chrs']:
|
---|
52 | chrom = org['chrs'][chrom]
|
---|
53 | chrs.append( "%s=%s" % ( chrom['chromosome'], chrom['length'] ) )
|
---|
54 | print "%s\t%s\t%s" % ( build, org['name'], ",".join( chrs ) )
|
---|
55 |
|
---|
56 | if __name__ == "__main__": __main__()
|
---|