[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.3 - (view) (download) (as text)

1 : olson 1.1 from FigKernelPackages.FIG2 import FIG
2 :     import FIG_Config
3 :     import re
4 :     import os, sys, string
5 : olson 1.2 import shutil
6 : olson 1.1
7 :     IN_DIR = "%s/SubsystemDiagrams/" % FIG_Config.data
8 :     OUT_DIR = "%s/MAP_SUPPORT/Maps/" % FIG_Config.data
9 :    
10 : olson 1.2 if not os.path.isdir(IN_DIR):
11 :     print "Creating ", IN_DIR
12 :     os.makedirs(IN_DIR)
13 :    
14 :     if not os.path.isdir(OUT_DIR):
15 :     print "Creating ", OUT_DIR
16 :     os.makedirs(OUT_DIR)
17 :    
18 : olson 1.1 def add_to_index(id, name):
19 :     line = "%s\t%s\n" % (id, name)
20 : olson 1.2 index_file = "%s/MAP_SUPPORT/INDEX" % FIG_Config.data
21 :    
22 :     if os.path.isfile(index_file):
23 :    
24 :     file = open(index_file, "r")
25 :     l = file.readlines()
26 :     file.close()
27 :     else:
28 :     l = []
29 :    
30 : olson 1.1 if line not in l:
31 :     l.append(line)
32 :     print "Adding ", line
33 : olson 1.2
34 :     file = open(index_file, "w")
35 : olson 1.1 file.writelines(l)
36 :     file.close()
37 :    
38 :    
39 :     def create_tables(dir):
40 :     # for each area in teh diagram,
41 :     #format a line in the role_coords tabel (role\tcoords)
42 :     #format a line in the link table (coord\tlink)
43 :     #write out the role_coords table in directory OUT_DIR+dir
44 :     #write out the link_table in directory OUT_DIR+dir
45 :     area_table = open("%s%s/area_table" % ( OUT_DIR, dir), "w")
46 :     area_table.write("Test")
47 :     area_table.close()
48 :    
49 :    
50 :     def make_maps(in_dir, dir):
51 :     print
52 :     sub = fig.get_subsystem(dir)
53 : olson 1.2 if sub is None:
54 :     return
55 :    
56 : olson 1.1 diags = sub.get_diagrams()
57 : olson 1.2 if diags is None:
58 :     return
59 : olson 1.1 for diagram in diags:
60 :     mapname = dir+"_"+diagram
61 :     if not os.path.isdir(OUT_DIR+mapname):
62 :     os.mkdir(OUT_DIR+mapname)
63 :     os.system("cp %s%s/%s/diagram.png %s%s/diagram.png" % (in_dir, dir, diagram, OUT_DIR, mapname))
64 :     dia = sub.get_diagram(diagram)[0]
65 :     areas = dia.get_areas()
66 :     roles = {}
67 :     coords = {}
68 :     link_coords={}
69 :     links = {}
70 : disz 1.3 compounds = {}
71 : olson 1.1 for aitem in areas:
72 :     area, tag, value = aitem
73 : olson 1.2 # print "area=%s tag=%s value=%s" % (area, tag, value)
74 : olson 1.1
75 :     if tag == "role":
76 :     roles[area] = value
77 : disz 1.3 if tag == "compound":
78 :     compounds[area] = value
79 : olson 1.1 if tag == "shape":
80 :     shape_kind, shape_coords = value.split(":", 1)
81 :    
82 :     if shape_kind == "rect":
83 :     x1,y1,x2,y2 = shape_coords.split(",");
84 :     cvalue = "rect (%s,%s) (%s,%s)" %(x1, y1, x2, y2)
85 : olson 1.2 link_coords[area] = "<AREA shape=rect coords=%s,%s,%s,%s " % (x1,y1,x2,y2)
86 :    
87 :     elif shape_kind == "circle":
88 :     x, y, r = shape_coords.split(",");
89 :     cvalue = "circ (%s,%s) %s" % (x, y, r)
90 :     link_coords[area] = "<AREA shape=circle coords=%s,%s,%s " % (x, y, r)
91 : olson 1.1 else:
92 :     print "Unknown shape kind ", shape_kind
93 :     cvalue = ""
94 :    
95 :     coords[area] = cvalue
96 :     if tag == "link":
97 :     m = re.search(r'^"([^"]+)",(.*)$', value)
98 :     if m:
99 :     value = m.group(2)
100 :     else:
101 :     print "Didn't match", value
102 :     links[area] = value
103 :    
104 :     link_table = open(OUT_DIR+mapname+"/link.table", "w")
105 :     role_coords = open(OUT_DIR+mapname+"/role_coords.table", "w")
106 :     for area in roles.keys():
107 :     role_coords.write(roles[area]+"\t"+coords[area]+"\n")
108 :     if links.has_key(area):
109 :     link_table.write('%s href="%s">\n' % (link_coords[area], links[area]))
110 : disz 1.3 for compound in compounds.keys():
111 :     #for link in links.keys():
112 :     #print "("+link+")", link_coords[compound], links[compound]
113 :     link_table.write('%s href="%s">\n' % (link_coords[compound], links[compound]))
114 : olson 1.1 role_coords.close()
115 :     link_table.close()
116 : olson 1.2
117 :     #
118 :     # mapstuff needs name_coords.table with the same contents as role_coords.table
119 :     #
120 :    
121 :     shutil.copyfile(OUT_DIR + mapname + "/role_coords.table",
122 :     OUT_DIR + mapname + "/name_coords.table")
123 :    
124 : olson 1.1 add_to_index(mapname, dir)
125 :    
126 :    
127 :    
128 :     fig = FIG()
129 :    
130 :     for dir in os.listdir(IN_DIR):
131 :     print dir
132 :     make_maps(IN_DIR, dir)
133 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3