[Bio] / FigKernelScripts / make_maps_from_sub.py Repository:
ViewVC logotype

Annotation of /FigKernelScripts/make_maps_from_sub.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (view) (download) (as text)

1 : olson 1.5 #
2 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
3 :     # for Interpretations of Genomes. All Rights Reserved.
4 :     #
5 :     # This file is part of the SEED Toolkit.
6 :     #
7 :     # The SEED Toolkit is free software. You can redistribute
8 :     # it and/or modify it under the terms of the SEED Toolkit
9 :     # Public License.
10 :     #
11 :     # You should have received a copy of the SEED Toolkit Public License
12 :     # along with this program; if not write to the University of Chicago
13 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
14 :     # Genomes at veronika@thefig.info or download a copy from
15 :     # http://www.theseed.org/LICENSE.TXT.
16 :     #
17 :    
18 : olson 1.1 from FigKernelPackages.FIG2 import FIG
19 :     import FIG_Config
20 :     import re
21 :     import os, sys, string
22 : olson 1.2 import shutil
23 : olson 1.1
24 :     IN_DIR = "%s/SubsystemDiagrams/" % FIG_Config.data
25 :     OUT_DIR = "%s/MAP_SUPPORT/Maps/" % FIG_Config.data
26 :    
27 : olson 1.2 if not os.path.isdir(IN_DIR):
28 :     print "Creating ", IN_DIR
29 :     os.makedirs(IN_DIR)
30 :    
31 :     if not os.path.isdir(OUT_DIR):
32 :     print "Creating ", OUT_DIR
33 :     os.makedirs(OUT_DIR)
34 :    
35 : olson 1.1 def add_to_index(id, name):
36 :     line = "%s\t%s\n" % (id, name)
37 : olson 1.2 index_file = "%s/MAP_SUPPORT/INDEX" % FIG_Config.data
38 :    
39 :     if os.path.isfile(index_file):
40 :    
41 :     file = open(index_file, "r")
42 :     l = file.readlines()
43 :     file.close()
44 :     else:
45 :     l = []
46 :    
47 : olson 1.1 if line not in l:
48 :     l.append(line)
49 :     print "Adding ", line
50 : olson 1.2
51 :     file = open(index_file, "w")
52 : olson 1.1 file.writelines(l)
53 :     file.close()
54 :    
55 :    
56 :     def create_tables(dir):
57 :     # for each area in teh diagram,
58 :     #format a line in the role_coords tabel (role\tcoords)
59 :     #format a line in the link table (coord\tlink)
60 :     #write out the role_coords table in directory OUT_DIR+dir
61 :     #write out the link_table in directory OUT_DIR+dir
62 :     area_table = open("%s%s/area_table" % ( OUT_DIR, dir), "w")
63 :     area_table.write("Test")
64 :     area_table.close()
65 :    
66 :    
67 :     def make_maps(in_dir, dir):
68 :     print
69 :     sub = fig.get_subsystem(dir)
70 : olson 1.2 if sub is None:
71 :     return
72 :    
73 : olson 1.1 diags = sub.get_diagrams()
74 : olson 1.2 if diags is None:
75 :     return
76 : olson 1.1 for diagram in diags:
77 :     mapname = dir+"_"+diagram
78 :     if not os.path.isdir(OUT_DIR+mapname):
79 :     os.mkdir(OUT_DIR+mapname)
80 :     os.system("cp %s%s/%s/diagram.png %s%s/diagram.png" % (in_dir, dir, diagram, OUT_DIR, mapname))
81 :     dia = sub.get_diagram(diagram)[0]
82 :     areas = dia.get_areas()
83 :     roles = {}
84 :     coords = {}
85 :     link_coords={}
86 :     links = {}
87 : disz 1.3 compounds = {}
88 : olson 1.1 for aitem in areas:
89 :     area, tag, value = aitem
90 : olson 1.2 # print "area=%s tag=%s value=%s" % (area, tag, value)
91 : olson 1.1
92 :     if tag == "role":
93 :     roles[area] = value
94 : disz 1.3 if tag == "compound":
95 :     compounds[area] = value
96 : olson 1.1 if tag == "shape":
97 :     shape_kind, shape_coords = value.split(":", 1)
98 :    
99 :     if shape_kind == "rect":
100 :     x1,y1,x2,y2 = shape_coords.split(",");
101 :     cvalue = "rect (%s,%s) (%s,%s)" %(x1, y1, x2, y2)
102 : olson 1.2 link_coords[area] = "<AREA shape=rect coords=%s,%s,%s,%s " % (x1,y1,x2,y2)
103 :    
104 :     elif shape_kind == "circle":
105 :     x, y, r = shape_coords.split(",");
106 :     cvalue = "circ (%s,%s) %s" % (x, y, r)
107 :     link_coords[area] = "<AREA shape=circle coords=%s,%s,%s " % (x, y, r)
108 : olson 1.1 else:
109 :     print "Unknown shape kind ", shape_kind
110 :     cvalue = ""
111 :    
112 :     coords[area] = cvalue
113 :     if tag == "link":
114 :     m = re.search(r'^"([^"]+)",(.*)$', value)
115 :     if m:
116 :     value = m.group(2)
117 :     else:
118 :     print "Didn't match", value
119 :     links[area] = value
120 :    
121 :     link_table = open(OUT_DIR+mapname+"/link.table", "w")
122 :     role_coords = open(OUT_DIR+mapname+"/role_coords.table", "w")
123 :     for area in roles.keys():
124 :     role_coords.write(roles[area]+"\t"+coords[area]+"\n")
125 :     if links.has_key(area):
126 :     link_table.write('%s href="%s">\n' % (link_coords[area], links[area]))
127 : disz 1.3 for compound in compounds.keys():
128 :     #for link in links.keys():
129 :     #print "("+link+")", link_coords[compound], links[compound]
130 : olson 1.4 if links.has_key(compound):
131 :     link_table.write('%s href="%s">\n' % (link_coords[compound], links[compound]))
132 : olson 1.1 role_coords.close()
133 :     link_table.close()
134 : olson 1.2
135 :     #
136 :     # mapstuff needs name_coords.table with the same contents as role_coords.table
137 :     #
138 :    
139 :     shutil.copyfile(OUT_DIR + mapname + "/role_coords.table",
140 :     OUT_DIR + mapname + "/name_coords.table")
141 :    
142 : olson 1.1 add_to_index(mapname, dir)
143 :    
144 :    
145 :    
146 :     fig = FIG()
147 :    
148 :     for dir in os.listdir(IN_DIR):
149 :     print dir
150 :     make_maps(IN_DIR, dir)
151 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3